CLodArchiveLoader.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * CLodArchiveLoader.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 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 realSize;
  29. /** Size with compression in bytes or 0 if not compressed **/
  30. int size;
  31. };
  32. /**
  33. * A class which can scan and load files of a LOD archive.
  34. */
  35. class DLL_LINKAGE CLodArchiveLoader : 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. explicit CLodArchiveLoader(const std::string & archive);
  49. /**
  50. * Loads a resource with the given resource name.
  51. *
  52. * @param resourceName The unqiue resource name in space of the archive.
  53. * @return a input stream object, not null.
  54. *
  55. * @throws std::runtime_error if the archive entry wasn't found
  56. */
  57. std::unique_ptr<CInputStream> load(const std::string & resourceName) const;
  58. /**
  59. * Gets all entries in the archive.
  60. *
  61. * @return a list of all entries in the archive.
  62. */
  63. boost::unordered_map<ResourceID, std::string> getEntries() const;
  64. /**
  65. * Gets the archive entry for the requested resource
  66. *
  67. * @param resourceName The unqiue resource name in space of the archive.
  68. * @return the archive entry for the requested resource or a null ptr if the archive wasn't found
  69. */
  70. const ArchiveEntry * getArchiveEntry(const std::string & resourceName) const;
  71. /**
  72. * Checks if the archive entry exists.
  73. *
  74. * @return true if the entry exists, false if not.
  75. */
  76. bool existsEntry(const std::string & resourceName) const;
  77. /**
  78. * Gets the origin of the archive loader.
  79. *
  80. * @return the file path to the archive which is scanned and indexed.
  81. */
  82. std::string getOrigin() const;
  83. private:
  84. /**
  85. * Initializes a LOD archive.
  86. *
  87. * @param fileStream File stream to the .lod archive
  88. */
  89. void initLODArchive(CFileInputStream & fileStream);
  90. /**
  91. * Initializes a VID archive.
  92. *
  93. * @param fileStream File stream to the .vid archive
  94. */
  95. void initVIDArchive(CFileInputStream & fileStream);
  96. /**
  97. * Initializes a SND archive.
  98. *
  99. * @param fileStream File stream to the .snd archive
  100. */
  101. void initSNDArchive(CFileInputStream & fileStream);
  102. /** The file path to the archive which is scanned and indexed. */
  103. std::string archive;
  104. /** Holds all entries of the archive file. An entry can be accessed via the entry name. **/
  105. boost::unordered_map<std::string, ArchiveEntry> entries;
  106. };