|
resonance 1.0.1
|
Mounted ark archive. More...
#include <openarkobject.h>
Public Member Functions | |
| OpenArkObject () | |
| Construct an unmounted archive. | |
| ~OpenArkObject () | |
| Release the tables the mount allocated. | |
| int | OpenStream (ArkFileEntry *pEntry) |
| Open a stream on one file of this archive. | |
| void | PrintHeader () const |
| Write every field of the copied archive header to standard output. | |
| void | PrintRelPaths () const |
| Write every entry of the relative path table to standard output. | |
| void | PrintFiles () const |
| Write every entry of the file table to standard output. | |
| void | DumpStrings () const |
| Write every file name and every relative path to standard output. | |
| void | PrintAll () const |
| Write the header, the file table, the relative path table, and the strings, in that order. | |
Static Public Member Functions | |
| static int | Open (const char *pszPath) |
| Mount an ark archive by path. | |
| static int | Close (const char *pszPath) |
| Unmount a previously mounted archive. | |
| static ArkFileEntry * | FindFileEntryByPath (const char *pszPath, char *pszName, char *pszRelPath, int *pnArk) |
| Find the entry of a file in whichever mounted archive the path maps to. | |
Friends | |
| OpenArkObject * | ArkStream::FindArk () const |
| int | SeekArkStream (int nStream, int nOffset, int nOrigin) |
| Move an ark stream's read position. | |
| int | ArkfileGetBaseSector (int nFile) |
| Report the disc sector a mounted archive starts at. | |
| int | ArkfileLogicalToPhysicalSector (int nFile, int nSector) |
| Map a chunk of an archive to the chunk position the disc stores it at. | |
Mounted ark archive.
An ark stores the game's data files in one seekable blob, so the streaming layer can read a file without a directory lookup per file. This class is not polymorphic and has no RTTI, so it has no vptr. Its name comes from the debug strings of its dump routines, and its allocations use the ArkFile.cpp tag. The record is 424 bytes and begins with an embedded HxStr. The mount therefore assigns a path through the record pointer itself.
A mount copies the whole 256-byte header into the record, then allocates one block for the file table, the relative path table, and the string table together, and rebases every string offset into that block. The header's own path is lowercased in place and must include a run component, which is what fixes the archive's mount point.
The header member titles come from the labels PrintHeader() writes. The data members are private. The stream and sector routines of this unit (ArkStream::FindArk(), SeekArkStream(), ArkfileGetBaseSector(), and ArkfileLogicalToPhysicalSector()) are free functions that read the file, sector size, base sector, and optimized block members directly, and are friends.
| OpenArkObject::OpenArkObject | ( | ) |
Construct an unmounted archive.
Only the path and the four table pointers are cleared. mFile is deliberately not, which the one unreachable branch of Open() depends on.
| OpenArkObject::~OpenArkObject | ( | ) |
Release the tables the mount allocated.
The destructor is inlined into Close(), which is where its line number comes from.
|
static |
Mount an ark archive by path.
| pszPath | The archive path, relative to the data root. |
|
static |
Unmount a previously mounted archive.
The unmount is refused, and reports zero, when the path is not mounted and when a stream is still open on the archive's file. In the second case the offending stream record is erased first.
| pszPath | The same path that was passed to Open(). |
|
static |
Find the entry of a file in whichever mounted archive the path maps to.
The path is copied, with every backslash turned into a slash and every capital letter lowercased, before OpenArkObject::MapPathToArkIndex() splits it and selects the archive. The archive's file table is then searched for the name and relative path hashes, and the strings confirm a hash match.
| pszPath | The path to find. |
| pszName | Receives the file name, at least kArkNameBufferSize bytes. |
| pszRelPath | Receives the path relative to the archive's mount point, at least kArkRelPathBufferSize bytes. |
| pnArk | Receives the index of the archive in g_apMountedArks, or -1 when the file was not found. |
| int OpenArkObject::OpenStream | ( | ArkFileEntry * | pEntry | ) |
Open a stream on one file of this archive.
The stream starts at the file's first byte, and its record is appended to gOpenArkFileTable.
| pEntry | The file to read, one of this archive's file entries. |
| void OpenArkObject::PrintHeader | ( | ) | const |
Write every field of the copied archive header to standard output.
The shipped program does not call it.
| void OpenArkObject::PrintRelPaths | ( | ) | const |
Write every entry of the relative path table to standard output.
The shipped program does not call it.
| void OpenArkObject::PrintFiles | ( | ) | const |
Write every entry of the file table to standard output.
The shipped program does not call it.
| void OpenArkObject::DumpStrings | ( | ) | const |
Write every file name and every relative path to standard output.
The shipped program does not call it.
| void OpenArkObject::PrintAll | ( | ) | const |
Write the header, the file table, the relative path table, and the strings, in that order.
The shipped program does not call it.
|
friend |
|
friend |
Move an ark stream's read position.
A resulting position before the start of the stream is clamped back to the start. A stream whose archive is no longer mounted, and an origin outside FileSeekOrigin, both report -1.
| nStream | The ark stream handle, kFileHandleArkStream included. |
| nOffset | The offset to move by. |
| nOrigin | One of FileSeekOrigin. |
|
friend |
Report the disc sector a mounted archive starts at.
A file that is not a mounted archive is fatal, and the report lists every mounted archive's file before stopping.
| nFile | The archive's file. |
|
friend |
Map a chunk of an archive to the chunk position the disc stores it at.
An archive built without the optimized block stores its chunks in order, and the argument is returned unchanged. An optimized archive stores them in the order the game reads them, and its optimized block is an array of two-byte logical chunk indices whose slot number is the position on the disc. The lookup is therefore a search of that array for the logical index, returning the slot it was found in.
OpenArkObject::mOptimizedCursor makes the common case constant time. It records the slot after the one the last lookup resolved. That is the slot a sequential read wants next. A miss on the guess reports through the log, abandons the cursor, and falls back to searching the whole array. A chunk that appears in no slot is fatal.
A file that is not a mounted archive is reported through the log, and the argument is returned unchanged.
| nFile | The archive's file. |
| nSector | The logical chunk index. |