CFilesystemLoader.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * CFilesystemLoader.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "ISimpleResourceLoader.h"
  12. class CFileInfo;
  13. class CInputStream;
  14. /**
  15. * A class which can scan and load files of directories.
  16. */
  17. class DLL_LINKAGE CFilesystemLoader : public ISimpleResourceLoader
  18. {
  19. public:
  20. /**
  21. * Default c-tor.
  22. */
  23. CFilesystemLoader();
  24. /**
  25. * Ctor.
  26. *
  27. * @param baseDirectory Specifies the base directory and their sub-directories which should be indexed.
  28. *
  29. * @throws std::runtime_error if the base directory is not a directory or if it is not available
  30. */
  31. explicit CFilesystemLoader(const std::string & baseDirectory);
  32. /**
  33. * Ctor.
  34. *
  35. * @param baseDirectory Specifies the base directory and their sub-directories which should be indexed.
  36. *
  37. * @throws std::runtime_error if the base directory is not a directory or if it is not available
  38. */
  39. explicit CFilesystemLoader(const CFileInfo & baseDirectory);
  40. /**
  41. * Opens a base directory to be read and indexed.
  42. *
  43. * @param baseDirectory Specifies the base directory and their sub-directories which should be indexed.
  44. *
  45. * @throws std::runtime_error if the base directory is not a directory or if it is not available
  46. */
  47. void open(const std::string & baseDirectory);
  48. /**
  49. * Opens a base directory to be read and indexed.
  50. *
  51. * @param baseDirectory Specifies the base directory and their sub-directories which should be indexed.
  52. *
  53. * @throws std::runtime_error if the base directory is not a directory or if it is not available
  54. */
  55. void open(const CFileInfo & baseDirectory);
  56. /**
  57. * Loads a resource with the given resource name.
  58. *
  59. * @param resourceName The unqiue resource name in space of the filesystem.
  60. * @return a input stream object, not null
  61. */
  62. std::unique_ptr<CInputStream> load(const std::string & resourceName) const;
  63. /**
  64. * Checks if the file entry exists.
  65. *
  66. * @return true if the entry exists, false if not.
  67. */
  68. bool existsEntry(const std::string & resourceName) const;
  69. /**
  70. * Gets all entries in the filesystem.
  71. *
  72. * @return a list of all entries in the filesystem.
  73. */
  74. std::list<std::string> getEntries() const;
  75. private:
  76. /** The base directory which is scanned and indexed. */
  77. std::string baseDirectory;
  78. /** A list of files in the directory */
  79. std::list<CFileInfo> fileList;
  80. };