libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Archive.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <string>
5#include <unordered_map>
6#include <mutex>
8
9namespace tinyxml2 {
10class XMLDocument;
11class XMLElement;
12} // namespace tinyxml2
13
14namespace Ship {
15class Keystore;
17#define OTR_HEADER_SIZE ((size_t)64)
18
19struct File;
20struct ResourceInitData;
21class ResourceManager;
22
31 std::string Name;
32 std::string Icon;
33 std::string Author;
34 std::string Version;
35 std::string Website;
36 std::string Description;
37 std::string License;
38
39 uint32_t CodeVersion;
40 uint32_t GameVersion;
41
42 std::string Main;
43 std::unordered_map<std::string, std::string> Binaries;
44 std::vector<std::string> Dependencies;
45
46 std::string Checksum;
47 std::string Signature;
48 std::string PublicKey;
49};
50
61class Archive : public std::enable_shared_from_this<Archive> {
62 friend class ArchiveManager;
63
64 public:
69 Archive(const std::string& path, std::shared_ptr<ResourceManager> resourceManager = nullptr,
70 std::shared_ptr<Keystore> keystore = nullptr);
72
74 bool operator==(const Archive& rhs) const;
75
81 void Load();
82
88 void Unload();
89
95 virtual std::shared_ptr<File> LoadFile(const std::string& filePath) = 0;
96
102 virtual std::shared_ptr<File> LoadFile(uint64_t hash) = 0;
103
108 std::shared_ptr<std::unordered_map<uint64_t, std::string>> ListFiles();
109
115 std::shared_ptr<std::unordered_map<uint64_t, std::string>> ListFiles(const std::string& filter);
116
122 bool HasFile(const std::string& filePath);
123
129 bool HasFile(uint64_t hash);
130
135
140 uint32_t GetGameVersion();
141
144
148 bool IsSigned();
149
154
156 const std::string& GetPath();
157
160
165 virtual bool Open() = 0;
166
171 virtual bool Close() = 0;
172
179 virtual bool WriteFile(const std::string& filename, const std::vector<uint8_t>& data) = 0;
180
181 protected:
183 void SetInitialized(bool isInitialized);
185 void SetGameVersion(uint32_t gameVersion);
190 void IndexFile(const std::string& filePath);
192 void Validate();
193
194 std::shared_ptr<ResourceManager> mResourceManager;
195 std::shared_ptr<Keystore> mKeystore;
196
197 private:
198 bool mIsInitialized;
199 bool mIsSigned;
200 bool mIsChecksumValid;
201 bool mHasGameVersion;
202 uint32_t mGameVersion;
203 ArchiveManifest mManifest;
204 std::string mPath;
205 std::shared_ptr<std::unordered_map<uint64_t, std::string>> mHashes;
206};
207} // namespace Ship
Manages a prioritised collection of mounted Archive objects.
Definition ArchiveManager.h:51
Abstract base class representing a mounted archive (OTR, O2R, or folder).
Definition Archive.h:61
const std::string & GetPath()
Returns the filesystem path this archive was opened from.
uint32_t GetGameVersion()
Returns the game version encoded in the archive manifest.
bool IsChecksumValid()
Returns true if the archive's checksum field matches the computed checksum.
std::shared_ptr< ResourceManager > mResourceManager
Definition Archive.h:194
const ArchiveManifest & GetManifest()
Returns the parsed archive manifest.
bool IsSigned()
Returns true if the archive carries a digital signature in its manifest.
bool operator==(const Archive &rhs) const
Two archives are equal when they refer to the same underlying path.
bool HasFile(uint64_t hash)
Checks whether the archive contains a file with the given hash.
bool HasGameVersion()
Returns true if a game version value was found in the manifest.
void SetGameVersion(uint32_t gameVersion)
Stores the game version parsed from the manifest.
void SetInitialized(bool isInitialized)
Sets the initialized state flag. Called by Load() / Unload().
bool HasFile(const std::string &filePath)
Checks whether the archive contains a file at the given path.
std::shared_ptr< std::unordered_map< uint64_t, std::string > > ListFiles(const std::string &filter)
Returns only the files whose paths match the given filter string.
virtual std::shared_ptr< File > LoadFile(const std::string &filePath)=0
Loads a file by its virtual path.
std::shared_ptr< std::unordered_map< uint64_t, std::string > > ListFiles()
Returns a map of all files indexed in this archive (hash → path).
Archive(const std::string &path, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
Constructs an Archive for the given filesystem path.
virtual std::shared_ptr< File > LoadFile(uint64_t hash)=0
Loads a file by its 64-bit content hash.
void Unload()
Closes the archive and releases all associated resources.
void IndexFile(const std::string &filePath)
Adds a file to the internal hash→path index.
virtual bool Close()=0
Closes the underlying archive file or directory.
void Validate()
Validates the manifest checksum and signature, setting mIsSigned / mIsChecksumValid.
void Load()
Opens and indexes the archive, making its contents available for loading.
std::shared_ptr< Keystore > mKeystore
Definition Archive.h:195
bool IsInitialized()
Returns true if the archive has been successfully initialized/opened.
virtual bool Open()=0
Opens the underlying archive file or directory for reading.
virtual bool WriteFile(const std::string &filename, const std::vector< uint8_t > &data)=0
Writes raw data into the archive at the given path.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
Metadata block embedded in an archive's manifest file.
Definition Archive.h:30
std::string Name
Display name of the mod/archive.
Definition Archive.h:31
std::unordered_map< std::string, std::string > Binaries
Platform → binary path map for bundled native libs.
Definition Archive.h:43
std::string License
SPDX license identifier or URL.
Definition Archive.h:37
uint32_t CodeVersion
API version of compiled script modules bundled with this archive.
Definition Archive.h:39
std::string PublicKey
Base64-encoded public key used to verify the signature.
Definition Archive.h:48
std::string Version
Human-readable version string.
Definition Archive.h:34
std::string Author
Author(s) of the archive.
Definition Archive.h:33
std::string Website
Author's website URL.
Definition Archive.h:35
std::string Icon
Path to the mod's icon within the archive.
Definition Archive.h:32
std::vector< std::string > Dependencies
Archive names that must be loaded before this one.
Definition Archive.h:44
std::string Main
Entry-point script path within the archive.
Definition Archive.h:42
std::string Signature
Base64-encoded digital signature over the checksum.
Definition Archive.h:47
std::string Description
Short description of the archive contents.
Definition Archive.h:36
std::string Checksum
Hex-encoded SHA-256 checksum of the archive contents.
Definition Archive.h:46
uint32_t GameVersion
Numeric game version this archive targets.
Definition Archive.h:40