Commit 72db61da authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

reg: Recursively export all subkeys and data.

parent 49180106
......@@ -236,14 +236,18 @@ static void export_key_name(HANDLE hFile, WCHAR *name)
heap_free(buf);
}
#define MAX_SUBKEY_LEN 257
static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path)
{
LONG rc;
DWORD max_value_len = 256, value_len;
DWORD max_data_bytes = 2048, data_size;
DWORD i, type;
WCHAR *value_name;
DWORD subkey_len;
DWORD i, type, path_len;
WCHAR *value_name, *subkey_name, *subkey_path;
BYTE *data;
HKEY subkey;
export_key_name(hFile, path);
......@@ -280,6 +284,31 @@ static int export_registry_data(HANDLE hFile, HKEY key, WCHAR *path)
heap_free(data);
heap_free(value_name);
subkey_name = heap_xalloc(MAX_SUBKEY_LEN * sizeof(WCHAR));
path_len = lstrlenW(path);
i = 0;
for (;;)
{
subkey_len = MAX_SUBKEY_LEN;
rc = RegEnumKeyExW(key, 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))
{
export_registry_data(hFile, subkey, subkey_path);
RegCloseKey(subkey);
}
heap_free(subkey_path);
i++;
}
else break;
}
heap_free(subkey_name);
return 0;
}
......
......@@ -637,7 +637,7 @@ static void output_value(const WCHAR *value_name, DWORD type, BYTE *data, DWORD
output_string(newlineW);
}
static WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len)
WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len)
{
WCHAR *subkey_path;
static const WCHAR fmt[] = {'%','s','\\','%','s',0};
......
......@@ -31,6 +31,7 @@ void output_writeconsole(const WCHAR *str, DWORD wlen);
void WINAPIV output_message(unsigned int id, ...);
BOOL ask_confirm(unsigned int msgid, WCHAR *reg_info);
HKEY path_get_rootkey(const WCHAR *path);
WCHAR *build_subkey_path(WCHAR *path, DWORD path_len, WCHAR *subkey_name, DWORD subkey_len);
BOOL parse_registry_key(const WCHAR *key, HKEY *root, WCHAR **path, WCHAR **long_key);
/* import.c */
......
......@@ -4489,7 +4489,7 @@ static void test_export(void)
run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
ok(compare_export("file.reg", complex_test, TODO_REG_COMPARE), "compare_export() failed\n");
ok(compare_export("file.reg", complex_test, 0), "compare_export() failed\n");
err = delete_tree(HKEY_CURRENT_USER, KEY_BASE);
ok(err == ERROR_SUCCESS, "delete_tree() failed: %d\n", err);
......@@ -4503,7 +4503,7 @@ static void test_export(void)
run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
ok(compare_export("file.reg", key_order_test, TODO_REG_COMPARE), "compare_export() failed\n");
ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n");
delete_key(hkey, "Subkey1");
delete_key(hkey, "Subkey2");
......
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