Commit 20f4c5d090fa6ce3664ba9308e1b1f9d90b948a5

Authored by Perry Werneck
1 parent 4870467d
Exists in master and in 1 other branch develop

Workin in automatic detection of application path when running on

windows.
Showing 1 changed file with 25 additions and 7 deletions   Show diff stats
client/src/session/local/session.cc
@@ -106,6 +106,29 @@ @@ -106,6 +106,29 @@
106 } 106 }
107 107
108 } 108 }
  109 +
  110 + static HKEY openKey() {
  111 +
  112 + LSTATUS rc;
  113 + HKEY hKey = 0;
  114 +
  115 + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\pw3270",0,KEY_QUERY_VALUE,&hKey);
  116 + if(rc == ERROR_SUCCESS) {
  117 + return hKey;
  118 + }
  119 +
  120 + write_log("Can't open HKLM\\Software\\pw3270", (int) rc);
  121 +
  122 + rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270",0,KEY_QUERY_VALUE,&hKey);
  123 + if(rc == ERROR_SUCCESS) {
  124 + return hKey;
  125 + }
  126 +
  127 + write_log("Can't open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270", (int) rc);
  128 +
  129 + return 0;
  130 + }
  131 +
109 #endif // _WIN32 132 #endif // _WIN32
110 133
111 Local::Session::Session() : Abstract::Session() { 134 Local::Session::Session() : Abstract::Session() {
@@ -123,13 +146,12 @@ @@ -123,13 +146,12 @@
123 // https://github.com/curl/curl/blob/master/lib/system_win32.c 146 // https://github.com/curl/curl/blob/master/lib/system_win32.c
124 147
125 char datadir[4096]; 148 char datadir[4096];
126 - HKEY hKey = 0; 149 + HKEY hKey = openKey();
127 unsigned long datalen = sizeof(datadir); 150 unsigned long datalen = sizeof(datadir);
128 151
129 memset(datadir,0,sizeof(datadir)); 152 memset(datadir,0,sizeof(datadir));
130 153
131 - LSTATUS rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270",0,KEY_QUERY_VALUE,&hKey);  
132 - if(rc == ERROR_SUCCESS) { 154 + if(hKey) {
133 155
134 unsigned long datatype; // #defined in winnt.h (predefined types 0-11) 156 unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
135 157
@@ -142,10 +164,6 @@ @@ -142,10 +164,6 @@
142 164
143 RegCloseKey(hKey); 165 RegCloseKey(hKey);
144 166
145 - } else {  
146 -  
147 - write_log("Can't open HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\pw3270", (int) rc);  
148 -  
149 } 167 }
150 168
151 if(*datadir) { 169 if(*datadir) {