From 0e2dd87c08eddee68b31f0d72c37d72b6f606790 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 12 Sep 2010 22:20:19 +0000 Subject: [PATCH] #3518 Snow Leopard systems should show file sizes and speeds in base 10 --- macosx/Controller.m | 6 ++++-- macosx/NSStringAdditions.m | 27 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 577850386..dd5656792 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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? diff --git a/macosx/NSStringAdditions.m b/macosx/NSStringAdditions.m index 88eae9ca6..028c5fec9 100644 --- a/macosx/NSStringAdditions.m +++ b/macosx/NSStringAdditions.m @@ -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