[misc] cleanup and refactoring + fix WIM 7z minor issue

* remove hardcoded path from WimExtractFile_7z
* move some drive related functions to drive.c
* cleanup
This commit is contained in:
Pete Batard 2013-01-22 02:40:43 +00:00
parent 8ff8b41273
commit c8acf1b84a
8 changed files with 209 additions and 202 deletions

View file

@ -189,6 +189,25 @@ char* GuidToString(const GUID* guid)
return guid_string;
}
// Convert a file size to human readable
char* SizeToHumanReadable(LARGE_INTEGER size)
{
int suffix = 0;
static char str_size[24];
const char* sizes[] = { "", "KB", "MB", "GB", "TB" };
double hr_size = (double)size.QuadPart;
while ((suffix < ARRAYSIZE(sizes)) && (hr_size >= 1024.0)) {
hr_size /= 1024.0;
suffix++;
}
if (suffix == 0) {
safe_sprintf(str_size, sizeof(str_size), "%d bytes", (int)hr_size);
} else {
safe_sprintf(str_size, sizeof(str_size), "%0.1f %s", hr_size, sizes[suffix]);
}
return str_size;
}
const char* StrError(DWORD error_code)
{
if ( (!IS_ERROR(error_code)) || (SCODE_CODE(error_code) == ERROR_SUCCESS)) {