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).
This commit is contained in:
Winos 2024-12-10 20:10:07 -03:00
parent 89327b8e20
commit 63aee03969

View File

@ -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<std::string> steamappsCommonPaths = {
"/.steam/root/steamapps/", // default
"/.var/app/com.valvesoftware.Steam/.steam/root/steamapps/", // flatpak
"/snap/steam/common/.local/share/Steam/steamapps/" //snap
std::vector<std::filesystem::path> 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) {