From 96ff3f7bc127889c9f47e4ec17faa445ade623f1 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 30 Apr 2014 21:33:43 -0400 Subject: system: Refactor error dialog box. When showing error message via Zenity, show the expanded (sprintf'ed) error, not the format string. Refactor the sprintf part to be part of the common code to avoid duplication. --- src/i_system.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/i_system.c b/src/i_system.c index 5aa57348..4e076d9d 100644 --- a/src/i_system.c +++ b/src/i_system.c @@ -356,6 +356,7 @@ static boolean already_quitting = false; void I_Error (char *error, ...) { + char msgbuf[512]; va_list argptr; atexit_listentry_t *entry; boolean exit_gui_popup; @@ -369,7 +370,7 @@ void I_Error (char *error, ...) { already_quitting = true; } - + // Message first. va_start(argptr, error); //fprintf(stderr, "\nError: "); @@ -378,6 +379,12 @@ void I_Error (char *error, ...) va_end(argptr); fflush(stderr); + // Write a copy of the message into buffer. + va_start(argptr, error); + memset(msgbuf, 0, sizeof(msgbuf)); + M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr); + va_end(argptr); + // Shutdown. Here might be other errors. entry = exit_funcs; @@ -394,19 +401,14 @@ void I_Error (char *error, ...) exit_gui_popup = !M_ParmExists("-nogui"); + // Pop up a GUI dialog box to show the error message, if the + // game was not run from the console (and the user will + // therefore be unable to otherwise see the message). + if (exit_gui_popup && !I_ConsoleStdout()) #ifdef _WIN32 - // On Windows, pop up a dialog box with the error message. - - if (exit_gui_popup) { - char msgbuf[512]; wchar_t wmsgbuf[512]; - va_start(argptr, error); - memset(msgbuf, 0, sizeof(msgbuf)); - M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr); - va_end(argptr); - MultiByteToWideChar(CP_ACP, 0, msgbuf, strlen(msgbuf) + 1, wmsgbuf, sizeof(wmsgbuf)); @@ -414,17 +416,10 @@ void I_Error (char *error, ...) MessageBoxW(NULL, wmsgbuf, L"", MB_OK); } #elif defined(__MACOSX__) - if (exit_gui_popup && !I_ConsoleStdout()) { CFStringRef message; - char msgbuf[512]; int i; - va_start(argptr, error); - memset(msgbuf, 0, sizeof(msgbuf)); - M_vsnprintf(msgbuf, sizeof(msgbuf), error, argptr); - va_end(argptr); - // The CoreFoundation message box wraps text lines, so replace // newline characters with spaces so that multiline messages // are continuous. @@ -450,9 +445,8 @@ void I_Error (char *error, ...) NULL); } #else - if (exit_gui_popup && !I_ConsoleStdout()) { - ZenityErrorBox(error); + ZenityErrorBox(msgbuf); } #endif -- cgit v1.2.3