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

Abstract base class representing a mounted archive (OTR, O2R, or folder). More...

#include <Archive.h>

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

Public Member Functions

 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.
 
virtual std::shared_ptr< FileLoadFile (const std::string &filePath)=0
 Loads a file by its virtual path.
 
virtual std::shared_ptr< FileLoadFile (uint64_t hash)=0
 Loads a file by its 64-bit content hash.
 
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.
 
virtual bool Open ()=0
 Opens the underlying archive file or directory for reading.
 
virtual bool Close ()=0
 Closes the underlying archive file or directory.
 
virtual bool WriteFile (const std::string &filename, const std::vector< uint8_t > &data)=0
 Writes raw data into the archive at the given path.
 

Protected Member Functions

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.
 

Protected Attributes

std::shared_ptr< ResourceManagermResourceManager
 
std::shared_ptr< KeystoremKeystore
 

Friends

class ArchiveManager
 

Detailed Description

Abstract base class representing a mounted archive (OTR, O2R, or folder).

An Archive encapsulates a collection of virtual files addressable by path or 64-bit hash. Concrete subclasses (OtrArchive, O2rArchive, FolderArchive) implement the platform- and format-specific I/O logic.

Archives are managed by ArchiveManager, which distributes load requests across all currently mounted archives.

Constructor & Destructor Documentation

◆ Archive()

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.

Parameters
pathAbsolute or relative path to the archive file or directory.

◆ ~Archive()

Ship::Archive::~Archive ( )

Member Function Documentation

◆ Close()

virtual bool Ship::Archive::Close ( )
pure virtual

Closes the underlying archive file or directory.

Returns
true on success.

Implemented in Ship::FolderArchive, Ship::O2rArchive, and Ship::OtrArchive.

◆ GetGameVersion()

uint32_t Ship::Archive::GetGameVersion ( )

Returns the game version encoded in the archive manifest.

Note
Check HasGameVersion() first; the value is undefined if there is none.

◆ GetManifest()

const ArchiveManifest & Ship::Archive::GetManifest ( )

Returns the parsed archive manifest.

◆ GetPath()

const std::string & Ship::Archive::GetPath ( )

Returns the filesystem path this archive was opened from.

◆ HasFile() [1/2]

bool Ship::Archive::HasFile ( const std::string &  filePath)

Checks whether the archive contains a file at the given path.

Parameters
filePathVirtual path to look up.
Returns
true if the file exists in this archive.

◆ HasFile() [2/2]

bool Ship::Archive::HasFile ( uint64_t  hash)

Checks whether the archive contains a file with the given hash.

Parameters
hash64-bit hash of the file path.
Returns
true if the hash is found in this archive.

◆ HasGameVersion()

bool Ship::Archive::HasGameVersion ( )

Returns true if a game version value was found in the manifest.

◆ IndexFile()

void Ship::Archive::IndexFile ( const std::string &  filePath)
protected

Adds a file to the internal hash→path index.

Parameters
filePathVirtual path of the file to index.

◆ IsChecksumValid()

bool Ship::Archive::IsChecksumValid ( )

Returns true if the archive's checksum field matches the computed checksum.

◆ IsInitialized()

bool Ship::Archive::IsInitialized ( )

Returns true if the archive has been successfully initialized/opened.

◆ IsSigned()

bool Ship::Archive::IsSigned ( )

Returns true if the archive carries a digital signature in its manifest.

◆ ListFiles() [1/2]

std::shared_ptr< std::unordered_map< uint64_t, std::string > > Ship::Archive::ListFiles ( )

Returns a map of all files indexed in this archive (hash → path).

Returns
Shared pointer to the complete hash→path map.

◆ ListFiles() [2/2]

std::shared_ptr< std::unordered_map< uint64_t, std::string > > Ship::Archive::ListFiles ( const std::string &  filter)

Returns only the files whose paths match the given filter string.

Parameters
filterSubstring or glob pattern to match against virtual paths.
Returns
Shared pointer to a filtered hash→path map.

◆ Load()

void Ship::Archive::Load ( )

Opens and indexes the archive, making its contents available for loading.

Calls Open() and then validates the manifest and signature if present.

◆ LoadFile() [1/2]

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

Loads a file by its virtual path.

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

Implemented in Ship::FolderArchive, Ship::O2rArchive, and Ship::OtrArchive.

◆ LoadFile() [2/2]

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

Loads a file by its 64-bit content hash.

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

Implemented in Ship::FolderArchive, Ship::O2rArchive, and Ship::OtrArchive.

◆ Open()

virtual bool Ship::Archive::Open ( )
pure virtual

Opens the underlying archive file or directory for reading.

Returns
true on success.

Implemented in Ship::FolderArchive, Ship::O2rArchive, and Ship::OtrArchive.

◆ operator==()

bool Ship::Archive::operator== ( const Archive rhs) const

Two archives are equal when they refer to the same underlying path.

◆ SetGameVersion()

void Ship::Archive::SetGameVersion ( uint32_t  gameVersion)
protected

Stores the game version parsed from the manifest.

◆ SetInitialized()

void Ship::Archive::SetInitialized ( bool  isInitialized)
protected

Sets the initialized state flag. Called by Load() / Unload().

◆ Unload()

void Ship::Archive::Unload ( )

Closes the archive and releases all associated resources.

Calls Close() and clears the internal hash table.

◆ Validate()

void Ship::Archive::Validate ( )
protected

Validates the manifest checksum and signature, setting mIsSigned / mIsChecksumValid.

◆ WriteFile()

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

Writes raw data into the archive at the given path.

Parameters
filenameTarget virtual path within the archive.
dataRaw bytes to write.
Returns
true on success.

Implemented in Ship::FolderArchive, Ship::O2rArchive, and Ship::OtrArchive.

Friends And Related Symbol Documentation

◆ ArchiveManager

friend class ArchiveManager
friend

Member Data Documentation

◆ mKeystore

std::shared_ptr<Keystore> Ship::Archive::mKeystore
protected

◆ mResourceManager

std::shared_ptr<ResourceManager> Ship::Archive::mResourceManager
protected

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