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
This commit is contained in:
Joseph Lee 2008-03-12 23:28:33 +00:00
parent fc46272823
commit 28d07f2cd1

View File

@ -35,7 +35,9 @@
// prior to calling this function. // prior to calling this function.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool WindowsRegistry:: 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; TextEncoder encoder;
wstring wvalue = encoder.decode_text(value); 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"; << "' 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. // to calling this function.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool WindowsRegistry:: 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; 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. // the key is not known or is some unsupported type.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
WindowsRegistry::Type WindowsRegistry:: 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; int data_type;
string data; string data;
if (!do_get(key, name, data_type, data)) { if (!do_get(key, name, data_type, data, rl)) {
return T_none; return T_none;
} }
@ -126,10 +132,12 @@ get_key_type(const string &key, const string &name) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
string WindowsRegistry:: string WindowsRegistry::
get_string_value(const string &key, const string &name, get_string_value(const string &key, const string &name,
const string &default_value) { const string &default_value,
WindowsRegistry::RegLevel rl)
{
int data_type; int data_type;
string data; string data;
if (!do_get(key, name, data_type, data)) { if (!do_get(key, name, data_type, data, rl)) {
return default_value; return default_value;
} }
@ -184,10 +192,12 @@ get_string_value(const string &key, const string &name,
// value, default_value is returned instead. // value, default_value is returned instead.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int WindowsRegistry:: 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; int data_type;
string data; string data;
if (!do_get(key, name, data_type, data)) { if (!do_get(key, name, data_type, data, rl)) {
return default_value; return default_value;
} }
@ -211,12 +221,17 @@ get_int_value(const string &key, const string &name, int default_value) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool WindowsRegistry:: bool WindowsRegistry::
do_set(const string &key, const string &name, do_set(const string &key, const string &name,
int data_type, const void *data, int data_length) { int data_type, const void *data, int data_length,
HKEY hkey; const WindowsRegistry::RegLevel rl)
{
HKEY hkey, regkey = HKEY_LOCAL_MACHINE;
LONG error; LONG error;
if (rl == rl_user) // switch to user local settings
regkey = HKEY_CURRENT_USER;
error = 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) { if (error != ERROR_SUCCESS) {
express_cat.error() express_cat.error()
<< "Unable to open registry key " << key << "Unable to open registry key " << key
@ -254,12 +269,17 @@ do_set(const string &key, const string &name,
// value. // value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool WindowsRegistry:: bool WindowsRegistry::
do_get(const string &key, const string &name, int &data_type, string &data) { do_get(const string &key, const string &name, int &data_type, string &data,
HKEY hkey; const WindowsRegistry::RegLevel rl)
{
HKEY hkey, regkey = HKEY_LOCAL_MACHINE;
LONG error; LONG error;
if (rl == rl_user) // switch to user local settings
regkey = HKEY_CURRENT_USER;
error = 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) { if (error != ERROR_SUCCESS) {
express_cat.debug() express_cat.debug()
<< "Unable to open registry key " << key << "Unable to open registry key " << key