Convert GetGamePath() to fs::path

This commit is contained in:
Tixx 2025-06-08 14:01:23 +02:00
parent e0257e9526
commit 9c53f86593
No known key found for this signature in database
GPG Key ID: EC6E7A2BAABF0B8C
4 changed files with 25 additions and 25 deletions

View File

@ -13,7 +13,7 @@
void InitLauncher();
beammp_fs_string GetEP(const beammp_fs_char* P = nullptr);
beammp_fs_string GetGamePath();
std::filesystem::path GetGamePath();
std::string GetVer();
std::string GetPatch();
beammp_fs_string GetEN();

View File

@ -28,7 +28,7 @@
unsigned long GamePID = 0;
#if defined(_WIN32)
std::wstring QueryKey(HKEY hKey, int ID);
std::wstring GetGamePath() {
std::filesystem::path GetGamePath() {
static std::filesystem::path Path;
if (!Path.empty())
return Path.wstring();
@ -95,11 +95,11 @@ std::wstring GetGamePath() {
std::string Ver = CheckVer(GetGameDir());
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
(Path /= Utils::ToWString(Ver)) /= L"\\";
Path /= Utils::ToWString(Ver);
return Path;
}
#elif defined(__linux__)
std::string GetGamePath() {
std::filesystem::path GetGamePath() {
// Right now only steam is supported
struct passwd* pw = getpwuid(getuid());
std::string homeDir = pw->pw_dir;

View File

@ -450,8 +450,8 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
try {
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
}
auto modname = ModInfoIter->FileName;
#if defined(__linux__)
@ -483,8 +483,8 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
try {
fs::copy_file(OldCachedPath, PathToSaveTo, fs::copy_options::overwrite_existing);
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
}
auto modname = ModInfoIter->FileName;
@ -568,8 +568,8 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
}
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
if (!Terminate) {
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
}
// Linux version of the game doesnt support uppercase letters in mod names
@ -667,8 +667,8 @@ void SyncResources(SOCKET Sock) {
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + PathToSaveTo.substr(PathToSaveTo.find_last_of('/')));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
try {
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
}
auto modname = PathToSaveTo.substr(PathToSaveTo.find_last_of('/'));
#if defined(__linux__)
@ -677,8 +677,8 @@ void SyncResources(SOCKET Sock) {
c = ::tolower(c);
}
#endif
auto name = GetGamePath() + beammp_wide("mods/multiplayer") + Utils::ToWString(modname);
auto tmp_name = name + beammp_wide(".tmp");
auto name = GetGamePath() / beammp_wide("mods/multiplayer") / Utils::ToWString(modname);
auto tmp_name = name / beammp_wide(".tmp");
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
fs::rename(tmp_name, name);
UpdateModUsage(modname);
@ -725,8 +725,8 @@ void SyncResources(SOCKET Sock) {
}
} while (fs::file_size(PathToSaveTo) != std::stoull(*FS) && !Terminate);
if (!Terminate) {
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
}
// Linux version of the game doesnt support uppercase letters in mod names
@ -736,7 +736,7 @@ void SyncResources(SOCKET Sock) {
}
#endif
fs::copy_file(PathToSaveTo, GetGamePath() + beammp_wide("mods/multiplayer") + Utils::ToWString(FName), fs::copy_options::overwrite_existing);
fs::copy_file(PathToSaveTo, GetGamePath() / beammp_wide("mods/multiplayer") / Utils::ToWString(FName), fs::copy_options::overwrite_existing);
UpdateModUsage(FN->substr(pos));
}
WaitForConfirm();

View File

@ -267,7 +267,7 @@ void CheckMP(const beammp_fs_string& Path) {
}
void EnableMP() {
beammp_fs_string File(GetGamePath() + beammp_wide("mods/db.json"));
beammp_fs_string File(GetGamePath() / beammp_wide("mods/db.json"));
if (!fs::exists(File))
return;
auto Size = fs::file_size(File);
@ -300,8 +300,8 @@ void PreGame(const beammp_fs_string& GamePath) {
std::string GameVer = CheckVer(GamePath);
info("Game Version : " + GameVer);
CheckMP(GetGamePath() + beammp_wide("mods/multiplayer"));
info(beammp_wide("Game user path: ") + GetGamePath());
CheckMP(GetGamePath() / beammp_wide("mods/multiplayer"));
info(beammp_wide("Game user path: ") + beammp_fs_string(GetGamePath()));
if (!options.no_download) {
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
@ -311,18 +311,18 @@ void PreGame(const beammp_fs_string& GamePath) {
LatestHash.end());
try {
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
if (!fs::exists(GetGamePath() / beammp_wide("mods/multiplayer"))) {
fs::create_directories(GetGamePath() / beammp_wide("mods/multiplayer"));
}
EnableMP();
} catch (std::exception& e) {
fatal(e.what());
}
#if defined(_WIN32)
std::wstring ZipPath(GetGamePath() + LR"(mods\multiplayer\BeamMP.zip)");
std::wstring ZipPath(GetGamePath() / LR"(mods\multiplayer\BeamMP.zip)");
#elif defined(__linux__)
// Linux version of the game cant handle mods with uppercase names
std::string ZipPath(GetGamePath() + R"(mods/multiplayer/beammp.zip)");
std::string ZipPath(GetGamePath() / R"(mods/multiplayer/beammp.zip)");
#endif
std::string FileHash = Utils::GetSha256HashReallyFast(ZipPath);
@ -335,7 +335,7 @@ void PreGame(const beammp_fs_string& GamePath) {
ZipPath);
}
beammp_fs_string Target(GetGamePath() + beammp_wide("mods/unpacked/beammp"));
beammp_fs_string Target(GetGamePath() / beammp_wide("mods/unpacked/beammp"));
if (fs::is_directory(Target) && !fs::is_directory(Target + beammp_wide("/.git"))) {
fs::remove_all(Target);