mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[iso] reload label after formatting
* The Windows APIs may further modify the label compared to our proposed version (e.g. remove trailing spaces), and we need an exact label for the Syslinux/GRUB config file update. * This issue was reported against Springdale Linux, where the isolinux.cfg label was patched using 'SPRINGDALE\x20' instead of 'SPRINGDALE' * Closes #784 * Also ensure that we don't replace NULL buffers in msapi_utf8.h and add GetVolumeInformationU()
This commit is contained in:
		
							parent
							
								
									60517f1e50
								
							
						
					
					
						commit
						ed1b3fd72e
					
				
					 4 changed files with 56 additions and 15 deletions
				
			
		
							
								
								
									
										13
									
								
								src/drive.c
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								src/drive.c
									
										
									
									
									
								
							|  | @ -486,10 +486,8 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label) | ||||||
| { | { | ||||||
| 	HANDLE hPhysical; | 	HANDLE hPhysical; | ||||||
| 	DWORD size; | 	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; | 	*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
 | 	// We only care about an autorun.inf if we have a single volume
 | ||||||
| 	AutorunPath[0] = letters[0]; | 	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.
 | 	// 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
 | 	// 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_strcpy(VolumeLabel, sizeof(VolumeLabel), AutorunLabel); | ||||||
| 		safe_free(AutorunLabel); | 		safe_free(AutorunLabel); | ||||||
| 		*label = VolumeLabel; | 		*label = VolumeLabel; | ||||||
| 	} else if (GetVolumeInformationW(wDrivePath, wVolumeLabel, ARRAYSIZE(wVolumeLabel), | 	} else if (GetVolumeInformationU(DrivePath, VolumeLabel, ARRAYSIZE(VolumeLabel), | ||||||
| 		NULL, NULL, NULL, NULL, 0) && *wVolumeLabel) { | 		NULL, NULL, NULL, NULL, 0) && (VolumeLabel[0] != 0)) { | ||||||
| 		wchar_to_utf8_no_alloc(wVolumeLabel, VolumeLabel, sizeof(VolumeLabel)); |  | ||||||
| 		*label = VolumeLabel; | 		*label = VolumeLabel; | ||||||
|  | 	} else { | ||||||
|  | 		duprintf("Failed to read label: %s", WindowsErrorString()); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return TRUE; | 	return TRUE; | ||||||
|  |  | ||||||
|  | @ -1848,6 +1848,13 @@ DWORD WINAPI FormatThread(void* param) | ||||||
| 	} | 	} | ||||||
| 	CHECK_FOR_USER_CANCEL; | 	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 (IsChecked(IDC_BOOT)) { | ||||||
| 		if (bt == BT_UEFI_NTFS) { | 		if (bt == BT_UEFI_NTFS) { | ||||||
| 			// All good
 | 			// All good
 | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ extern "C" { | ||||||
| 
 | 
 | ||||||
| #define sfree(p) do {if (p != NULL) {free((void*)(p)); p = NULL;}} while(0) | #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 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) | #define wfree(p) sfree(w ## p) | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  | @ -107,6 +107,9 @@ static __inline wchar_t* utf8_to_wchar(const char* str) | ||||||
| 	int size = 0; | 	int size = 0; | ||||||
| 	wchar_t* wstr = NULL; | 	wchar_t* wstr = NULL; | ||||||
| 
 | 
 | ||||||
|  | 	if (str == NULL) | ||||||
|  | 		return NULL; | ||||||
|  | 
 | ||||||
| 	// Find out the size we need to allocate for our converted string
 | 	// Find out the size we need to allocate for our converted string
 | ||||||
| 	size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); | 	size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); | ||||||
| 	if (size <= 1)	// An empty string would be size 1
 | 	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, | static __inline BOOL SetupDiGetDeviceRegistryPropertyU(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, | ||||||
| 	DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize) | 	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); | 	walloc(PropertyBuffer, PropertyBufferSize); | ||||||
| 
 | 
 | ||||||
| 	ret = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, | 	ret = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, | ||||||
|  | @ -883,6 +887,37 @@ static __inline BOOL SetupDiGetDeviceRegistryPropertyU(HDEVINFO DeviceInfoSet, P | ||||||
| 	return ret; | 	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 | #ifdef __cplusplus | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 242, 376 | IDD_DIALOG DIALOGEX 12, 12, 242, 376 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| EXSTYLE WS_EX_ACCEPTFILES | EXSTYLE WS_EX_ACCEPTFILES | ||||||
| CAPTION "Rufus 2.10.962" | CAPTION "Rufus 2.10.963" | ||||||
| FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 |     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 | ||||||
|  | @ -320,8 +320,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 2,10,962,0 |  FILEVERSION 2,10,963,0 | ||||||
|  PRODUCTVERSION 2,10,962,0 |  PRODUCTVERSION 2,10,963,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -338,13 +338,13 @@ BEGIN | ||||||
|         BEGIN |         BEGIN | ||||||
|             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" |             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "2.10.962" |             VALUE "FileVersion", "2.10.963" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" |             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" | ||||||
|             VALUE "OriginalFilename", "rufus.exe" |             VALUE "OriginalFilename", "rufus.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "2.10.962" |             VALUE "ProductVersion", "2.10.963" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue