wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
roundtrip_wdt_wdl.cpp
Go to the documentation of this file.
1
6
7#include <string>
8
12
13namespace {
14 using namespace wowlib;
15 using namespace wowlib::audit;
16 using namespace wowlib::formats;
17
25 template <typename E>
26 RoundtripReport roundtripParsed(const E& entity, const FileBuffer& raw, RoundtripReport& report) {
27 audit::detail::tallyUnknown(report, entity);
28 const auto rewritten = entity.write();
29 if (!rewritten)
30 return audit::detail::failWith(report, "write", rewritten.error().message);
31 if (auto divergence = audit::detail::firstDivergenceChunked(raw, *rewritten)) return audit::detail::failWith(
32 report, "compare", *divergence);
33 return report;
34 }
35
41 template <ClientVersion V>
42 RoundtripReport roundtripWdt(fs::FileSystem& fs, const std::string& path) {
43 RoundtripReport report;
44 const auto raw = fs.readFile(FileKey{path});
45 if (auto outcome = audit::detail::classifyRead(report, "read", raw)) return *outcome;
46
48 if (auto r = root.read(*raw); !r) return audit::detail::failWith(report, "parse", r.error().message);
49 return roundtripParsed(root, *raw, report);
50 }
51
57 template <ClientVersion V>
58 RoundtripReport roundtripWdl(fs::FileSystem& fs, const std::string& path) {
59 RoundtripReport report;
60 const auto raw = fs.readFile(FileKey{path});
61 if (auto outcome = audit::detail::classifyRead(report, "read", raw)) return *outcome;
62
63 wdl::WDL < V > entity;
64 if (auto r = entity.read(*raw); !r) return audit::detail::failWith(report, "parse", r.error().message);
65 return roundtripParsed(entity, *raw, report);
66 }
67}
68
69namespace wowlib::audit::detail {
71 RoundtripReport report = skipped("unsupported-version");
72 const bool matched = withVersion(version, [&]<ClientVersion V>() {
73 if constexpr (versionSupported(formats::wdt::WdtVersions, V)) report = guarded([&] {
74 return roundtripWdt<V>(fs, path);
75 });
76 });
77 if (!matched) return unrecognizedVersion(version);
78 return report;
79 }
80
82 RoundtripReport report = skipped("unsupported-version");
83 const bool matched = withVersion(version, [&]<ClientVersion V>() {
84 if constexpr (versionSupported(formats::wdl::WdlVersions, V)) report = guarded([&] {
85 return roundtripWdl<V>(fs, path);
86 });
87 });
88 if (!matched) return unrecognizedVersion(version);
89 return report;
90 }
91}
static RoundtripReport wdl(fs::FileSystem &fs, const std::string &path, ClientVersion version)
Byte-perfect round-trip of one WDL file.
static RoundtripReport wdt(fs::FileSystem &fs, const std::string &path, ClientVersion version)
Byte-perfect round-trip of one main WDT file.
Internals of the round-trip audit (namespace wowlib::audit::detail): the per-format driver class — on...
RoundtripReport failWith(RoundtripReport &report, std::string stage, std::string error)
Mark report failed in place and hand it back — keeps the unknown-chunk tally gathered before the fail...
Definition detail.hpp:57
std::optional< RoundtripReport > classifyRead(RoundtripReport &report, std::string stage, const Result< FileBuffer > &result)
Classify a client-file read for the audit: content behind an unknown TACT key and zero-byte archive e...
Definition detail.hpp:72
bool withVersion(const ClientVersion v, F &&f)
Invoke f with the targeted release constant matching v as a compile-time template argument — the runt...
Definition detail.hpp:166
constexpr bool versionSupported(std::span< const ClientVersion > grid, const ClientVersion v)
Whether a format's instantiation grid carries v — the per-format if constexpr guard of the version di...
Definition detail.hpp:193
RoundtripReport skipped(std::string_view reason)
A skipped outcome — ok, tagged with the reason.
Definition detail.hpp:45
std::optional< std::string > firstDivergenceChunked(const FileBuffer &original, const FileBuffer &rewritten)
The first byte divergence between an original chunk stream and its rewrite, located within the enclos...
Definition detail.hpp:134
RoundtripReport guarded(F &&f)
Run one file's driver, converting any escaping exception into a failed outcome — one pathological fil...
Definition detail.hpp:100
void tallyUnknown(RoundtripReport &report, const formats::ChunkExtras &extras, formats::FourCCEndian endian=formats::FourCCEndian::Reversed)
Append every unmodeled chunk of a parsed entity to the report's tally, one fourcc spelling per occurr...
Definition detail.hpp:87
RoundtripReport unrecognizedVersion(const ClientVersion v)
The dispatch-failure outcome for a version outside the targeted releases.
Definition detail.hpp:202
detail::WDL< canonicalVersion(V, WdlPivots, WdlVersions)> WDL
A WDL low-resolution heightmap — the canonicalizing face of detail::WDL: every client version maps to...
Definition wdl.hpp:276
constexpr std::array WdlVersions
The versions WDL is instantiated (and welded) for: every targeted last-minor-of-major release,...
root::detail::WDTRoot< canonicalVersion(V, WdtRootPivots, WdtVersions)> WDTRoot
A WDT main file — the canonicalizing face of detail::WDTRoot: every client version maps to its range'...
Definition root.hpp:145
constexpr std::array WdtVersions
The versions WDT is instantiated (and welded) for: every targeted last-minor-of-major release,...
std::vector< std::byte > FileBuffer
Owning byte buffer for file contents read out of a client storage.
Definition buffer.hpp:16
Result< void > read(std::span< const std::byte > data)
Deserialize file bytes into this entity, replacing its contents.
Result< void > read(fs::FileSystem &fs, const FileKey &key)
Load the WDL from a client filesystem, replacing this entity's contents.
Definition wdl.hpp:498
The WDL entity (namespace wowlib::formats::wdl): a map's low-resolution heightmap — the background mo...
The WDT entity (namespace wowlib::formats::wdt): a map description — the main .wdt file plus its era'...