2013-07-28 17:49:50 +03:00
|
|
|
#pragma once
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ISimpleResourceLoader.h"
|
2013-07-28 17:49:50 +03:00
|
|
|
#include "Filesystem.h"
|
2012-07-22 18:02:13 +03:00
|
|
|
|
|
|
|
class CFileInfo;
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @throws std::runtime_error if the archive wasn't found or if the archive isn't supported
|
|
|
|
*/
|
2013-07-28 17:49:50 +03:00
|
|
|
explicit CArchiveLoader(const std::string & mountPoint, const std::string & archive);
|
2012-07-22 18:02:13 +03:00
|
|
|
|
2013-05-04 16:14:23 +03:00
|
|
|
/// Interface implementation
|
|
|
|
/// @see ISimpleResourceLoader
|
2013-07-28 17:49:50 +03:00
|
|
|
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
|
|
|
|
bool existsResource(const ResourceID & resourceName) const override;
|
|
|
|
std::string getMountPoint() const override;
|
|
|
|
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) 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. */
|
|
|
|
std::string archive;
|
|
|
|
|
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. **/
|
2013-07-28 17:49:50 +03:00
|
|
|
std::unordered_map<ResourceID, ArchiveEntry> entries;
|
2012-07-22 18:02:13 +03:00
|
|
|
};
|