wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
project_directory.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <filesystem>
8#include <optional>
9#include <shared_mutex>
10#include <span>
11#include <string>
12#include <string_view>
13#include <unordered_map>
14
16#include <wowlib/core/error.hpp>
18
19namespace wowlib::fs {
26 public:
27 ProjectDirectory() = default;
28
32 static Result<ProjectDirectory> open(std::filesystem::path root);
33
38 std::optional<std::filesystem::path> resolve(std::string_view path) const;
39
43 bool exists(std::string_view path) const;
44
48 Result<FileBuffer> read(std::string_view path) const;
49
55 Result<void> write(std::string_view path, std::span<const std::byte> content);
56
58 void rescan();
59
61 const std::filesystem::path& root() const { return _root; }
62
64 std::size_t size() const;
65
68 ProjectDirectory(ProjectDirectory&& other) noexcept;
70
71 private:
74 void _indexTreeLocked();
75
76 std::filesystem::path _root;
77 mutable SharedMutex _mtx;
78 std::unordered_map<std::string, std::filesystem::path> _index;
79 // canonical -> on-disk
80 };
81}
The owning byte buffer file contents are read into.
ProjectDirectory(const ProjectDirectory &)=delete
Result< void > write(std::string_view path, std::span< const std::byte > content)
Write (create or overwrite) a file under the overlay, creating intermediate directories,...
void rescan()
Rebuild the index from disk, picking up files changed by other tools.
ProjectDirectory & operator=(const ProjectDirectory &)=delete
std::optional< std::filesystem::path > resolve(std::string_view path) const
The real on-disk location of a client-internal path, if the overlay carries it.
static Result< ProjectDirectory > open(std::filesystem::path root)
Open (and index) a project directory; it is created if missing.
Result< FileBuffer > read(std::string_view path) const
Read an overlay file into memory.
bool exists(std::string_view path) const
Whether the overlay carries a file.
const std::filesystem::path & root() const
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
std::shared_mutex SharedMutex
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition error.hpp:100
Reader/writer mutex used across the library.