Skip to content

Commit ecccf27

Browse files
Misc fixes
1 parent 71fed03 commit ecccf27

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

ffrunner.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ gen_temp_file(char *outPath)
591591
HANDLE hFile;
592592
DWORD fileFlags = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY;
593593

594-
if (!GetTempPath2A(MAX_PATH, tempPath)) {
595-
logmsg("GetTempPath2A failed: %d\n", GetLastError());
594+
if (!GetTempPathA(MAX_PATH, tempPath)) {
595+
logmsg("GetTempPathA failed: %d\n", GetLastError());
596596
return INVALID_HANDLE_VALUE;
597597
}
598598

@@ -617,7 +617,7 @@ gen_temp_file(char *outPath)
617617
return hFile;
618618
}
619619

620-
void
620+
bool
621621
fetch_icon(char *iconUrl, char *outPath)
622622
{
623623
HANDLE iconFile;
@@ -626,27 +626,30 @@ fetch_icon(char *iconUrl, char *outPath)
626626

627627
iconFile = gen_temp_file(outPath);
628628
if (iconFile == INVALID_HANDLE_VALUE) {
629-
return;
629+
logmsg("Failed to create temp file for icon: %d\n", GetLastError());
630+
return false;
630631
}
631632

633+
logmsg("Downloading icon to %s\n", outPath);
632634
doneSignal = CreateEventA(NULL, TRUE, FALSE, NULL);
633635
register_temp_request(iconUrl, iconFile, doneSignal);
634636

635-
waitResult = WaitForSingleObject(doneSignal, 5000);
637+
/* 3-second timeout for icon download so we don't hang if something goes wrong */
638+
waitResult = WaitForSingleObject(doneSignal, 3000);
636639
CloseHandle(doneSignal);
637-
complete_request();
638640

639641
if (waitResult == WAIT_OBJECT_0) {
640642
logmsg("Icon downloaded successfully.\n");
641643
CloseHandle(iconFile);
642-
return;
644+
return true;
643645
} else if (waitResult == WAIT_TIMEOUT) {
644646
logmsg("Failed to download icon within timeout.\n");
645647
} else {
646648
logmsg("Error while waiting for icon download: %d\n", GetLastError());
647649
}
648650

649651
CloseHandle(iconFile);
652+
return false;
650653
}
651654

652655
int
@@ -721,11 +724,14 @@ main(int argc, char **argv)
721724

722725
srcUrl = args.mainPathOrAddress;
723726
init_network(srcUrl);
727+
logmsg("Request pool initialized\n");
724728

725729
char *iconToUse = NULL;
726730
if (args.windowIcon) {
727-
fetch_icon(args.windowIcon, iconFile);
728-
iconToUse = iconFile;
731+
logmsg("Fetching icon: %s\n", args.windowIcon);
732+
if (fetch_icon(args.windowIcon, iconFile)) {
733+
iconToUse = iconFile;
734+
}
729735
}
730736

731737
prepare_window(args.windowWidth, args.windowHeight, iconToUse);

graphics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ prepare_window(uint32_t width, uint32_t height, const char *iconFile)
8888
wc.style = CS_DBLCLKS;
8989

9090
if (iconFile) {
91-
hIcon = (HICON)LoadImageA(NULL, iconFile, IMAGE_ICON, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
91+
hIcon = (HICON)LoadImageA(NULL, iconFile, IMAGE_ICON, 256, 256, LR_LOADFROMFILE);
9292
if (!hIcon) {
9393
logmsg("Failed to load icon from %s: %d\n", iconFile, GetLastError());
9494
}

requests.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ handle_request(PTP_CALLBACK_INSTANCE inst, void *reqArg, PTP_WORK work)
523523
}
524524
}
525525

526-
void
527-
submit_request(Request *req)
526+
static void
527+
submit_request_work(Request *req)
528528
{
529529
PTP_WORK work;
530530

@@ -535,6 +535,12 @@ submit_request(Request *req)
535535
assert(work);
536536

537537
SubmitThreadpoolWork(work);
538+
}
539+
540+
void
541+
submit_request(Request *req)
542+
{
543+
submit_request_work(req);
538544
nRequests++;
539545
}
540546

@@ -602,7 +608,7 @@ register_temp_request(const char *url, HANDLE outFile, HANDLE onDone)
602608
};
603609
strncpy(req->originalUrl, url, MAX_URL_LENGTH);
604610

605-
submit_request(req);
611+
submit_request_work(req);
606612
}
607613

608614
void complete_request()

0 commit comments

Comments
 (0)