From 6e6b20ea6404a194bcd5a7f6bc669fcaecbdd663 Mon Sep 17 00:00:00 2001 From: kichik Date: Wed, 24 Jan 2007 12:51:26 +0000 Subject: [PATCH] fixed bug #1411970 - Settings in HKLM instead of HKCU? git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4874 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/Makensisw/makensisw.cpp | 4 ++-- Contrib/Makensisw/makensisw.h | 3 ++- Contrib/Makensisw/utils.cpp | 37 +++++++++++++++++++++++++-------- Contrib/Makensisw/utils.h | 1 + 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Contrib/Makensisw/makensisw.cpp b/Contrib/Makensisw/makensisw.cpp index bad61a04..b57744f9 100644 --- a/Contrib/Makensisw/makensisw.cpp +++ b/Contrib/Makensisw/makensisw.cpp @@ -1125,10 +1125,10 @@ BOOL CALLBACK SymbolSetProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam HKEY hKey; EnableWindow(GetDlgItem(hwndDlg, IDDEL), FALSE); - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey)) { HKEY hSubKey; - if (RegCreateKey(hKey,REGSYMSUBKEY,&hSubKey) == ERROR_SUCCESS) { + if (RegOpenKeyEx(hKey,REGSYMSUBKEY,0,KEY_READ,&hSubKey) == ERROR_SUCCESS) { char subkey[1024]; int i=0; diff --git a/Contrib/Makensisw/makensisw.h b/Contrib/Makensisw/makensisw.h index d71b8605..5b02f707 100644 --- a/Contrib/Makensisw/makensisw.h +++ b/Contrib/Makensisw/makensisw.h @@ -45,7 +45,8 @@ #define SYMBOLSERROR "Symbol cannot contain whitespace characters" #define MULTIDROPERROR "Dropping more than one script at a time is not supported" #define NSISUPDATEPROMPT "Running NSIS Update will close MakeNSISW.\nContinue?" -#define REGSEC HKEY_LOCAL_MACHINE +#define REGSEC HKEY_CURRENT_USER +#define REGSECDEF HKEY_LOCAL_MACHINE #define REGKEY "Software\\NSIS" #define REGLOC "MakeNSISWPlacement" #define REGCOMPRESSOR "MakeNSISWCompressor" diff --git a/Contrib/Makensisw/utils.cpp b/Contrib/Makensisw/utils.cpp index e990f1e5..ef35e5d8 100644 --- a/Contrib/Makensisw/utils.cpp +++ b/Contrib/Makensisw/utils.cpp @@ -299,10 +299,29 @@ void CompileNSISScript() { g_sdata.thread=CreateThread(NULL,0,MakeNSISProc,0,0,&id); } +static bool InternalOpenRegSettingsKey(HKEY root, HKEY &key, bool create) { + if (create) { + if (RegCreateKey(root, REGKEY, &key) == ERROR_SUCCESS) + return true; + } else { + if (RegOpenKeyEx(root, REGKEY, 0, KEY_READ, &key) == ERROR_SUCCESS) + return true; + } + return false; +} + +bool OpenRegSettingsKey(HKEY &hKey, bool create) { + if (InternalOpenRegSettingsKey(REGSEC, hKey, create)) + return true; + if (InternalOpenRegSettingsKey(REGSECDEF, hKey, create)) + return true; + return false; +} + void RestoreWindowPos(HWND hwnd) { HKEY hKey; WINDOWPLACEMENT p; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey)) { DWORD l = sizeof(p); DWORD t; if ((RegQueryValueEx(hKey,REGLOC,NULL,&t,(unsigned char*)&p,&l)==ERROR_SUCCESS)&&(t == REG_BINARY)&&(l==sizeof(p))) { @@ -352,7 +371,7 @@ void SaveWindowPos(HWND hwnd) { WINDOWPLACEMENT p; p.length = sizeof(p); GetWindowPlacement(hwnd, &p); - if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey, true)) { RegSetValueEx(hKey,REGLOC,0,REG_BINARY,(unsigned char*)&p,sizeof(p)); RegCloseKey(hKey); } @@ -372,7 +391,7 @@ void DeleteSymbolSet(char *name) { if(name) { HKEY hKey; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey)) { char subkey[1024]; wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name); RegDeleteKey(hKey,subkey); @@ -386,7 +405,7 @@ char** LoadSymbolSet(char *name) HKEY hKey; HKEY hSubKey; char **symbols = NULL; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey)) { char subkey[1024]; if(name) { wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name); @@ -448,7 +467,7 @@ void SaveSymbolSet(char *name, char **symbols) HKEY hKey; HKEY hSubKey; int n = 0; - if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey, true)) { char subkey[1024]; if(name) { wsprintf(subkey,"%s\\%s",REGSYMSUBKEY,name); @@ -815,7 +834,7 @@ void RestoreMRUList() HKEY hSubKey; int n = 0; int i; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey)) { if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) { char buf[8]; DWORD l; @@ -843,7 +862,7 @@ void SaveMRUList() HKEY hKey; HKEY hSubKey; int i = 0; - if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey, true)) { if (RegCreateKey(hKey,REGMRUSUBKEY,&hSubKey) == ERROR_SUCCESS) { char buf[8]; for(i = 0; i < MRU_LIST_SIZE; i++) { @@ -870,7 +889,7 @@ void RestoreCompressor() { HKEY hKey; NCOMPRESSOR v = COMPRESSOR_SCRIPT; - if (RegOpenKeyEx(REGSEC,REGKEY,0,KEY_READ,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey)) { char compressor_name[32]; DWORD l = sizeof(compressor_name); DWORD t; @@ -899,7 +918,7 @@ void SaveCompressor() n = (int)v; } - if (RegCreateKey(REGSEC,REGKEY,&hKey) == ERROR_SUCCESS) { + if (OpenRegSettingsKey(hKey, true)) { RegSetValueEx(hKey,REGCOMPRESSOR,0,REG_SZ,(unsigned char*)compressor_names[n], lstrlen(compressor_names[n])); RegCloseKey(hKey); diff --git a/Contrib/Makensisw/utils.h b/Contrib/Makensisw/utils.h index a2755973..2a344966 100644 --- a/Contrib/Makensisw/utils.h +++ b/Contrib/Makensisw/utils.h @@ -40,6 +40,7 @@ void ErrorMessage(HWND hwnd,const char *str); void Items(HWND hwnd, int on); /*void DisableItems(HWND hwnd); void EnableItems(HWND hwnd);*/ +bool OpenRegSettingsKey(HKEY &hKey, bool create = false); void RestoreWindowPos(HWND hwnd); void SaveWindowPos(HWND hwnd); void ResetObjects();