reg: Move duplicate path_get_rootkey() calls to wmain.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2016-06-03 05:24:23 +00:00 committed by Alexandre Julliard
parent d57ad7b054
commit ee71883964
1 changed files with 19 additions and 33 deletions

View File

@ -345,22 +345,15 @@ static BOOL sane_path(const WCHAR *key)
return TRUE; return TRUE;
} }
static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, static int reg_add(HKEY root, WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
WCHAR *type, WCHAR separator, WCHAR *data, BOOL force) WCHAR *type, WCHAR separator, WCHAR *data, BOOL force)
{ {
LPWSTR p; LPWSTR p;
HKEY root,subkey; HKEY subkey;
p = strchrW(key_name,'\\'); p = strchrW(key_name,'\\');
if (p) p++; if (p) p++;
root = path_get_rootkey(key_name);
if (!root)
{
output_message(STRING_INVALID_KEY);
return 1;
}
if (value_name && value_empty) if (value_name && value_empty)
{ {
output_message(STRING_INVALID_CMDLINE); output_message(STRING_INVALID_CMDLINE);
@ -422,22 +415,15 @@ static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
return 0; return 0;
} }
static int reg_delete(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, static int reg_delete(HKEY root, WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
BOOL value_all, BOOL force) BOOL value_all, BOOL force)
{ {
LPWSTR p; LPWSTR p;
HKEY root,subkey; HKEY subkey;
p = strchrW(key_name,'\\'); p = strchrW(key_name,'\\');
if (p) p++; if (p) p++;
root = path_get_rootkey(key_name);
if (!root)
{
output_message(STRING_INVALID_KEY);
return 1;
}
if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all)) if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))
{ {
output_message(STRING_INVALID_CMDLINE); output_message(STRING_INVALID_CMDLINE);
@ -823,10 +809,10 @@ static int query_all(HKEY key, WCHAR *path, BOOL recurse)
return 0; return 0;
} }
static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL recurse) static int reg_query(HKEY root, WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL recurse)
{ {
WCHAR *p; WCHAR *p;
HKEY root, key; HKEY key;
WCHAR newlineW[] = {'\n',0}; WCHAR newlineW[] = {'\n',0};
int ret; int ret;
@ -836,13 +822,6 @@ static int reg_query(WCHAR *key_name, WCHAR *value_name, BOOL value_empty, BOOL
return 1; return 1;
} }
root = path_get_rootkey(key_name);
if (!root)
{
output_message(STRING_INVALID_KEY);
return 1;
}
p = strchrW(key_name, '\\'); p = strchrW(key_name, '\\');
if (p) p++; if (p) p++;
@ -909,6 +888,7 @@ int wmain(int argc, WCHAR *argvW[])
int i, op; int i, op;
BOOL show_op_help = FALSE; BOOL show_op_help = FALSE;
WCHAR *key_name; WCHAR *key_name;
HKEY root;
static const WCHAR slashDW[] = {'/','d',0}; static const WCHAR slashDW[] = {'/','d',0};
static const WCHAR slashFW[] = {'/','f',0}; static const WCHAR slashFW[] = {'/','f',0};
static const WCHAR slashSW[] = {'/','s',0}; static const WCHAR slashSW[] = {'/','s',0};
@ -964,6 +944,13 @@ int wmain(int argc, WCHAR *argvW[])
if (!sane_path(key_name)) if (!sane_path(key_name))
return 1; return 1;
root = path_get_rootkey(key_name);
if (!root)
{
output_message(STRING_INVALID_KEY);
return 1;
}
if (op == REG_ADD) if (op == REG_ADD)
{ {
WCHAR *value_name = NULL, *type = NULL, separator = '\0', *data = NULL; WCHAR *value_name = NULL, *type = NULL, separator = '\0', *data = NULL;
@ -1005,8 +992,7 @@ int wmain(int argc, WCHAR *argvW[])
else if (!lstrcmpiW(argvW[i], slashFW)) else if (!lstrcmpiW(argvW[i], slashFW))
force = TRUE; force = TRUE;
} }
return reg_add(key_name, value_name, value_empty, type, separator, return reg_add(root, key_name, value_name, value_empty, type, separator, data, force);
data, force);
} }
else if (op == REG_DELETE) else if (op == REG_DELETE)
{ {
@ -1030,7 +1016,7 @@ int wmain(int argc, WCHAR *argvW[])
else if (!lstrcmpiW(argvW[i], slashFW)) else if (!lstrcmpiW(argvW[i], slashFW))
force = TRUE; force = TRUE;
} }
return reg_delete(key_name, value_name, value_empty, value_all, force); return reg_delete(root, key_name, value_name, value_empty, value_all, force);
} }
else if (op == REG_QUERY) else if (op == REG_QUERY)
{ {
@ -1052,7 +1038,7 @@ int wmain(int argc, WCHAR *argvW[])
else if (!lstrcmpiW(argvW[i], slashSW)) else if (!lstrcmpiW(argvW[i], slashSW))
recurse = TRUE; recurse = TRUE;
} }
return reg_query(key_name, value_name, value_empty, recurse); return reg_query(root, key_name, value_name, value_empty, recurse);
} }
else else
{ {