diff --git a/src/drive.c b/src/drive.c index 1fa40018..e84c773f 100644 --- a/src/drive.c +++ b/src/drive.c @@ -486,10 +486,8 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label) { HANDLE hPhysical; DWORD size; - char AutorunPath[] = "#:\\autorun.inf", *AutorunLabel = NULL; - wchar_t wDrivePath[] = L"#:\\"; - wchar_t wVolumeLabel[MAX_PATH+1]; - static char VolumeLabel[MAX_PATH+1]; + static char VolumeLabel[MAX_PATH + 1]; + char DrivePath[] = "#:\\", AutorunPath[] = "#:\\autorun.inf", *AutorunLabel = NULL; *label = STR_NO_LABEL; @@ -501,7 +499,7 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label) } // We only care about an autorun.inf if we have a single volume AutorunPath[0] = letters[0]; - wDrivePath[0] = letters[0]; + DrivePath[0] = letters[0]; // Try to read an extended label from autorun first. Fallback to regular label if not found. // In the case of card readers with no card, users can get an annoying popup asking them @@ -518,10 +516,11 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label) safe_strcpy(VolumeLabel, sizeof(VolumeLabel), AutorunLabel); safe_free(AutorunLabel); *label = VolumeLabel; - } else if (GetVolumeInformationW(wDrivePath, wVolumeLabel, ARRAYSIZE(wVolumeLabel), - NULL, NULL, NULL, NULL, 0) && *wVolumeLabel) { - wchar_to_utf8_no_alloc(wVolumeLabel, VolumeLabel, sizeof(VolumeLabel)); + } else if (GetVolumeInformationU(DrivePath, VolumeLabel, ARRAYSIZE(VolumeLabel), + NULL, NULL, NULL, NULL, 0) && (VolumeLabel[0] != 0)) { *label = VolumeLabel; + } else { + duprintf("Failed to read label: %s", WindowsErrorString()); } return TRUE; diff --git a/src/format.c b/src/format.c index b78495d4..bf4e67b1 100644 --- a/src/format.c +++ b/src/format.c @@ -1848,6 +1848,13 @@ DWORD WINAPI FormatThread(void* param) } CHECK_FOR_USER_CANCEL; + // Refresh the drive label - This is needed as Windows may have altered it from + // the name we proposed, and we require an exact label, to patch config files. + if (!GetVolumeInformationU(drive_name, img_report.usb_label, ARRAYSIZE(img_report.usb_label), + NULL, NULL, NULL, NULL, 0)) { + uprintf("Warning: Failed to refresh label: %s", WindowsErrorString()); + } + if (IsChecked(IDC_BOOT)) { if (bt == BT_UEFI_NTFS) { // All good diff --git a/src/msapi_utf8.h b/src/msapi_utf8.h index 4fccd257..44174f79 100644 --- a/src/msapi_utf8.h +++ b/src/msapi_utf8.h @@ -70,7 +70,7 @@ extern "C" { #define sfree(p) do {if (p != NULL) {free((void*)(p)); p = NULL;}} while(0) #define wconvert(p) wchar_t* w ## p = utf8_to_wchar(p) -#define walloc(p, size) wchar_t* w ## p = (wchar_t*)calloc(size, sizeof(wchar_t)) +#define walloc(p, size) wchar_t* w ## p = (p == NULL)?NULL:(wchar_t*)calloc(size, sizeof(wchar_t)) #define wfree(p) sfree(w ## p) /* @@ -107,6 +107,9 @@ static __inline wchar_t* utf8_to_wchar(const char* str) int size = 0; wchar_t* wstr = NULL; + if (str == NULL) + return NULL; + // Find out the size we need to allocate for our converted string size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); if (size <= 1) // An empty string would be size 1 @@ -867,7 +870,8 @@ static __inline int _mkdirU(const char* dirname) static __inline BOOL SetupDiGetDeviceRegistryPropertyU(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize) { - DWORD ret = FALSE, err = ERROR_INVALID_DATA; + BOOL ret = FALSE; + DWORD err = ERROR_INVALID_DATA; walloc(PropertyBuffer, PropertyBufferSize); ret = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, @@ -883,6 +887,37 @@ static __inline BOOL SetupDiGetDeviceRegistryPropertyU(HDEVINFO DeviceInfoSet, P return ret; } +static __inline BOOL GetVolumeInformationU(LPCSTR lpRootPathName, LPSTR lpVolumeNameBuffer, + DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber, LPDWORD lpMaximumComponentLength, + LPDWORD lpFileSystemFlags, LPSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize) +{ + BOOL ret = FALSE; + DWORD err = ERROR_INVALID_DATA; + wconvert(lpRootPathName); + walloc(lpVolumeNameBuffer, nVolumeNameSize); + walloc(lpFileSystemNameBuffer, nFileSystemNameSize); + + ret = GetVolumeInformationW(wlpRootPathName, wlpVolumeNameBuffer, nVolumeNameSize, + lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, + wlpFileSystemNameBuffer, nFileSystemNameSize); + err = GetLastError(); + if (ret) { + if ( ((lpVolumeNameBuffer != NULL) && (wchar_to_utf8_no_alloc(wlpVolumeNameBuffer, + lpVolumeNameBuffer, nVolumeNameSize) == 0)) + || ((lpFileSystemNameBuffer != NULL) && (wchar_to_utf8_no_alloc(wlpFileSystemNameBuffer, + lpFileSystemNameBuffer, nFileSystemNameSize) == 0)) ) { + err = GetLastError(); + ret = FALSE; + } + } + wfree(lpVolumeNameBuffer); + wfree(lpFileSystemNameBuffer); + wfree(lpRootPathName); + SetLastError(err); + return ret; +} + + #ifdef __cplusplus } #endif diff --git a/src/rufus.rc b/src/rufus.rc index 4b55397e..61bb4ab4 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,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 EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 2.10.962" +CAPTION "Rufus 2.10.963" FONT 8, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8 @@ -320,8 +320,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,10,962,0 - PRODUCTVERSION 2,10,962,0 + FILEVERSION 2,10,963,0 + PRODUCTVERSION 2,10,963,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -338,13 +338,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.10.962" + VALUE "FileVersion", "2.10.963" 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.10.962" + VALUE "ProductVersion", "2.10.963" END END BLOCK "VarFileInfo"