regedit: asking for confirmation before importing a file
Nowres Rafid
nowres.rafed at gmail.com
Wed Aug 17 19:56:37 CDT 2011
---
programs/regedit/regedit.c | 51 ++++++++++++++++++++++++++++++++++++------
programs/regedit/regedit.rc | 7 ++++++
programs/regedit/resource.h | 3 ++
3 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/programs/regedit/regedit.c b/programs/regedit/regedit.c
index cc0fc3a..7cd167b 100644
--- a/programs/regedit/regedit.c
+++ b/programs/regedit/regedit.c
@@ -18,10 +18,14 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#include <ctype.h>
-#include <stdio.h>
#include <windows.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include "resource.h"
#include "regproc.h"
+#include "wine/unicode.h"
static const char *usage =
"Usage:\n"
@@ -40,7 +44,6 @@ static const char *usage =
" file. Exports the whole registry if no key is specified.\n"
" /D - deletes specified registry key\n"
" /S - silent execution, can be used with any other switch.\n"
- " Default. The only existing mode, exists for compatibility with Windows regedit.\n"
" /V - advanced mode, can be used with any other switch.\n"
" Ignored, exists for compatibility with Windows regedit.\n"
" /L - location of system.dat file. Can be used with any other switch.\n"
@@ -122,7 +125,7 @@ static void get_file_name(CHAR **command_line, CHAR *file_name)
(*command_line) += pos;
}
-static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
+static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s, BOOL silent)
{
switch (action) {
case ACTION_ADD: {
@@ -142,6 +145,7 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
if (strcmp(filename, "-") == 0)
{
reg_file = stdin;
+ import_registry_file(reg_file);
}
else
{
@@ -159,6 +163,7 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
getAppName(), filename, GetLastError());
exit(1);
}
+
reg_file = fopen(realname, "r");
if (reg_file == NULL)
{
@@ -166,8 +171,34 @@ static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
fprintf(stderr, "%s: Can't open file \"%s\"\n", getAppName(), filename);
exit(1);
}
+
+ if (silent == FALSE)
+ {
+ if (MessageBoxW(NULL, MAKEINTRESOURCEW(IDS_IMPORT_BOX_TEXT),
+ MAKEINTRESOURCEW(IDS_APP_TITLE),
+ MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
+ {
+ if (import_registry_file(reg_file))
+ {
+ MessageBoxW(NULL, MAKEINTRESOURCEW(IDS_IMPORT_SUCCESS_BOX_TEXT),
+ MAKEINTRESOURCEW(IDS_APP_TITLE),
+ MB_OK | MB_ICONINFORMATION);
+ }
+ else
+ {
+ MessageBoxW(NULL, MAKEINTRESOURCEW(IDS_IMPORT_FAIL_BOX_TEXT),
+ MAKEINTRESOURCEW(IDS_APP_TITLE),
+ MB_OK | MB_ICONERROR);
+ }
+ }
+ }
+ else
+ {
+ import_registry_file(reg_file);
+ }
+
}
- import_registry_file(reg_file);
+
if (realname)
{
HeapFree(GetProcessHeap(),0,realname);
@@ -252,6 +283,7 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
REGEDIT_ACTION action = ACTION_UNDEF;
LPSTR s = lpCmdLine; /* command line pointer */
CHAR ch = *s; /* current character */
+ BOOL silent = FALSE;
while (ch && ((ch == '-') || (ch == '/'))) {
char chu;
@@ -268,8 +300,8 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
ch2 = *(s+1);
chu = toupper(ch);
if (!ch2 || isspace(ch2)) {
- if (chu == 'S' || chu == 'V') {
- /* ignore these switches */
+ if (chu == 'V') {
+ /* ignore this switch */
} else {
switch (chu) {
case 'D':
@@ -278,6 +310,9 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
case 'E':
action = ACTION_EXPORT;
break;
+ case 'S':
+ silent = TRUE;
+ break;
case '?':
fprintf(stderr,usage);
exit(0);
@@ -323,5 +358,5 @@ BOOL ProcessCmdLine(LPSTR lpCmdLine)
if (action == ACTION_UNDEF)
return FALSE;
- return PerformRegAction(action, s);
+ return PerformRegAction(action, s, silent);
}
diff --git a/programs/regedit/regedit.rc b/programs/regedit/regedit.rc
index 8d3b333..ed04a00 100644
--- a/programs/regedit/regedit.rc
+++ b/programs/regedit/regedit.rc
@@ -188,6 +188,13 @@ END
STRINGTABLE
BEGIN
+ IDS_IMPORT_BOX_TEXT "Are you sure you want to add file informations to the registry?"
+ IDS_IMPORT_SUCCESS_BOX_TEXT "Values successfuly added to the registry"
+ IDS_IMPORT_FAIL_BOX_TEXT "Failed to add values to the registry"
+END
+
+STRINGTABLE
+BEGIN
IDS_FILEDIALOG_IMPORT_TITLE "Import Registry File"
IDS_FILEDIALOG_EXPORT_TITLE "Export Registry File"
IDS_FILEDIALOG_FILTER_REG "Registry files (*.reg)"
diff --git a/programs/regedit/resource.h b/programs/regedit/resource.h
index 020765e..a520850 100644
--- a/programs/regedit/resource.h
+++ b/programs/regedit/resource.h
@@ -58,6 +58,9 @@
#define IDS_REGISTRY_VALUE_NOT_SET 162
#define IDS_REGISTRY_VALUE_CANT_DISPLAY 164
#define IDS_REGISTRY_UNKNOWN_TYPE 165
+#define IDS_IMPORT_BOX_TEXT 304
+#define IDS_IMPORT_SUCCESS_BOX_TEXT 305
+#define IDS_IMPORT_FAIL_BOX_TEXT 306
#define IDC_LICENSE_EDIT 1029
#define ID_REGISTRY_EXIT 32770
#define ID_FAVORITES_ADDTOFAVORITES 32772
--
1.7.4.1
--=-4c85M1aX+DohDY0Gslfh--
More information about the wine-devel
mailing list