wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
mpq_storage.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <filesystem>
9#include <memory>
10#include <mutex>
11#include <span>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
18#include <wowlib/core/error.hpp>
21
22namespace wowlib::fs {
37 class MpqStorage {
38 public:
40 struct Options {
41 std::filesystem::path dataDir;
45 };
46
50 static Result<MpqStorage> open(Options options);
51
52 ~MpqStorage() { _close(); }
53
54 MpqStorage(const MpqStorage&) = delete;
55 MpqStorage& operator=(const MpqStorage&) = delete;
56
57 MpqStorage(MpqStorage&& other) noexcept
58 : _options(std::move(other._options)), _archives(std::move(other._archives)) {}
59
60 MpqStorage& operator=(MpqStorage&& other) noexcept {
61 if (this != &other) {
62 _close();
63 _options = std::move(other._options);
64 _archives = std::move(other._archives);
65 }
66 return *this;
67 }
68
75
79 bool exists(const FileKey& key);
80
91
93 static constexpr StorageKind kind() { return StorageKind::Mpq; }
94
99 std::filesystem::path path;
100 bool isDirectory = false;
101
102 void* handle = nullptr;
103 std::unique_ptr<std::mutex> mtx;
104
109 bool patched = false;
110
114 std::unordered_map<std::string, std::filesystem::path> loose;
115 };
116
118 std::span<const OpenedArchive> archives() const { return _archives; }
119
121 Locale locale() const { return _options.locale; }
122
123 private:
126 explicit MpqStorage(Options options)
127 : _options(std::move(options)) {}
128
132 Result<void> _openChain();
133
135 void _close() noexcept;
136
138 bool _isOpen() const { return !_archives.empty(); }
139
140 Options _options;
141 std::vector<OpenedArchive> _archives;
142 };
143}
The owning byte buffer file contents are read into.
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 inte...
static constexpr StorageKind kind()
std::span< const OpenedArchive > archives() const
MpqStorage(MpqStorage &&other) noexcept
MpqStorage & operator=(MpqStorage &&other) noexcept
static Result< MpqStorage > open(Options options)
Expand the version's chain and open every archive present on disk.
MpqStorage & operator=(const MpqStorage &)=delete
Result< FileBuffer > readFile(const FileKey &key)
Read a file into memory.
MpqStorage(const MpqStorage &)=delete
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
File identity types: the strong FileDataID and the FileKey a read request travels as.
Per-version MPQ archive chain tables and their expansion against a real or fake Data/ directory.
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
@ Mpq
Pre-WoD retail clients (< 6.0), StormLib.
One opened member of the chain, for introspection and tests.
std::unordered_map< std::string, std::filesystem::path > loose
Loose members: canonical in-game path -> the file on disk.
std::unique_ptr< std::mutex > mtx
Serializes StormLib calls (archive members).
void * handle
StormLib HANDLE (archive members).
bool isDirectory
true => served from loose files below.
bool patched
Whether wow-update patch archives are attached (Cata+).
std::filesystem::path path
The archive file or loose-dir root on disk.
Locale locale
The locale to open; its Data/{code}/ directory must exist on disk.
std::filesystem::path dataDir
The client's Data/ directory.
ClientVersion version
Selects the chain table.