From 9c53f8659385f068170b9e36dcc52c1b4371aa3a Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sun, 8 Jun 2025 14:01:23 +0200 Subject: [PATCH] Convert GetGamePath() to fs::path --- include/Startup.h | 2 +- src/GameStart.cpp | 6 +++--- src/Network/Resources.cpp | 26 +++++++++++++------------- src/Startup.cpp | 16 ++++++++-------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/Startup.h b/include/Startup.h index 65084d0..55809b8 100644 --- a/include/Startup.h +++ b/include/Startup.h @@ -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(); diff --git a/src/GameStart.cpp b/src/GameStart.cpp index ddcc796..2230443 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -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; diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index bee2da6..a8e1fb5 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -450,8 +450,8 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vectorFileName); 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::vectorFileName; @@ -568,8 +568,8 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vectorFileSize && !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(); diff --git a/src/Startup.cpp b/src/Startup.cpp index 86f59a6..f6f95c5 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -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);