Nugget
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
psyqo::paths::ArchiveManager Class Reference

This class manages the reading and decompression of files from an archive. More...

#include <psyqo-paths/archive-manager.hh>

Classes

union  IndexEntry
 The IndexEntry struct represents an entry in the archive index. More...
 

Public Member Functions

void initialize (eastl::string_view archiveName, ISO9660Parser &parser, eastl::function< void(bool)> &&callback)
 Asynchronous initialization of the archive manager.
 
psyqo::TaskQueue::Task scheduleInitialize (eastl::string_view archiveName, ISO9660Parser &parser)
 
InitAwaiterWithFilename initialize (eastl::string_view archiveName, ISO9660Parser &parser)
 
void initialize (uint32_t LBA, CDRom &device, eastl::function< void(bool)> &&callback)
 
psyqo::TaskQueue::Task scheduleInitialize (uint32_t LBA, CDRom &device)
 
InitAwaiter initialize (uint32_t LBA, CDRom &device)
 
const IndexEntrygetFirstIndexEntry () const
 Get the First IndexEntry object.
 
uint32_t getIndexCount () const
 Get the number of entries in the index.
 
const IndexEntrygetIndexEntry (eastl::string_view path) const
 Get the IndexEntry object for a given path.
 
template<unsigned S>
const IndexEntrygetIndexEntry (const char(&path)[S]) const
 
const IndexEntrygetIndexEntry (uint64_t hash) const
 
uint32_t getIndexEntrySectorStart (const IndexEntry *entry) const
 Get the LBA of the first sector of the file in the archive.
 
void setBuffer (Buffer< uint8_t > &&buffer)
 Set the Buffer object for the next read operation.
 
template<unsigned S>
void readFile (const char(&path)[S], CDRom &device, eastl::function< void(Buffer< uint8_t > &&)> &&callback)
 Read a file from the archive.
 
void readFile (eastl::string_view path, CDRom &device, eastl::function< void(Buffer< uint8_t > &&)> &&callback)
 
void readFile (uint64_t hash, CDRom &device, eastl::function< void(Buffer< uint8_t > &&)> &&callback)
 
void readFile (const IndexEntry *entry, CDRom &device, eastl::function< void(Buffer< uint8_t > &&)> &&callback)
 
template<unsigned S>
psyqo::TaskQueue::Task scheduleReadFile (const char(&path)[S], CDRom &device)
 
psyqo::TaskQueue::Task scheduleReadFile (eastl::string_view path, CDRom &device)
 
psyqo::TaskQueue::Task scheduleReadFile (uint64_t hash, CDRom &device)
 
psyqo::TaskQueue::Task scheduleReadFile (const IndexEntry *entry, CDRom &device)
 
template<unsigned S>
ReadFileAwaiter readFile (const char(&path)[S], CDRom &device)
 
ReadFileAwaiter readFile (eastl::string_view path, CDRom &device)
 
ReadFileAwaiter readFile (uint64_t hash, CDRom &device)
 
ReadFileAwaiter readFile (const IndexEntry *entry, CDRom &device)
 

Static Public Member Functions

static void registerUCL_NRV2EDecompressor ()
 Register a decompressor for a specific compression method.
 
static void registerLZ4Decompressor ()
 
static void registerAllDecompressors ()
 Register all decompressors.
 

Detailed Description

This class manages the reading and decompression of files from an archive.

The ArchiveManager class is a helper class that manages the reading and decompression of files from an archive. The archive format is specified in the mkarchive.lua tool available in the tools directory, and this is where the reader can find rationales and details on the format itself. The archive is a collection of files that are compressed using different compression methods, and is designed to be used specifically with the PlayStation 1. Parsing the iso9660 filesystem is an expensive operation, so using a single archive for all files will speed up loading times, as the archive index is kept in memory in a compact and efficient format.

If multiple archives are used, it is reasonable to create and destroy the ArchiveManager object multiple times, or to have multiple ArchiveManager objects. The latter is recommended, as it allows for caching of the index in memory, and allows for faster loading times.

Member Function Documentation

◆ getFirstIndexEntry()

const IndexEntry * psyqo::paths::ArchiveManager::getFirstIndexEntry ( ) const
inline

Get the First IndexEntry object.

This function returns a pointer to the first IndexEntry object in the index. In case the user has used a custom hashing mechanism for locating the files, this function becomes relevant in order to do any sort of custom search over the index. If the archive manager was not initialized, or failed to initialize, this function will return nullptr.

Returns
IndexEntry* Pointer to the first IndexEntry object in the index.

◆ getIndexCount()

uint32_t psyqo::paths::ArchiveManager::getIndexCount ( ) const
inline

Get the number of entries in the index.

This function returns the number of entries in the index. Calling this function before the archive manager is initialized successfully is undefined behavior.

Returns
uint32_t The number of entries in the index.

◆ getIndexEntry() [1/3]

template<unsigned S>
const IndexEntry * psyqo::paths::ArchiveManager::getIndexEntry ( const char(&)  path[S]) const
inline

◆ getIndexEntry() [2/3]

const psyqo::paths::ArchiveManager::IndexEntry * psyqo::paths::ArchiveManager::getIndexEntry ( eastl::string_view  path) const

Get the IndexEntry object for a given path.

This function returns a pointer to the IndexEntry object corresponding to the given path. The path is hashed using the djb2 hash function, and the resulting hash is used to look up the entry in the index using a binary search. If the archive manager was not initialized, failed to initialize, or the path was not found in the index, this function will return nullptr.

Parameters
pathThe path to look up.
Returns
IndexEntry* Pointer to the IndexEntry object corresponding to the path.

◆ getIndexEntry() [3/3]

const psyqo::paths::ArchiveManager::IndexEntry * psyqo::paths::ArchiveManager::getIndexEntry ( uint64_t  hash) const

◆ getIndexEntrySectorStart()

uint32_t psyqo::paths::ArchiveManager::getIndexEntrySectorStart ( const IndexEntry entry) const
inline

Get the LBA of the first sector of the file in the archive.

Parameters
entryThe IndexEntry object for the file.
Returns
uint32_t The LBA of the first sector of the file in the archive.

◆ initialize() [1/4]

InitAwaiterWithFilename psyqo::paths::ArchiveManager::initialize ( eastl::string_view  archiveName,
ISO9660Parser parser 
)
inline

◆ initialize() [2/4]

void psyqo::paths::ArchiveManager::initialize ( eastl::string_view  archiveName,
ISO9660Parser parser,
eastl::function< void(bool)> &&  callback 
)
inline

Asynchronous initialization of the archive manager.

This function initializes the archive manager asynchronously. There are two overloads of this function. The first one takes a filename and an ISO9660Parser object, and the second one takes a LBA and a CDRom object. The first overload is when the user wants the system to find the archive in the ISO9660 filesystem, while the second one is when the user already knows the LBA of the archive. Note that using exclusively the second overload means the iso9660 filesystem parsing code will not be used, which is a further reduction in the final binary's code footprint.

◆ initialize() [3/4]

InitAwaiter psyqo::paths::ArchiveManager::initialize ( uint32_t  LBA,
CDRom device 
)
inline

◆ initialize() [4/4]

void psyqo::paths::ArchiveManager::initialize ( uint32_t  LBA,
CDRom device,
eastl::function< void(bool)> &&  callback 
)
inline

◆ readFile() [1/8]

template<unsigned S>
ReadFileAwaiter psyqo::paths::ArchiveManager::readFile ( const char(&)  path[S],
CDRom device 
)
inline

◆ readFile() [2/8]

template<unsigned S>
void psyqo::paths::ArchiveManager::readFile ( const char(&)  path[S],
CDRom device,
eastl::function< void(Buffer< uint8_t > &&)> &&  callback 
)
inline

Read a file from the archive.

This function reads a file from the archive. The file may be specified by its path, hash, or IndexEntry object. The callback will be called with the data of the file, or an empty buffer if the file could not be read. Note that the template variants of this function should be guaranteed to be computing the hash of the string at compile time.

◆ readFile() [3/8]

ReadFileAwaiter psyqo::paths::ArchiveManager::readFile ( const IndexEntry entry,
CDRom device 
)
inline

◆ readFile() [4/8]

void psyqo::paths::ArchiveManager::readFile ( const IndexEntry entry,
CDRom device,
eastl::function< void(Buffer< uint8_t > &&)> &&  callback 
)
inline

◆ readFile() [5/8]

ReadFileAwaiter psyqo::paths::ArchiveManager::readFile ( eastl::string_view  path,
CDRom device 
)
inline

◆ readFile() [6/8]

void psyqo::paths::ArchiveManager::readFile ( eastl::string_view  path,
CDRom device,
eastl::function< void(Buffer< uint8_t > &&)> &&  callback 
)
inline

◆ readFile() [7/8]

ReadFileAwaiter psyqo::paths::ArchiveManager::readFile ( uint64_t  hash,
CDRom device 
)
inline

◆ readFile() [8/8]

void psyqo::paths::ArchiveManager::readFile ( uint64_t  hash,
CDRom device,
eastl::function< void(Buffer< uint8_t > &&)> &&  callback 
)
inline

◆ registerAllDecompressors()

static void psyqo::paths::ArchiveManager::registerAllDecompressors ( )
inlinestatic

Register all decompressors.

This function registers all decompressors. This is in the case the user doesn't know which decompressors will be used, or if the user wants to use all decompressors. This will increase the final binary size of the program, as all decompressor code will be included in the final binary.

◆ registerLZ4Decompressor()

static void psyqo::paths::ArchiveManager::registerLZ4Decompressor ( )
inlinestatic

◆ registerUCL_NRV2EDecompressor()

static void psyqo::paths::ArchiveManager::registerUCL_NRV2EDecompressor ( )
inlinestatic

Register a decompressor for a specific compression method.

In the spirit of paying for what you use, these functions allow the user to register a decompressor for a specific compression method. For instance, if the user knows that the archive will only contain LZ4 compressed files, they can register the LZ4 decompressor and the UCL_NRV2E decompressor will not be registered. This will reduce the final binary size of the program, as the decompressor code will not be included in the final binary. The UCL_NRV2E decompressor takes 340 bytes of code, while the LZ4 decompressor takes 200 bytes of code. It is also reasonable to not register any decompressors at all, if the user is sure that the archive will not contain any compressed files.

◆ scheduleInitialize() [1/2]

psyqo::TaskQueue::Task psyqo::paths::ArchiveManager::scheduleInitialize ( eastl::string_view  archiveName,
ISO9660Parser parser 
)
inline

◆ scheduleInitialize() [2/2]

psyqo::TaskQueue::Task psyqo::paths::ArchiveManager::scheduleInitialize ( uint32_t  LBA,
CDRom device 
)
inline

◆ scheduleReadFile() [1/4]

template<unsigned S>
psyqo::TaskQueue::Task psyqo::paths::ArchiveManager::scheduleReadFile ( const char(&)  path[S],
CDRom device 
)
inline

◆ scheduleReadFile() [2/4]

psyqo::TaskQueue::Task psyqo::paths::ArchiveManager::scheduleReadFile ( const IndexEntry entry,
CDRom device 
)
inline

◆ scheduleReadFile() [3/4]

psyqo::TaskQueue::Task psyqo::paths::ArchiveManager::scheduleReadFile ( eastl::string_view  path,
CDRom device 
)
inline

◆ scheduleReadFile() [4/4]

psyqo::TaskQueue::Task psyqo::paths::ArchiveManager::scheduleReadFile ( uint64_t  hash,
CDRom device 
)
inline

◆ setBuffer()

void psyqo::paths::ArchiveManager::setBuffer ( Buffer< uint8_t > &&  buffer)
inline

Set the Buffer object for the next read operation.

This function sets the buffer to be used for the next read operation. By default, the archive manager will allocate a buffer of the appropriate size for the file being read. However, if the user wants to use an already allocated buffer, they can use this function to set the buffer to be used.

Parameters
bufferThe buffer to be used for the next read operation.

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