1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[misc] factorize SizeToHumanReadable() and ensure log sizes are in English

* Also use an allocated buffer for DD operations
This commit is contained in:
Pete Batard 2014-02-17 22:41:04 +00:00
parent 5ad2ac0d47
commit b83b087b52
7 changed files with 33 additions and 40 deletions

View file

@ -2,10 +2,11 @@ o Version 1.4.4 (2013.02.??)
Add *uncompressed* DD Image support (FreeBSD, FreeNAS, etc.) Add *uncompressed* DD Image support (FreeBSD, FreeNAS, etc.)
Add right-to-left language support Add right-to-left language support
Add NTFS Compression support (unofficial) Add NTFS Compression support (unofficial)
Improve Syslinux v5+ support (requires an internet connection to download extra files)
Improve hotplug detection Improve hotplug detection
Fix detection for Toshiba drives (again) Improve Syslinux v5+ support (requires an internet connection to download extra files)
Fix support for latest gparted, ArchLinux, and other Syslinux v5+ based ISOs Fix support for latest gparted, ArchLinux, and other Syslinux v5+ based ISOs
Fix detection for Toshiba drives (again)
Fix UDF Unicode support
o Version 1.4.3 (2013.01.21) [BUGFIX RELEASE] o Version 1.4.3 (2013.01.21) [BUGFIX RELEASE]
Fix format operation not starting on Windows XP (reported by ank91) Fix format operation not starting on Windows XP (reported by ank91)

View file

@ -617,7 +617,7 @@ int GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSyst
part_type = DriveLayout->PartitionEntry[i].Mbr.PartitionType; part_type = DriveLayout->PartitionEntry[i].Mbr.PartitionType;
uprintf(" Type: %s (0x%02x)\r\n Size: %s (%lld bytes)\r\n Start Sector: %d, Boot: %s, Recognized: %s\n", uprintf(" Type: %s (0x%02x)\r\n Size: %s (%lld bytes)\r\n Start Sector: %d, Boot: %s, Recognized: %s\n",
((part_type==0x07)&&(FileSystemName[0]!=0))?FileSystemName:GetPartitionType(part_type), part_type, ((part_type==0x07)&&(FileSystemName[0]!=0))?FileSystemName:GetPartitionType(part_type), part_type,
SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE),
DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors, DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors,
DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No", DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No"); DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No");
@ -641,7 +641,7 @@ int GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSyst
uprintf("Partition %d:\r\n Type: %s\r\n Name: '%s'\n", DriveLayout->PartitionEntry[i].PartitionNumber, uprintf("Partition %d:\r\n Type: %s\r\n Name: '%s'\n", DriveLayout->PartitionEntry[i].PartitionNumber,
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp); GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp);
uprintf(" ID: %s\r\n Size: %s (%lld bytes)\r\n Start Sector: %lld, Attributes: 0x%016llX\n", uprintf(" ID: %s\r\n Size: %s (%lld bytes)\r\n Start Sector: %lld, Attributes: 0x%016llX\n",
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength), GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE),
DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].StartingOffset.QuadPart / DiskGeometry->Geometry.BytesPerSector, DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].StartingOffset.QuadPart / DiskGeometry->Geometry.BytesPerSector,
DriveLayout->PartitionEntry[i].Gpt.Attributes); DriveLayout->PartitionEntry[i].Gpt.Attributes);
} }

View file

@ -569,7 +569,7 @@ static BOOL FormatFAT32(DWORD DriveIndex)
} }
// Now we're committed - print some info first // Now we're committed - print some info first
uprintf("Size : %s %u sectors\n", SizeToHumanReadable(piDrive.PartitionLength), TotalSectors); uprintf("Size : %s %u sectors\n", SizeToHumanReadable(piDrive.PartitionLength.QuadPart, TRUE), TotalSectors);
uprintf("Cluster size %d bytes, %d Bytes Per Sector\n", SectorsPerCluster*BytesPerSect, BytesPerSect); uprintf("Cluster size %d bytes, %d Bytes Per Sector\n", SectorsPerCluster*BytesPerSect, BytesPerSect);
uprintf("Volume ID is %x:%x\n", VolumeId>>16, VolumeId&0xffff); uprintf("Volume ID is %x:%x\n", VolumeId>>16, VolumeId&0xffff);
uprintf("%d Reserved Sectors, %d Sectors per FAT, %d FATs\n", ReservedSectCount, FatSize, NumFATs); uprintf("%d Reserved Sectors, %d Sectors per FAT, %d FATs\n", ReservedSectCount, FatSize, NumFATs);
@ -1184,7 +1184,7 @@ DWORD WINAPI FormatThread(void* param)
FILE* log_fd; FILE* log_fd;
LARGE_INTEGER li; LARGE_INTEGER li;
uint64_t wb; uint64_t wb;
uint8_t buffer[65536]; uint8_t *buffer = NULL;
char *bb_msg, *guid_volume = NULL; char *bb_msg, *guid_volume = NULL;
char drive_name[] = "?:\\"; char drive_name[] = "?:\\";
char drive_letters[27]; char drive_letters[27];
@ -1334,11 +1334,18 @@ DWORD WINAPI FormatThread(void* param)
} }
uprintf("Writing Image..."); uprintf("Writing Image...");
buffer = (uint8_t*)malloc(DD_BUFFER_SIZE);
if (buffer == NULL) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY;
uprintf("could not allocate DD buffer");
goto out;
}
// Don't bother trying for something clever, using double buffering overlapped and whatnot: // Don't bother trying for something clever, using double buffering overlapped and whatnot:
// With Windows' default optimizations, sync read + sync write for sequential operations // With Windows' default optimizations, sync read + sync write for sequential operations
// will be as fast, if not faster, than whatever async scheme you can come up with. // will be as fast, if not faster, than whatever async scheme you can come up with.
for (wb = 0; ; wb += wSize) { for (wb = 0; ; wb += wSize) {
s = ReadFile(hSourceImage, buffer, sizeof(buffer), &rSize, NULL); s = ReadFile(hSourceImage, buffer, DD_BUFFER_SIZE, &rSize, NULL);
if (!s) { if (!s) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT; FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT;
uprintf("read error: %s", WindowsErrorString()); uprintf("read error: %s", WindowsErrorString());
@ -1561,6 +1568,7 @@ DWORD WINAPI FormatThread(void* param)
out: out:
safe_free(guid_volume); safe_free(guid_volume);
safe_free(buffer);
SendMessage(hISOProgressDlg, UM_ISO_EXIT, 0, 0); SendMessage(hISOProgressDlg, UM_ISO_EXIT, 0, 0);
safe_closehandle(hSourceImage); safe_closehandle(hSourceImage);
safe_unlockclose(hLogicalVolume); safe_unlockclose(hLogicalVolume);

View file

@ -78,26 +78,6 @@ static uint64_t total_blocks, nb_blocks;
static BOOL scan_only = FALSE; static BOOL scan_only = FALSE;
static StrArray config_path, isolinux_path; static StrArray config_path, isolinux_path;
// TODO: Timestamp & permissions preservation
// Convert a file size to human readable
static __inline char* size_to_hr(int64_t size)
{
int suffix = 0;
static char str_size[24];
double hr_size = (double)size;
while ((suffix < MAX_SIZE_SUFFIXES) && (hr_size >= 1024.0)) {
hr_size /= 1024.0;
suffix++;
}
if (suffix == 0) {
safe_sprintf(str_size, sizeof(str_size), " (%d %s)", (int)hr_size, lmprintf(MSG_020));
} else {
safe_sprintf(str_size, sizeof(str_size), " (%0.1f %s)", hr_size, lmprintf(MSG_020+suffix));
}
return str_size;
}
// Ensure filenames do not contain invalid FAT32 or NTFS characters // Ensure filenames do not contain invalid FAT32 or NTFS characters
static __inline BOOL sanitize_filename(char* filename) static __inline BOOL sanitize_filename(char* filename)
{ {
@ -261,8 +241,9 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha
nul_pos = safe_strlen(psz_fullpath); nul_pos = safe_strlen(psz_fullpath);
for (i=0; i<nul_pos; i++) for (i=0; i<nul_pos; i++)
if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\'; if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\';
safe_strcpy(&psz_fullpath[nul_pos], 24, size_to_hr(i_file_length)); safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, TRUE));
uprintf("Extracting: %s\n", psz_fullpath); uprintf("Extracting: %s\n", psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, FALSE));
SetWindowTextU(hISOFileName, psz_fullpath); SetWindowTextU(hISOFileName, psz_fullpath);
// Remove the appended size for extraction // Remove the appended size for extraction
psz_fullpath[nul_pos] = 0; psz_fullpath[nul_pos] = 0;
@ -407,8 +388,9 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
nul_pos = safe_strlen(psz_fullpath); nul_pos = safe_strlen(psz_fullpath);
for (i=0; i<nul_pos; i++) for (i=0; i<nul_pos; i++)
if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\'; if (psz_fullpath[i] == '/') psz_fullpath[i] = '\\';
safe_strcpy(&psz_fullpath[nul_pos], 24, size_to_hr(i_file_length)); safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, TRUE));
uprintf("Extracting: %s\n", psz_fullpath); uprintf("Extracting: %s\n", psz_fullpath);
safe_sprintf(&psz_fullpath[nul_pos], 24, " (%s)", SizeToHumanReadable(i_file_length, FALSE));
SetWindowTextU(hISOFileName, psz_fullpath); SetWindowTextU(hISOFileName, psz_fullpath);
// ISO9660 cannot handle backslashes // ISO9660 cannot handle backslashes
for (i=0; i<nul_pos; i++) if (psz_fullpath[i] == '\\') psz_fullpath[i] = '/'; for (i=0; i<nul_pos; i++) if (psz_fullpath[i] == '\\') psz_fullpath[i] = '/';

View file

@ -59,6 +59,7 @@
#define UDF_FORMAT_SPEED 3.1f // Speed estimate at which we expect UDF drives to be formatted (GB/s) #define UDF_FORMAT_SPEED 3.1f // Speed estimate at which we expect UDF drives to be formatted (GB/s)
#define UDF_FORMAT_WARN 20 // Duration (in seconds) above which we warn about long UDF formatting times #define UDF_FORMAT_WARN 20 // Duration (in seconds) above which we warn about long UDF formatting times
#define MAX_FAT32_SIZE 2.0f // Threshold above which we disable FAT32 formatting (in TB) #define MAX_FAT32_SIZE 2.0f // Threshold above which we disable FAT32 formatting (in TB)
#define DD_BUFFER_SIZE 65536 // Size of the buffer we use for DD operations
#define WHITE RGB(255,255,255) #define WHITE RGB(255,255,255)
#define SEPARATOR_GREY RGB(223,223,223) #define SEPARATOR_GREY RGB(223,223,223)
#define RUFUS_URL "http://rufus.akeo.ie" #define RUFUS_URL "http://rufus.akeo.ie"
@ -318,7 +319,7 @@ extern void PrintStatus(unsigned int duration, BOOL debug, int msg_id, ...);
extern void UpdateProgress(int op, float percent); extern void UpdateProgress(int op, float percent);
extern const char* StrError(DWORD error_code, BOOL use_default_locale); extern const char* StrError(DWORD error_code, BOOL use_default_locale);
extern char* GuidToString(const GUID* guid); extern char* GuidToString(const GUID* guid);
extern char* SizeToHumanReadable(LARGE_INTEGER size); extern char* SizeToHumanReadable(uint64_t size, BOOL log);
extern void CenterDialog(HWND hDlg); extern void CenterDialog(HWND hDlg);
extern void ResizeMoveCtrl(HWND hDlg, HWND hCtrl, int dx, int dy, int dw, int dh); extern void ResizeMoveCtrl(HWND hDlg, HWND hCtrl, int dx, int dy, int dw, int dh);
extern void CreateStatusBar(void); extern void CreateStatusBar(void);

View file

@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 329 IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 1.4.4.414" CAPTION "Rufus 1.4.4.415"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14 DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -165,7 +165,7 @@ END
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329 RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 1.4.4.414" CAPTION "Rufus 1.4.4.415"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14 DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -427,8 +427,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,4,414 FILEVERSION 1,4,4,415
PRODUCTVERSION 1,4,4,414 PRODUCTVERSION 1,4,4,415
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -445,13 +445,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", "1.4.4.414" VALUE "FileVersion", "1.4.4.415"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2014 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", "1.4.4.414" VALUE "ProductVersion", "1.4.4.415"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -147,19 +147,20 @@ char* GuidToString(const GUID* guid)
} }
// Convert a file size to human readable // Convert a file size to human readable
char* SizeToHumanReadable(LARGE_INTEGER size) char* SizeToHumanReadable(uint64_t size, BOOL log)
{ {
int suffix = 0; int suffix = 0;
static char str_size[32]; static char str_size[32];
double hr_size = (double)size.QuadPart; double hr_size = (double)size;
char **_msg_table = log?default_msg_table:msg_table;
while ((suffix < MAX_SIZE_SUFFIXES) && (hr_size >= 1024.0)) { while ((suffix < MAX_SIZE_SUFFIXES) && (hr_size >= 1024.0)) {
hr_size /= 1024.0; hr_size /= 1024.0;
suffix++; suffix++;
} }
if (suffix == 0) { if (suffix == 0) {
safe_sprintf(str_size, sizeof(str_size), "%d %s", (int)hr_size, lmprintf(MSG_020)); safe_sprintf(str_size, sizeof(str_size), "%d %s", (int)hr_size, _msg_table[MSG_020-MSG_000]);
} else { } else {
safe_sprintf(str_size, sizeof(str_size), "%0.1f %s", hr_size, lmprintf(MSG_020 + suffix)); safe_sprintf(str_size, sizeof(str_size), "%0.1f %s", hr_size, _msg_table[MSG_020+suffix-MSG_000]);
} }
return str_size; return str_size;
} }