mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
Look for a userfolder specficied in the game's ini config
This commit is contained in:
parent
a63f1bd27c
commit
f9d347bd9b
@ -23,17 +23,41 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
unsigned long GamePID = 0;
|
unsigned long GamePID = 0;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::string QueryKey(HKEY hKey, int ID);
|
std::string QueryKey(HKEY hKey, int ID);
|
||||||
std::string GetGamePath() {
|
std::string GetGamePath() {
|
||||||
static std::string Path;
|
static std::filesystem::path Path;
|
||||||
if (!Path.empty())
|
if (!Path.empty())
|
||||||
return Path;
|
return Path.string();
|
||||||
if (options.user_path && std::filesystem::exists(options.user_path)) {
|
|
||||||
|
if (options.user_path) {
|
||||||
|
if (std::filesystem::exists(options.user_path)) {
|
||||||
Path = options.user_path;
|
Path = options.user_path;
|
||||||
} else {
|
debug("Using custom user folder path: " + Path.string());
|
||||||
|
} else
|
||||||
|
warn("Invalid or non-existent path (" + std::string(options.user_path) + ") specified using --user-path, skipping");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::string startupIniPath = GetGameDir() + "\\startup.ini"; std::filesystem::exists(startupIniPath)) {
|
||||||
|
|
||||||
|
std::ifstream startupIni(startupIniPath);
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(startupIni, line))
|
||||||
|
if (line.find("UserPath = ") == 0) {
|
||||||
|
std::string userPath = line.substr(11);
|
||||||
|
if (!userPath.empty())
|
||||||
|
if (std::filesystem::exists(userPath)) {
|
||||||
|
Path = userPath;
|
||||||
|
debug("Using custom user folder path from startup.ini: " + Path.string());
|
||||||
|
} else
|
||||||
|
warn("Found custom user folder path ("+ userPath + ") in startup.ini but it doesn't exist, skipping");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Path.empty()) {
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
|
||||||
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
@ -43,25 +67,22 @@ std::string GetGamePath() {
|
|||||||
Path = QueryKey(hKey, 4);
|
Path = QueryKey(hKey, 4);
|
||||||
|
|
||||||
if (Path.empty()) {
|
if (Path.empty()) {
|
||||||
Path = "";
|
|
||||||
char appDataPath[MAX_PATH];
|
char appDataPath[MAX_PATH];
|
||||||
HRESULT result = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath);
|
HRESULT result = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath);
|
||||||
if (SUCCEEDED(result)) {
|
|
||||||
Path = appDataPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Path.empty()) {
|
if (!SUCCEEDED(result)) {
|
||||||
fatal("Cannot get Local Appdata directory");
|
fatal("Cannot get Local Appdata directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
Path += "\\BeamNG.drive\\";
|
Path = std::filesystem::path(appDataPath) / "BeamNG.drive";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Ver = CheckVer(GetGameDir());
|
std::string Ver = CheckVer(GetGameDir());
|
||||||
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
Ver = Ver.substr(0, Ver.find('.', Ver.find('.') + 1));
|
||||||
Path += Ver + "\\";
|
Path = Path / (Ver + "\\");
|
||||||
return Path;
|
return Path.string();
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
std::string GetGamePath() {
|
std::string GetGamePath() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user