diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 6f551baf..2e53dd15 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -17,6 +17,7 @@ #import "SUUpdateAlert.h" #import "SULocalizations.h" #import "SUApplicationInfo.h" +#import "SUOperatingSystem.h" @interface SPUStandardUserDriver () @@ -339,8 +340,32 @@ - (NSString *)localizedStringFromByteCount:(long long)value { - return [NSByteCountFormatter stringFromByteCount:value - countStyle:NSByteCountFormatterCountStyleFile]; + if (![SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}]) { + if (value < 1000) { + return [NSString stringWithFormat:@"%.0lf %@", value / 1.0, + SULocalizedString(@"B", @"the unit for bytes")]; + } + + if (value < 1000 * 1000) { + return [NSString stringWithFormat:@"%.0lf %@", value / 1000.0, + SULocalizedString(@"KB", @"the unit for kilobytes")]; + } + + if (value < 1000 * 1000 * 1000) { + return [NSString stringWithFormat:@"%.1lf %@", value / 1000.0 / 1000.0, + SULocalizedString(@"MB", @"the unit for megabytes")]; + } + + return [NSString stringWithFormat:@"%.2lf %@", value / 1000.0 / 1000.0 / 1000.0, + SULocalizedString(@"GB", @"the unit for gigabytes")]; + } + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpartial-availability" + NSByteCountFormatter *formatter = [[NSByteCountFormatter alloc] init]; + [formatter setZeroPadsFractionDigits:YES]; + return [formatter stringFromByteCount:value]; +#pragma clang diagnostic pop } - (void)showDownloadDidReceiveDataOfLength:(uint64_t)length