CArchiveLoader.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. /*
  3. * CArchiveLoader.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  11. #include "ISimpleResourceLoader.h"
  12. #include "ResourceID.h"
  13. class CFileInfo;
  14. class CFileInputStream;
  15. /**
  16. * A struct which holds information about the archive entry e.g. where it is located in space of the archive container.
  17. */
  18. struct ArchiveEntry
  19. {
  20. /**
  21. * Default c-tor.
  22. */
  23. ArchiveEntry();
  24. /** Entry name **/
  25. std::string name;
  26. /** Distance in bytes from beginning **/
  27. int offset;
  28. /** Size without compression in bytes **/
  29. int fullSize;
  30. /** Size with compression in bytes or 0 if not compressed **/
  31. int compressedSize;
  32. };
  33. /**
  34. * A class which can scan and load files of a LOD archive.
  35. */
  36. class DLL_LINKAGE CArchiveLoader : public ISimpleResourceLoader
  37. {
  38. public:
  39. /**
  40. * Ctor.
  41. *
  42. * The file extension of the param archive determines the type of the Lod file.
  43. * These are valid extensions: .LOD, .SND, .VID
  44. *
  45. * @param archive Specifies the file path to the archive which should be indexed and loaded.
  46. *
  47. * @throws std::runtime_error if the archive wasn't found or if the archive isn't supported
  48. */
  49. CArchiveLoader(std::string mountPoint, boost::filesystem::path archive);
  50. /// Interface implementation
  51. /// @see ISimpleResourceLoader
  52. std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
  53. bool existsResource(const ResourceID & resourceName) const override;
  54. std::string getMountPoint() const override;
  55. std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
  56. private:
  57. /**
  58. * Initializes a LOD archive.
  59. *
  60. * @param fileStream File stream to the .lod archive
  61. */
  62. void initLODArchive(const std::string &mountPoint, CFileInputStream & fileStream);
  63. /**
  64. * Initializes a VID archive.
  65. *
  66. * @param fileStream File stream to the .vid archive
  67. */
  68. void initVIDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
  69. /**
  70. * Initializes a SND archive.
  71. *
  72. * @param fileStream File stream to the .snd archive
  73. */
  74. void initSNDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
  75. /** The file path to the archive which is scanned and indexed. */
  76. boost::filesystem::path archive;
  77. std::string mountPoint;
  78. /** Holds all entries of the archive file. An entry can be accessed via the entry name. **/
  79. std::unordered_map<ResourceID, ArchiveEntry> entries;
  80. };