CArchiveLoader.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * CArchiveLoader.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. #include "ResourceID.h"
  13. class CFileInputStream;
  14. /**
  15. * A struct which holds information about the archive entry e.g. where it is located in space of the archive container.
  16. */
  17. struct ArchiveEntry
  18. {
  19. /**
  20. * Default c-tor.
  21. */
  22. ArchiveEntry();
  23. /** Entry name **/
  24. std::string name;
  25. /** Distance in bytes from beginning **/
  26. int offset;
  27. /** Size without compression in bytes **/
  28. int fullSize;
  29. /** Size with compression in bytes or 0 if not compressed **/
  30. int compressedSize;
  31. };
  32. /**
  33. * A class which can scan and load files of a LOD archive.
  34. */
  35. class DLL_LINKAGE CArchiveLoader : public ISimpleResourceLoader
  36. {
  37. public:
  38. /**
  39. * Ctor.
  40. *
  41. * The file extension of the param archive determines the type of the Lod file.
  42. * These are valid extensions: .LOD, .SND, .VID
  43. *
  44. * @param archive Specifies the file path to the archive which should be indexed and loaded.
  45. *
  46. * @throws std::runtime_error if the archive wasn't found or if the archive isn't supported
  47. */
  48. CArchiveLoader(std::string mountPoint, boost::filesystem::path archive);
  49. /// Interface implementation
  50. /// @see ISimpleResourceLoader
  51. std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
  52. bool existsResource(const ResourceID & resourceName) const override;
  53. std::string getMountPoint() const override;
  54. void updateFilteredFiles(std::function<bool(const std::string &)> filter) 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. };