From e0b5c6d96f24ae1d4bd2c8a124e3ffe1d04abc54 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Thu, 9 Nov 2023 17:39:38 +0000 Subject: [PATCH] [misc] improve the code related to the commandline hogger deletion * Also small additional code improvements --- _sign.cmd | 2 +- src/rufus.c | 32 ++++++++++++++++---------------- src/rufus.rc | 10 +++++----- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/_sign.cmd b/_sign.cmd index e8c149b3..ca68f4f1 100644 --- a/_sign.cmd +++ b/_sign.cmd @@ -1,2 +1,2 @@ @echo off -"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\signtool" sign /v /sha1 3dbc3a2a0e9ce8803b422cfdbc60acd33164965d /fd SHA256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td SHA256 %1 +"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\signtool" sign /v /sha1 3dbc3a2a0e9ce8803b422cfdbc60acd33164965d /fd SHA256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td SHA256 %* diff --git a/src/rufus.c b/src/rufus.c index 6d719b0b..ba376861 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -3364,8 +3364,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine // and the automated VS2019 package building process doesn't like renaming the .exe // right under its nose (else we would use the same trick as for portable vs regular) // we use yet another workaround to detect if we are running the AppStore version... - static_sprintf(ini_path, "%srufus.app", app_dir); - if (PathFileExistsU(ini_path)) { + static_sprintf(tmp_path, "%srufus.app", app_dir); + if (PathFileExistsU(tmp_path)) { appstore_version = TRUE; goto skip_args_processing; } @@ -3507,7 +3507,7 @@ skip_args_processing: static_strcpy(app_data_dir, app_dir); fclose(fd); } - uprintf("Will use settings from %s", (ini_file != NULL)?"INI file":"registry"); + uprintf("Will use settings from %s", (ini_file != NULL) ? "INI file" : "registry"); // Use the locale specified by the settings, if any tmp = ReadSettingStr(SETTING_LOCALE); @@ -3629,7 +3629,7 @@ skip_args_processing: // Prevent 2 applications from running at the same time, unless "/W" is passed as an option // in which case we wait for the mutex to be relinquished - if ((safe_strlen(lpCmdLine)==2) && (lpCmdLine[0] == '/') && (lpCmdLine[1] == 'W')) + if ((safe_strlen(lpCmdLine) == 2) && (lpCmdLine[0] == '/') && (lpCmdLine[1] == 'W')) wait_for_mutex = 150; // Try to acquire the mutex for 15 seconds mutex = CreateMutexA(NULL, TRUE, "Global/" APPLICATION_NAME); for (;(wait_for_mutex>0) && (mutex != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS); wait_for_mutex--) { @@ -3653,9 +3653,8 @@ skip_args_processing: IGNORE_RETVAL(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)); // Some dialogs have Rich Edit controls and won't display without this - if (GetLibraryHandle("Riched20") == NULL) { - uprintf("Could not load RichEdit library - some dialogs may not display: %s\n", WindowsErrorString()); - } + if (GetLibraryHandle("Riched20") == NULL) + uprintf("Could not load RichEdit library - some dialogs may not display: %s", WindowsErrorString()); // Increase the application privileges (SE_DEBUG_PRIVILEGE), so that we can report // the Windows Services preventing access to the disk or volume we want to format. @@ -4101,10 +4100,14 @@ extern int TestHashes(void); } out: + _chdirU(app_dir); // Destroy the hogger mutex first, so that the cmdline app can exit and we can delete it - if (attached_console && !disable_hogger) { + if (hogmutex != NULL) { ReleaseMutex(hogmutex); safe_closehandle(hogmutex); + // Unconditional delete with retry, just in case... + for (i = 0; (!DeleteFileA(cmdline_hogger)) && (i <= 10); i++) + Sleep(200); } // Kill the update check thread if running if (update_check_thread != NULL) @@ -4126,7 +4129,8 @@ out: safe_free(fido_script); safe_free(pe256ssp); if (argv != NULL) { - for (i=0; i