From c7184c21da819287d08d10a958d6de1af54e53e3 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Fri, 10 Jul 2015 09:40:49 -0700 Subject: [PATCH 01/13] Add script to generate a report comparing the Sparkle.strings files --- Makefile | 5 ++ Sparkle/CheckLocalizations.swift | 89 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 Sparkle/CheckLocalizations.swift diff --git a/Makefile b/Makefile index 6912bdda..58dd0724 100644 --- a/Makefile +++ b/Makefile @@ -26,3 +26,8 @@ ci: xcodebuild -sdk "macosx10.$$i" -scheme Distribution -configuration Debug test ; \ fi ; \ done + +check-localizations: + xcrun swiftc -sdk `xcrun --show-sdk-path` -o "$(TMPDIR)/CheckLocalizations" Sparkle/CheckLocalizations.swift + "$(TMPDIR)/CheckLocalizations" . "$(TMPDIR)/LocalizationsReport.htm" + open "$(TMPDIR)/LocalizationsReport.htm" diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift new file mode 100755 index 00000000..a8eac8d1 --- /dev/null +++ b/Sparkle/CheckLocalizations.swift @@ -0,0 +1,89 @@ +import Foundation + +let args = NSProcessInfo.processInfo().arguments +if args.count < 3 { + println("ERROR: Missing arguments.") + exit(1) +} +let sparkleRoot = args[1] as! String +let htmlPath = args[2] as! String + +let enStringsPath = sparkleRoot + "/Sparkle/en.lproj/Sparkle.strings" +let enStringsDict = NSDictionary(contentsOfFile: enStringsPath) +if enStringsDict == nil { + println("ERROR: Invalid English strings.") + exit(1) +} +let enStringsDictKeys = enStringsDict!.allKeys + +let dirPath = sparkleRoot + "/Sparkle" +let dirContents = NSFileManager.defaultManager().contentsOfDirectoryAtPath(dirPath, error: nil) as! [String] +let css = + "body { font-family: sans-serif; font-size: 10pt; }" + + "h1 { font-size: 12pt; }" + + ".missing { background-color: #FFBABA; color: #D6010E; }" + + ".unused { background-color: #BDE5F8; color: #00529B; }" + + ".unlocalized { background-color: #FEEFB3; color: #9F6000; }" +var html = "\n\nLocalizations\n\n\n" +let locale = NSLocale.currentLocale() +for dirEntry in dirContents { + if dirEntry.pathExtension != "lproj" || dirEntry == "en.lproj" { + continue + } + + let lang = locale.displayNameForKey(NSLocaleLanguageCode, value: dirEntry.stringByDeletingPathExtension) + html += "

\(dirEntry) (\(lang!))

\n" + + let stringsPath = dirPath.stringByAppendingPathComponent(dirEntry).stringByAppendingPathComponent("Sparkle.strings") + let stringsDict = NSDictionary(contentsOfFile: stringsPath) + if stringsDict == nil { + println(" ERROR: Invalid strings file \(dirEntry)") + continue + } + + var missing: [String] = [] + var unlocalized: [String] = [] + var unused: [String] = [] + + for key in enStringsDictKeys { + let str = stringsDict?.objectForKey(key) as? String + if str == nil { + missing.append(key as! String) + } else if let enStr = enStringsDict?.objectForKey(key) as? String { + if enStr == str { + unlocalized.append(key as! String) + } + } + } + + let stringsDictKeys = stringsDict!.allKeys + for key in stringsDictKeys { + if enStringsDict?.objectForKey(key) == nil { + unused.append(key as! String) + } + } + + let sorter = { (s1: String, s2: String) -> Bool in + return s1 < s2 + } + missing.sort(sorter) + unlocalized.sort(sorter) + unused.sort(sorter) + + for key in missing { + html += "Missing \"\(key)\"
\n" + } + for key in unlocalized { + html += "Unlocalized \"\(key)\"
\n" + } + for key in unused { + html += "Unused \"\(key)\"
\n" + } +} +html += "" + +var err: NSError? +if !html.writeToFile(htmlPath, atomically: true, encoding: NSUTF8StringEncoding, error: &err) { + println("ERROR: Can't write report: \(err)") + exit(1) +} From b3d8cf11f71f318027fcbdd4b86457fc6238d740 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Fri, 10 Jul 2015 12:56:13 -0700 Subject: [PATCH 02/13] CheckLocalizations: escape HTML --- Sparkle/CheckLocalizations.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift index a8eac8d1..7d04d9ae 100755 --- a/Sparkle/CheckLocalizations.swift +++ b/Sparkle/CheckLocalizations.swift @@ -1,5 +1,12 @@ import Foundation +func escapeHTML(str: String) -> String { + if let node = NSXMLNode.textWithStringValue(str) as? NSXMLNode { + return node.XMLString + } + return "" +} + let args = NSProcessInfo.processInfo().arguments if args.count < 3 { println("ERROR: Missing arguments.") @@ -71,13 +78,13 @@ for dirEntry in dirContents { unused.sort(sorter) for key in missing { - html += "Missing \"\(key)\"
\n" + html += "Missing \"\(escapeHTML(key))\"
\n" } for key in unlocalized { - html += "Unlocalized \"\(key)\"
\n" + html += "Unlocalized \"\(escapeHTML(key))\"
\n" } for key in unused { - html += "Unused \"\(key)\"
\n" + html += "Unused \"\(escapeHTML(key))\"
\n" } } html += "" From 0d9597c9a9fd907a088ab546009900e72f618c52 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Fri, 10 Jul 2015 13:02:16 -0700 Subject: [PATCH 03/13] CheckLocalizations: add a helper for error handling --- Sparkle/CheckLocalizations.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift index 7d04d9ae..6da698c2 100755 --- a/Sparkle/CheckLocalizations.swift +++ b/Sparkle/CheckLocalizations.swift @@ -1,16 +1,20 @@ import Foundation +func die(msg: String) { + println("ERROR: \(msg)") + exit(1) +} + func escapeHTML(str: String) -> String { if let node = NSXMLNode.textWithStringValue(str) as? NSXMLNode { return node.XMLString } - return "" + die("NSXMLNode failure"); return "" } let args = NSProcessInfo.processInfo().arguments if args.count < 3 { - println("ERROR: Missing arguments.") - exit(1) + die("Missing arguments") } let sparkleRoot = args[1] as! String let htmlPath = args[2] as! String @@ -18,8 +22,7 @@ let htmlPath = args[2] as! String let enStringsPath = sparkleRoot + "/Sparkle/en.lproj/Sparkle.strings" let enStringsDict = NSDictionary(contentsOfFile: enStringsPath) if enStringsDict == nil { - println("ERROR: Invalid English strings.") - exit(1) + die("Invalid English strings") } let enStringsDictKeys = enStringsDict!.allKeys @@ -44,7 +47,7 @@ for dirEntry in dirContents { let stringsPath = dirPath.stringByAppendingPathComponent(dirEntry).stringByAppendingPathComponent("Sparkle.strings") let stringsDict = NSDictionary(contentsOfFile: stringsPath) if stringsDict == nil { - println(" ERROR: Invalid strings file \(dirEntry)") + die("Invalid strings file \(dirEntry)") continue } @@ -91,6 +94,5 @@ html += "" var err: NSError? if !html.writeToFile(htmlPath, atomically: true, encoding: NSUTF8StringEncoding, error: &err) { - println("ERROR: Can't write report: \(err)") - exit(1) + die("Can't write report: \(err)") } From 14fe42e7da586aab0b86f6980f93699fa7322338 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Fri, 10 Jul 2015 13:10:38 -0700 Subject: [PATCH 04/13] CheckLocalizations: use NSUserDefaults to read args --- Makefile | 2 +- Sparkle/CheckLocalizations.swift | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 58dd0724..ab7ee819 100644 --- a/Makefile +++ b/Makefile @@ -29,5 +29,5 @@ ci: check-localizations: xcrun swiftc -sdk `xcrun --show-sdk-path` -o "$(TMPDIR)/CheckLocalizations" Sparkle/CheckLocalizations.swift - "$(TMPDIR)/CheckLocalizations" . "$(TMPDIR)/LocalizationsReport.htm" + "$(TMPDIR)/CheckLocalizations" -root . -htmlPath "$(TMPDIR)/LocalizationsReport.htm" open "$(TMPDIR)/LocalizationsReport.htm" diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift index 6da698c2..4c2a518b 100755 --- a/Sparkle/CheckLocalizations.swift +++ b/Sparkle/CheckLocalizations.swift @@ -12,21 +12,21 @@ func escapeHTML(str: String) -> String { die("NSXMLNode failure"); return "" } -let args = NSProcessInfo.processInfo().arguments -if args.count < 3 { +let ud = NSUserDefaults.standardUserDefaults() +let sparkleRoot = ud.objectForKey("root") as? String +let htmlPath = ud.objectForKey("htmlPath") as? String +if sparkleRoot == nil || htmlPath == nil { die("Missing arguments") } -let sparkleRoot = args[1] as! String -let htmlPath = args[2] as! String -let enStringsPath = sparkleRoot + "/Sparkle/en.lproj/Sparkle.strings" +let enStringsPath = sparkleRoot! + "/Sparkle/en.lproj/Sparkle.strings" let enStringsDict = NSDictionary(contentsOfFile: enStringsPath) if enStringsDict == nil { die("Invalid English strings") } let enStringsDictKeys = enStringsDict!.allKeys -let dirPath = sparkleRoot + "/Sparkle" +let dirPath = sparkleRoot! + "/Sparkle" let dirContents = NSFileManager.defaultManager().contentsOfDirectoryAtPath(dirPath, error: nil) as! [String] let css = "body { font-family: sans-serif; font-size: 10pt; }" + @@ -93,6 +93,6 @@ for dirEntry in dirContents { html += "" var err: NSError? -if !html.writeToFile(htmlPath, atomically: true, encoding: NSUTF8StringEncoding, error: &err) { +if !html.writeToFile(htmlPath!, atomically: true, encoding: NSUTF8StringEncoding, error: &err) { die("Can't write report: \(err)") } From 9992fa28ed3df8bf0ef19d7cc690134ad8063611 Mon Sep 17 00:00:00 2001 From: Kevin Wojniak Date: Fri, 10 Jul 2015 13:14:22 -0700 Subject: [PATCH 05/13] CheckLocalizations: use swift shebang --- Makefile | 3 +-- Sparkle/CheckLocalizations.swift | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ab7ee819..b3de3f8f 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,5 @@ ci: done check-localizations: - xcrun swiftc -sdk `xcrun --show-sdk-path` -o "$(TMPDIR)/CheckLocalizations" Sparkle/CheckLocalizations.swift - "$(TMPDIR)/CheckLocalizations" -root . -htmlPath "$(TMPDIR)/LocalizationsReport.htm" + ./Sparkle/CheckLocalizations.swift -root . -htmlPath "$(TMPDIR)/LocalizationsReport.htm" open "$(TMPDIR)/LocalizationsReport.htm" diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift index 4c2a518b..1f751fda 100755 --- a/Sparkle/CheckLocalizations.swift +++ b/Sparkle/CheckLocalizations.swift @@ -1,3 +1,5 @@ +#!/usr/bin/xcrun swift + import Foundation func die(msg: String) { From 59d372222e51c953bd81c3eae37db83212f8e05b Mon Sep 17 00:00:00 2001 From: Daniel Jalkut Date: Mon, 27 Jul 2015 14:40:15 -0400 Subject: [PATCH 06/13] Remove unused temporaryName: parameter and supporting code. The temporaryName: parameter to SUPlainInstaller's copyPathWithAuthentication... method was not being used internally but was still mucking up the (already long) method signature for the method and related methods up the chain. Also remove related, no-longer-used temporaryNameForPath method. --- Sparkle/SUBasicUpdateDriver.m | 2 +- Sparkle/SUPlainInstaller.m | 3 +-- Sparkle/SUPlainInstallerInternals.h | 3 +-- Sparkle/SUPlainInstallerInternals.m | 24 +----------------------- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index c092f49c..9f17008c 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -431,7 +431,7 @@ NSError *error = nil; [[NSFileManager defaultManager] createDirectoryAtPath:[targetPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:@{} error:&error]; - if ([SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil appendVersion:SPARKLE_APPEND_VERSION_NUMBER error:&error]) { + if ([SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath appendVersion:SPARKLE_APPEND_VERSION_NUMBER error:&error]) { self.relaunchPath = targetPath; } else { [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{ diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 95afaba0..975e1184 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -33,9 +33,8 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSError *error = nil; NSString *oldPath = [host bundlePath]; - NSString *tempName = [self temporaryNameForPath:[host installationPath]]; - BOOL result = [self copyPathWithAuthentication:path overPath:installationPath temporaryName:tempName appendVersion:SPARKLE_APPEND_VERSION_NUMBER error:&error]; + BOOL result = [self copyPathWithAuthentication:path overPath:installationPath appendVersion:SPARKLE_APPEND_VERSION_NUMBER error:&error]; if (result) { if ([SUCodeSigningVerifier applicationAtPathIsCodeSigned:installationPath]) { diff --git a/Sparkle/SUPlainInstallerInternals.h b/Sparkle/SUPlainInstallerInternals.h index cc6778b4..25b2b6f7 100644 --- a/Sparkle/SUPlainInstallerInternals.h +++ b/Sparkle/SUPlainInstallerInternals.h @@ -14,8 +14,7 @@ #import "SUPlainInstaller.h" @interface SUPlainInstaller (Internals) -+ (NSString *)temporaryNameForPath:(NSString *)path; -+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp appendVersion:(BOOL)a error:(NSError **)error; ++ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst appendVersion:(BOOL)a error:(NSError **)error; + (void)_movePathToTrash:(NSString *)path appendVersion:(BOOL)a; + (BOOL)_removeFileAtPath:(NSString *)path error:(NSError **)error; + (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError **)error; diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 3f126875..7fd97e27 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -85,28 +85,6 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @implementation SUPlainInstaller (Internals) -+ (NSString *)temporaryNameForPath:(NSString *)path -{ - // Let's try to read the version number so the filename will be more meaningful. - NSString *postFix; - NSString *version; - if ((version = [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]) && ![version isEqualToString:@""]) - { - NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet]; - [validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]]; - postFix = [version stringByTrimmingCharactersInSet:[validCharacters invertedSet]]; - } - else - postFix = @"old"; - NSString *prefix = [[path stringByDeletingPathExtension] stringByAppendingFormat:@" (%@)", postFix]; - NSString *tempDir = [prefix stringByAppendingPathExtension:[path pathExtension]]; - // Now let's make sure we get a unique path. - unsigned int cnt = 2; - while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999) - tempDir = [NSString stringWithFormat:@"%@ %u.%@", prefix, cnt++, [path pathExtension]]; - return [tempDir lastPathComponent]; -} - + (NSString *)_temporaryCopyNameForPath:(NSString *)path appendVersion:(BOOL)appendVersion didFindTrash:(BOOL *)outDidFindTrash { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! @@ -464,7 +442,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza } } -+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)__unused tmp appendVersion:(BOOL)appendVersion error:(NSError *__autoreleasing *)error ++ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst appendVersion:(BOOL)appendVersion error:(NSError *__autoreleasing *)error { FSRef srcRef, dstRef, dstDirRef, tmpDirRef; OSStatus err; From 73c337b14ef8f975cc22d9a262392f54c7ae3863 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 15:27:24 -0700 Subject: [PATCH 07/13] Use NSXML the whole way through for building the report document. --- Sparkle/CheckLocalizations.swift | 57 ++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift index 1f751fda..f0c05797 100755 --- a/Sparkle/CheckLocalizations.swift +++ b/Sparkle/CheckLocalizations.swift @@ -7,11 +7,11 @@ func die(msg: String) { exit(1) } -func escapeHTML(str: String) -> String { - if let node = NSXMLNode.textWithStringValue(str) as? NSXMLNode { - return node.XMLString +extension NSXMLElement { + convenience init(name: String, attributes: [String: String], stringValue string: String? = nil) { + self.init(name: name, stringValue: string) + setAttributesWithDictionary(attributes) } - die("NSXMLNode failure"); return "" } let ud = NSUserDefaults.standardUserDefaults() @@ -32,31 +32,43 @@ let dirPath = sparkleRoot! + "/Sparkle" let dirContents = NSFileManager.defaultManager().contentsOfDirectoryAtPath(dirPath, error: nil) as! [String] let css = "body { font-family: sans-serif; font-size: 10pt; }" + - "h1 { font-size: 12pt; }" + - ".missing { background-color: #FFBABA; color: #D6010E; }" + - ".unused { background-color: #BDE5F8; color: #00529B; }" + - ".unlocalized { background-color: #FEEFB3; color: #9F6000; }" -var html = "\n\nLocalizations\n\n\n" + "h1 { font-size: 12pt; }" + + ".missing { background-color: #FFBABA; color: #D6010E; white-space: pre; }" + + ".unused { background-color: #BDE5F8; color: #00529B; white-space: pre; }" + + ".unlocalized { background-color: #FEEFB3; color: #9F6000; white-space: pre; }" +var html = NSXMLDocument(rootElement: NSXMLElement(name: "html")) +html.DTD = NSXMLDTD() +html.DTD!.name = html.rootElement()!.name +html.characterEncoding = "UTF-8" +html.documentContentKind = NSXMLDocumentContentKind.XHTMLKind +var body = NSXMLElement(name: "body") +var head = NSXMLElement(name: "head") +html.rootElement()!.addChild(head) +html.rootElement()!.addChild(body) +head.addChild(NSXMLElement(name: "meta", attributes: ["charset": html.characterEncoding!])) +head.addChild(NSXMLElement(name: "title", stringValue: "Sparkle Localizations Report")) +head.addChild(NSXMLElement(name: "style", stringValue: css)) + let locale = NSLocale.currentLocale() for dirEntry in dirContents { if dirEntry.pathExtension != "lproj" || dirEntry == "en.lproj" { continue } - + let lang = locale.displayNameForKey(NSLocaleLanguageCode, value: dirEntry.stringByDeletingPathExtension) - html += "

\(dirEntry) (\(lang!))

\n" - + body.addChild(NSXMLElement(name: "h1", stringValue: "\(dirEntry) (\(lang!))")) + let stringsPath = dirPath.stringByAppendingPathComponent(dirEntry).stringByAppendingPathComponent("Sparkle.strings") let stringsDict = NSDictionary(contentsOfFile: stringsPath) if stringsDict == nil { die("Invalid strings file \(dirEntry)") continue } - + var missing: [String] = [] var unlocalized: [String] = [] var unused: [String] = [] - + for key in enStringsDictKeys { let str = stringsDict?.objectForKey(key) as? String if str == nil { @@ -74,27 +86,30 @@ for dirEntry in dirContents { unused.append(key as! String) } } - + let sorter = { (s1: String, s2: String) -> Bool in return s1 < s2 } missing.sort(sorter) unlocalized.sort(sorter) unused.sort(sorter) - + + let addRow = { (prefix: String, cssClass: String, key: String) -> Void in + body.addChild(NSXMLElement(name: "span", attributes: ["class": cssClass], stringValue: " ".join([prefix, key]) + "\n")) + } + for key in missing { - html += "Missing \"\(escapeHTML(key))\"
\n" + addRow("Missing", "missing", key) } for key in unlocalized { - html += "Unlocalized \"\(escapeHTML(key))\"
\n" + addRow("Unlocalized", "unlocalized", key) } for key in unused { - html += "Unused \"\(escapeHTML(key))\"
\n" + addRow("Unused", "unused", key) } } -html += "" var err: NSError? -if !html.writeToFile(htmlPath!, atomically: true, encoding: NSUTF8StringEncoding, error: &err) { +if !html.XMLData.writeToFile(htmlPath!, atomically: true) { die("Can't write report: \(err)") } From 0167c50b1d938b281b8f58d4afa0f836796e3c55 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 15:27:36 -0700 Subject: [PATCH 08/13] Add SparkleLocalizations.swift to the Xcode project. --- Sparkle.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index aef95ef1..41405694 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -340,6 +340,7 @@ 14732BC41960F3FF00593899 /* sign_update */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sign_update; sourceTree = ""; }; 14732BC91960F70A00593899 /* make-release-package.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "make-release-package.sh"; sourceTree = ""; }; 14732BD219610A1800593899 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + 147D6D9E1B66DC3C006607AB /* CheckLocalizations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CheckLocalizations.swift; path = Sparkle/CheckLocalizations.swift; sourceTree = SOURCE_ROOT; }; 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterTest.m; sourceTree = ""; usesTabs = 0; }; 14958C6B19AEBC530061B14F /* signed-test-file.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "signed-test-file.txt"; sourceTree = ""; }; 14958C6C19AEBC610061B14F /* test-pubkey.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "test-pubkey.pem"; sourceTree = ""; }; @@ -750,6 +751,7 @@ isa = PBXGroup; children = ( 14732BC21960F3FF00593899 /* bin */, + 147D6D9E1B66DC3C006607AB /* CheckLocalizations.swift */, 14732BBA1960EF7100593899 /* CHANGELOG */, 61C268090E2DB5D000175E6C /* LICENSE */, 14732BC11960F3B200593899 /* Makefile */, From c1f10ac7f0f9d0127d743775715e6a0cd80fb1b5 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 15:46:23 -0700 Subject: [PATCH 09/13] Add existing localization files to Xcode project. Catalan, Finnish, Hebrew. --- Sparkle.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 41405694..154c4e35 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -341,6 +341,9 @@ 14732BC91960F70A00593899 /* make-release-package.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "make-release-package.sh"; sourceTree = ""; }; 14732BD219610A1800593899 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 147D6D9E1B66DC3C006607AB /* CheckLocalizations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CheckLocalizations.swift; path = Sparkle/CheckLocalizations.swift; sourceTree = SOURCE_ROOT; }; + 147D6DA71B66EC1C006607AB /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Sparkle.strings; sourceTree = ""; }; + 147D6DA91B66EC22006607AB /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/Sparkle.strings; sourceTree = ""; }; + 147D6DAA1B66EC25006607AB /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Sparkle.strings; sourceTree = ""; }; 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterTest.m; sourceTree = ""; usesTabs = 0; }; 14958C6B19AEBC530061B14F /* signed-test-file.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "signed-test-file.txt"; sourceTree = ""; }; 14958C6C19AEBC610061B14F /* test-pubkey.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "test-pubkey.pem"; sourceTree = ""; }; @@ -1697,6 +1700,9 @@ 0263187214FEBB31005EBF43 /* uk */, 61131A090F846D0A00E97AF6 /* zh_CN */, 61131A0A0F846D1100E97AF6 /* zh_TW */, + 147D6DA71B66EC1C006607AB /* ca */, + 147D6DA91B66EC22006607AB /* fi */, + 147D6DAA1B66EC25006607AB /* he */, ); name = Sparkle.strings; sourceTree = ""; From 59b94a2c7d56ff4aba637ccaf410a556923d2412 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 15:53:14 -0700 Subject: [PATCH 10/13] Delete languages which don't actually have any translations. --- Sparkle/cy.lproj/Sparkle.strings | 52 -------------------------------- Sparkle/hu.lproj/Sparkle.strings | 52 -------------------------------- Sparkle/id.lproj/Sparkle.strings | 52 -------------------------------- 3 files changed, 156 deletions(-) delete mode 100644 Sparkle/cy.lproj/Sparkle.strings delete mode 100644 Sparkle/hu.lproj/Sparkle.strings delete mode 100644 Sparkle/id.lproj/Sparkle.strings diff --git a/Sparkle/cy.lproj/Sparkle.strings b/Sparkle/cy.lproj/Sparkle.strings deleted file mode 100644 index a9b47b25..00000000 --- a/Sparkle/cy.lproj/Sparkle.strings +++ /dev/null @@ -1,52 +0,0 @@ -"%@ of %@" = "%1$@ of %2$@"; - -"%@ %@ has been installed and will be ready to use next time %@ starts! Would you like to relaunch now?" = "%1$@ %2$@ has been installed and will be ready to use next time %3$@ starts! Would you like to relaunch now?"; - -"%@ %@ is currently the newest version available." = "%1$@ %2$@ is currently the newest version available."; - -"%@ %@ is now available (you have %@). Would you like to download it now?" = "%1$@ %2$@ is now available (you have %3$@). Would you like to download it now?"; - -"%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help." = "%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help."; - -"A new version of %@ has been installed!" = "A new version of %@ has been installed!"; - -"A new version of %@ is available!" = "A new version of %@ is available!"; - -"An error occurred during installation. Please try again later." = "An error occurred during installation. Please try again later."; - -"An error occurred in retrieving update information. Please try again later." = "An error occurred in retrieving update information. Please try again later."; - -"An error occurred while extracting the archive. Please try again later." = "An error occurred while extracting the archive. Please try again later."; - -"An error occurred while trying to download the file. Please try again later." = "An error occurred while trying to download the file. Please try again later."; - -"An update is already in progress!" = "An update is already in progress!"; - -"Cancel" = "Cancel"; - -"Check for updates on startup?" = "Check for updates on startup?"; - -"Downloading update..." = "Downloading update…"; - -"Extracting update..." = "Extracting update…"; - -"Install and Relaunch" = "Install and Relaunch"; - -"Installing update..." = "Installing update…"; - -"No" = "No"; - -"OK" = "OK"; - -"Ready to Install" = "Ready to Install"; - -"Update Error!" = "Update Error!"; - -"Updating %@" = "Updating %@"; - -"Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the application menu." = "Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the application menu."; - -"Yes" = "Yes"; - -"You're up to date!" = "You're up to date!"; - diff --git a/Sparkle/hu.lproj/Sparkle.strings b/Sparkle/hu.lproj/Sparkle.strings deleted file mode 100644 index a9b47b25..00000000 --- a/Sparkle/hu.lproj/Sparkle.strings +++ /dev/null @@ -1,52 +0,0 @@ -"%@ of %@" = "%1$@ of %2$@"; - -"%@ %@ has been installed and will be ready to use next time %@ starts! Would you like to relaunch now?" = "%1$@ %2$@ has been installed and will be ready to use next time %3$@ starts! Would you like to relaunch now?"; - -"%@ %@ is currently the newest version available." = "%1$@ %2$@ is currently the newest version available."; - -"%@ %@ is now available (you have %@). Would you like to download it now?" = "%1$@ %2$@ is now available (you have %3$@). Would you like to download it now?"; - -"%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help." = "%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help."; - -"A new version of %@ has been installed!" = "A new version of %@ has been installed!"; - -"A new version of %@ is available!" = "A new version of %@ is available!"; - -"An error occurred during installation. Please try again later." = "An error occurred during installation. Please try again later."; - -"An error occurred in retrieving update information. Please try again later." = "An error occurred in retrieving update information. Please try again later."; - -"An error occurred while extracting the archive. Please try again later." = "An error occurred while extracting the archive. Please try again later."; - -"An error occurred while trying to download the file. Please try again later." = "An error occurred while trying to download the file. Please try again later."; - -"An update is already in progress!" = "An update is already in progress!"; - -"Cancel" = "Cancel"; - -"Check for updates on startup?" = "Check for updates on startup?"; - -"Downloading update..." = "Downloading update…"; - -"Extracting update..." = "Extracting update…"; - -"Install and Relaunch" = "Install and Relaunch"; - -"Installing update..." = "Installing update…"; - -"No" = "No"; - -"OK" = "OK"; - -"Ready to Install" = "Ready to Install"; - -"Update Error!" = "Update Error!"; - -"Updating %@" = "Updating %@"; - -"Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the application menu." = "Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the application menu."; - -"Yes" = "Yes"; - -"You're up to date!" = "You're up to date!"; - diff --git a/Sparkle/id.lproj/Sparkle.strings b/Sparkle/id.lproj/Sparkle.strings deleted file mode 100644 index a9b47b25..00000000 --- a/Sparkle/id.lproj/Sparkle.strings +++ /dev/null @@ -1,52 +0,0 @@ -"%@ of %@" = "%1$@ of %2$@"; - -"%@ %@ has been installed and will be ready to use next time %@ starts! Would you like to relaunch now?" = "%1$@ %2$@ has been installed and will be ready to use next time %3$@ starts! Would you like to relaunch now?"; - -"%@ %@ is currently the newest version available." = "%1$@ %2$@ is currently the newest version available."; - -"%@ %@ is now available (you have %@). Would you like to download it now?" = "%1$@ %2$@ is now available (you have %3$@). Would you like to download it now?"; - -"%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help." = "%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help."; - -"A new version of %@ has been installed!" = "A new version of %@ has been installed!"; - -"A new version of %@ is available!" = "A new version of %@ is available!"; - -"An error occurred during installation. Please try again later." = "An error occurred during installation. Please try again later."; - -"An error occurred in retrieving update information. Please try again later." = "An error occurred in retrieving update information. Please try again later."; - -"An error occurred while extracting the archive. Please try again later." = "An error occurred while extracting the archive. Please try again later."; - -"An error occurred while trying to download the file. Please try again later." = "An error occurred while trying to download the file. Please try again later."; - -"An update is already in progress!" = "An update is already in progress!"; - -"Cancel" = "Cancel"; - -"Check for updates on startup?" = "Check for updates on startup?"; - -"Downloading update..." = "Downloading update…"; - -"Extracting update..." = "Extracting update…"; - -"Install and Relaunch" = "Install and Relaunch"; - -"Installing update..." = "Installing update…"; - -"No" = "No"; - -"OK" = "OK"; - -"Ready to Install" = "Ready to Install"; - -"Update Error!" = "Update Error!"; - -"Updating %@" = "Updating %@"; - -"Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the application menu." = "Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the application menu."; - -"Yes" = "Yes"; - -"You're up to date!" = "You're up to date!"; - From f3e44d39ee062aaed336afa40136e545d529e64d Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 15:43:41 -0700 Subject: [PATCH 11/13] Fix some simple translation issues. --- Sparkle/ca.lproj/Sparkle.strings | 2 +- Sparkle/cs.lproj/Sparkle.strings | 2 +- Sparkle/fi.lproj/Sparkle.strings | 2 +- Sparkle/he.lproj/Sparkle.strings | 2 +- Sparkle/is.lproj/Sparkle.strings | 2 +- Sparkle/ko.lproj/Sparkle.strings | 2 +- Sparkle/no.lproj/Sparkle.strings | 2 +- Sparkle/pl.lproj/Sparkle.strings | 2 +- Sparkle/pt_BR.lproj/Sparkle.strings | 2 +- Sparkle/sk.lproj/Sparkle.strings | 1 - Sparkle/tr.lproj/Sparkle.strings | 2 +- 11 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Sparkle/ca.lproj/Sparkle.strings b/Sparkle/ca.lproj/Sparkle.strings index d0ab278c..4f0876a2 100644 --- a/Sparkle/ca.lproj/Sparkle.strings +++ b/Sparkle/ca.lproj/Sparkle.strings @@ -50,5 +50,5 @@ "Yes" = "Sí"; -"You're up to date!" = "Ja esteu al dia!"; +"You're up-to-date!" = "Ja esteu al dia!"; diff --git a/Sparkle/cs.lproj/Sparkle.strings b/Sparkle/cs.lproj/Sparkle.strings index 843f0b2f..2ca1b168 100644 --- a/Sparkle/cs.lproj/Sparkle.strings +++ b/Sparkle/cs.lproj/Sparkle.strings @@ -67,5 +67,5 @@ "You already have the newest version of %@." = "Máte nainstalovanou nejnovější verzi aplikace @."; -"You're up to date!" = "Vaše verze je aktuální!"; +"You're up-to-date!" = "Vaše verze je aktuální!"; diff --git a/Sparkle/fi.lproj/Sparkle.strings b/Sparkle/fi.lproj/Sparkle.strings index f57a8b5a..02268cdb 100644 --- a/Sparkle/fi.lproj/Sparkle.strings +++ b/Sparkle/fi.lproj/Sparkle.strings @@ -48,5 +48,5 @@ "Yes" = "Kyllä"; -"You're up to date!" = "Sinulla on viimeisin versio!"; +"You're up-to-date!" = "Sinulla on viimeisin versio!"; diff --git a/Sparkle/he.lproj/Sparkle.strings b/Sparkle/he.lproj/Sparkle.strings index 0d2aa275..7390d3d8 100644 --- a/Sparkle/he.lproj/Sparkle.strings +++ b/Sparkle/he.lproj/Sparkle.strings @@ -48,5 +48,5 @@ "Yes" = "כן"; -"You're up to date!" = "התכנה עדכנית!"; +"You're up-to-date!" = "התכנה עדכנית!"; diff --git a/Sparkle/is.lproj/Sparkle.strings b/Sparkle/is.lproj/Sparkle.strings index da6f2c63..f3256406 100644 --- a/Sparkle/is.lproj/Sparkle.strings +++ b/Sparkle/is.lproj/Sparkle.strings @@ -48,5 +48,5 @@ "Yes" = "Já"; -"You're up to date!" = "Það er allt uppfært hjá þér!"; +"You're up-to-date!" = "Það er allt uppfært hjá þér!"; diff --git a/Sparkle/ko.lproj/Sparkle.strings b/Sparkle/ko.lproj/Sparkle.strings index 50a93997..5d908b7e 100644 --- a/Sparkle/ko.lproj/Sparkle.strings +++ b/Sparkle/ko.lproj/Sparkle.strings @@ -67,5 +67,5 @@ "You already have the newest version of %@." = "이미 %@ 최신 버전입니다."; -"You're up to date!" = "최신 버전입니다."; +"You're up-to-date!" = "최신 버전입니다."; diff --git a/Sparkle/no.lproj/Sparkle.strings b/Sparkle/no.lproj/Sparkle.strings index 866607cb..ff803c7a 100644 --- a/Sparkle/no.lproj/Sparkle.strings +++ b/Sparkle/no.lproj/Sparkle.strings @@ -48,5 +48,5 @@ "Yes" = "Ja"; -"You're up to date!" = "Du er oppdatert!"; +"You're up-to-date!" = "Du er oppdatert!"; diff --git a/Sparkle/pl.lproj/Sparkle.strings b/Sparkle/pl.lproj/Sparkle.strings index e8bc35c2..953bf45f 100644 --- a/Sparkle/pl.lproj/Sparkle.strings +++ b/Sparkle/pl.lproj/Sparkle.strings @@ -69,5 +69,5 @@ "You already have the newest version of %@." = "Posiadasz najnowszą wersję %@."; -"You're up to date!" = "Jesteś na bieżąco!"; +"You're up-to-date!" = "Jesteś na bieżąco!"; diff --git a/Sparkle/pt_BR.lproj/Sparkle.strings b/Sparkle/pt_BR.lproj/Sparkle.strings index 3b7893e8..a911f9ca 100755 --- a/Sparkle/pt_BR.lproj/Sparkle.strings +++ b/Sparkle/pt_BR.lproj/Sparkle.strings @@ -67,5 +67,5 @@ "You already have the newest version of %@." = "Você já possui a versão mais recente do %@."; -"You're up to date!" = "Você está atualizado!"; +"You're up-to-date!" = "Você está atualizado!"; diff --git a/Sparkle/sk.lproj/Sparkle.strings b/Sparkle/sk.lproj/Sparkle.strings index 4efb5311..7d5760b9 100644 --- a/Sparkle/sk.lproj/Sparkle.strings +++ b/Sparkle/sk.lproj/Sparkle.strings @@ -67,5 +67,4 @@ "You already have the newest version of %@." = "Máte aktuálnu verziu aplikácie %@."; -"You're up to date!" = "Máte aktuálnu verziu!"; "You're up-to-date!" = "Máte aktuálnu verziu!"; diff --git a/Sparkle/tr.lproj/Sparkle.strings b/Sparkle/tr.lproj/Sparkle.strings index b394c64c..177c111c 100644 --- a/Sparkle/tr.lproj/Sparkle.strings +++ b/Sparkle/tr.lproj/Sparkle.strings @@ -119,5 +119,5 @@ "You already have the newest version of %@." = "%@ uygulamasının en güncel sürümü sizde mevcut."; -"You're up to date!" = "Uygulama güncel!"; +"You're up-to-date!" = "Uygulama güncel!"; From 87702985dccf1eed99c9666b88c59bc8e3d6c18f Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 16:10:59 -0700 Subject: [PATCH 12/13] Fix a few more easy translation issues. Here, the English text changed slightly but the original meaning is mostly kept, so the translations can be reconnected. --- Sparkle/ca.lproj/Sparkle.strings | 4 ++-- Sparkle/is.lproj/Sparkle.strings | 4 ++-- Sparkle/tr.lproj/Sparkle.strings | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sparkle/ca.lproj/Sparkle.strings b/Sparkle/ca.lproj/Sparkle.strings index 4f0876a2..2c3eec74 100644 --- a/Sparkle/ca.lproj/Sparkle.strings +++ b/Sparkle/ca.lproj/Sparkle.strings @@ -42,12 +42,12 @@ "Ready to Install" = "A punt per instal·lar"; +"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu." = "Voleu que %1$@ comprovi si hi ha noves actualitzacions al iniciar? Si no, podeu inciar la comprovació manualment des del menú %1$@."; + "Update Error!" = "Error d'actualització!"; "Updating %@" = "Actualitzant %@"; -"Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the %@ menu." = "Voleu que %@ comprovi si hi ha noves actualitzacions al iniciar? Si no, podeu inciar la comprovació manualment des del menú @."; - "Yes" = "Sí"; "You're up-to-date!" = "Ja esteu al dia!"; diff --git a/Sparkle/is.lproj/Sparkle.strings b/Sparkle/is.lproj/Sparkle.strings index f3256406..2ba44113 100644 --- a/Sparkle/is.lproj/Sparkle.strings +++ b/Sparkle/is.lproj/Sparkle.strings @@ -40,12 +40,12 @@ "OK" = "Í lagi"; +"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu." = "Viltu að forritið %1$@ athugi með uppfærslur þegar það er ræst? Ef ekki getur þú athugað handvirkt af %1$@-valblaðinu."; + "Update Error!" = "Villa við uppfærslu!"; "Updating %@" = "Uppfæri %@"; -"Would you like %@ to check for updates on startup? If not, you can initiate the check manually from the %@ menu." = "Viltu að forritið %@ athugi með uppfærslur þegar það er ræst? Ef ekki getur þú athugað handvirkt af %@-valblaðinu."; - "Yes" = "Já"; "You're up-to-date!" = "Það er allt uppfært hjá þér!"; diff --git a/Sparkle/tr.lproj/Sparkle.strings b/Sparkle/tr.lproj/Sparkle.strings index 177c111c..73072cdc 100644 --- a/Sparkle/tr.lproj/Sparkle.strings +++ b/Sparkle/tr.lproj/Sparkle.strings @@ -4,7 +4,7 @@ /* de_DE v0.1 - No comment provided by engineer. */ -"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it from there, and try again." = "%1$@ uygulaması disk kalıbı içerisindeyken güncellenemez. Lütfen %1$@ uygulamasını Uygulamalar dizinine kopyalayıp yeniden başlatınız."; +"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again." = "%1$@ uygulaması disk kalıbı içerisindeyken güncellenemez. Lütfen %1$@ uygulamasını Uygulamalar dizinine kopyalayıp yeniden başlatınız."; /* de_DE v0.1 - No comment provided by engineer. */ From 147906f067728c0083821acde171ba49cbfe8f33 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 27 Jul 2015 16:45:02 -0700 Subject: [PATCH 13/13] Use NSByteCountFormatter if available. --- Sparkle/SUUIBasedUpdateDriver.m | 54 ++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index b1e09370..9a3524c4 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -14,6 +14,21 @@ #import "SUStatusController.h" #import "SUConstants.h" +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1080 +@interface NSByteCountFormatter : NSFormatter { +@private + unsigned int _allowedUnits; + char _countStyle; + BOOL _allowsNonnumericFormatting, _includesUnit, _includesCount, _includesActualByteCount, + _adaptive, _zeroPadsFractionDigits; + int _formattingContext; + int _reserved[5]; +} ++ (NSString *)stringFromByteCount:(long long)byteCount + countStyle:(NSByteCountFormatterCountStyle)countStyle; +@end +#endif + @interface SUUIBasedUpdateDriver () @property (strong) SUStatusController *statusController; @@ -111,30 +126,41 @@ [self.statusController setMaxProgressValue:[response expectedContentLength]]; } -- (NSString *)humanReadableSizeFromDouble:(double)value +- (NSString *)localizedStringFromByteCount:(long long)value { - if (value < 1000) { - return [NSString stringWithFormat:@"%.0lf %@", value, SULocalizedString(@"B", @"the unit for bytes")]; + SInt32 minor = 0; + Gestalt(gestaltSystemVersionMinor, &minor); + if (minor < 8) { + 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")]; } - 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")]; + return [NSByteCountFormatter stringFromByteCount:value + countStyle:NSByteCountFormatterCountStyleFile]; } - (void)download:(NSURLDownload *)__unused download didReceiveDataOfLength:(NSUInteger)length { [self.statusController setProgressValue:[self.statusController progressValue] + (double)length]; if ([self.statusController maxProgressValue] > 0.0) - [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self humanReadableSizeFromDouble:[self.statusController progressValue]], [self humanReadableSizeFromDouble:[self.statusController maxProgressValue]]]]; + [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self localizedStringFromByteCount:(long long)self.statusController.progressValue], [self localizedStringFromByteCount:(long long)self.statusController.maxProgressValue]]]; else - [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self humanReadableSizeFromDouble:[self.statusController progressValue]]]]; + [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self localizedStringFromByteCount:(long long)self.statusController.progressValue]]]; } - (IBAction)cancelDownload:(id)__unused sender