Skip to content

Commit

Permalink
refactor: Trim superfluous error handling in GUI message dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcheung committed Dec 6, 2023
1 parent 8e01711 commit 6af502d
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/utils-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,13 @@ static HANDLE winerr_fh = NULL;
void
gui_message (const char *message)
{
gunichar2 *title, *body;
GError *error = NULL;

title = g_utf8_to_utf16 (_("This is a command line application"),
-1, NULL, NULL, &error);
if (error) {
g_clear_error (&error);
title = g_utf8_to_utf16 ("This is a command line application",
-1, NULL, NULL, NULL);
}
gunichar2 *title = L"This is a command line application";
gunichar2 *body = g_utf8_to_utf16 (message, -1, NULL, NULL, NULL);

body = g_utf8_to_utf16 (message, -1, NULL, NULL, &error);
if (error) {
g_clear_error (&error);
body = g_utf8_to_utf16 ("(Original message failed to be displayed in UTF-16)",
if (body == NULL)
body = g_utf8_to_utf16 ("(Failure to display help)",
-1, NULL, NULL, NULL);
}

/* Takes advantage of the fact that LPCWSTR (wchar_t) is actually 16bit on Windows */
MessageBoxW (NULL, (LPCWSTR) body, (LPCWSTR) title,
MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
g_free (title);
Expand Down

0 comments on commit 6af502d

Please sign in to comment.