VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ServerAssets.cpp
Go to the documentation of this file.
2
4#include <filesystem.h>
5#include <filesystem>
6#include <system_error>
7
8namespace VoltMod
9{
10
11void ServerAssets::Mount(std::string_view plugin)
12{
13 const std::filesystem::path folder = ResolvePath(PluginFile(plugin, "server-assets"));
14 std::error_code ignored;
15 if (!_files || !std::filesystem::is_directory(folder, ignored))
16 {
17 return;
18 }
19 const std::string path = folder.generic_string();
20 _files->AddSearchPath(path.c_str(), "GAME", PATH_ADD_TO_HEAD, SEARCH_PATH_PRIORITY_VPK);
21 _mounted.insert_or_assign(std::string(plugin), path);
22}
23
24void ServerAssets::Unmount(std::string_view plugin)
25{
26 const auto found = _mounted.find(plugin);
27 if (found == _mounted.end())
28 {
29 return;
30 }
31 _files->RemoveSearchPath(found->second.c_str(), "GAME");
32 _mounted.erase(found);
33}
34
35} // namespace VoltMod
void Mount(std::string_view plugin)
void Unmount(std::string_view plugin)
std::filesystem::path ResolvePath(std::string_view relativePath)
a relative path against the base directory. If the path is already absolute, returns it as-is.
Definition Paths.cpp:14
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::string PluginFile(std::string_view plugin, std::string_view relative)
"addons/voltmod/plugins/<plugin>/<relative>".
Definition Paths.cpp:25