Added cli option for user-path

This commit is contained in:
Tyler Hoyt 2024-11-11 19:14:17 -05:00 committed by Tixx
parent e216b6ec06
commit ffc36e7f3d
No known key found for this signature in database
GPG Key ID: EC6E7A2BAABF0B8C
3 changed files with 29 additions and 18 deletions

View File

@ -19,6 +19,7 @@ struct Options {
bool no_download = false;
bool no_update = false;
bool no_launch = false;
const char* user_path = nullptr;
const char **game_arguments = nullptr;
int game_arguments_length = 0;
const char** argv = nullptr;

View File

@ -31,28 +31,31 @@ std::string GetGamePath() {
static std::string Path;
if (!Path.empty())
return Path;
HKEY hKey;
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes != ERROR_SUCCESS) {
fatal("Please launch the game at least once!");
}
Path = QueryKey(hKey, 4);
if (Path.empty()) {
Path = "";
char appDataPath[MAX_PATH];
HRESULT result = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath);
if (SUCCEEDED(result)) {
Path = appDataPath;
if (options.user_path) {
Path = options.user_path;
} else {
HKEY hKey;
LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive";
LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey);
if (openRes != ERROR_SUCCESS) {
fatal("Please launch the game at least once!");
}
Path = QueryKey(hKey, 4);
if (Path.empty()) {
fatal("Cannot get Local Appdata directory");
}
Path = "";
char appDataPath[MAX_PATH];
HRESULT result = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath);
if (SUCCEEDED(result)) {
Path = appDataPath;
}
Path += "\\BeamNG.drive\\";
if (Path.empty()) {
fatal("Cannot get Local Appdata directory");
}
Path += "\\BeamNG.drive\\";
}
}
std::string Ver = CheckVer(GetGameDir());

View File

@ -86,6 +86,12 @@ void InitOptions(int argc, const char *argv[], Options &options) {
options.no_download = true;
options.no_launch = true;
options.no_update = true;
} else if (argument == "--user-path") {
if (i + 1 >= argc) {
error("No user path specified after flag");
}
options.user_path = argv[i + 1];
i++;
} else if (argument == "--" || argument == "--game") {
options.game_arguments = &argv[i + 1];
options.game_arguments_length = argc - i - 1;
@ -101,6 +107,7 @@ void InitOptions(int argc, const char *argv[], Options &options) {
"\t--no-update Skip applying launcher updates (you must update manually)\n"
"\t--no-launch Skip launching the game (you must launch the game manually)\n"
"\t--dev Developer mode, same as --verbose --no-download --no-launch --no-update\n"
"\t--user-path <path> Path to BeamNG's User Path\n"
"\t--game <args...> Passes ALL following arguments to the game, see also `--`\n"
<< std::flush;
exit(0);