mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-07 00:06:08 +00:00
registry query complete
This commit is contained in:
@@ -33,6 +33,7 @@ public: //Getters
|
||||
const std::string& getUserRole();
|
||||
const std::string& getVersion();
|
||||
private: //functions
|
||||
std::string GetLocalAppdata();
|
||||
void AdminRelaunch();
|
||||
void RichPresence();
|
||||
void WindowsInit();
|
||||
|
||||
@@ -46,16 +46,28 @@ void Launcher::WindowsInit() {
|
||||
SetConsoleTitleA(("BeamMP Launcher v" + FullVersion).c_str());
|
||||
}
|
||||
|
||||
std::string QueryValue(HKEY& BeamNG, const char* Name) {
|
||||
std::string QueryValue(HKEY& hKey, const char* Name) {
|
||||
DWORD keySize;
|
||||
BYTE buffer[1024];
|
||||
ZeroMemory(buffer, 1024);
|
||||
if(RegQueryValueExA(BeamNG, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
|
||||
BYTE buffer[16384];
|
||||
if(RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
|
||||
return {(char*)buffer, keySize};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string Launcher::GetLocalAppdata() {
|
||||
HKEY Folders;
|
||||
LONG RegRes = RegOpenKeyExA(HKEY_CURRENT_USER, R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)", 0, KEY_READ, &Folders);
|
||||
if(RegRes == ERROR_SUCCESS) {
|
||||
std::string Path = QueryValue(Folders, "Local AppData");
|
||||
if(!Path.empty()) {
|
||||
Path += "\\BeamNG.drive\\";
|
||||
VersionParser GameVer(BeamVersion);
|
||||
Path += std::to_string(GameVer.data[0]) + '.' + std::to_string(GameVer.data[1]) + '\\';
|
||||
return Path;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
void Launcher::QueryRegistry() {
|
||||
HKEY BeamNG;
|
||||
LONG RegRes = RegOpenKeyExA(HKEY_CURRENT_USER, R"(Software\BeamNG\BeamNG.drive)", 0, KEY_READ, &BeamNG);
|
||||
@@ -63,9 +75,11 @@ void Launcher::QueryRegistry() {
|
||||
BeamRoot = QueryValue(BeamNG, "rootpath");
|
||||
BeamVersion = QueryValue(BeamNG, "version");
|
||||
BeamUserPath = QueryValue(BeamNG, "userpath_override");
|
||||
//get shell folders for appdata dir
|
||||
RegCloseKey(BeamNG);
|
||||
if(!BeamRoot.empty() && !BeamVersion.empty())return;
|
||||
if(BeamUserPath.empty() && !BeamVersion.empty()) {
|
||||
BeamUserPath = GetLocalAppdata();
|
||||
}
|
||||
if(!BeamRoot.empty() && !BeamVersion.empty() && !BeamUserPath.empty())return;
|
||||
}
|
||||
LOG(FATAL) << "Please launch the game at least once, failed to read registry key Software\\BeamNG\\BeamNG.drive";
|
||||
throw ShutdownException("Fatal Error");
|
||||
|
||||
@@ -12,9 +12,9 @@ int main(int argc, char* argv[]) {
|
||||
launcher.RunDiscordRPC();
|
||||
launcher.LoadConfig();
|
||||
launcher.CheckKey();
|
||||
launcher.QueryRegistry();
|
||||
launcher.LaunchGame();
|
||||
//launcher.WaitForGame();
|
||||
launcher.QueryRegistry();
|
||||
//UI call
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user