7#include <unordered_map>
8#include <unordered_set>
13#ifdef ENABLE_SCRIPTING
23#ifdef ENABLE_SCRIPTING
53 explicit ArchiveManager(std::shared_ptr<ResourceManager> resourceManager =
nullptr,
54 std::shared_ptr<Keystore> keystore =
nullptr);
60 void Init(
const std::vector<std::string>& archivePaths);
67 void Init(
const std::vector<std::string>& archivePaths,
const std::unordered_set<uint32_t>& validGameVersions);
75 std::shared_ptr<Archive>
AddArchive(
const std::string& archivePath);
82 std::shared_ptr<Archive>
AddArchive(std::shared_ptr<Archive> archive);
85 std::shared_ptr<std::vector<std::shared_ptr<Archive>>>
GetArchives();
91 void SetArchives(std::shared_ptr<std::vector<std::shared_ptr<Archive>>> archives);
112 std::shared_ptr<File>
LoadFile(
const std::string& filePath);
128 bool WriteFile(std::shared_ptr<Archive> archive,
const std::string& filename,
const std::vector<uint8_t>& data);
156 std::shared_ptr<std::vector<std::string>>
ListFiles(
const std::string& searchMask =
"");
164 std::shared_ptr<std::vector<std::string>>
ListFiles(
const std::list<std::string>& includes,
165 const std::list<std::string>& excludes);
172 std::shared_ptr<std::vector<std::string>>
ListDirectories(
const std::string& searchMask =
"");
200#ifdef ENABLE_SCRIPTING
226 std::vector<std::shared_ptr<Archive>> mArchives;
227 std::vector<uint32_t> mGameVersions;
228 std::unordered_set<uint32_t> mValidGameVersions;
229 std::unordered_map<uint64_t, std::string> mHashes;
230 std::unordered_set<std::string> mDirectories;
231 std::unordered_map<uint64_t, std::shared_ptr<Archive>> mFileToArchive;
232 std::shared_ptr<ResourceManager> mResourceManager;
233 std::shared_ptr<Keystore> mKeystore;
234#ifdef ENABLE_SCRIPTING
Manages a prioritised collection of mounted Archive objects.
Definition ArchiveManager.h:51
std::shared_ptr< Archive > AddArchive(std::shared_ptr< Archive > archive)
Adds a pre-constructed Archive object to the managed collection.
bool HasFile(const std::string &filePath)
Checks whether any mounted archive contains a file at the given path.
std::shared_ptr< std::vector< std::string > > ListFiles(const std::string &searchMask="")
Lists virtual paths of all files matching the given search mask across all archives.
UntrustedArchiveHandler GetUntrustedArchiveHandler() const
Returns the current untrusted-archive handler.
std::shared_ptr< std::vector< std::shared_ptr< Archive > > > GetArchives()
Returns all currently mounted archives in priority order (last = highest priority).
bool HasFile(uint64_t hash)
Checks whether any mounted archive contains a file with the given hash.
void SetUntrustedArchiveHandler(const UntrustedArchiveHandler &handler)
Sets the callback invoked when an untrusted (unsigned/unknown-key) archive is added.
std::shared_ptr< File > LoadFile(uint64_t hash)
Loads raw file bytes by 64-bit hash from the highest-priority matching archive.
static std::vector< std::string > GetArchiveListInPaths(const std::vector< std::string > &archivePaths)
Scans the given filesystem paths and returns a flat list of archive file paths.
const std::string * HashToString(uint64_t hash) const
Looks up the virtual path string for a given 64-bit hash.
void Init(const std::vector< std::string > &archivePaths, const std::unordered_set< uint32_t > &validGameVersions)
Discovers and mounts archives, filtering by acceptable game versions.
bool WriteFile(std::shared_ptr< Archive > archive, const std::string &filename, const std::vector< uint8_t > &data)
Writes raw data into a specific archive.
void AddGameVersion(uint32_t newGameVersion)
Adds a game-version value to the internal version set.
void Init(const std::vector< std::string > &archivePaths)
Discovers and mounts all archives found under the given paths.
std::shared_ptr< std::vector< std::string > > ListDirectories(const std::string &searchMask="")
Lists virtual directory paths matching the given search mask across all archives.
size_t RemoveArchive(std::shared_ptr< Archive > archive)
Removes a specific archive from the managed collection.
std::shared_ptr< Archive > AddArchive(const std::string &archivePath)
Opens and adds an archive by filesystem path.
size_t RemoveArchive(const std::string &path)
Removes the archive at the given filesystem path.
std::shared_ptr< Archive > GetArchiveFromFile(const std::string &filePath)
Returns the highest-priority archive that contains the given file.
const char * HashToCString(uint64_t hash) const
Looks up the virtual path C-string for a given 64-bit hash.
void SetArchives(std::shared_ptr< std::vector< std::shared_ptr< Archive > > > archives)
Replaces the entire archive list with a new collection.
std::vector< uint32_t > GetGameVersions()
Returns the union of all game-version values found across mounted archives.
std::shared_ptr< File > LoadFile(const std::string &filePath)
Loads raw file bytes from the highest-priority archive that contains the path.
void ResetVirtualFileSystem()
Rebuilds the hash-to-path and path-to-archive lookup tables from the current archive list.
ArchiveManager(std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
std::shared_ptr< std::vector< std::string > > ListFiles(const std::list< std::string > &includes, const std::list< std::string > &excludes)
Lists virtual paths matching include/exclude glob masks across all archives.
bool IsGameVersionValid(uint32_t gameVersion)
Returns true if the given game version is in the set of valid versions.
Abstract base class representing a mounted archive (OTR, O2R, or folder).
Definition Archive.h:61
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
std::function< bool(Archive &archive, KeystoreEntry &key)> UntrustedArchiveHandler
Callback invoked when an archive without a trusted key is added.
Definition ArchiveManager.h:30
A single named key stored in the Keystore.
Definition Keystore.h:24