Commit ae147a5b authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

regedit: Output an error message and exit with error code zero instead of calling exit(1).

parent 7d0f2dec
...@@ -83,6 +83,23 @@ void __cdecl output_message(unsigned int id, ...) ...@@ -83,6 +83,23 @@ void __cdecl output_message(unsigned int id, ...)
__ms_va_end(va_args); __ms_va_end(va_args);
} }
void __cdecl error_exit(unsigned int id, ...)
{
WCHAR fmt[1536];
__ms_va_list va_args;
if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, sizeof(fmt)/sizeof(*fmt)))
{
WINE_FIXME("LoadString failed with %u\n", GetLastError());
return;
}
__ms_va_start(va_args, id);
output_formatstring(fmt, va_args);
__ms_va_end(va_args);
exit(0); /* regedit.exe always terminates with error code zero */
}
typedef enum { typedef enum {
ACTION_ADD, ACTION_EXPORT, ACTION_DELETE ACTION_ADD, ACTION_EXPORT, ACTION_DELETE
} REGEDIT_ACTION; } REGEDIT_ACTION;
...@@ -147,8 +164,7 @@ static void PerformRegAction(REGEDIT_ACTION action, WCHAR **argv, int *i) ...@@ -147,8 +164,7 @@ static void PerformRegAction(REGEDIT_ACTION action, WCHAR **argv, int *i)
break; break;
} }
default: default:
output_message(STRING_UNHANDLED_ACTION); error_exit(STRING_UNHANDLED_ACTION);
exit(1);
break; break;
} }
} }
...@@ -184,8 +200,7 @@ BOOL ProcessCmdLine(WCHAR *cmdline) ...@@ -184,8 +200,7 @@ BOOL ProcessCmdLine(WCHAR *cmdline)
switch (toupperW(argv[i][1])) switch (toupperW(argv[i][1]))
{ {
case '?': case '?':
output_message(STRING_USAGE); error_exit(STRING_USAGE);
exit(0);
break; break;
case 'D': case 'D':
action = ACTION_DELETE; action = ACTION_DELETE;
...@@ -204,8 +219,7 @@ BOOL ProcessCmdLine(WCHAR *cmdline) ...@@ -204,8 +219,7 @@ BOOL ProcessCmdLine(WCHAR *cmdline)
break; break;
default: default:
output_message(STRING_INVALID_SWITCH, argv[i]); output_message(STRING_INVALID_SWITCH, argv[i]);
output_message(STRING_HELP); error_exit(STRING_HELP);
exit(1);
} }
} }
...@@ -221,8 +235,7 @@ BOOL ProcessCmdLine(WCHAR *cmdline) ...@@ -221,8 +235,7 @@ BOOL ProcessCmdLine(WCHAR *cmdline)
output_message(STRING_NO_REG_KEY); output_message(STRING_NO_REG_KEY);
break; break;
} }
output_message(STRING_HELP); error_exit(STRING_HELP);
exit(1);
} }
for (; i < argc; i++) for (; i < argc; i++)
......
...@@ -1421,8 +1421,7 @@ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode) ...@@ -1421,8 +1421,7 @@ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
file = _wfopen(file_name, wb_mode); file = _wfopen(file_name, wb_mode);
if (!file) { if (!file) {
_wperror(regedit); _wperror(regedit);
output_message(STRING_CANNOT_OPEN_FILE, file_name); error_exit(STRING_CANNOT_OPEN_FILE, file_name);
exit(1);
} }
} }
if(unicode) if(unicode)
...@@ -1478,10 +1477,9 @@ BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format) ...@@ -1478,10 +1477,9 @@ BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
lstrcpyW(reg_key_name_buf, reg_key_name); lstrcpyW(reg_key_name_buf, reg_key_name);
/* open the specified key */ /* open the specified key */
if (!(reg_key_class = parse_key_name(reg_key_name, &branch_name))) { if (!(reg_key_class = parse_key_name(reg_key_name, &branch_name)))
output_message(STRING_INCORRECT_REG_CLASS, reg_key_name); error_exit(STRING_INCORRECT_REG_CLASS, reg_key_name);
exit(1);
}
if (!branch_name || !*branch_name) { if (!branch_name || !*branch_name) {
/* no branch - registry class is specified */ /* no branch - registry class is specified */
file = REGPROC_open_export_file(file_name, unicode); file = REGPROC_open_export_file(file_name, unicode);
...@@ -1591,14 +1589,11 @@ void delete_registry_key(WCHAR *reg_key_name) ...@@ -1591,14 +1589,11 @@ void delete_registry_key(WCHAR *reg_key_name)
if (!reg_key_name || !reg_key_name[0]) if (!reg_key_name || !reg_key_name[0])
return; return;
if (!(key_class = parse_key_name(reg_key_name, &key_name))) { if (!(key_class = parse_key_name(reg_key_name, &key_name)))
output_message(STRING_INCORRECT_REG_CLASS, reg_key_name); error_exit(STRING_INCORRECT_REG_CLASS, reg_key_name);
exit(1);
} if (!*key_name)
if (!*key_name) { error_exit(STRING_DELETE_REG_CLASS_FAILED, reg_key_name);
output_message(STRING_DELETE_REG_CLASS_FAILED, reg_key_name);
exit(1);
}
RegDeleteTreeW(key_class, key_name); RegDeleteTreeW(key_class, key_name);
} }
...@@ -34,6 +34,7 @@ if (!(p)) \ ...@@ -34,6 +34,7 @@ if (!(p)) \
} }
void __cdecl output_message(unsigned int id, ...); void __cdecl output_message(unsigned int id, ...);
void __cdecl error_exit(unsigned int id, ...);
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format); BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format);
BOOL import_registry_file(FILE *in); BOOL import_registry_file(FILE *in);
......
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