1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

issue 1243

Move console attach closer to the creation of the hogger, and only even attempt the attach if the user did not request a GUI program.
This commit is contained in:
Charles Stevens 2018-11-10 13:52:58 -06:00
parent 08019ea67c
commit 30fa87afd9

30
src/rufus.c Normal file → Executable file
View file

@ -2694,7 +2694,7 @@ static void PrintUsage(char* appname)
printf(" This usage guide.\n"); printf(" This usage guide.\n");
} }
static HANDLE SetHogger(BOOL attached_console, BOOL disable_hogger) static HANDLE SetHogger(void)
{ {
INPUT* input; INPUT* input;
BYTE* hog_data; BYTE* hog_data;
@ -2702,12 +2702,9 @@ static HANDLE SetHogger(BOOL attached_console, BOOL disable_hogger)
HANDLE hogmutex = NULL, hFile = NULL; HANDLE hogmutex = NULL, hFile = NULL;
int i; int i;
if (!attached_console)
return NULL;
hog_data = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_XT_HOGGER), hog_data = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_XT_HOGGER),
_RT_RCDATA, cmdline_hogger, &hog_size, FALSE); _RT_RCDATA, cmdline_hogger, &hog_size, FALSE);
if ((hog_data != NULL) && (!disable_hogger)) { if (hog_data != NULL) {
// Create our synchronisation mutex // Create our synchronisation mutex
hogmutex = CreateMutexA(NULL, TRUE, "Global/Rufus_CmdLine"); hogmutex = CreateMutexA(NULL, TRUE, "Global/Rufus_CmdLine");
@ -2806,15 +2803,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
uprintf("*** " APPLICATION_NAME " init ***\n"); uprintf("*** " APPLICATION_NAME " init ***\n");
// Reattach the console, if we were started from commandline
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
attached_console = TRUE;
IGNORE_RETVAL(freopen("CONIN$", "r", stdin));
IGNORE_RETVAL(freopen("CONOUT$", "w", stdout));
IGNORE_RETVAL(freopen("CONOUT$", "w", stderr));
_flushall();
}
// We have to process the arguments before we acquire the lock and process the locale // We have to process the arguments before we acquire the lock and process the locale
PF_INIT(__wgetmainargs, Msvcrt); PF_INIT(__wgetmainargs, Msvcrt);
if (pf__wgetmainargs != NULL) { if (pf__wgetmainargs != NULL) {
@ -2843,7 +2831,19 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
ini_flags[0] = 'a'; ini_flags[0] = 'a';
// Now enable the hogger before processing the rest of the arguments // Now enable the hogger before processing the rest of the arguments
hogmutex = SetHogger(attached_console, disable_hogger); if (!disable_hogger)
{
// Reattach the console, if we were started from commandline
if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
attached_console = TRUE;
IGNORE_RETVAL(freopen("CONIN$", "r", stdin));
IGNORE_RETVAL(freopen("CONOUT$", "w", stdout));
IGNORE_RETVAL(freopen("CONOUT$", "w", stderr));
_flushall();
hogmutex = SetHogger();
}
}
while ((opt = getopt_long(argc, argv, "?xghf:i:w:l:", long_options, &option_index)) != EOF) { while ((opt = getopt_long(argc, argv, "?xghf:i:w:l:", long_options, &option_index)) != EOF) {
switch (opt) { switch (opt) {