CArchiveLoader.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 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. std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
  55. private:
  56. /**
  57. * Initializes a LOD archive.
  58. *
  59. * @param fileStream File stream to the .lod archive
  60. */
  61. void initLODArchive(const std::string &mountPoint, CFileInputStream & fileStream);
  62. /**
  63. * Initializes a VID archive.
  64. *
  65. * @param fileStream File stream to the .vid archive
  66. */
  67. void initVIDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
  68. /**
  69. * Initializes a SND archive.
  70. *
  71. * @param fileStream File stream to the .snd archive
  72. */
  73. void initSNDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
  74. /** The file path to the archive which is scanned and indexed. */
  75. boost::filesystem::path archive;
  76. std::string mountPoint;
  77. /** Holds all entries of the archive file. An entry can be accessed via the entry name. **/
  78. std::unordered_map<ResourceID, ArchiveEntry> entries;
  79. };