2012-07-22 18:02:13 +03:00
|
|
|
/*
|
2013-07-28 17:49:50 +03:00
|
|
|
* CArchiveLoader.h, part of VCMI engine
|
2012-07-22 18:02:13 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
#include "ISimpleResourceLoader.h"
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "ResourcePath.h"
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2012-07-22 18:02:13 +03:00
|
|
|
class CFileInputStream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A struct which holds information about the archive entry e.g. where it is located in space of the archive container.
|
|
|
|
*/
|
|
|
|
struct ArchiveEntry
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Default c-tor.
|
|
|
|
*/
|
|
|
|
ArchiveEntry();
|
|
|
|
|
|
|
|
/** Entry name **/
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
/** Distance in bytes from beginning **/
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
/** Size without compression in bytes **/
|
2013-07-28 17:49:50 +03:00
|
|
|
int fullSize;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
/** Size with compression in bytes or 0 if not compressed **/
|
2013-07-28 17:49:50 +03:00
|
|
|
int compressedSize;
|
2012-07-22 18:02:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class which can scan and load files of a LOD archive.
|
|
|
|
*/
|
2013-07-28 17:49:50 +03:00
|
|
|
class DLL_LINKAGE CArchiveLoader : public ISimpleResourceLoader
|
2012-07-22 18:02:13 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Ctor.
|
|
|
|
*
|
|
|
|
* The file extension of the param archive determines the type of the Lod file.
|
|
|
|
* These are valid extensions: .LOD, .SND, .VID
|
|
|
|
*
|
|
|
|
* @param archive Specifies the file path to the archive which should be indexed and loaded.
|
2022-11-20 18:48:31 +02:00
|
|
|
* @param extractArchives Specifies if the original H3 archives should be extracted to a separate folder.
|
2012-07-22 18:02:13 +03:00
|
|
|
*
|
|
|
|
* @throws std::runtime_error if the archive wasn't found or if the archive isn't supported
|
|
|
|
*/
|
2023-07-28 14:51:14 +02:00
|
|
|
CArchiveLoader(std::string mountPoint, boost::filesystem::path archive, bool extractArchives = false);
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2013-05-04 16:14:23 +03:00
|
|
|
/// Interface implementation
|
|
|
|
/// @see ISimpleResourceLoader
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unique_ptr<CInputStream> load(const ResourcePath & resourceName) const override;
|
|
|
|
bool existsResource(const ResourcePath & resourceName) const override;
|
2013-07-28 17:49:50 +03:00
|
|
|
std::string getMountPoint() const override;
|
2024-09-01 12:23:10 +02:00
|
|
|
const std::unordered_map<ResourcePath, ArchiveEntry> & getEntries() const;
|
2016-10-16 22:09:57 +02:00
|
|
|
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_set<ResourcePath> getFilteredFiles(std::function<bool(const ResourcePath &)> filter) const override;
|
2022-11-08 23:39:56 +02:00
|
|
|
/** Extracts one archive entry to the specified subfolder. Used for Video and Sound */
|
2024-08-31 00:44:20 +02:00
|
|
|
void extractToFolder(const std::string & outputSubFolder, CInputStream & fileStream, const ArchiveEntry & entry, bool absolute = false) const;
|
2022-11-08 23:39:56 +02:00
|
|
|
/** Extracts one archive entry to the specified subfolder. Used for Images, Sprites, etc */
|
2024-08-31 00:44:20 +02:00
|
|
|
void extractToFolder(const std::string & outputSubFolder, const std::string & mountPoint, ArchiveEntry entry, bool absolute = false) const;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2013-05-04 16:14:23 +03:00
|
|
|
private:
|
2012-07-22 18:02:13 +03:00
|
|
|
/**
|
|
|
|
* Initializes a LOD archive.
|
|
|
|
*
|
|
|
|
* @param fileStream File stream to the .lod archive
|
|
|
|
*/
|
2013-07-28 17:49:50 +03:00
|
|
|
void initLODArchive(const std::string &mountPoint, CFileInputStream & fileStream);
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a VID archive.
|
|
|
|
*
|
|
|
|
* @param fileStream File stream to the .vid archive
|
|
|
|
*/
|
2013-07-28 17:49:50 +03:00
|
|
|
void initVIDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a SND archive.
|
|
|
|
*
|
|
|
|
* @param fileStream File stream to the .snd archive
|
|
|
|
*/
|
2013-07-28 17:49:50 +03:00
|
|
|
void initSNDArchive(const std::string &mountPoint, CFileInputStream & fileStream);
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
/** The file path to the archive which is scanned and indexed. */
|
2023-07-28 14:51:14 +02:00
|
|
|
boost::filesystem::path archive;
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
std::string mountPoint;
|
|
|
|
|
2012-07-22 18:02:13 +03:00
|
|
|
/** Holds all entries of the archive file. An entry can be accessed via the entry name. **/
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_map<ResourcePath, ArchiveEntry> entries;
|
2022-11-20 18:48:31 +02:00
|
|
|
|
|
|
|
/** Specifies if Original H3 archives should be extracted to a separate folder **/
|
|
|
|
bool extractArchives;
|
2012-07-22 18:02:13 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2022-11-08 23:39:56 +02:00
|
|
|
/** Constructs the file path for the extracted file. Creates the subfolder hierarchy aswell **/
|
2024-08-31 00:44:20 +02:00
|
|
|
boost::filesystem::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName, bool absolute);
|
2022-11-08 23:39:56 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|