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

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>

wine commit id a0dc4d7ce37fa8cc515cd4c908245d12fc07cfae by Hugh McMaster <hugh.mcmaster@outlook.com>
This commit is contained in:
winesync 2022-01-16 21:17:20 +01:00 committed by Thomas Csovcsity
parent 1bfb496303
commit 39593a1e16
3 changed files with 49 additions and 52 deletions

View file

@ -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;
}
if (!(reg_data = get_regdata(data, reg_type, separator, &data_size)))
{
RegCloseKey(hkey);
return 1;
}
RegSetValueExW(hkey, value_name, 0, reg_type, reg_data, data_size);
free(reg_data);
}
data_type = wchar_get_type(type);
if (data_type == ~0u)
{
RegCloseKey(hkey);
output_message(STRING_UNSUPPORTED_TYPE, type);
return 1;
}
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);

View file

@ -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);

View file

@ -4,4 +4,4 @@ directories:
files:
programs/reg/resource.h: base/applications/cmdutils/reg/resource.h
tags:
wine: 2c73949a46c2dda10b544cef44c0f6c3623cc74e
wine: a0dc4d7ce37fa8cc515cd4c908245d12fc07cfae