From 28d07f2cd1cde1f43174a08b73abcd9e0a4dca57 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Wed, 12 Mar 2008 23:28:33 +0000 Subject: [PATCH] MF_1_1_8 (1.7.12.1): o respect registry HKEY difference between _LOCAL_MACHINE settings and _CURRENT_USER o allow selection of different HKEY --- panda/src/express/windowsRegistry.cxx | 52 ++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/panda/src/express/windowsRegistry.cxx b/panda/src/express/windowsRegistry.cxx index d36f3554f7..7185b238d2 100755 --- a/panda/src/express/windowsRegistry.cxx +++ b/panda/src/express/windowsRegistry.cxx @@ -35,7 +35,9 @@ // prior to calling this function. //////////////////////////////////////////////////////////////////// bool WindowsRegistry:: -set_string_value(const string &key, const string &name, const string &value) { +set_string_value(const string &key, const string &name, const string &value, + WindowsRegistry::RegLevel rl) +{ TextEncoder encoder; wstring wvalue = encoder.decode_text(value); @@ -72,7 +74,7 @@ set_string_value(const string &key, const string &name, const string &value) { << "' for storing in registry.\n"; } - return do_set(key, name, REG_SZ, mb_result, mb_result_len); + return do_set(key, name, REG_SZ, mb_result, mb_result_len, rl); } //////////////////////////////////////////////////////////////////// @@ -83,9 +85,11 @@ set_string_value(const string &key, const string &name, const string &value) { // to calling this function. //////////////////////////////////////////////////////////////////// bool WindowsRegistry:: -set_int_value(const string &key, const string &name, int value) { +set_int_value(const string &key, const string &name, int value, + WindowsRegistry::RegLevel rl) +{ DWORD dw = value; - return do_set(key, name, REG_DWORD, &dw, sizeof(dw)); + return do_set(key, name, REG_DWORD, &dw, sizeof(dw), rl); } //////////////////////////////////////////////////////////////////// @@ -95,10 +99,12 @@ set_int_value(const string &key, const string &name, int value) { // the key is not known or is some unsupported type. //////////////////////////////////////////////////////////////////// WindowsRegistry::Type WindowsRegistry:: -get_key_type(const string &key, const string &name) { +get_key_type(const string &key, const string &name, + WindowsRegistry::RegLevel rl) +{ int data_type; string data; - if (!do_get(key, name, data_type, data)) { + if (!do_get(key, name, data_type, data, rl)) { return T_none; } @@ -126,10 +132,12 @@ get_key_type(const string &key, const string &name) { //////////////////////////////////////////////////////////////////// string WindowsRegistry:: get_string_value(const string &key, const string &name, - const string &default_value) { + const string &default_value, + WindowsRegistry::RegLevel rl) +{ int data_type; string data; - if (!do_get(key, name, data_type, data)) { + if (!do_get(key, name, data_type, data, rl)) { return default_value; } @@ -184,10 +192,12 @@ get_string_value(const string &key, const string &name, // value, default_value is returned instead. //////////////////////////////////////////////////////////////////// int WindowsRegistry:: -get_int_value(const string &key, const string &name, int default_value) { +get_int_value(const string &key, const string &name, int default_value, + WindowsRegistry::RegLevel rl) +{ int data_type; string data; - if (!do_get(key, name, data_type, data)) { + if (!do_get(key, name, data_type, data, rl)) { return default_value; } @@ -211,12 +221,17 @@ get_int_value(const string &key, const string &name, int default_value) { //////////////////////////////////////////////////////////////////// bool WindowsRegistry:: do_set(const string &key, const string &name, - int data_type, const void *data, int data_length) { - HKEY hkey; + int data_type, const void *data, int data_length, + const WindowsRegistry::RegLevel rl) +{ + HKEY hkey, regkey = HKEY_LOCAL_MACHINE; LONG error; + if (rl == rl_user) // switch to user local settings + regkey = HKEY_CURRENT_USER; + error = - RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_SET_VALUE, &hkey); + RegOpenKeyEx(regkey, key.c_str(), 0, KEY_SET_VALUE, &hkey); if (error != ERROR_SUCCESS) { express_cat.error() << "Unable to open registry key " << key @@ -254,12 +269,17 @@ do_set(const string &key, const string &name, // value. //////////////////////////////////////////////////////////////////// bool WindowsRegistry:: -do_get(const string &key, const string &name, int &data_type, string &data) { - HKEY hkey; +do_get(const string &key, const string &name, int &data_type, string &data, + const WindowsRegistry::RegLevel rl) +{ + HKEY hkey, regkey = HKEY_LOCAL_MACHINE; LONG error; + if (rl == rl_user) // switch to user local settings + regkey = HKEY_CURRENT_USER; + error = - RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_QUERY_VALUE, &hkey); + RegOpenKeyEx(regkey, key.c_str(), 0, KEY_QUERY_VALUE, &hkey); if (error != ERROR_SUCCESS) { express_cat.debug() << "Unable to open registry key " << key