registry query complete

This commit is contained in:
Anonymous275
2022-01-19 00:18:06 +02:00
parent 2e4db92640
commit ebe8d15362
3 changed files with 23 additions and 8 deletions
+1
View File
@@ -33,6 +33,7 @@ public: //Getters
const std::string& getUserRole(); const std::string& getUserRole();
const std::string& getVersion(); const std::string& getVersion();
private: //functions private: //functions
std::string GetLocalAppdata();
void AdminRelaunch(); void AdminRelaunch();
void RichPresence(); void RichPresence();
void WindowsInit(); void WindowsInit();
+21 -7
View File
@@ -46,16 +46,28 @@ void Launcher::WindowsInit() {
SetConsoleTitleA(("BeamMP Launcher v" + FullVersion).c_str()); 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; DWORD keySize;
BYTE buffer[1024]; BYTE buffer[16384];
ZeroMemory(buffer, 1024); if(RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
if(RegQueryValueExA(BeamNG, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
return {(char*)buffer, keySize}; return {(char*)buffer, keySize};
} }
return {}; 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() { void Launcher::QueryRegistry() {
HKEY BeamNG; HKEY BeamNG;
LONG RegRes = RegOpenKeyExA(HKEY_CURRENT_USER, R"(Software\BeamNG\BeamNG.drive)", 0, KEY_READ, &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"); BeamRoot = QueryValue(BeamNG, "rootpath");
BeamVersion = QueryValue(BeamNG, "version"); BeamVersion = QueryValue(BeamNG, "version");
BeamUserPath = QueryValue(BeamNG, "userpath_override"); BeamUserPath = QueryValue(BeamNG, "userpath_override");
//get shell folders for appdata dir
RegCloseKey(BeamNG); 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"; LOG(FATAL) << "Please launch the game at least once, failed to read registry key Software\\BeamNG\\BeamNG.drive";
throw ShutdownException("Fatal Error"); throw ShutdownException("Fatal Error");
+1 -1
View File
@@ -12,9 +12,9 @@ int main(int argc, char* argv[]) {
launcher.RunDiscordRPC(); launcher.RunDiscordRPC();
launcher.LoadConfig(); launcher.LoadConfig();
launcher.CheckKey(); launcher.CheckKey();
launcher.QueryRegistry();
launcher.LaunchGame(); launcher.LaunchGame();
//launcher.WaitForGame(); //launcher.WaitForGame();
launcher.QueryRegistry();
//UI call //UI call