diff --git a/src/net.c b/src/net.c index 7d4a89f4..c2f9d19e 100644 --- a/src/net.c +++ b/src/net.c @@ -221,8 +221,8 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog) { HWND hProgressBar = NULL; BOOL r = FALSE; - DWORD dwFlags, dwSize, dwDownloaded, dwTotalSize; - FILE* fd = NULL; + DWORD dwFlags, dwSize, dwWritten, dwDownloaded, dwTotalSize; + HANDLE hFile = INVALID_HANDLE_VALUE; const char* accept_types[] = {"*/*\0", NULL}; unsigned char buf[DOWNLOAD_BUFFER_SIZE]; char agent[64], hostname[64], urlpath[128]; @@ -318,8 +318,8 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog) } uprintf("File length: %d bytes\n", dwTotalSize); - fd = fopenU(file, "wb"); - if (fd == NULL) { + hFile = CreateFileU(file, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) { uprintf("Unable to create file '%s': %s\n", &file[last_slash], WinInetErrorString()); goto out; } @@ -335,9 +335,12 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog) dwSize += dwDownloaded; SendMessage(hProgressBar, PBM_SETPOS, (WPARAM)(MAX_PROGRESS*((1.0f*dwSize)/(1.0f*dwTotalSize))), 0); PrintInfo(0, MSG_241, (100.0f*dwSize)/(1.0f*dwTotalSize)); - if (fwrite(buf, 1, dwDownloaded, fd) != dwDownloaded) { + if (!WriteFile(hFile, buf, dwDownloaded, &dwWritten, NULL)) { uprintf("Error writing file '%s': %s\n", &file[last_slash], WinInetErrorString()); goto out; + } else if (dwDownloaded != dwWritten) { + uprintf("Error writing file '%s': Only %d/%d bytes written\n", dwWritten, dwDownloaded); + goto out; } } @@ -353,7 +356,11 @@ DWORD DownloadFile(const char* url, const char* file, HWND hProgressDialog) out: if (hProgressDialog != NULL) SendMessage(hProgressDialog, UM_PROGRESS_EXIT, (WPARAM)r, 0); - if (fd != NULL) fclose(fd); + if (hFile != INVALID_HANDLE_VALUE) { + // Force a flush - May help with the PKI API trying to process downloaded updates too early... + FlushFileBuffers(hFile); + CloseHandle(hFile); + } if (!r) { if (file != NULL) _unlinkU(file); diff --git a/src/pki.c b/src/pki.c index ba041abb..b0e5c2f2 100644 --- a/src/pki.c +++ b/src/pki.c @@ -141,6 +141,7 @@ char* GetSignatureName(const char* path, const char* country_code) static char szSubjectName[128]; char szCountry[3] = "__"; char *p = NULL, *mpath = NULL; + int i; BOOL r; HMODULE hm; HCERTSTORE hStore = NULL; @@ -174,13 +175,21 @@ char* GetSignatureName(const char* path, const char* country_code) } // Get message handle and store handle from the signed file. - r = CryptQueryObject(CERT_QUERY_OBJECT_FILE, szFileName, - CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, CERT_QUERY_FORMAT_FLAG_BINARY, - 0, &dwEncoding, &dwContentType, &dwFormatType, &hStore, &hMsg, NULL); - if (!r) { - uprintf("PKI: Failed to get signature for '%s': %s", (path==NULL)?mpath:path, WinPKIErrorString()); - goto out; + for (i = 0; i < 5; i++) { + r = CryptQueryObject(CERT_QUERY_OBJECT_FILE, szFileName, + CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, CERT_QUERY_FORMAT_FLAG_BINARY, + 0, &dwEncoding, &dwContentType, &dwFormatType, &hStore, &hMsg, NULL); + if (r) + break; + if (i == 0) + uprintf("PKI: Failed to get signature for '%s': %s", (path==NULL)?mpath:path, WinPKIErrorString()); + if (path == NULL) + break; + uprintf("PKI: Retrying..."); + Sleep(2000); } + if (!r) + goto out; // Get signer information size. r = CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &dwSignerInfo); diff --git a/src/rufus.rc b/src/rufus.rc index 2230b034..4fb3389b 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 3.0.1278" +CAPTION "Rufus 3.0.1279" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -389,8 +389,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,0,1278,0 - PRODUCTVERSION 3,0,1278,0 + FILEVERSION 3,0,1279,0 + PRODUCTVERSION 3,0,1279,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -407,13 +407,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.0.1278" + VALUE "FileVersion", "3.0.1279" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.0.1278" + VALUE "ProductVersion", "3.0.1279" END END BLOCK "VarFileInfo"