From af3607715a3d719a7035754a7048766f91523ea6 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Thu, 1 Dec 2011 15:01:10 +0000 Subject: [PATCH] [ui] fs and cluster size selection improvements * also added support for FCC_DONE_WITH_STRUCTURE which is used on Small FAT16 formatting --- rufus.c | 130 +++++++++++++++++++++++++++++++++++++++---------------- rufus.h | 6 ++- rufus.rc | 12 ++--- 3 files changed, 102 insertions(+), 46 deletions(-) diff --git a/rufus.c b/rufus.c index 7c2ae2d1..0246895e 100644 --- a/rufus.c +++ b/rufus.c @@ -57,10 +57,11 @@ const GUID GUID_DEVINTERFACE_DISK = { 0x53f56307L, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b} }; #endif +const char* FileSystemLabel[FS_MAX] = { "FAT", "FAT32", "NTFS", "exFAT" }; // Don't ask me - just following the MS standard here -const char* ClusterSizeLabel[] = {"512 bytes", "1024 bytes","2048 bytes","4096 bytes","8192 bytes", +const char* ClusterSizeLabel[] = { "512 bytes", "1024 bytes","2048 bytes","4096 bytes","8192 bytes", "16 kilobytes", "32 kilobytes", "64 kilobytes", "128 kilobytes", "256 kilobytes", "512 kilobytes", - "1024 kilobytes","2048 kilobytes","4096 kilobytes","8192 kilobytes","16 megabytes","32 megabytes"}; + "1024 kilobytes","2048 kilobytes","4096 kilobytes","8192 kilobytes","16 megabytes","32 megabytes" }; // For MinGW #ifndef PBS_MARQUEE @@ -78,6 +79,8 @@ HWND hMainDialog; char szFolderPath[MAX_PATH]; HWND hStatus; float fScale = 1.0f; +int default_fs; +ULONG default_clutersize; BOOL bBootable; BOOL bQuickFormat; @@ -87,7 +90,7 @@ struct { LONGLONG DiskSize; DISK_GEOMETRY Geometry; DWORD FirstSector; - enum _FSType FSType; + int FSType; struct { ULONG Allowed; ULONG Default; @@ -123,13 +126,15 @@ void _uprintf(const char *format, ...) } #endif -void DumpBufferHex(unsigned char *buffer, size_t size) +void DumpBufferHex(void *buf, size_t size) { + unsigned char* buffer = (unsigned char*)buf; size_t i, j, k; char line[80] = ""; for (i=0; i= FS_MAX)) { + uprintf("Invalid FS value passed to SetClusterSizes\n"); + return FALSE; + } + if ( (SelectedDrive.ClusterSize[FSType].Allowed == 0) || (SelectedDrive.ClusterSize[FSType].Default == 0) ) { uprintf("The drive is incompatible with FS type #%d\n", FSType); @@ -503,27 +530,44 @@ static BOOL GetDriveInfo(void) safe_closehandle(hDrive); - SelectedDrive.FSType = FS_DEFAULT; + if (!DefineClusterSizes()) { + uprintf("no file system is selectable for this drive\n"); + return FALSE; + } + // re-select existing FS if it's one we know if (GetVolumeInformationA(DrivePath, NULL, 0, NULL, NULL, NULL, fs_type, sizeof(fs_type))) { - // re-select existing FS if it's one we know - for (SelectedDrive.FSType=FS_FAT16; SelectedDrive.FSType=0; SelectedDrive.FSType--) { + if (safe_strcmp(fs_type, FileSystemLabel[SelectedDrive.FSType]) == 0) { break; } } - if (SelectedDrive.FSType == FS_MAX) - SelectedDrive.FSType = FS_DEFAULT; + } else { + SelectedDrive.FSType = FS_UNKNOWN; } - IGNORE_RETVAL(ComboBox_SetCurSel(hFileSystem, SelectedDrive.FSType)); - DefineClusterSizes(); - SetClusterSizes(SelectedDrive.FSType); - return TRUE; + for (i=0; i pick default + for (i=0; i enable formatting + EnableWindow(GetDlgItem(hMainDialog, IDC_START), TRUE); + + return SetClusterSizes((int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))); } /* @@ -540,6 +584,7 @@ static BOOL PopulateProperties(int ComboIndex) IGNORE_RETVAL(ComboBox_ResetContent(hCapacity)); IGNORE_RETVAL(ComboBox_ResetContent(hFileSystem)); IGNORE_RETVAL(ComboBox_ResetContent(hClusterSize)); + EnableWindow(GetDlgItem(hMainDialog, IDC_START), FALSE); SetWindowTextA(hLabel, ""); DestroyTooltip(hDeviceTooltip); DestroyTooltip(hFSTooltip); @@ -551,12 +596,6 @@ static BOOL PopulateProperties(int ComboIndex) return TRUE; } - // Populate the FileSystem values - IGNORE_RETVAL(ComboBox_AddStringU(hFileSystem, "FAT")); - IGNORE_RETVAL(ComboBox_AddStringU(hFileSystem, "FAT32")); - IGNORE_RETVAL(ComboBox_AddStringU(hFileSystem, "NTFS")); - IGNORE_RETVAL(ComboBox_AddStringU(hFileSystem, "exFAT")); - SelectedDrive.DeviceNumber = (DWORD)ComboBox_GetItemData(hDeviceList, ComboIndex); if (!GetDriveInfo()) return FALSE; @@ -645,7 +684,7 @@ static BOOL CreatePartition(HANDLE hDrive) /* * FormatEx callback. Return FALSE to halt operations */ -static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DWORD Action, PVOID Data) +static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DWORD Action, PVOID pData) { DWORD* percent; int task_number = 0; @@ -655,7 +694,7 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, switch(Command) { case FCC_PROGRESS: - percent = (DWORD*)Data; + percent = (DWORD*)pData; PostMessage(hMainDialog, UM_FORMAT_PROGRESS, (WPARAM)*percent, (LPARAM)0); uprintf("%d percent completed.\n", *percent); break; @@ -663,11 +702,17 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, uprintf("Format task %d/? completed.\n", ++task_number); break; case FCC_DONE: - if(*(BOOLEAN*)Data == FALSE) { + if(*(BOOLEAN*)pData == FALSE) { uprintf("Error while formatting.\n"); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE; } break; + case FCC_DONE_WITH_STRUCTURE: // We get this message when formatting Small FAT16 + // pData Seems to be a struct with at least one (32 BIT!!!) string pointer to the size in MB + uprintf("Done with that sort of things: Action=%d pData=%0p\n", Action, pData); + DumpBufferHex(pData, 8); + uprintf("Volume size: %s MB\n", (char*)(LONG_PTR)(*(ULONG32*)pData)); + break; case FCC_INCOMPATIBLE_FILE_SYSTEM: uprintf("Incompatible File System\n"); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INCOMPATIBLE_FS; @@ -693,7 +738,7 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_LABEL_TOO_LONG; break; case FCC_OUTPUT: - uprintf("%s\n", ((PTEXTOUTPUT)Data)->Output); + uprintf("%s\n", ((PTEXTOUTPUT)pData)->Output); break; case FCC_CLUSTER_SIZE_TOO_BIG: case FCC_CLUSTER_SIZE_TOO_SMALL: @@ -726,6 +771,7 @@ static BOOL FormatDrive(char DriveLetter) WCHAR wDriveRoot[] = L"?:\\"; WCHAR wFSType[32]; WCHAR wLabel[128]; + size_t i; wDriveRoot[0] = (WCHAR)DriveLetter; PrintStatus("Formatting..."); @@ -733,6 +779,14 @@ static BOOL FormatDrive(char DriveLetter) // TODO: properly set MediaType GetWindowTextW(hFileSystem, wFSType, ARRAYSIZE(wFSType)); + // We may have a " (Default)" trail + for (i=0; ihttps://github.com/pbatard/rufus",IDC_ABOUT_RUFUS_URL, "SysLink",WS_TABSTOP,46,47,114,9 - LTEXT "Version 1.0.0 (Build 54)",IDC_STATIC,46,19,78,8 + LTEXT "Version 1.0.0 (Build 55)",IDC_STATIC,46,19,78,8 PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 @@ -162,8 +162,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,54 - PRODUCTVERSION 1,0,0,54 + FILEVERSION 1,0,0,55 + PRODUCTVERSION 1,0,0,55 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -180,13 +180,13 @@ BEGIN BEGIN VALUE "CompanyName", "akeo.ie" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "1.0.0.54" + VALUE "FileVersion", "1.0.0.55" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "1.0.0.54" + VALUE "ProductVersion", "1.0.0.55" END END BLOCK "VarFileInfo" @@ -212,7 +212,7 @@ IDI_ICON ICON "rufus.ico" STRINGTABLE BEGIN - IDS_VERSION "Rufus v1.0.0.54" + IDS_VERSION "Rufus v1.0.0.55" END #endif // English resources