Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/add.c | 18 +++++++++--------- programs/reg/delete.c | 16 ++++++++-------- programs/reg/export.c | 8 ++++---- programs/reg/query.c | 26 +++++++++++++------------- 4 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/programs/reg/add.c b/programs/reg/add.c index de22874b901..ff209bfc0ff 100644 --- a/programs/reg/add.c +++ b/programs/reg/add.c @@ -152,10 +152,10 @@ static LPBYTE get_regdata(const WCHAR *data, DWORD reg_type, WCHAR separator, DW static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty, WCHAR *type, WCHAR separator, WCHAR *data, BOOL force) { - HKEY key; + HKEY hkey;
if (RegCreateKeyExW(root, path, 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_READ|KEY_WRITE, NULL, &key, NULL)) + KEY_READ|KEY_WRITE, NULL, &hkey, NULL)) { output_message(STRING_INVALID_KEY); return 1; @@ -169,11 +169,11 @@ static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
if (!force) { - if (RegQueryValueExW(key, value_name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) + if (RegQueryValueExW(hkey, value_name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { if (!ask_confirm(STRING_OVERWRITE_VALUE, value_name)) { - RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_CANCELLED); return 0; } @@ -183,28 +183,28 @@ static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty, reg_type = wchar_get_type(type); if (reg_type == ~0u) { - RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_UNSUPPORTED_TYPE, type); return 1; } if ((reg_type == REG_DWORD || reg_type == REG_DWORD_BIG_ENDIAN) && !data) { - RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_INVALID_CMDLINE); return 1; }
if (!(reg_data = get_regdata(data, reg_type, separator, ®_count))) { - RegCloseKey(key); + RegCloseKey(hkey); return 1; }
- RegSetValueExW(key, value_name, 0, reg_type, reg_data, reg_count); + RegSetValueExW(hkey, value_name, 0, reg_type, reg_data, reg_count); free(reg_data); }
- RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_SUCCESS);
return 0; diff --git a/programs/reg/delete.c b/programs/reg/delete.c index db1ed0f5337..f8e62e490b9 100644 --- a/programs/reg/delete.c +++ b/programs/reg/delete.c @@ -21,7 +21,7 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL value_all, BOOL force) { - HKEY key; + HKEY hkey;
if (!force) { @@ -53,7 +53,7 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name return 0; }
- if (RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE, &key)) + if (RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE, &hkey)) { output_message(STRING_KEY_NONEXIST); return 1; @@ -70,14 +70,14 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name while (1) { value_len = max_value_len; - rc = RegEnumValueW(key, 0, value_name, &value_len, NULL, NULL, NULL, NULL); + rc = RegEnumValueW(hkey, 0, value_name, &value_len, NULL, NULL, NULL, NULL); if (rc == ERROR_SUCCESS) { - rc = RegDeleteValueW(key, value_name); + rc = RegDeleteValueW(hkey, value_name); if (rc != ERROR_SUCCESS) { free(value_name); - RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_VALUEALL_FAILED, key_name); return 1; } @@ -93,15 +93,15 @@ static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name } else if (value_name || value_empty) { - if (RegDeleteValueW(key, value_name)) + if (RegDeleteValueW(hkey, value_name)) { - RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_VALUE_NONEXIST); return 1; } }
- RegCloseKey(key); + RegCloseKey(hkey); output_message(STRING_SUCCESS); return 0; } diff --git a/programs/reg/export.c b/programs/reg/export.c index 78331498406..79f6997ce35 100644 --- a/programs/reg/export.c +++ b/programs/reg/export.c @@ -225,7 +225,7 @@ static void export_key_name(HANDLE hFile, WCHAR *name) free(buf); }
-static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path) +static int export_registry_data(HANDLE hFile, HKEY hkey, WCHAR *path) { LONG rc; DWORD max_value_len = 256, value_len; @@ -246,7 +246,7 @@ static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path) { value_len = max_value_len; data_size = max_data_bytes; - rc = RegEnumValueW(key, i, value_name, &value_len, NULL, &type, data, &data_size); + rc = RegEnumValueW(hkey, i, value_name, &value_len, NULL, &type, data, &data_size);
if (rc == ERROR_SUCCESS) { @@ -280,11 +280,11 @@ static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path) for (;;) { subkey_len = MAX_SUBKEY_LEN; - rc = RegEnumKeyExW(key, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL); + rc = RegEnumKeyExW(hkey, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL); if (rc == ERROR_SUCCESS) { subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len); - if (!RegOpenKeyExW(key, subkey_name, 0, KEY_READ, &subkey)) + if (!RegOpenKeyExW(hkey, subkey_name, 0, KEY_READ, &subkey)) { export_registry_data(hFile, subkey, subkey_path); RegCloseKey(subkey); diff --git a/programs/reg/query.c b/programs/reg/query.c index 9d840c8947d..6485d36db6f 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -133,7 +133,7 @@ static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD
static unsigned int num_values_found = 0;
-static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) +static int query_value(HKEY hkey, WCHAR *value_name, WCHAR *path, BOOL recurse) { LONG rc; DWORD max_data_bytes = 2048, data_size; @@ -149,7 +149,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) for (;;) { data_size = max_data_bytes; - rc = RegQueryValueExW(key, value_name, NULL, &type, data, &data_size); + rc = RegQueryValueExW(hkey, value_name, NULL, &type, data, &data_size); if (rc == ERROR_MORE_DATA) { max_data_bytes = data_size; @@ -191,11 +191,11 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) for (;;) { subkey_len = MAX_SUBKEY_LEN; - rc = RegEnumKeyExW(key, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL); + rc = RegEnumKeyExW(hkey, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL); if (rc == ERROR_SUCCESS) { subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len); - if (!RegOpenKeyExW(key, subkey_name, 0, KEY_READ, &subkey)) + if (!RegOpenKeyExW(hkey, subkey_name, 0, KEY_READ, &subkey)) { query_value(subkey, value_name, subkey_path, recurse); RegCloseKey(subkey); @@ -210,7 +210,7 @@ static int query_value(HKEY key, WCHAR *value_name, WCHAR *path, BOOL recurse) return 0; }
-static int query_all(HKEY key, WCHAR *path, BOOL recurse) +static int query_all(HKEY hkey, WCHAR *path, BOOL recurse) { LONG rc; DWORD max_value_len = 256, value_len; @@ -231,7 +231,7 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) { value_len = max_value_len; data_size = max_data_bytes; - rc = RegEnumValueW(key, i, value_name, &value_len, NULL, &type, data, &data_size); + rc = RegEnumValueW(hkey, i, value_name, &value_len, NULL, &type, data, &data_size); if (rc == ERROR_SUCCESS) { output_value(value_name, type, data, data_size); @@ -267,13 +267,13 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) for (;;) { subkey_len = MAX_SUBKEY_LEN; - rc = RegEnumKeyExW(key, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL); + rc = RegEnumKeyExW(hkey, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL); if (rc == ERROR_SUCCESS) { if (recurse) { subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len); - if (!RegOpenKeyExW(key, subkey_name, 0, KEY_READ, &subkey)) + if (!RegOpenKeyExW(hkey, subkey_name, 0, KEY_READ, &subkey)) { query_all(subkey, subkey_path, recurse); RegCloseKey(subkey); @@ -297,10 +297,10 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse) static int run_query(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL recurse) { - HKEY key; + HKEY hkey; int ret;
- if (RegOpenKeyExW(root, path, 0, KEY_READ, &key) != ERROR_SUCCESS) + if (RegOpenKeyExW(root, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS) { output_message(STRING_KEY_NONEXIST); return 1; @@ -310,14 +310,14 @@ static int run_query(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
if (value_name || value_empty) { - ret = query_value(key, value_name, key_name, recurse); + ret = query_value(hkey, value_name, key_name, recurse); if (recurse) output_message(STRING_MATCHES_FOUND, num_values_found); } else - ret = query_all(key, key_name, recurse); + ret = query_all(hkey, key_name, recurse);
- RegCloseKey(key); + RegCloseKey(hkey);
return ret; }
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/query.c | 4 ---- programs/reg/tests/query.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/programs/reg/query.c b/programs/reg/query.c index 6485d36db6f..efcd16f8ad5 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -287,10 +287,6 @@ static int query_all(HKEY hkey, WCHAR *path, BOOL recurse) }
free(subkey_name); - - if (i && !recurse) - output_string(newlineW); - return 0; }
diff --git a/programs/reg/tests/query.c b/programs/reg/tests/query.c index 34196c77aa4..a8720da8da1 100644 --- a/programs/reg/tests/query.c +++ b/programs/reg/tests/query.c @@ -225,7 +225,7 @@ static void test_query(void)
read_reg_output("reg query HKCU\" KEY_BASE, buf, sizeof(buf), &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - compare_query(buf, test3, FALSE, TODO_REG_COMPARE); + compare_query(buf, test3, FALSE, 0);
add_value(subkey, "Test3", REG_SZ, "Some string data", 16); dword = 0xabc;
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/query.c | 14 ++++++++++---- programs/reg/tests/query.c | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/programs/reg/query.c b/programs/reg/query.c index efcd16f8ad5..4af6c7f5449 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -210,9 +210,10 @@ static int query_value(HKEY hkey, WCHAR *value_name, WCHAR *path, BOOL recurse) return 0; }
-static int query_all(HKEY hkey, WCHAR *path, BOOL recurse) +static int query_all(HKEY hkey, WCHAR *path, BOOL recurse, BOOL recursing) { LONG rc; + DWORD num_values; DWORD max_value_len = 256, value_len; DWORD max_data_bytes = 2048, data_size; DWORD subkey_len; @@ -221,7 +222,12 @@ static int query_all(HKEY hkey, WCHAR *path, BOOL recurse) BYTE *data; HKEY subkey;
- output_string(L"%1\n", path); + rc = RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, + &num_values, NULL, NULL, NULL, NULL); + if (rc) return 1; + + if (num_values || recursing) + output_string(L"%1\n", path);
value_name = malloc(max_value_len * sizeof(WCHAR)); data = malloc(max_data_bytes); @@ -275,7 +281,7 @@ static int query_all(HKEY hkey, WCHAR *path, BOOL recurse) subkey_path = build_subkey_path(path, path_len, subkey_name, subkey_len); if (!RegOpenKeyExW(hkey, subkey_name, 0, KEY_READ, &subkey)) { - query_all(subkey, subkey_path, recurse); + query_all(subkey, subkey_path, recurse, TRUE); RegCloseKey(subkey); } free(subkey_path); @@ -311,7 +317,7 @@ static int run_query(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name, output_message(STRING_MATCHES_FOUND, num_values_found); } else - ret = query_all(hkey, key_name, recurse); + ret = query_all(hkey, key_name, recurse, FALSE);
RegCloseKey(hkey);
diff --git a/programs/reg/tests/query.c b/programs/reg/tests/query.c index a8720da8da1..4ccbab58cb8 100644 --- a/programs/reg/tests/query.c +++ b/programs/reg/tests/query.c @@ -282,7 +282,7 @@ static void test_query(void)
read_reg_output("reg query HKCU\" KEY_BASE, buf, sizeof(buf), &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - compare_query(buf, test8a, FALSE, TODO_REG_COMPARE); + compare_query(buf, test8a, FALSE, 0);
read_reg_output("reg query HKCU\" KEY_BASE " /s", buf, sizeof(buf), &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/query.c | 2 +- programs/reg/tests/query.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/programs/reg/query.c b/programs/reg/query.c index 4af6c7f5449..66e54548688 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -262,7 +262,7 @@ static int query_all(HKEY hkey, WCHAR *path, BOOL recurse, BOOL recursing) free(data); free(value_name);
- if (i || recurse) + if (i || recursing) output_string(newlineW);
subkey_name = malloc(MAX_SUBKEY_LEN * sizeof(WCHAR)); diff --git a/programs/reg/tests/query.c b/programs/reg/tests/query.c index 4ccbab58cb8..76186794f5e 100644 --- a/programs/reg/tests/query.c +++ b/programs/reg/tests/query.c @@ -286,7 +286,7 @@ static void test_query(void)
read_reg_output("reg query HKCU\" KEY_BASE " /s", buf, sizeof(buf), &r); ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); - compare_query(buf, test8b, FALSE, TODO_REG_COMPARE); + compare_query(buf, test8b, FALSE, 0);
delete_tree(HKEY_CURRENT_USER, KEY_BASE); }
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/reg/query.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/programs/reg/query.c b/programs/reg/query.c index 66e54548688..7e42719faf9 100644 --- a/programs/reg/query.c +++ b/programs/reg/query.c @@ -213,7 +213,7 @@ static int query_value(HKEY hkey, WCHAR *value_name, WCHAR *path, BOOL recurse) static int query_all(HKEY hkey, WCHAR *path, BOOL recurse, BOOL recursing) { LONG rc; - DWORD num_values; + DWORD num_subkeys, num_values; DWORD max_value_len = 256, value_len; DWORD max_data_bytes = 2048, data_size; DWORD subkey_len; @@ -222,8 +222,8 @@ static int query_all(HKEY hkey, WCHAR *path, BOOL recurse, BOOL recursing) BYTE *data; HKEY subkey;
- rc = RegQueryInfoKeyW(hkey, NULL, NULL, NULL, NULL, NULL, NULL, - &num_values, NULL, NULL, NULL, NULL); + rc = RegQueryInfoKeyW(hkey, NULL, NULL, NULL, &num_subkeys, NULL, + NULL, &num_values, NULL, NULL, NULL, NULL); if (rc) return 1;
if (num_values || recursing) @@ -265,6 +265,9 @@ static int query_all(HKEY hkey, WCHAR *path, BOOL recurse, BOOL recursing) if (i || recursing) output_string(newlineW);
+ if (!num_subkeys) + return 0; + subkey_name = malloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = lstrlenW(path);