Signed-off-by: Hugh McMaster <hugh.mcmaster(a)outlook.com>
---
programs/reg/add.c | 63 +++++++++++++++++++---------------------
programs/reg/tests/add.c | 30 +++++++++----------
2 files changed, 45 insertions(+), 48 deletions(-)
diff --git a/programs/reg/add.c b/programs/reg/add.c
index c3dec2d5b7f..897c6f60621 100644
--- a/programs/reg/add.c
+++ b/programs/reg/add.c
@@ -154,6 +154,8 @@ static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
WCHAR *type, WCHAR separator, WCHAR *data, BOOL force)
{
HKEY hkey;
+ DWORD data_type, data_size;
+ BYTE *reg_data = NULL;
if (RegCreateKeyExW(root, path, 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_READ|KEY_WRITE, NULL, &hkey, NULL))
@@ -162,49 +164,44 @@ static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
return 1;
}
- if (value_name || value_empty || data)
+ if (!force)
{
- DWORD reg_type;
- DWORD data_size = 0;
- BYTE* reg_data = NULL;
-
- if (!force)
+ if (RegQueryValueExW(hkey, 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))
{
- if (!ask_confirm(STRING_OVERWRITE_VALUE, value_name))
- {
- RegCloseKey(hkey);
- output_message(STRING_CANCELLED);
- return 0;
- }
+ RegCloseKey(hkey);
+ output_message(STRING_CANCELLED);
+ return 0;
}
}
+ }
- reg_type = wchar_get_type(type);
- if (reg_type == ~0u)
- {
- RegCloseKey(hkey);
- output_message(STRING_UNSUPPORTED_TYPE, type);
- return 1;
- }
- if ((reg_type == REG_DWORD || reg_type == REG_DWORD_BIG_ENDIAN) && !data)
- {
- RegCloseKey(hkey);
- output_message(STRING_INVALID_CMDLINE);
- return 1;
- }
+ data_type = wchar_get_type(type);
- if (!(reg_data = get_regdata(data, reg_type, separator, &data_size)))
- {
- RegCloseKey(hkey);
- return 1;
- }
+ if (data_type == ~0u)
+ {
+ RegCloseKey(hkey);
+ output_message(STRING_UNSUPPORTED_TYPE, type);
+ return 1;
+ }
- RegSetValueExW(hkey, value_name, 0, reg_type, reg_data, data_size);
- free(reg_data);
+ if ((data_type == REG_DWORD || data_type == REG_DWORD_BIG_ENDIAN) && !data)
+ {
+ RegCloseKey(hkey);
+ output_message(STRING_INVALID_CMDLINE);
+ return 1;
}
+ if (!(reg_data = get_regdata(data, data_type, separator, &data_size)))
+ {
+ RegCloseKey(hkey);
+ return 1;
+ }
+
+ RegSetValueExW(hkey, value_name, 0, data_type, reg_data, data_size);
+ free(reg_data);
+
RegCloseKey(hkey);
output_message(STRING_SUCCESS);
diff --git a/programs/reg/tests/add.c b/programs/reg/tests/add.c
index 23d0115fd64..7fad8333ed5 100644
--- a/programs/reg/tests/add.c
+++ b/programs/reg/tests/add.c
@@ -330,8 +330,8 @@ static void test_add(void)
open_key(HKEY_CURRENT_USER, KEY_BASE, KEY_WRITE, &hkey);
/* The Default value is initialized if no parameters are specified */
- todo_wine verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
- todo_wine delete_value(hkey, NULL);
+ verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
+ delete_value(hkey, NULL);
/* This also occurs when specifying a registry type and passing data */
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /d 0x5 /f", &r);
@@ -342,7 +342,7 @@ static void test_add(void)
/* The Default value can also be overwritten as an empty string */
run_reg_exe("reg add HKCU\\" KEY_BASE " /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
- verify_reg(hkey, NULL, REG_SZ, "", 1, TODO_REG_TYPE|TODO_REG_SIZE|TODO_REG_DATA);
+ verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
close_key(hkey);
delete_key(HKEY_CURRENT_USER, KEY_BASE);
@@ -366,8 +366,8 @@ static void test_add(void)
/* ... but we can add it without passing [/f] to reg.exe */
run_reg_exe("reg add HKCU\\" KEY_BASE, &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
- todo_wine verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
- todo_wine delete_value(hkey, NULL);
+ verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
+ delete_value(hkey, NULL);
/* Test whether overwriting a registry key modifies existing keys and values */
add_key(hkey, "Subkey", NULL);
@@ -382,7 +382,7 @@ static void test_add(void)
verify_key(hkey, "Subkey");
verify_reg(hkey, "Test1", REG_SZ, "Value1", 7, 0);
verify_reg(hkey, "Test2", REG_DWORD, &dword, sizeof(dword), 0);
- todo_wine verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
+ verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_NONE /d Test /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
@@ -406,9 +406,9 @@ static void test_reg_none(void)
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_NONE /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
- todo_wine verify_reg(hkey, NULL, REG_NONE, "\0", 2, 0);
+ verify_reg(hkey, NULL, REG_NONE, "\0", 2, 0);
- todo_wine delete_value(hkey, NULL);
+ delete_value(hkey, NULL);
run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_NONE /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
@@ -435,7 +435,7 @@ static void test_reg_sz(void)
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
- todo_wine verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
+ verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
run_reg_exe("reg add HKCU\\" KEY_BASE " /d WineTest /f", &r);
ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
@@ -513,9 +513,9 @@ static void test_reg_expand_sz(void)
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
- todo_wine verify_reg(hkey, NULL, REG_EXPAND_SZ, "", 1, 0);
+ verify_reg(hkey, NULL, REG_EXPAND_SZ, "", 1, 0);
- todo_wine delete_value(hkey, NULL);
+ delete_value(hkey, NULL);
run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_EXPAND_SZ /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
@@ -556,9 +556,9 @@ static void test_reg_binary(void)
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
- todo_wine verify_reg(hkey, NULL, REG_BINARY, buffer, 0, 0);
+ verify_reg(hkey, NULL, REG_BINARY, buffer, 0, 0);
- todo_wine delete_value(hkey, NULL);
+ delete_value(hkey, NULL);
run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_BINARY /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
@@ -754,9 +754,9 @@ static void test_reg_multi_sz(void)
run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
- todo_wine verify_reg(hkey, NULL, REG_MULTI_SZ, "", 1, 0);
+ verify_reg(hkey, NULL, REG_MULTI_SZ, "", 1, 0);
- todo_wine delete_value(hkey, NULL);
+ delete_value(hkey, NULL);
run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_MULTI_SZ /f", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
--
2.31.1