Add support for appdata path

This commit is contained in:
momo5502 2023-02-18 19:13:13 +01:00
parent ccbb8e411c
commit 21ce390a53
2 changed files with 26 additions and 0 deletions

View File

@ -2,6 +2,8 @@
#include "game.hpp"
#include <utils/finally.hpp>
namespace game
{
namespace
@ -34,4 +36,26 @@ namespace game
static const auto server = get_host_library().get_optional_header()->CheckSum == 0x14C28B4;
return server;
}
std::filesystem::path get_appdata_path()
{
static const auto appdata_path = []
{
PWSTR path;
if (FAILED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &path)))
{
throw std::runtime_error("Failed to read APPDATA path!");
}
auto _ = utils::finally([&path]
{
CoTaskMemFree(path);
});
static auto appdata = std::filesystem::path(path) / "boiii";
return appdata;
}();
return appdata_path;
}
}

View File

@ -73,6 +73,8 @@ namespace game
size_t address_{};
size_t server_address_{};
};
std::filesystem::path get_appdata_path();
}
inline size_t operator"" _g(const size_t val)