libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::FolderArchive Class Referencefinal

Archive implementation backed by an on-disk directory tree. More...

#include <FolderArchive.h>

Inheritance diagram for Ship::FolderArchive:
[legend]
Collaboration diagram for Ship::FolderArchive:
[legend]

Public Member Functions

 FolderArchive (const std::string &archivePath, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
 Constructs a FolderArchive rooted at the given directory.
 
 ~FolderArchive ()
 
bool Open ()
 Scans the directory and indexes all files found within it.
 
bool Close ()
 Closes the archive and clears the internal file index.
 
bool WriteFile (const std::string &filename, const std::vector< uint8_t > &data)
 Writes raw data to a file inside the archive directory.
 
std::shared_ptr< FileLoadFile (const std::string &filePath)
 Loads a file by its virtual path relative to the archive root.
 
std::shared_ptr< FileLoadFile (uint64_t hash)
 Loads a file by its 64-bit path hash.
 
- Public Member Functions inherited from Ship::Archive
 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.
 
 ~Archive ()
 
bool operator== (const Archive &rhs) const
 Two archives are equal when they refer to the same underlying path.
 
void Load ()
 Opens and indexes the archive, making its contents available for loading.
 
void Unload ()
 Closes the archive and releases all associated resources.
 
std::shared_ptr< std::unordered_map< uint64_t, std::string > > ListFiles ()
 Returns a map of all files indexed in this archive (hash → 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.
 
bool HasFile (const std::string &filePath)
 Checks whether the archive contains a file at the given 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.
 
uint32_t GetGameVersion ()
 Returns the game version encoded in the archive manifest.
 
const ArchiveManifestGetManifest ()
 Returns the parsed archive manifest.
 
bool IsSigned ()
 Returns true if the archive carries a digital signature in its manifest.
 
bool IsChecksumValid ()
 Returns true if the archive's checksum field matches the computed checksum.
 
const std::string & GetPath ()
 Returns the filesystem path this archive was opened from.
 
bool IsInitialized ()
 Returns true if the archive has been successfully initialized/opened.
 

Protected Member Functions

std::shared_ptr< FileLoadFileRaw (const std::string &filePath)
 Reads a file from disk without header parsing.
 
std::shared_ptr< FileLoadFileRaw (uint64_t hash)
 Reads a file from disk by hash without header parsing.
 
- Protected Member Functions inherited from Ship::Archive
void SetInitialized (bool isInitialized)
 Sets the initialized state flag. Called by Load() / Unload().
 
void SetGameVersion (uint32_t gameVersion)
 Stores the game version parsed from the manifest.
 
void IndexFile (const std::string &filePath)
 Adds a file to the internal hash→path index.
 
void Validate ()
 Validates the manifest checksum and signature, setting mIsSigned / mIsChecksumValid.
 

Additional Inherited Members

- Protected Attributes inherited from Ship::Archive
std::shared_ptr< ResourceManagermResourceManager
 
std::shared_ptr< KeystoremKeystore
 

Detailed Description

Archive implementation backed by an on-disk directory tree.

FolderArchive treats an ordinary filesystem directory as a virtual archive. Files inside the directory are addressed by their relative paths, just like files inside an OTR or O2R archive. This makes it easy to load loose-file mods or development assets without packing them first.

Constructor & Destructor Documentation

◆ FolderArchive()

Ship::FolderArchive::FolderArchive ( const std::string &  archivePath,
std::shared_ptr< ResourceManager resourceManager = nullptr,
std::shared_ptr< Keystore keystore = nullptr 
)

Constructs a FolderArchive rooted at the given directory.

Parameters
archivePathPath to the directory to use as the archive root.

◆ ~FolderArchive()

Ship::FolderArchive::~FolderArchive ( )

Member Function Documentation

◆ Close()

bool Ship::FolderArchive::Close ( )
virtual

Closes the archive and clears the internal file index.

Returns
true on success.

Implements Ship::Archive.

◆ LoadFile() [1/2]

std::shared_ptr< File > Ship::FolderArchive::LoadFile ( const std::string &  filePath)
virtual

Loads a file by its virtual path relative to the archive root.

Parameters
filePathRelative file path (e.g. "textures/foo.tex").
Returns
Loaded File with a populated buffer, or nullptr if not found.

Implements Ship::Archive.

◆ LoadFile() [2/2]

std::shared_ptr< File > Ship::FolderArchive::LoadFile ( uint64_t  hash)
virtual

Loads a file by its 64-bit path hash.

Parameters
hashCRC/hash of the file path.
Returns
Loaded File with a populated buffer, or nullptr if not found.

Implements Ship::Archive.

◆ LoadFileRaw() [1/2]

std::shared_ptr< File > Ship::FolderArchive::LoadFileRaw ( const std::string &  filePath)
protected

Reads a file from disk without header parsing.

Parameters
filePathRelative file path within the archive directory.
Returns
Raw File, or nullptr if the file cannot be read.

◆ LoadFileRaw() [2/2]

std::shared_ptr< File > Ship::FolderArchive::LoadFileRaw ( uint64_t  hash)
protected

Reads a file from disk by hash without header parsing.

Parameters
hash64-bit hash of the file path.
Returns
Raw File, or nullptr if the hash is unknown or the file cannot be read.

◆ Open()

bool Ship::FolderArchive::Open ( )
virtual

Scans the directory and indexes all files found within it.

Returns
true on success, false if the directory does not exist or cannot be read.

Implements Ship::Archive.

◆ WriteFile()

bool Ship::FolderArchive::WriteFile ( const std::string &  filename,
const std::vector< uint8_t > &  data 
)
virtual

Writes raw data to a file inside the archive directory.

Parameters
filenameRelative path within the archive directory.
dataRaw bytes to write.
Returns
true on success.

Implements Ship::Archive.


The documentation for this class was generated from the following file: