Commit 6b2a3dcd authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

regedit: Use message boxes by default for output.

regedit is in GUI subsystem and shouldn't interact with console. Keeping unix I/O output in silent mode (forcing English locale for Unix integration). Signed-off-by: 's avatarEric Pouech <epouech@codeweavers.com>
parent ac8da35b
......@@ -154,7 +154,7 @@ BOOL IsDefaultValue(HWND hwndLV, int i);
/* regedit.c */
void WINAPIV output_message(unsigned int id, ...);
void WINAPIV error_exit(unsigned int id, ...);
void WINAPIV error_exit(void);
/* regproc.c */
char *GetMultiByteString(const WCHAR *strW);
......
......@@ -28,74 +28,76 @@
WINE_DEFAULT_DEBUG_CHANNEL(regedit);
static void output_writeconsole(const WCHAR *str, DWORD wlen)
{
DWORD count;
static BOOL silent;
if (!WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL))
{
static void output_formatstring(BOOL with_help, UINT id, va_list va_args)
{
WCHAR buffer[4096];
WCHAR fmt[1536];
DWORD len;
char *msgA;
LCID current_lcid;
/* WriteConsole() fails on Windows if its output is redirected. If this occurs,
* we should call WriteFile() with OEM code page.
*/
len = WideCharToMultiByte(GetOEMCP(), 0, str, wlen, NULL, 0, NULL, NULL);
msgA = malloc(len);
if (!msgA) return;
if (silent && with_help) return;
WideCharToMultiByte(GetOEMCP(), 0, str, wlen, msgA, len, NULL, NULL);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
free(msgA);
}
}
current_lcid = GetThreadLocale();
if (silent) /* force en-US not to have localized strings */
SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
static void output_formatstring(const WCHAR *fmt, va_list va_args)
{
WCHAR *str;
DWORD len;
if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, ARRAY_SIZE(fmt)))
{
WINE_FIXME("LoadString failed with %ld\n", GetLastError());
if (silent) SetThreadLocale(current_lcid);
return;
}
len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
fmt, 0, 0, (WCHAR *)&str, 0, &va_args);
len = FormatMessageW(FORMAT_MESSAGE_FROM_STRING,
fmt, 0, 0, buffer, ARRAY_SIZE(buffer), &va_args);
if (len == 0 && GetLastError() != ERROR_NO_WORK_DONE)
{
WINE_FIXME("Could not format string: le=%lu, fmt=%s\n", GetLastError(), wine_dbgstr_w(fmt));
if (silent) SetThreadLocale(current_lcid);
return;
}
if (with_help &&
!LoadStringW(GetModuleHandleW(NULL), STRING_HELP,
&buffer[wcslen(buffer)], ARRAY_SIZE(buffer) - wcslen(buffer)))
{
WINE_FIXME("LoadString failed with %ld\n", GetLastError());
if (silent) SetThreadLocale(current_lcid);
return;
}
output_writeconsole(str, len);
LocalFree(str);
if (silent)
{
MESSAGE("%ls", buffer);
SetThreadLocale(current_lcid);
}
else
MessageBoxW(NULL, buffer, MAKEINTRESOURCEW(IDS_APP_TITLE), MB_OK | MB_ICONHAND);
}
void WINAPIV output_message(unsigned int id, ...)
{
WCHAR fmt[1536];
va_list va_args;
if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, ARRAY_SIZE(fmt)))
{
WINE_FIXME("LoadString failed with %ld\n", GetLastError());
return;
}
va_start(va_args, id);
output_formatstring(fmt, va_args);
output_formatstring(FALSE, id, va_args);
va_end(va_args);
}
void WINAPIV error_exit(unsigned int id, ...)
void WINAPIV error_exit(void)
{
exit(0); /* regedit.exe always terminates with error code zero */
}
static void WINAPIV usage(unsigned int id, ...)
{
WCHAR fmt[1536];
va_list va_args;
if (!LoadStringW(GetModuleHandleW(NULL), id, fmt, ARRAY_SIZE(fmt)))
{
WINE_FIXME("LoadString failed with %lu\n", GetLastError());
return;
}
va_start(va_args, id);
output_formatstring(fmt, va_args);
output_formatstring(TRUE, id, va_args);
va_end(va_args);
exit(0); /* regedit.exe always terminates with error code zero */
error_exit();
}
typedef enum {
......@@ -159,8 +161,8 @@ static void PerformRegAction(REGEDIT_ACTION action, WCHAR **argv, int *i)
break;
}
default:
error_exit(STRING_UNHANDLED_ACTION);
break;
output_message(STRING_UNHANDLED_ACTION);
error_exit();
}
}
......@@ -195,7 +197,8 @@ BOOL ProcessCmdLine(WCHAR *cmdline)
switch (towupper(argv[i][1]))
{
case '?':
error_exit(STRING_USAGE);
output_message(STRING_USAGE);
error_exit();
break;
case 'D':
action = ACTION_DELETE;
......@@ -210,12 +213,13 @@ BOOL ProcessCmdLine(WCHAR *cmdline)
/* unhandled */;
break;
case 'S':
silent = TRUE;
break;
case 'V':
/* ignored */;
break;
default:
output_message(STRING_INVALID_SWITCH, argv[i]);
error_exit(STRING_HELP);
usage(STRING_INVALID_SWITCH, argv[i]);
}
}
......@@ -225,13 +229,12 @@ BOOL ProcessCmdLine(WCHAR *cmdline)
{
case ACTION_ADD:
case ACTION_EXPORT:
output_message(STRING_NO_FILENAME);
usage(STRING_NO_FILENAME);
break;
case ACTION_DELETE:
output_message(STRING_NO_REG_KEY);
usage(STRING_NO_REG_KEY);
break;
}
error_exit(STRING_HELP);
}
for (; i < argc; i++)
......
......@@ -1091,11 +1091,15 @@ void delete_registry_key(WCHAR *reg_key_name)
if (!(key_class = parse_key_name(reg_key_name, &key_name)))
{
if (key_name) *(key_name - 1) = 0;
error_exit(STRING_INVALID_SYSTEM_KEY, reg_key_name);
output_message(STRING_INVALID_SYSTEM_KEY, reg_key_name);
error_exit();
}
if (!key_name || !*key_name)
error_exit(STRING_DELETE_FAILED, reg_key_name);
{
output_message(STRING_DELETE_FAILED, reg_key_name);
error_exit();
}
RegDeleteTreeW(key_class, key_name);
}
......@@ -1411,7 +1415,8 @@ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode)
if (!file)
{
_wperror(L"regedit");
error_exit(STRING_CANNOT_OPEN_FILE, file_name);
output_message(STRING_CANNOT_OPEN_FILE, file_name);
error_exit();
}
}
......
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