recursedir.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "precomp_wasabi_bfc.h"
  2. #include "recursedir.h"
  3. RecurseDir::RecurseDir( const wchar_t *_path, const wchar_t *_match ) :
  4. path( _path ), match( _match )
  5. {
  6. if ( match.isempty() ) match = Wasabi::Std::matchAllFiles();
  7. curdir = new ReadDir( path, match );
  8. }
  9. RecurseDir::~RecurseDir()
  10. {
  11. dirstack.deleteAll();
  12. }
  13. int RecurseDir::next()
  14. {
  15. for ( ;;)
  16. {
  17. if ( curdir == NULL )
  18. { // pop one off the stack
  19. curdir = dirstack.getLast();
  20. if ( curdir == NULL ) return 0; // done
  21. dirstack.removeLastItem();
  22. }
  23. int r = curdir->next();
  24. if ( r <= 0 )
  25. {
  26. delete curdir; curdir = NULL;
  27. continue; // get another one
  28. }
  29. // ok, we have a file to look at
  30. if ( curdir->isDir() )
  31. { // descend into it
  32. StringW newpath = curdir->getPath();
  33. newpath.AppendPath( curdir->getFilename() );
  34. dirstack.addItem( curdir ); // push the old one
  35. curdir = new ReadDir( newpath, match ); // start new one
  36. continue;
  37. }
  38. return r;
  39. }
  40. }
  41. const wchar_t *RecurseDir::getPath()
  42. {
  43. if ( curdir == NULL )
  44. return NULL;
  45. return curdir->getPath();
  46. }
  47. const wchar_t *RecurseDir::getFilename()
  48. {
  49. if ( curdir == NULL )
  50. return NULL;
  51. return curdir->getFilename();
  52. }
  53. const wchar_t *RecurseDir::getOriginalPath()
  54. {
  55. return path;
  56. }