[PATCH 3/4] reg: Add initial support for the 'copy' command

Hugh McMaster hugh.mcmaster at outlook.com
Mon May 17 08:41:05 CDT 2021


Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
---
 programs/reg/Makefile.in  |  1 +
 programs/reg/copy.c       | 24 ++++++++++++++++++++++++
 programs/reg/reg.c        |  6 ++++++
 programs/reg/reg.h        |  3 +++
 programs/reg/reg.rc       | 24 +++++++++++++++++++++++-
 programs/reg/resource.h   |  1 +
 programs/reg/tests/copy.c | 14 +++++++-------
 7 files changed, 65 insertions(+), 8 deletions(-)
 create mode 100644 programs/reg/copy.c

diff --git a/programs/reg/Makefile.in b/programs/reg/Makefile.in
index 5ef0d0854aa..7f7a5bc8032 100644
--- a/programs/reg/Makefile.in
+++ b/programs/reg/Makefile.in
@@ -6,6 +6,7 @@ EXTRADLLFLAGS = -mconsole -municode -mno-cygwin
 
 C_SRCS = \
 	add.c \
+	copy.c \
 	delete.c \
 	export.c \
 	import.c \
diff --git a/programs/reg/copy.c b/programs/reg/copy.c
new file mode 100644
index 00000000000..ba0916e9956
--- /dev/null
+++ b/programs/reg/copy.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2021 Hugh McMaster
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "reg.h"
+
+int reg_copy(int argc, WCHAR *argvW[])
+{
+    return 1;
+}
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index 8ffbc5054d9..652fb19d931 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -1,5 +1,6 @@
 /*
  * Copyright 2008 Andrew Riedi
+ * Copyright 2016-2017, 2021 Hugh McMaster
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -285,6 +286,7 @@ static BOOL is_help_switch(const WCHAR *s)
 
 enum operations {
     REG_ADD,
+    REG_COPY,
     REG_DELETE,
     REG_EXPORT,
     REG_IMPORT,
@@ -299,6 +301,7 @@ static enum operations get_operation(const WCHAR *str, int *op_help)
     static const struct op_info op_array[] =
     {
         { L"add",     REG_ADD,     STRING_ADD_USAGE },
+        { L"copy",    REG_COPY,    STRING_COPY_USAGE },
         { L"delete",  REG_DELETE,  STRING_DELETE_USAGE },
         { L"export",  REG_EXPORT,  STRING_EXPORT_USAGE },
         { L"import",  REG_IMPORT,  STRING_IMPORT_USAGE },
@@ -362,6 +365,9 @@ int __cdecl wmain(int argc, WCHAR *argvW[])
     if (op == REG_ADD)
         return reg_add(argc, argvW);
 
+    if (op == REG_COPY)
+        return reg_copy(argc, argvW);
+
     if (op == REG_DELETE)
         return reg_delete(argc, argvW);
 
diff --git a/programs/reg/reg.h b/programs/reg/reg.h
index b12d936d672..67b49b7797f 100644
--- a/programs/reg/reg.h
+++ b/programs/reg/reg.h
@@ -47,6 +47,9 @@ BOOL is_switch(const WCHAR *s, const WCHAR c);
 /* add.c */
 int reg_add(int argc, WCHAR *argvW[]);
 
+/* copy.c */
+int reg_copy(int argc, WCHAR *argvW[]);
+
 /* delete.c */
 int reg_delete(int argc, WCHAR *argvW[]);
 
diff --git a/programs/reg/reg.rc b/programs/reg/reg.rc
index 117365547ca..c091023384c 100644
--- a/programs/reg/reg.rc
+++ b/programs/reg/reg.rc
@@ -29,7 +29,7 @@ STRINGTABLE
     STRING_USAGE, "Usage:\n\
 \  REG [operation] [parameters]\n\n\
 \Supported operations:\n\
-\  ADD | DELETE | EXPORT | IMPORT | QUERY\n\n\
+\  ADD | COPY | DELETE | EXPORT | IMPORT | QUERY\n\n\
 \For help on a specific operation, type:\n\
 \  REG [operation] /?\n\n"
 
@@ -172,9 +172,31 @@ STRINGTABLE
     STRING_OVERWRITE_FILE, "The file '%1' already exists. Do you want to overwrite it?"
     STRING_KEY_NONEXIST, "reg: Unable to find the specified registry key\n"
     STRING_KEY_IMPORT_FAILED, "reg: Unable to import the registry key '%1'\n"
+
     STRING_REG_VIEW_USAGE, "  /reg:32\n\
 \     Access the registry using the 32-bit view.\n\n\
 \  /reg:64\n\
 \     Access the registry using the 64-bit view.\n\n"
     STRING_ACCESS_DENIED, "reg: Unable to access or create the specified registry key\n"
+
+    STRING_COPY_USAGE, "REG COPY <key1> <key2> [/s] [/f]\n\n\
+\  Copies the contents of a specified registry key to another location.\n\
+\  By default, this operation only copies registry values. Use [/s] to\n\
+\  recursively copy all subkeys and values.\n\n\
+\  <key1>, <key2>\n\
+\     Registry keys specifying the source (<key1>) and destination (<key2>)\n\
+\     of the data. If <key2> does not exist, it is created.\n\n\
+\     Format: ROOT\\Subkey\n\n\
+\     ROOT: A predefined registry key. This must be one of the following:\n\n\
+\         HKEY_LOCAL_MACHINE  | HKLM\n\
+\         HKEY_CURRENT_USER   | HKCU\n\
+\         HKEY_CLASSES_ROOT   | HKCR\n\
+\         HKEY_USERS          | HKU\n\
+\         HKEY_CURRENT_CONFIG | HKCC\n\n\
+\     Subkey: The full path to a registry key under a given ROOT key.\n\n\
+\  /s\n\
+\     Copy all subkeys and values from <key1> to <key2>.\n\n\
+\  /f\n\
+\     Overwrite all registry data in <key2> without prompting for confirmation.\n\
+\     This option does not modify subkeys and values that only exist in <key2>.\n\n"
 }
diff --git a/programs/reg/resource.h b/programs/reg/resource.h
index ecc4c09337c..670d297389a 100644
--- a/programs/reg/resource.h
+++ b/programs/reg/resource.h
@@ -63,3 +63,4 @@
 #define STRING_KEY_IMPORT_FAILED      140
 #define STRING_REG_VIEW_USAGE         141
 #define STRING_ACCESS_DENIED          142
+#define STRING_COPY_USAGE             143
diff --git a/programs/reg/tests/copy.c b/programs/reg/tests/copy.c
index 53d990811ac..ecd3cc5b29d 100644
--- a/programs/reg/tests/copy.c
+++ b/programs/reg/tests/copy.c
@@ -28,25 +28,25 @@ static void test_command_syntax(void)
     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
 
     run_reg_exe("reg copy /?", &r);
-    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
 
     run_reg_exe("reg copy /h", &r);
-    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
 
     run_reg_exe("reg copy -H", &r);
-    todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
+    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
 
     run_reg_exe("reg copy /? /f", &r);
-    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
 
     run_reg_exe("reg copy /h /f", &r);
-    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
 
     run_reg_exe("reg copy /? /s", &r);
-    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
 
     run_reg_exe("reg copy /h /s", &r);
-    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
+    todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
 
     run_reg_exe("reg copy /f", &r);
     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
-- 
2.31.1




More information about the wine-devel mailing list