Commit a0dc4d7c authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

reg: Add or modify the (Default) registry value if [/v] is not specified.

parent df9c11ff
......@@ -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,12 +164,6 @@ static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
return 1;
}
if (value_name || value_empty || data)
{
DWORD reg_type;
DWORD data_size = 0;
BYTE* reg_data = NULL;
if (!force)
{
if (RegQueryValueExW(hkey, value_name, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
......@@ -181,29 +177,30 @@ static int run_add(HKEY root, WCHAR *path, WCHAR *value_name, BOOL value_empty,
}
}
reg_type = wchar_get_type(type);
if (reg_type == ~0u)
data_type = wchar_get_type(type);
if (data_type == ~0u)
{
RegCloseKey(hkey);
output_message(STRING_UNSUPPORTED_TYPE, type);
return 1;
}
if ((reg_type == REG_DWORD || reg_type == REG_DWORD_BIG_ENDIAN) && !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, reg_type, separator, &data_size)))
if (!(reg_data = get_regdata(data, data_type, separator, &data_size)))
{
RegCloseKey(hkey);
return 1;
}
RegSetValueExW(hkey, value_name, 0, reg_type, reg_data, data_size);
RegSetValueExW(hkey, value_name, 0, data_type, reg_data, data_size);
free(reg_data);
}
RegCloseKey(hkey);
output_message(STRING_SUCCESS);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment