[loc] fix crash when two Rufus applications are running

* Closes #261
* Also remove the need for a separate get_loc_data_file call to
  initialize the en-US messages
* Also fix a possible issue with setLGP
This commit is contained in:
Pete Batard 2013-12-28 16:48:02 +00:00
parent 83a9ec472c
commit 0f02284164
3 changed files with 29 additions and 34 deletions

View File

@ -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;

View File

@ -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<argc; i++) safe_free(argv[i]);
safe_free(argv);
}
SetLGP(TRUE, &existing_key, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDriveTypeAutorun", 0);
if (lgp_set)
SetLGP(TRUE, &existing_key, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", "NoDriveTypeAutorun", 0);
if (attached_console)
DetachConsole();
CloseHandle(mutex);

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.4.2.365"
CAPTION "Rufus v1.4.2.366"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -288,8 +288,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,2,365
PRODUCTVERSION 1,4,2,365
FILEVERSION 1,4,2,366
PRODUCTVERSION 1,4,2,366
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -306,13 +306,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.4.2.365"
VALUE "FileVersion", "1.4.2.366"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2013 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.4.2.365"
VALUE "ProductVersion", "1.4.2.366"
END
END
BLOCK "VarFileInfo"