CLodArchiveLoader.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /// Interface implementation
  50. /// @see ISimpleResourceLoader
  51. std::unique_ptr<CInputStream> load(const std::string & resourceName) const override;
  52. boost::unordered_map<ResourceID, std::string> getEntries() const override;
  53. bool existsEntry(const std::string & resourceName) const override;
  54. std::string getOrigin() const override;
  55. private:
  56. const ArchiveEntry * getArchiveEntry(const std::string & resourceName) const;
  57. /**
  58. * Initializes a LOD archive.
  59. *
  60. * @param fileStream File stream to the .lod archive
  61. */
  62. void initLODArchive(CFileInputStream & fileStream);
  63. /**
  64. * Initializes a VID archive.
  65. *
  66. * @param fileStream File stream to the .vid archive
  67. */
  68. void initVIDArchive(CFileInputStream & fileStream);
  69. /**
  70. * Initializes a SND archive.
  71. *
  72. * @param fileStream File stream to the .snd archive
  73. */
  74. void initSNDArchive(CFileInputStream & fileStream);
  75. /** The file path to the archive which is scanned and indexed. */
  76. std::string archive;
  77. /** Holds all entries of the archive file. An entry can be accessed via the entry name. **/
  78. boost::unordered_map<std::string, ArchiveEntry> entries;
  79. };