wildcharsenum.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // NONPORTABLE NONPORTABLE NONPORTABLE
  2. #include "precomp_wasabi_bfc.h"
  3. #ifdef WIN32
  4. #include <windows.h>
  5. #endif
  6. #include "wildcharsenum.h"
  7. #include <bfc/parse/pathparse.h>
  8. #include <bfc/parse/paramparser.h>
  9. #include <bfc/file/readdir.h>
  10. WildcharsEnumerator::WildcharsEnumerator(const wchar_t *_selection) : selection(_selection)
  11. {
  12. // Then scan.
  13. rescan();
  14. }
  15. WildcharsEnumerator::~WildcharsEnumerator() {
  16. finddatalist.deleteAll();
  17. }
  18. int WildcharsEnumerator::getNumFiles()
  19. {
  20. return finddatalist.getNumItems();
  21. }
  22. const wchar_t *WildcharsEnumerator::enumFile(int n) {
  23. StringW path = finddatalist.enumItem(n)->path;
  24. if (!path.isempty())
  25. {
  26. enumFileString = StringPathCombine(path.getValue(), finddatalist.enumItem(n)->filename.getValue());
  27. return enumFileString;
  28. }
  29. return finddatalist.enumItem(n)->filename;
  30. }
  31. void WildcharsEnumerator::rescan()
  32. {
  33. finddatalist.removeAll();
  34. ParamParser pp(selection, L";");
  35. for (int is = 0; is < pp.getNumItems(); is++)
  36. {
  37. StringW _selection = pp.enumItem(is);
  38. PathParserW parse(_selection);
  39. StringW path = L"";
  40. StringW mask = L"";
  41. for (int i=0;i<parse.getNumStrings()-1;i++)
  42. path.AppendFolder(parse.enumString(i));
  43. mask = parse.getLastString();
  44. // enum files and store a list
  45. ReadDir rd(path, mask, true);
  46. while (rd.next()) {
  47. finddatalist.addItem(new find_entry(rd.getPath(), rd.getFilename()));
  48. }
  49. }
  50. }
  51. int WildcharsEnumerator::isWildchars(const wchar_t *filename)
  52. {
  53. return (wcschr(filename, '*') || wcschr(filename, '?'));
  54. }