diff --git a/src/rufus.c b/src/rufus.c index 89364e91..21f3b5f2 100644 --- a/src/rufus.c +++ b/src/rufus.c @@ -2948,11 +2948,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine hFile = CreateFileU(loc_file, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if ((hFile == INVALID_HANDLE_VALUE) || (!WriteFileWithRetry(hFile, loc_data, loc_size, &size, WRITE_RETRIES))) { - uprintf("localization: unable to extract '%s': %s.\n", loc_file, WindowsErrorString()); + uprintf("localization: unable to extract '%s': %s", loc_file, WindowsErrorString()); safe_closehandle(hFile); goto out; } - uprintf("localization: extracted data to '%s'\n", loc_file); + uprintf("localization: extracted data to '%s'", loc_file); safe_closehandle(hFile); } else { safe_sprintf(loc_file, sizeof(loc_file), "%s\\%s", app_dir, rufus_loc); @@ -2962,7 +2962,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine if ( (!get_supported_locales(loc_file)) || ((selected_locale = ((locale_name == NULL)?get_locale_from_lcid(lcid, TRUE):get_locale_from_name(locale_name, TRUE))) == NULL) ) { - uprintf("FATAL: Could not access locale!\n"); + uprintf("FATAL: Could not access locale!"); MessageBoxU(NULL, "The locale data is missing or invalid. This application will now exit.", "Fatal error", MB_ICONSTOP|MB_SYSTEMMODAL); goto out; diff --git a/src/rufus.rc b/src/rufus.rc index fec7df72..69cd1644 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 242, 376 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Rufus 2.7.831" +CAPTION "Rufus 2.7.832" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -319,8 +319,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,7,831,0 - PRODUCTVERSION 2,7,831,0 + FILEVERSION 2,7,832,0 + PRODUCTVERSION 2,7,832,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -337,13 +337,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.7.831" + VALUE "FileVersion", "2.7.832" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.7.831" + VALUE "ProductVersion", "2.7.832" END END BLOCK "VarFileInfo" diff --git a/src/stdfn.c b/src/stdfn.c index a075a438..99235128 100644 --- a/src/stdfn.c +++ b/src/stdfn.c @@ -810,38 +810,3 @@ BOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* s return FALSE; return (BOOL) r; } - -BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, DWORD nNumRetries) -{ - DWORD nTry = 1; - BOOL readFilePointer; - LARGE_INTEGER liFilePointer, liZero = { {0,0} }; - static char* retry_msg = " - retrying..."; - - // Need to get the current file pointer in case we need to retry - readFilePointer = SetFilePointerEx(hFile, liZero, &liFilePointer, FILE_CURRENT); - if (!readFilePointer) - uprintf(" Warning - could not read file pointer: %s", WindowsErrorString()); - - do { - // Need to rewind our file position on retry - if ((nTry > 1) && (!SetFilePointerEx(hFile, liFilePointer, NULL, FILE_BEGIN))) { - uprintf(" Could not set file pointer%s", retry_msg); - goto next_try; - } - if (WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, NULL)) { - if (nNumberOfBytesToWrite == *lpNumberOfBytesWritten) - return TRUE; - uprintf(" Wrote %d bytes but requested %d%s", *lpNumberOfBytesWritten, - nNumberOfBytesToWrite, nTry < nNumRetries ? retry_msg : ""); - SetLastError(ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INCORRECT_SIZE); - } else { - uprintf(" Write error%s", nTry < nNumRetries ? retry_msg : ""); - } -next_try: - Sleep(200); - nTry++; - } while((readFilePointer) && (nTry < nNumRetries)); - return FALSE; -} diff --git a/src/stdio.c b/src/stdio.c index 68db69a0..583bc2ce 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -62,12 +62,14 @@ void _uprintf(const char *format, ...) // Send output to Windows debug facility OutputDebugStringA(buf); - // Send output to our log Window - Edit_SetSel(hLog, MAX_LOG_SIZE, MAX_LOG_SIZE); - Edit_ReplaceSelU(hLog, buf); - // Make sure the message scrolls into view - // (Or see code commented in LogProc:WM_SHOWWINDOW for a less forceful scroll) - SendMessage(hLog, EM_LINESCROLL, 0, SendMessage(hLog, EM_GETLINECOUNT, 0, 0)); + if ((hLog != NULL) && (hLog != INVALID_HANDLE_VALUE)) { + // Send output to our log Window + Edit_SetSel(hLog, MAX_LOG_SIZE, MAX_LOG_SIZE); + Edit_ReplaceSelU(hLog, buf); + // Make sure the message scrolls into view + // (Or see code commented in LogProc:WM_SHOWWINDOW for a less forceful scroll) + SendMessage(hLog, EM_LINESCROLL, 0, SendMessage(hLog, EM_GETLINECOUNT, 0, 0)); + } } #endif @@ -280,3 +282,44 @@ const char* StrError(DWORD error_code, BOOL use_default_locale) toggle_default_locale(); return ret; } + + +BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, + LPDWORD lpNumberOfBytesWritten, DWORD nNumRetries) +{ + DWORD nTry; + BOOL readFilePointer; + LARGE_INTEGER liFilePointer, liZero = { { 0,0 } }; + static char* retry_msg = " - retrying..."; + + // Need to get the current file pointer in case we need to retry + readFilePointer = SetFilePointerEx(hFile, liZero, &liFilePointer, FILE_CURRENT); + if (!readFilePointer) + uprintf(" Warning - Could not read file pointer: %s", WindowsErrorString()); + + if (nNumRetries == 0) + nNumRetries = 1; + for (nTry = 1; nTry <= nNumRetries; nTry++) { + // Need to rewind our file position on retry - if we can't even do that, just give up + if ((nTry > 1) && (!SetFilePointerEx(hFile, liFilePointer, NULL, FILE_BEGIN))) { + uprintf(" Could not set file pointer - aborting"); + break; + } + if (WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, NULL)) { + if (nNumberOfBytesToWrite == *lpNumberOfBytesWritten) + return TRUE; + uprintf(" Wrote %d bytes but requested %d%s", *lpNumberOfBytesWritten, + nNumberOfBytesToWrite, nTry < nNumRetries ? retry_msg : ""); + } + else { + uprintf(" Write error [0x%8X]%s", GetLastError(), nTry < nNumRetries ? retry_msg : ""); + } + // If we can't reposition for the next run, just abort + if (!readFilePointer) + break; + Sleep(200); + } + if (SCODE_CODE(GetLastError()) == ERROR_SUCCESS) + SetLastError(ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT); + return FALSE; +}