wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
wowlib::fs::MpqStorage Class Reference

MPQ chain storage. More...

#include <wowlib/fs/mpq/mpq_storage.hpp>

Classes

struct  Options
 What to open and how. More...
struct  OpenedArchive
 One opened member of the chain, for introspection and tests. More...

Public Member Functions

 ~MpqStorage ()
 MpqStorage (const MpqStorage &)=delete
MpqStorage & operator= (const MpqStorage &)=delete
 MpqStorage (MpqStorage &&other) noexcept
MpqStorage & operator= (MpqStorage &&other) noexcept
Result< FileBuffer > readFile (const FileKey &key)
 Read a file into memory.
bool exists (const FileKey &key)
 Whether the file exists in any archive of the chain.
Result< std::vector< std::string > > enumeratePaths ()
 Enumerate every file path reachable through the chain: the members of each archive (named by its internal listfile, loaded on demand — the archives themselves open with MPQ_OPEN_NO_LISTFILE) plus the loose-dir members, canonicalized, deduplicated across the chain and sorted.
std::span< const OpenedArchive > archives () const
Locale locale () const

Static Public Member Functions

static Result< MpqStorage > open (Options options)
 Expand the version's chain and open every archive present on disk.
static constexpr StorageKind kind ()

Detailed Description

MPQ chain storage.

Opens every member of the version's chain — a StormLib archive, or a directory of loose files standing in for one — and resolves reads through them in reverse load order (last loaded wins), which replicates the client's patch override semantics.

RAII: open() — the only way to obtain an instance — returns a fully open storage, so a constructed MpqStorage is an open one. The destructor (and move-assignment onto an open storage) closes every archive; the only not-open state C++ can hold is a moved-from storage, which is empty and safe to destroy.

Thread safety: reads lock only the archive currently probed (one mutex per archive), so reads of different archives proceed in parallel. StormLib mutates internal state even on lookups, hence probing locks too.

Definition at line 37 of file mpq_storage.hpp.

Constructor & Destructor Documentation

◆ ~MpqStorage()

wowlib::fs::MpqStorage::~MpqStorage ( )
inline

Definition at line 52 of file mpq_storage.hpp.

◆ MpqStorage() [1/2]

wowlib::fs::MpqStorage::MpqStorage ( const MpqStorage & )
delete

◆ MpqStorage() [2/2]

wowlib::fs::MpqStorage::MpqStorage ( MpqStorage && other)
inlinenoexcept

Definition at line 57 of file mpq_storage.hpp.

References MpqStorage().

Member Function Documentation

◆ archives()

std::span< const OpenedArchive > wowlib::fs::MpqStorage::archives ( ) const
inline
Returns
the opened archives in load order (lowest -> highest priority).

Definition at line 118 of file mpq_storage.hpp.

◆ enumeratePaths()

Result< std::vector< std::string > > wowlib::fs::MpqStorage::enumeratePaths ( )

Enumerate every file path reachable through the chain: the members of each archive (named by its internal listfile, loaded on demand — the archives themselves open with MPQ_OPEN_NO_LISTFILE) plus the loose-dir members, canonicalized, deduplicated across the chain and sorted.

Best-effort by design: an archive that cannot enumerate (no internal listfile) is skipped silently, as are StormLib's metadata pseudo-files and the nameless hash-table placeholders — a partial listing is more useful than none.

Returns
the sorted canonical paths, or StorageNotOpen.

Definition at line 245 of file mpq_storage.cpp.

References wowlib::makeError(), wowlib::normalizePath(), and wowlib::StorageNotOpen.

◆ exists()

bool wowlib::fs::MpqStorage::exists ( const FileKey & key)

Whether the file exists in any archive of the chain.

Parameters
keythe file identity (path required).
Returns
true if a read would find it.

Definition at line 220 of file mpq_storage.cpp.

References wowlib::FileKey::path.

◆ kind()

constexpr StorageKind wowlib::fs::MpqStorage::kind ( )
inlinestaticconstexpr
Returns
the storage technology tag (Mpq).

Definition at line 93 of file mpq_storage.hpp.

References wowlib::Mpq.

◆ locale()

Locale wowlib::fs::MpqStorage::locale ( ) const
inline
Returns
the locale the chain was expanded with.

Definition at line 121 of file mpq_storage.hpp.

◆ open()

Result< MpqStorage > wowlib::fs::MpqStorage::open ( Options options)
static

Expand the version's chain and open every archive present on disk.

Parameters
optionswhat to open.
Returns
the open storage, or StorageOpenFailed / ArchiveOpenFailed.

Definition at line 52 of file mpq_storage.cpp.

References MpqStorage().

Referenced by wowlib::fs::FileSystem::open().

◆ operator=() [1/2]

MpqStorage & wowlib::fs::MpqStorage::operator= ( const MpqStorage & )
delete

References MpqStorage().

◆ operator=() [2/2]

MpqStorage & wowlib::fs::MpqStorage::operator= ( MpqStorage && other)
inlinenoexcept

Definition at line 60 of file mpq_storage.hpp.

References MpqStorage().

◆ readFile()

Result< FileBuffer > wowlib::fs::MpqStorage::readFile ( const FileKey & key)

Read a file into memory.

MPQ storage is path-addressed: a key without a path fails with FdidNotResolvable (resolve ids through a listfile in the composition layer first).

Parameters
keythe file identity.
Returns
the file bytes, or FileNotFound / FdidNotResolvable.

Definition at line 162 of file mpq_storage.cpp.

References wowlib::BackendError, wowlib::FdidNotResolvable, wowlib::FileNotFound, wowlib::makeError(), wowlib::FileKey::path, and wowlib::StorageNotOpen.


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