From 63aee0396937d0429f6808b0eddb2b489b22b8ec Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:10:07 -0300 Subject: [PATCH] Update BeamNG.cpp As requested: - Changed 'string' variables that referred to paths to 'filesystem'. - Added error log for when a valid 'GameDir' isn't found. Also readded error log for when 'libraryfolders.vdf' is missing for better contextualization for the 'basic_string::_M_replace_aux' error (the code doesn't reach the GameDir segment when that file is not found). --- src/Security/BeamNG.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index d8bf370..0759e29 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -180,34 +180,44 @@ void LegitimacyCheck() { RegCloseKey(hKey); #elif defined(__linux__) struct passwd* pw = getpwuid(getuid()); - std::string homeDir = pw->pw_dir; + std::filesystem::path homeDir = pw->pw_dir; + // Right now only steam is supported - std::vector steamappsCommonPaths = { - "/.steam/root/steamapps/", // default - "/.var/app/com.valvesoftware.Steam/.steam/root/steamapps/", // flatpak - "/snap/steam/common/.local/share/Steam/steamapps/" //snap + std::vector steamappsCommonPaths = { + ".steam/root/steamapps", // default + ".var/app/com.valvesoftware.Steam/.steam/root/steamapps", // flatpak + "snap/steam/common/.local/share/Steam/steamapps" // snap }; - std::string libraryFoldersPath; + std::filesystem::path libraryFoldersPath; bool libraryFoldersFound = false; - for (const std::string& path : steamappsCommonPaths) { - std::string fullPath = homeDir + path + "/libraryfolders.vdf"; + for (const auto& path : steamappsCommonPaths) { + std::filesystem::path fullPath = homeDir / path / "libraryfolders.vdf"; if (std::filesystem::exists(fullPath)) { libraryFoldersPath = fullPath; libraryFoldersFound = true; break; } } + + if (!libraryFoldersFound) { + error("Did not find a valid path to a libraryfolders.vdf file."); + return; + } + std::ifstream libraryFolders(libraryFoldersPath); auto root = tyti::vdf::read(libraryFolders); - for (auto folderInfo : root.childs) { if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/")) { GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/"; break; } } + if (GameDir.empty()) { + error("The game directory was not found."); + return; + } #endif } std::string CheckVer(const std::string& dir) { @@ -228,4 +238,4 @@ std::string CheckVer(const std::string& dir) { temp += a; } return temp; -} +} \ No newline at end of file