#3518 Snow Leopard systems should show file sizes and speeds in base 10

This commit is contained in:
Mitchell Livingston 2010-09-12 22:20:19 +00:00
parent 9135d5e061
commit 0e2dd87c08
2 changed files with 20 additions and 13 deletions

View File

@ -334,12 +334,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
tr_bencDictAddBool(&settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, [fDefaults boolForKey: @"RPCUseWhitelist"]);
tr_bencDictAddBool(&settings, TR_PREFS_KEY_START, [fDefaults boolForKey: @"AutoStartDownload"]);
tr_formatter_size_init(1024, [NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
tr_formatter_size_init([NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024,
[NSLocalizedString(@"KB", "File size - kilobytes") UTF8String],
[NSLocalizedString(@"MB", "File size - megabytes") UTF8String],
[NSLocalizedString(@"GB", "File size - gigabytes") UTF8String],
[NSLocalizedString(@"TB", "File size - terabytes") UTF8String]);
tr_formatter_speed_init(1024, [NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
tr_formatter_speed_init([NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024,
[NSLocalizedString(@"KB/s", "Transfer speed (kilobytes per second)") UTF8String],
[NSLocalizedString(@"MB/s", "Transfer speed (megabytes per second)") UTF8String],
[NSLocalizedString(@"GB/s", "Transfer speed (gigabytes per second)") UTF8String],
[NSLocalizedString(@"TB/s", "Transfer speed (terabytes per second)") UTF8String]); //why not?

View File

@ -48,7 +48,10 @@
+ (NSString *) stringForFileSize: (uint64_t) size
{
if (size < 1024)
const CGFloat baseFloat = [NSApp isOnSnowLeopardOrBetter] ? 1000.0 : 1024.0;
const NSInteger baseInt = [NSApp isOnSnowLeopardOrBetter] ? 1000 : 1024;
if (size < baseInt)
{
if (size != 1)
return [NSString stringWithFormat: @"%lld %@", size, NSLocalizedString(@"bytes", "File size - bytes")];
@ -58,24 +61,24 @@
CGFloat convertedSize;
NSString * unit;
if (size < pow(1024, 2))
if (size < pow(baseInt, 2))
{
convertedSize = size / 1024.0;
convertedSize = size / baseFloat;
unit = NSLocalizedString(@"KB", "File size - kilobytes");
}
else if (size < pow(1024, 3))
else if (size < pow(baseInt, 3))
{
convertedSize = size / (CGFloat)pow(1024, 2);
convertedSize = size / pow(baseFloat, 2);
unit = NSLocalizedString(@"MB", "File size - megabytes");
}
else if (size < pow(1024, 4))
else if (size < pow(baseInt, 4))
{
convertedSize = size / (CGFloat)pow(1024, 3);
convertedSize = size / pow(baseFloat, 3);
unit = NSLocalizedString(@"GB", "File size - gigabytes");
}
else
{
convertedSize = size / (CGFloat)pow(1024, 4);
convertedSize = size / pow(baseFloat, 4);
unit = NSLocalizedString(@"TB", "File size - terabytes");
}
@ -190,17 +193,19 @@
+ (NSString *) stringForSpeed: (CGFloat) speed kb: (NSString *) kb mb: (NSString *) mb gb: (NSString *) gb
{
const CGFloat baseFloat = [NSApp isOnSnowLeopardOrBetter] ? 1000.0 : 1024.0;
if (speed <= 999.95) //0.0 KB/s to 999.9 KB/s
return [NSString localizedStringWithFormat: @"%.1f %@", speed, kb];
speed /= 1024.0;
speed /= baseFloat;
if (speed <= 99.995) //0.98 MB/s to 99.99 MB/s
if (speed <= 99.995) //1.00 MB/s to 99.99 MB/s
return [NSString localizedStringWithFormat: @"%.2f %@", speed, mb];
else if (speed <= 999.95) //100.0 MB/s to 999.9 MB/s
return [NSString localizedStringWithFormat: @"%.1f %@", speed, mb];
else //insane speeds
return [NSString localizedStringWithFormat: @"%.2f %@", (speed / 1024.0), gb];
return [NSString localizedStringWithFormat: @"%.2f %@", (speed / baseFloat), gb];
}
@end