From 20f4c5d090fa6ce3664ba9308e1b1f9d90b948a5 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 12 Aug 2019 17:06:26 -0300 Subject: [PATCH] Workin in automatic detection of application path when running on windows. --- client/src/session/local/session.cc | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/client/src/session/local/session.cc b/client/src/session/local/session.cc index 15a7369..a2b3018 100644 --- a/client/src/session/local/session.cc +++ b/client/src/session/local/session.cc @@ -106,6 +106,29 @@ } } + + static HKEY openKey() { + + LSTATUS rc; + HKEY hKey = 0; + + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey); + if(rc == ERROR_SUCCESS) { + return hKey; + } + + write_log("Can't open HKLM\\Software\\pw3270", (int) rc); + + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270",0,KEY_QUERY_VALUE,&hKey); + if(rc == ERROR_SUCCESS) { + return hKey; + } + + write_log("Can't open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270", (int) rc); + + return 0; + } + #endif // _WIN32 Local::Session::Session() : Abstract::Session() { @@ -123,13 +146,12 @@ // https://github.com/curl/curl/blob/master/lib/system_win32.c char datadir[4096]; - HKEY hKey = 0; + HKEY hKey = openKey(); unsigned long datalen = sizeof(datadir); memset(datadir,0,sizeof(datadir)); - LSTATUS rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270",0,KEY_QUERY_VALUE,&hKey); - if(rc == ERROR_SUCCESS) { + if(hKey) { unsigned long datatype; // #defined in winnt.h (predefined types 0-11) @@ -142,10 +164,6 @@ RegCloseKey(hKey); - } else { - - write_log("Can't open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270", (int) rc); - } if(*datadir) { -- libgit2 0.21.2