diff --git a/src/parser.c b/src/parser.c index ea35b2cb..ba38da6e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -352,11 +352,13 @@ out: /* * Parse a locale section in a localization file (UTF-8, no BOM) * NB: this call is reentrant for the "base" command support + * TODO: Working on memory rather than on file would improve performance */ BOOL get_loc_data_file(const char* filename, loc_cmd* lcmd) { size_t bufsize = 1024; static FILE* fd = NULL; + static BOOL populate_default = FALSE; char *buf = NULL; size_t i = 0; int r = 0, line_nr_incr = 1; @@ -367,30 +369,29 @@ BOOL get_loc_data_file(const char* filename, loc_cmd* lcmd) // The default locale is always the first one loc_cmd* default_locale = list_entry(locale_list.next, loc_cmd, list); - // We keep a default message table populated with the en-US messages. - // Ensure that it got properly initialized first. - if ((msg_table == NULL) && (lcmd != NULL)) { - uprintf("localization: default message table has not been populated!"); - return FALSE; - } else if ((msg_table != NULL) && (lcmd == NULL)) { - uprintf("localization: default message table has already been populated!"); - return FALSE; + if ((lcmd == NULL) || (default_locale == NULL)) { + uprintf("localization: no %slocale", (default_locale == NULL)?"default ":" "); + goto out; + } + + if (msg_table == NULL) { + // Initialize the default message table (usually en-US) + msg_table = default_msg_table; + uprintf("localization: initializing default message table"); + populate_default = TRUE; + get_loc_data_file(filename, default_locale); + populate_default = FALSE; } if (!reentrant) { if ((filename == NULL) || (filename[0] == 0)) return FALSE; - if (lcmd == default_locale) { - // The default locale has already been populated => nothing to do - msg_table = default_msg_table; - return TRUE; - } - if (lcmd == NULL) { - // Fill the default table - lcmd = default_locale; - msg_table = default_msg_table; - } else { - // Fill the current table + if (!populate_default) { + if (lcmd == default_locale) { + // The default locale has already been populated => nothing to do + msg_table = default_msg_table; + return TRUE; + } msg_table = current_msg_table; } free_dialog_list(); @@ -404,10 +405,6 @@ BOOL get_loc_data_file(const char* filename, loc_cmd* lcmd) old_loc_line_nr = loc_line_nr; } - if (lcmd == NULL) { - uprintf("Spock gone crazy error!\n"); - goto out; - } offset = (long)lcmd->num[0]; end_offset = (long)lcmd->num[1]; start_line = lcmd->line_nr; diff --git a/src/rufus.c b/src/rufus.c index e54e2283..047aaa93 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -2064,7 +2064,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine { const char* old_wait_option = "/W"; int i, opt, option_index = 0, argc = 0, si = 0, lcid = GetUserDefaultUILanguage(); - BOOL attached_console = FALSE, external_loc_file = FALSE; + BOOL attached_console = FALSE, external_loc_file = FALSE, lgp_set = FALSE; BYTE* loc_data; DWORD loc_size, Size; char tmp_path[MAX_PATH], loc_file[MAX_PATH] = "", *tmp, *locale_name = NULL; @@ -2215,10 +2215,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine // We use local group policies rather than direct registry manipulation // 0x9e disables removable and fixed drive notifications - SetLGP(FALSE, &existing_key, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDriveTypeAutorun", 0x9e); - - // Populate the default locale (so that we can produce English messages in the log) - get_loc_data_file(loc_file, NULL); + lgp_set = SetLGP(FALSE, &existing_key, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDriveTypeAutorun", 0x9e); relaunch: uprintf("localization: using locale '%s'\n", selected_locale->txt[0]); @@ -2343,7 +2340,8 @@ out: for (i=0; i