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

Archive implementation backed by a ZIP file (.o2r format). More...

#include <O2rArchive.h>

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

Public Member Functions

 O2rArchive (const std::string &archivePath, std::shared_ptr< ResourceManager > resourceManager=nullptr, std::shared_ptr< Keystore > keystore=nullptr)
 Constructs an O2rArchive for the given ZIP file path.
 
 ~O2rArchive ()
 
bool Open ()
 Opens the ZIP file via libzip, creating the internal handle pool.
 
bool Close ()
 Closes all pooled handles and releases libzip resources.
 
bool WriteFile (const std::string &filename, const std::vector< uint8_t > &data)
 Writes raw data to a file entry inside the ZIP archive.
 
std::shared_ptr< FileLoadFile (const std::string &filePath)
 Loads a file from the archive by its virtual path.
 
std::shared_ptr< FileLoadFile (uint64_t hash)
 Loads a file from the archive by its 64-bit 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.
 

Additional Inherited Members

- 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.
 
- Protected Attributes inherited from Ship::Archive
std::shared_ptr< ResourceManagermResourceManager
 
std::shared_ptr< KeystoremKeystore
 

Detailed Description

Archive implementation backed by a ZIP file (.o2r format).

O2rArchive uses libzip to expose a Ship::Archive over a standard ZIP container. The ".o2r" format is the successor to the MPQ-based ".otr" format and requires no optional build flags to enable.

To improve concurrent read throughput a pool of zip_t* handles is maintained internally; reads acquire a handle from the pool and return it when done.

Constructor & Destructor Documentation

◆ O2rArchive()

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

Constructs an O2rArchive for the given ZIP file path.

Parameters
archivePathAbsolute or relative filesystem path to the ".o2r" file.

◆ ~O2rArchive()

Ship::O2rArchive::~O2rArchive ( )

Member Function Documentation

◆ Close()

bool Ship::O2rArchive::Close ( )
virtual

Closes all pooled handles and releases libzip resources.

Returns
true on success.

Implements Ship::Archive.

◆ LoadFile() [1/2]

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

Loads a file from the archive by its virtual path.

Parameters
filePathVirtual path of the file within the ZIP.
Returns
Loaded File with a populated buffer, or nullptr if not found.

Implements Ship::Archive.

◆ LoadFile() [2/2]

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

Loads a file from the archive by its 64-bit hash.

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

Implements Ship::Archive.

◆ Open()

bool Ship::O2rArchive::Open ( )
virtual

Opens the ZIP file via libzip, creating the internal handle pool.

Returns
true if the file was opened successfully.

Implements Ship::Archive.

◆ WriteFile()

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

Writes raw data to a file entry inside the ZIP archive.

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

Implements Ship::Archive.


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