From 0029688f1593ea433c61da2de1922ad49251e948 Mon Sep 17 00:00:00 2001 From: waltje Date: Tue, 4 Sep 2018 01:43:02 -0400 Subject: [PATCH] Fix for app crash if Windows installed language not supported. Fixes issue #44. --- src/plat.h | 5 +---- src/win/win.c | 27 +++++++++++++++++++++++---- src/win/win_lang.c | 13 ++++++++----- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/plat.h b/src/plat.h index be41fc8..c1a7aa8 100644 --- a/src/plat.h +++ b/src/plat.h @@ -124,7 +124,7 @@ extern const string_t *plat_strings; #ifdef _WIN32 extern void plat_console(int on); #endif -extern void plat_set_language(int id); +extern int plat_set_language(int id); extern wchar_t *fix_emu_path(const wchar_t *str); extern FILE *plat_fopen(const wchar_t *path, const wchar_t *mode); extern void plat_remove(const wchar_t *path); @@ -148,9 +148,6 @@ extern void plat_mouse_capture(int on); extern void plat_setfullscreen(int on); extern int plat_fdd_icon(int); -/* Resource management. */ -extern void set_language(int id); - /* Dynamic Module Loader interface. */ typedef struct { diff --git a/src/win/win.c b/src/win/win.c index bef01ff..f20e574 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * Platform main support module for Windows. * - * Version: @(#)win.c 1.0.18 2018/09/02 + * Version: @(#)win.c 1.0.19 2018/09/03 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -188,7 +188,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) { wchar_t **argw = NULL; - int argc, i; + int argc, i, lang; /* Set this to the default value (windowed mode). */ vid_fullscreen = 0; @@ -197,7 +197,22 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) hInstance = hInst; /* First, set our (default) language. */ - lang_id = (int)GetUserDefaultUILanguage(); + lang = (int)GetUserDefaultUILanguage(); + + /* + * Set the initial active language for this application. + * + * We must do this early, because if we are on a localized + * Windows system, we must have the language set up so the + * "pc_setup" phase (config file etc) can display error + * messages... *cough* + */ + if (! plat_set_language(lang)) { + /* That did not work. Revert back to default and try again. */ + lang = lang_id; + (void)plat_set_language(lang); + } + lang_id = lang; /* Initialize the version data. CrashDump needs it early. */ pc_version("Windows"); @@ -226,7 +241,11 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow) plat_console(0); /* Set the active language for this application. */ - plat_set_language(lang_id); + if (! plat_set_language(lang_id)) { + /* That did not work. Revert back to default and try again. */ + lang_id = 0x0409; + (void)plat_set_language(lang_id); + } /* Create a mutex for the video handler. */ hBlitMutex = CreateMutex(NULL, FALSE, MUTEX_NAME); diff --git a/src/win/win_lang.c b/src/win/win_lang.c index fcd4676..d1fb74b 100644 --- a/src/win/win_lang.c +++ b/src/win/win_lang.c @@ -8,7 +8,7 @@ * * Handle language support for the platform. * - * Version: @(#)win_lang.c 1.0.5 2018/08/26 + * Version: @(#)win_lang.c 1.0.6 2018/09/03 * * Author: Fred N. van Kempen, * @@ -351,7 +351,7 @@ lang_index(int id) /* Set (or re-set) the language for the application. */ -void +int plat_set_language(int id) { LANGID lang; @@ -370,14 +370,14 @@ plat_set_language(int id) /* Set new language ID if not already set. */ lang = MAKELANGID(id, dwSubLangID); - if (lang_curr == lang) return; + if (lang_curr == lang) return(1); /* Find language in the table. */ for (ptr = languages; ptr != NULL; ptr = ptr->next) if (ptr->id == id) break; if (ptr == NULL) { pclog("UI: language not supported, not setting.\n"); - return; + return(0); } /* Do we need to unload a resource DLL? */ @@ -393,7 +393,7 @@ plat_set_language(int id) LOAD_LIBRARY_AS_DATAFILE); if (lang_handle == NULL) { pclog("UI: unable to load resource DLL '%ls' !\n", ptr->dll); - return; + return(0); } } @@ -409,6 +409,9 @@ plat_set_language(int id) /* This can be removed, it no longer works since Vista+ */ lcid = MAKELCID(id, SORT_DEFAULT); SetThreadLocale(lcid); + + /* All is good, language set! */ + return(1); }