wowlib
0.0.0
Read & write World of Warcraft client files — a C++26 core
Toggle main menu visibility
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
15
#include <
wowlib/core/buffer.hpp
>
16
#include <
wowlib/core/error.hpp
>
17
#include <
wowlib/core/shared_mutex.hpp
>
18
19
namespace
wowlib::fs
{
25
class
ProjectDirectory
{
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
66
ProjectDirectory
(
const
ProjectDirectory
&) =
delete
;
67
ProjectDirectory
&
operator=
(
const
ProjectDirectory
&) =
delete
;
68
ProjectDirectory
(
ProjectDirectory
&& other)
noexcept
;
69
ProjectDirectory
&
operator=
(
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
}
buffer.hpp
The owning byte buffer file contents are read into.
wowlib::fs::ProjectDirectory::ProjectDirectory
ProjectDirectory(const ProjectDirectory &)=delete
wowlib::fs::ProjectDirectory::write
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,...
Definition
project_directory.cpp:96
wowlib::fs::ProjectDirectory::rescan
void rescan()
Rebuild the index from disk, picking up files changed by other tools.
Definition
project_directory.cpp:61
wowlib::fs::ProjectDirectory::ProjectDirectory
ProjectDirectory()=default
wowlib::fs::ProjectDirectory::size
std::size_t size() const
Definition
project_directory.cpp:122
wowlib::fs::ProjectDirectory::operator=
ProjectDirectory & operator=(const ProjectDirectory &)=delete
wowlib::fs::ProjectDirectory::resolve
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.
Definition
project_directory.cpp:66
wowlib::fs::ProjectDirectory::open
static Result< ProjectDirectory > open(std::filesystem::path root)
Open (and index) a project directory; it is created if missing.
Definition
project_directory.cpp:29
wowlib::fs::ProjectDirectory::read
Result< FileBuffer > read(std::string_view path) const
Read an overlay file into memory.
Definition
project_directory.cpp:77
wowlib::fs::ProjectDirectory::exists
bool exists(std::string_view path) const
Whether the overlay carries a file.
Definition
project_directory.cpp:73
wowlib::fs::ProjectDirectory::root
const std::filesystem::path & root() const
Definition
project_directory.hpp:61
error.hpp
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
wowlib::fs
Definition
table_core.hpp:46
wowlib::SharedMutex
std::shared_mutex SharedMutex
Definition
shared_mutex.hpp:47
wowlib::Result
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition
error.hpp:100
shared_mutex.hpp
Reader/writer mutex used across the library.
src
wowlib
fs
project_directory.hpp
Generated by
1.17.0