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

View File

@@ -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();

View File

@@ -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");

View File

@@ -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