diff --git a/.travis.yml b/.travis.yml index 2267c6ec..bfec1ffe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.2 +osx_image: xcode9 before_install: - brew update script: make ci diff --git a/CHANGELOG b/CHANGELOG index bd9c599e..c68454b4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,28 @@ -# 1.18.0 +# 1.19.0 + + * Refactoring of downloader code to avoid deprecated methods (Deadpikle) + * Changes to which methods run on the main thread. + Note: some delegate methods may be called on non-main thread now. (Kornel) + * Update Japanese localization (1024jp) + * Update Sparkle.strings (Stefan Paychère) + * Fix Sparkle clients polling too frequently (Jonathan Bullard) + * Handle SecTransformExecute errors (Kornel) + * Silence Touch Bar availability warnings on Xcode 9 by using API_AVAILABLE. Disable gnu-zero-variadic-macro-arguments to prevent warnings from use of API_AVAILABLE. (Kent Sutherland) + * 10.11 SDK compatibility (David Fuhrmann) + +# 1.18.1 + + * Add optional updaterDidRelaunchApplication: method on SUUpdaterDelegate (#1115) (App Tyrant) + * Implemented sparkle:os attribute as documented (Memphiz) + * Additional termination detection in case kpoll fails. (fujisoft) + * Included bin files in CocoaPods installation (Keith Smiley) + * Updated Dutch localization (Eitot) + * Updated German localization (Eitot) + * Updated Japanese translation (1024jp) + * Updated Portuguese translation (Victor) + * Updated to Xcode 9/Swift 4 + + # 1.18.0 * Name of the host app is used in authorization prompt (the `SPARKLE_RELAUNCH_TOOL_NAME` setting is now obsolete) * More detailed progress bar for package installers (Kornel Lesiński) diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index c1a8c503..a89af949 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -16,8 +16,8 @@ SPARKLE_AUTOMATED_DOWNGRADES = 0 SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0 SPARKLE_VERSION_MAJOR = 1 -SPARKLE_VERSION_MINOR = 18 -SPARKLE_VERSION_PATCH = 0 +SPARKLE_VERSION_MINOR = 19 +SPARKLE_VERSION_PATCH = 1 SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH) CURRENT_PROJECT_VERSION = $(SPARKLE_VERSION) @@ -88,4 +88,4 @@ CLANG_ENABLE_MODULES[sdk=macosx10.8] = NO WARNING_CFLAGS_EXTRA = -Wno-custom-atomic-properties -Wno-implicit-atomic-properties // Turn on all warnings, then disable a few which are almost impossible to avoid -WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import $(WARNING_CFLAGS_EXTRA) +WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import -Wno-gnu-zero-variadic-macro-arguments $(WARNING_CFLAGS_EXTRA) diff --git a/Configurations/ConfigCommonCoverage.xcconfig b/Configurations/ConfigCommonCoverage.xcconfig index afa2360c..1f95d774 100644 --- a/Configurations/ConfigCommonCoverage.xcconfig +++ b/Configurations/ConfigCommonCoverage.xcconfig @@ -1,4 +1,10 @@ #include "ConfigCommonDebug.xcconfig" +CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; +CLANG_WARN_COMMA = YES; +CLANG_WARN_INFINITE_RECURSION = YES; +CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; +CLANG_WARN_STRICT_PROTOTYPES = YES; +CLANG_WARN_SUSPICIOUS_MOVE = YES; GCC_GENERATE_TEST_COVERAGE_FILES = YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES diff --git a/Configurations/ConfigCommonDebug.xcconfig b/Configurations/ConfigCommonDebug.xcconfig index 824b79b3..a47e02c6 100644 --- a/Configurations/ConfigCommonDebug.xcconfig +++ b/Configurations/ConfigCommonDebug.xcconfig @@ -2,6 +2,12 @@ // Debug only +CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; +CLANG_WARN_COMMA = YES; +CLANG_WARN_INFINITE_RECURSION = YES; +CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; +CLANG_WARN_STRICT_PROTOTYPES = YES; +CLANG_WARN_SUSPICIOUS_MOVE = YES; GCC_OPTIMIZATION_LEVEL = 0 DEBUG_INFORMATION_FORMAT = dwarf ENABLE_TESTABILITY = YES diff --git a/Configurations/ConfigCommonRelease.xcconfig b/Configurations/ConfigCommonRelease.xcconfig index 0888aaff..99b4777e 100644 --- a/Configurations/ConfigCommonRelease.xcconfig +++ b/Configurations/ConfigCommonRelease.xcconfig @@ -2,6 +2,12 @@ // Release only +CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; +CLANG_WARN_COMMA = YES; +CLANG_WARN_INFINITE_RECURSION = YES; +CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; +CLANG_WARN_STRICT_PROTOTYPES = YES; +CLANG_WARN_SUSPICIOUS_MOVE = YES; GCC_OPTIMIZATION_LEVEL = s DEBUG_INFORMATION_FORMAT = dwarf-with-dsym GCC_GENERATE_DEBUGGING_SYMBOLS = YES diff --git a/Configurations/ConfigSwift.xcconfig b/Configurations/ConfigSwift.xcconfig index 8e0862f9..95c45171 100644 --- a/Configurations/ConfigSwift.xcconfig +++ b/Configurations/ConfigSwift.xcconfig @@ -1 +1,2 @@ -SWIFT_VERSION = 3.0 +SWIFT_VERSION = 4.0 +SWIFT_SWIFT3_OBJC_INFERENCE = Off; diff --git a/Configurations/make-release-package.sh b/Configurations/make-release-package.sh index 8580c55a..0e994806 100755 --- a/Configurations/make-release-package.sh +++ b/Configurations/make-release-package.sh @@ -2,11 +2,13 @@ set -e if [ "$ACTION" = "" ] ; then - # Sanity check that the Podspec version matches the Sparkle version - spec_version=$(printf "require 'cocoapods'\nspec = %s\nprint spec.version" "$(cat "$SRCROOT/Sparkle.podspec")" | LANG=en_US.UTF-8 ruby) - if [ "$spec_version" != "$CURRENT_PROJECT_VERSION" ] ; then - echo "podspec version '$spec_version' does not match the current project version '$CURRENT_PROJECT_VERSION'" >&2 - exit 1 + # If using cocoapods, sanity check that the Podspec version matches the Sparkle version + if [ -x "$(command -v pod)" ]; then + spec_version=$(printf "require 'cocoapods'\nspec = %s\nprint spec.version" "$(cat "$SRCROOT/Sparkle.podspec")" | LANG=en_US.UTF-8 ruby) + if [ "$spec_version" != "$CURRENT_PROJECT_VERSION" ] ; then + echo "podspec version '$spec_version' does not match the current project version '$CURRENT_PROJECT_VERSION'" >&2 + exit 1 + fi fi rm -rf "$CONFIGURATION_BUILD_DIR/staging" diff --git a/Documentation/build-docs.sh b/Documentation/build-docs.sh index 44b43bf4..65d5a000 100755 --- a/Documentation/build-docs.sh +++ b/Documentation/build-docs.sh @@ -5,6 +5,7 @@ if [ "$ACTION" = "" ] ; then doxygen Documentation/Doxyfile else echo "warning: Doxygen not found in PATH" + echo "open Terminal and type this command `brew install doxygen` then click `enter/return` key. finally build this target again" fi elif [ "$ACTION" = "clean" ] ; then rm -rf "$SRCROOT/Documentation/html" diff --git a/Makefile b/Makefile index aa89d64f..2eaced72 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .PHONY: all localizable-strings release build test ci +all: build + ifndef BUILDDIR BUILDDIR := $(shell mktemp -d "$(TMPDIR)/Sparkle.XXXXXX") endif diff --git a/Sparkle.podspec b/Sparkle.podspec index ccf1eb4f..7dfa6245 100644 --- a/Sparkle.podspec +++ b/Sparkle.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sparkle" - s.version = "1.18.0" + s.version = "1.19.1" s.summary = "A software update framework for macOS" s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers." s.homepage = "http://sparkle-project.org" @@ -22,6 +22,7 @@ Pod::Spec.new do |s| s.source = { :http => "https://github.com/sparkle-project/Sparkle/releases/download/#{s.version}/Sparkle-#{s.version}.tar.bz2" } s.source_files = 'Sparkle.framework/Versions/A/Headers/*.h' + s.preserve_paths = 'bin/*' s.public_header_files = 'Sparkle.framework/Versions/A/Headers/*.h' s.vendored_frameworks = 'Sparkle.framework' s.xcconfig = { diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 8175d07a..e8497ec9 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 47; objects = { /* Begin PBXAggregateTarget section */ @@ -49,6 +49,21 @@ 14950073195FCE4E00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; 14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6B19AEBC530061B14F /* signed-test-file.txt */; }; 14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6C19AEBC610061B14F /* test-pubkey.pem */; }; + 34074B901FEABD08001CB3A5 /* SPUDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 34074B8C1FEABD08001CB3A5 /* SPUDownloader.m */; }; + 34074B911FEABD08001CB3A5 /* SPUDownloader.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074B8D1FEABD08001CB3A5 /* SPUDownloader.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074B921FEABD08001CB3A5 /* SPUDownloaderDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074B8E1FEABD08001CB3A5 /* SPUDownloaderDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074B931FEABD08001CB3A5 /* SPUDownloaderProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074B8F1FEABD08001CB3A5 /* SPUDownloaderProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074B961FEABD24001CB3A5 /* SPULocalCacheDirectory.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074B941FEABD23001CB3A5 /* SPULocalCacheDirectory.h */; }; + 34074B971FEABD24001CB3A5 /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 34074B951FEABD23001CB3A5 /* SPULocalCacheDirectory.m */; }; + 34074B9A1FEABD49001CB3A5 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34074B981FEABD48001CB3A5 /* SPUURLRequest.m */; }; + 34074B9B1FEABD49001CB3A5 /* SPUURLRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074B991FEABD49001CB3A5 /* SPUURLRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074B9E1FEABD5A001CB3A5 /* SPUDownloadData.m in Sources */ = {isa = PBXBuildFile; fileRef = 34074B9C1FEABD5A001CB3A5 /* SPUDownloadData.m */; }; + 34074B9F1FEABD5A001CB3A5 /* SPUDownloadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074B9D1FEABD5A001CB3A5 /* SPUDownloadData.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074BA21FEABFD2001CB3A5 /* SPUDownloaderSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074BA01FEABFD2001CB3A5 /* SPUDownloaderSession.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074BA31FEABFD2001CB3A5 /* SPUDownloaderSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 34074BA11FEABFD2001CB3A5 /* SPUDownloaderSession.m */; }; + 34074BA71FEAC417001CB3A5 /* SPUDownloaderDeprecated.h in Headers */ = {isa = PBXBuildFile; fileRef = 34074BA51FEAC417001CB3A5 /* SPUDownloaderDeprecated.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34074BA81FEAC417001CB3A5 /* SPUDownloaderDeprecated.m in Sources */ = {isa = PBXBuildFile; fileRef = 34074BA61FEAC417001CB3A5 /* SPUDownloaderDeprecated.m */; }; + 342731481FF58E5B00285FBD /* SPUDownloaderTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342731461FF58E4F00285FBD /* SPUDownloaderTest.swift */; }; 3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; 55C14BD4136EEFCE00649790 /* Autoupdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14BD3136EEFCE00649790 /* Autoupdate.m */; }; 55C14BD9136EF00C00649790 /* SUStatus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BD8136EF00C00649790 /* SUStatus.xib */; }; @@ -160,7 +175,7 @@ 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A354530DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61A354560DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A354540DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.m */; }; 61AAE8280A321A7F00D8810D /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; - 61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B078CC15A5FB6100600039 /* SUCodeSigningVerifier.h */; }; + 61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B078CC15A5FB6100600039 /* SUCodeSigningVerifier.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B078CF15A5FB6100600039 /* SUCodeSigningVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B078CD15A5FB6100600039 /* SUCodeSigningVerifier.m */; }; 61B5F8ED09C4CE3C00B25A18 /* SUUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */; }; @@ -460,6 +475,11 @@ 0263187714FEBB42005EBF43 /* uk */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = uk; path = uk.lproj/SUUpdatePermissionPrompt.xib; sourceTree = ""; }; 0867D69BFE84028FC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; + 0A8DAD73207FA6F300FFD934 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Sparkle.strings; sourceTree = ""; }; + 0A8DAD74207FA6F300FFD934 /* hu */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = hu; path = hu.lproj/SUAutomaticUpdateAlert.xib; sourceTree = ""; }; + 0A8DAD75207FA6F300FFD934 /* hu */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = hu; path = hu.lproj/SUUpdateAlert.xib; sourceTree = ""; }; + 0A8DAD76207FA6F400FFD934 /* hu */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = hu; path = hu.lproj/SUUpdatePermissionPrompt.xib; sourceTree = ""; }; + 0A8DAD77207FA6F400FFD934 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/InfoPlist.strings; sourceTree = ""; }; 1420DF4D196247B500203BB0 /* build-docs.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "build-docs.sh"; sourceTree = ""; }; 1420DF4E196247B500203BB0 /* Doxyfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Doxyfile; sourceTree = ""; }; 1420DF4F196247F900203BB0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; @@ -498,7 +518,6 @@ 1A985A3B1C5C32A60001163A /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A3C1C5C32A70001163A /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A3D1C5C32A80001163A /* he */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/InfoPlist.strings; sourceTree = ""; }; - 1A985A3E1C5C32A90001163A /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A3F1C5C32AA0001163A /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = id; path = id.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A401C5C32AA0001163A /* is */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = is; path = is.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A411C5C32AB0001163A /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -520,6 +539,22 @@ 1A985A511C5C32BB0001163A /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A521C5C32BC0001163A /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/InfoPlist.strings; sourceTree = ""; }; 1A985A531C5C32BD0001163A /* el */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = el; path = el.lproj/InfoPlist.strings; sourceTree = ""; }; + 34074B8C1FEABD08001CB3A5 /* SPUDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUDownloader.m; sourceTree = ""; }; + 34074B8D1FEABD08001CB3A5 /* SPUDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloader.h; sourceTree = ""; }; + 34074B8E1FEABD08001CB3A5 /* SPUDownloaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloaderDelegate.h; sourceTree = ""; }; + 34074B8F1FEABD08001CB3A5 /* SPUDownloaderProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloaderProtocol.h; sourceTree = ""; }; + 34074B941FEABD23001CB3A5 /* SPULocalCacheDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPULocalCacheDirectory.h; sourceTree = ""; }; + 34074B951FEABD23001CB3A5 /* SPULocalCacheDirectory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPULocalCacheDirectory.m; sourceTree = ""; }; + 34074B981FEABD48001CB3A5 /* SPUURLRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUURLRequest.m; sourceTree = ""; }; + 34074B991FEABD49001CB3A5 /* SPUURLRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUURLRequest.h; sourceTree = ""; }; + 34074B9C1FEABD5A001CB3A5 /* SPUDownloadData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUDownloadData.m; sourceTree = ""; }; + 34074B9D1FEABD5A001CB3A5 /* SPUDownloadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloadData.h; sourceTree = ""; }; + 34074BA01FEABFD2001CB3A5 /* SPUDownloaderSession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUDownloaderSession.h; sourceTree = ""; }; + 34074BA11FEABFD2001CB3A5 /* SPUDownloaderSession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUDownloaderSession.m; sourceTree = ""; }; + 34074BA41FEAC0BC001CB3A5 /* SPUDownloader_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUDownloader_Private.h; sourceTree = ""; }; + 34074BA51FEAC417001CB3A5 /* SPUDownloaderDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUDownloaderDeprecated.h; sourceTree = ""; }; + 34074BA61FEAC417001CB3A5 /* SPUDownloaderDeprecated.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUDownloaderDeprecated.m; sourceTree = ""; }; + 342731461FF58E4F00285FBD /* SPUDownloaderTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPUDownloaderTest.swift; sourceTree = ""; }; 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionDisplayProtocol.h; sourceTree = ""; }; 4607BEA21948443800EF8DA4 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/Sparkle.strings; sourceTree = ""; }; 4607BEA31948443800EF8DA4 /* nb */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = nb; path = nb.lproj/SUAutomaticUpdateAlert.xib; sourceTree = ""; }; @@ -1047,15 +1082,16 @@ 1495006D195FBBBD00BC5B5B /* Sparkle */ = { isa = PBXGroup; children = ( - 720767D01E2E3DD300F9A850 /* AppKitPrevention.h */, 61299B3909CB055000B7442F /* Appcast Support */, 55C14BD5136EEFD000649790 /* Autoupdate */, + 34074B8B1FEABCE7001CB3A5 /* Downloader */, 089C1665FE841158C02AAC07 /* Framework Resources */, 618FA6DB0DB485440026945C /* Installation */, 61B5F8F309C4CE5900B25A18 /* Other Sources */, 6101354A0DD25B7F0049ACDF /* Unarchiving */, 61F83F6E0DBFE07A006FDD30 /* Update Control */, 61299B3A09CB056100B7442F /* User Interface */, + 720767D01E2E3DD300F9A850 /* AppKitPrevention.h */, ); path = Sparkle; sourceTree = ""; @@ -1079,6 +1115,28 @@ path = Resources; sourceTree = ""; }; + 34074B8B1FEABCE7001CB3A5 /* Downloader */ = { + isa = PBXGroup; + children = ( + 34074B9D1FEABD5A001CB3A5 /* SPUDownloadData.h */, + 34074B9C1FEABD5A001CB3A5 /* SPUDownloadData.m */, + 34074B8D1FEABD08001CB3A5 /* SPUDownloader.h */, + 34074B8C1FEABD08001CB3A5 /* SPUDownloader.m */, + 34074BA41FEAC0BC001CB3A5 /* SPUDownloader_Private.h */, + 34074BA51FEAC417001CB3A5 /* SPUDownloaderDeprecated.h */, + 34074BA61FEAC417001CB3A5 /* SPUDownloaderDeprecated.m */, + 34074BA01FEABFD2001CB3A5 /* SPUDownloaderSession.h */, + 34074BA11FEABFD2001CB3A5 /* SPUDownloaderSession.m */, + 34074B8E1FEABD08001CB3A5 /* SPUDownloaderDelegate.h */, + 34074B8F1FEABD08001CB3A5 /* SPUDownloaderProtocol.h */, + 34074B941FEABD23001CB3A5 /* SPULocalCacheDirectory.h */, + 34074B951FEABD23001CB3A5 /* SPULocalCacheDirectory.m */, + 34074B991FEABD49001CB3A5 /* SPUURLRequest.h */, + 34074B981FEABD48001CB3A5 /* SPUURLRequest.m */, + ); + name = Downloader; + sourceTree = ""; + }; 55C14BD5136EEFD000649790 /* Autoupdate */ = { isa = PBXGroup; children = ( @@ -1144,6 +1202,7 @@ 14958C7019AEBE350061B14F /* Resources */, 72AFC6121B9A944200F6B565 /* Sparkle Unit Tests-Bridging-Header.h */, 612279DA0DB5470200AB99EA /* SparkleTests-Info.plist */, + 342731461FF58E4F00285FBD /* SPUDownloaderTest.swift */, 5AA4DCD01C73E5510078F128 /* SUAppcastTest.swift */, 142E0E0819A83AAC00E4312B /* SUBinaryDeltaTest.m */, F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */, @@ -1383,19 +1442,24 @@ 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, + 34074BA71FEAC417001CB3A5 /* SPUDownloaderDeprecated.h in Headers */, 72316BDE1E0E17910039EFD9 /* SUApplicationInfo.h in Headers */, 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */, + 34074B921FEABD08001CB3A5 /* SPUDownloaderDelegate.h in Headers */, + 34074B961FEABD24001CB3A5 /* SPULocalCacheDirectory.h in Headers */, 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */, 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */, 5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */, 72316BD91E0E17180039EFD9 /* SUBundleIcon.h in Headers */, - 61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */, 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */, 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, + 61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */, 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, + 34074B9F1FEABD5A001CB3A5 /* SPUDownloadData.h in Headers */, 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, + 34074B911FEABD08001CB3A5 /* SPUDownloader.h in Headers */, 722954C41D04E66F00ECF9CA /* SUFileOperationConstants.h in Headers */, 767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */, 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, @@ -1414,10 +1478,12 @@ 72316BE31E0E1C7F0039EFD9 /* SUSystemUpdateInfo.h in Headers */, E1545EC51E1D7E0200FAECE8 /* SUTouchBarButtonGroup.h in Headers */, 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */, + 34074B931FEABD08001CB3A5 /* SPUDownloaderProtocol.h in Headers */, 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */, 722589DA1E0B19F4005EA0B9 /* SUUnarchiverNotifier.h in Headers */, 722589D71E0AD86B005EA0B9 /* SUUnarchiverProtocol.h in Headers */, 61B5FCDF09C52A9F00B25A18 /* SUUpdateAlert.h in Headers */, + 34074B9B1FEABD49001CB3A5 /* SPUURLRequest.h in Headers */, 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */, 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */, 7205C4311E1215AD00E370AE /* SUUpdatePermissionResponse.h in Headers */, @@ -1428,6 +1494,7 @@ 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, 3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */, + 34074BA21FEABFD2001CB3A5 /* SPUDownloaderSession.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1628,16 +1695,16 @@ attributes = { CLASSPREFIX = SU; LastSwiftUpdateCheck = 0800; - LastUpgradeCheck = 0830; + LastUpgradeCheck = 0920; ORGANIZATIONNAME = "Sparkle Project"; TargetAttributes = { 5AA96C541E0AE0DB00CA4346 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; ProvisioningStyle = Automatic; }; 612279D80DB5470200AB99EA = { - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; TestTargetID = 8DC2EF4F0486A6940098B216; }; 722954B31D04ADAF00ECF9CA = { @@ -1648,10 +1715,13 @@ LastSwiftMigration = 0800; TestTargetID = 61B5F90109C4CEE200B25A18; }; + 8DC2EF4F0486A6940098B216 = { + LastSwiftMigration = 0920; + }; }; }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Sparkle" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 6.3"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -1879,8 +1949,8 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, - 720767CF1E2DC37400F9A850 /* TerminationListener.m in Sources */, E1EC2A301E21667000245715 /* SUTouchBarButtonGroup.m in Sources */, + 720767CF1E2DC37400F9A850 /* TerminationListener.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1943,6 +2013,7 @@ 721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */, 721CF1A91AD7644C00D9AC09 /* sais.c in Sources */, 5A4094481C74EA5200983BE0 /* SUAppcastTest.swift in Sources */, + 342731481FF58E5B00285FBD /* SPUDownloaderTest.swift in Sources */, 72D4DAA11AD7632900B211E2 /* SUBinaryDeltaCreate.m in Sources */, 142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */, F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */, @@ -1997,6 +2068,7 @@ buildActionMask = 2147483647; files = ( 723B252D1CEAB3A600909873 /* bscommon.c in Sources */, + 34074B9E1FEABD5A001CB3A5 /* SPUDownloadData.m in Sources */, 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, @@ -2005,7 +2077,9 @@ 61B93B280DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m in Sources */, 61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */, 5D06E8EC0FD68CE4005AE3F6 /* SUBinaryDeltaApply.m in Sources */, + 34074B971FEABD24001CB3A5 /* SPULocalCacheDirectory.m in Sources */, 5D06E8ED0FD68CE4005AE3F6 /* SUBinaryDeltaCommon.m in Sources */, + 34074BA31FEABFD2001CB3A5 /* SPUDownloaderSession.m in Sources */, 5D06E93A0FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m in Sources */, 72316BDA1E0E17180039EFD9 /* SUBundleIcon.m in Sources */, 61B078CF15A5FB6100600039 /* SUCodeSigningVerifier.m in Sources */, @@ -2017,6 +2091,7 @@ 767B61AD1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */, 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */, 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */, + 34074B901FEABD08001CB3A5 /* SPUDownloader.m in Sources */, 55C14F07136EF6DB00649790 /* SULog.m in Sources */, 726F2CE61BC9C33D001971A4 /* SUOperatingSystem.m in Sources */, 618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */, @@ -2024,10 +2099,12 @@ 618FA5060DAE8AB80026945C /* SUPlainInstaller.m in Sources */, 6101347C0DD2541A0049ACDF /* SUProbingUpdateDriver.m in Sources */, 61B93C0A0DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m in Sources */, + 34074BA81FEAC417001CB3A5 /* SPUDownloaderDeprecated.m in Sources */, 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */, + 34074B9A1FEABD49001CB3A5 /* SPUURLRequest.m in Sources */, E1545EC61E1D7E0200FAECE8 /* SUTouchBarButtonGroup.m in Sources */, 61B93A3D0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.m in Sources */, 61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */, @@ -2163,6 +2240,7 @@ 0263187514FEBB42005EBF43 /* uk */, 55C14BEC136EF20D00649790 /* zh_CN */, 55C14BED136EF20D00649790 /* zh_TW */, + 0A8DAD74207FA6F300FFD934 /* hu */, ); name = SUAutomaticUpdateAlert.xib; sourceTree = ""; @@ -2197,6 +2275,7 @@ 0263187614FEBB42005EBF43 /* uk */, 55C14C02136EF26100649790 /* zh_CN */, 55C14C03136EF26100649790 /* zh_TW */, + 0A8DAD75207FA6F300FFD934 /* hu */, ); name = SUUpdateAlert.xib; sourceTree = ""; @@ -2231,6 +2310,7 @@ 0263187714FEBB42005EBF43 /* uk */, 55C14C17136EF2C700649790 /* zh_CN */, 55C14C18136EF2C700649790 /* zh_TW */, + 0A8DAD76207FA6F400FFD934 /* hu */, ); name = SUUpdatePermissionPrompt.xib; sourceTree = ""; @@ -2268,6 +2348,7 @@ 0263187214FEBB31005EBF43 /* uk */, 61131A090F846D0A00E97AF6 /* zh_CN */, 61131A0A0F846D1100E97AF6 /* zh_TW */, + 0A8DAD73207FA6F300FFD934 /* hu */, ); name = Sparkle.strings; sourceTree = ""; @@ -2288,7 +2369,6 @@ 1A985A331C5C329D0001163A /* fr */, 1A985A4B1C5C32B60001163A /* fr-CA */, 1A985A3D1C5C32A80001163A /* he */, - 1A985A3E1C5C32A90001163A /* hu */, 1A985A3F1C5C32AA0001163A /* id */, 1A985A401C5C32AA0001163A /* is */, 1A985A361C5C32A20001163A /* it */, @@ -2310,6 +2390,7 @@ 1A985A511C5C32BB0001163A /* uk */, 1A985A4A1C5C32B50001163A /* zh-Hans */, 1A985A351C5C329E0001163A /* zh-Hant */, + 0A8DAD77207FA6F400FFD934 /* hu */, ); name = InfoPlist.strings; sourceTree = ""; @@ -2372,6 +2453,11 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Coverage; }; @@ -2425,6 +2511,11 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -2432,6 +2523,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941D50D94A70100DD942E /* ConfigFrameworkRelease.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; + DEFINES_MODULE = YES; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -2446,6 +2541,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941CC0D94A70100DD942E /* ConfigCommonRelease.xcconfig */; buildSettings = { + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; }; name = Release; }; diff --git a/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme b/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme index ffa56e90..9b47082f 100644 --- a/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme +++ b/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme @@ -1,6 +1,6 @@ @@ -45,6 +46,7 @@ buildConfiguration = "Release" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" @@ -61,8 +63,6 @@ ReferencedContainer = "container:Sparkle.xcodeproj"> - - diff --git a/Sparkle/Autoupdate/TerminationListener.m b/Sparkle/Autoupdate/TerminationListener.m index 8c20fd07..5948fb51 100644 --- a/Sparkle/Autoupdate/TerminationListener.m +++ b/Sparkle/Autoupdate/TerminationListener.m @@ -116,6 +116,11 @@ if ([self terminated]) { [self invokeCompletionWithSuccess:YES]; } + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + if ([self terminated]) { + [self invokeCompletionWithSuccess:YES]; + } + }); } static void noteExitKQueueCallback(CFFileDescriptorRef file, CFOptionFlags __unused callBackTypes, void *info) diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift old mode 100755 new mode 100644 diff --git a/Sparkle/SPUDownloadData.h b/Sparkle/SPUDownloadData.h new file mode 100644 index 00000000..41cd5743 --- /dev/null +++ b/Sparkle/SPUDownloadData.h @@ -0,0 +1,43 @@ +// +// SPUDownloadData.h +// Sparkle +// +// Created by Mayur Pawashe on 8/10/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif + +#import "SUExport.h" + +NS_ASSUME_NONNULL_BEGIN + +/*! + * A class for containing downloaded data along with some information about it. + */ +SU_EXPORT @interface SPUDownloadData : NSObject + +- (instancetype)initWithData:(NSData *)data textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType; + +/*! + * The raw data that was downloaded. + */ +@property (nonatomic, readonly) NSData *data; + +/*! + * The IANA charset encoding name if available. Eg: "utf-8" + */ +@property (nonatomic, readonly, nullable, copy) NSString *textEncodingName; + +/*! + * The MIME type if available. Eg: "text/plain" + */ +@property (nonatomic, readonly, nullable, copy) NSString *MIMEType; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUDownloadData.m b/Sparkle/SPUDownloadData.m new file mode 100644 index 00000000..e769dd50 --- /dev/null +++ b/Sparkle/SPUDownloadData.m @@ -0,0 +1,71 @@ +// +// SPUDownloadData.m +// Sparkle +// +// Created by Mayur Pawashe on 8/10/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPUDownloadData.h" + + +#include "AppKitPrevention.h" + +static NSString *SPUDownloadDataKey = @"SPUDownloadData"; +static NSString *SPUDownloadTextEncodingKey = @"SPUDownloadTextEncoding"; +static NSString *SPUDownloadMIMETypeKey = @"SPUDownloadMIMEType"; + +@implementation SPUDownloadData + +@synthesize data = _data; +@synthesize textEncodingName = _textEncodingName; +@synthesize MIMEType = _MIMEType; + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (instancetype)initWithData:(NSData *)data textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString *)MIMEType +{ + self = [super init]; + if (self != nil) { + _data = data; + _textEncodingName = textEncodingName; + _MIMEType = MIMEType; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.data forKey:SPUDownloadDataKey]; + + if (self.textEncodingName != nil) { + [coder encodeObject:self.textEncodingName forKey:SPUDownloadTextEncodingKey]; + } + + if (self.MIMEType != nil) { + [coder encodeObject:self.MIMEType forKey:SPUDownloadMIMETypeKey]; + } +} + +- (nullable instancetype)initWithCoder:(NSCoder *)decoder +{ + if (@available(macOS 10.8, *)) { + NSData *data = [decoder decodeObjectOfClass:[NSData class] forKey:SPUDownloadDataKey]; + if (data == nil) { + return nil; + } + + NSString *textEncodingName = [decoder decodeObjectOfClass:[NSString class] forKey:SPUDownloadTextEncodingKey]; + + NSString *MIMEType = [decoder decodeObjectOfClass:[NSString class] forKey:SPUDownloadMIMETypeKey]; + + return [self initWithData:data textEncodingName:textEncodingName MIMEType:MIMEType]; + } else { + abort(); // Not used on 10.7 + } +} + +@end diff --git a/Sparkle/SPUDownloader.h b/Sparkle/SPUDownloader.h new file mode 100644 index 00000000..5eee9bd5 --- /dev/null +++ b/Sparkle/SPUDownloader.h @@ -0,0 +1,25 @@ +// +// SPUDownloader.h +// Downloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif +#import "SPUDownloaderProtocol.h" + +@protocol SPUDownloaderDelegate; + +// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection. +@interface SPUDownloader : NSObject + +// Due to XPC remote object reasons, this delegate is strongly referenced +// Invoke cleanup when done with this instance +- (instancetype)initWithDelegate:(id )delegate; + +@end diff --git a/Sparkle/SPUDownloader.m b/Sparkle/SPUDownloader.m new file mode 100644 index 00000000..ef6e9067 --- /dev/null +++ b/Sparkle/SPUDownloader.m @@ -0,0 +1,118 @@ +// +// SPUDownloader.m +// Downloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPUDownloader.h" +#import "SPUDownloaderDelegate.h" +#import "SPULocalCacheDirectory.h" +#import "SPUURLRequest.h" +#import "SPUDownloadData.h" +#import "SUErrors.h" +#import "SPUDownloader_Private.h" + +#include "AppKitPrevention.h" + +@interface SPUDownloader () + +@end + +@implementation SPUDownloader + +@synthesize delegate = _delegate; +@synthesize bundleIdentifier = _bundleIdentifier; +@synthesize desiredFilename = _desiredFilename; +@synthesize downloadFilename = _downloadFilename; +@synthesize disabledAutomaticTermination = _disabledAutomaticTermination; +@synthesize mode = _mode; +@synthesize receivedExpectedBytes = _receivedExpectedBytes; + +- (instancetype)initWithDelegate:(id )delegate +{ + self = [super init]; + if (self != nil) { + _delegate = delegate; + } + return self; +} + +// Don't implement dealloc - make the client call cleanup, which is the only way to remove the reference cycle from the delegate anyway + +- (void)startPersistentDownloadWithRequest:(SPUURLRequest *)__unused request bundleIdentifier:(NSString *)__unused bundleIdentifier desiredFilename:(NSString *)__unused desiredFilename +{ + +} + +- (void)startTemporaryDownloadWithRequest:(SPUURLRequest *)__unused request +{ + +} + +- (void)enableAutomaticTermination +{ + if (self.disabledAutomaticTermination) { + [[NSProcessInfo processInfo] enableAutomaticTermination:SUDownloadingReason]; + self.disabledAutomaticTermination = NO; + } +} + +- (void)cleanup +{ + [self enableAutomaticTermination]; + self.delegate = nil; + + if (self.mode == SPUDownloadModeTemporary && self.downloadFilename != nil) + { + [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:NULL]; + self.downloadFilename = nil; + } +} + +- (void)cancel +{ + +} + +- (void)downloadDidFinish +{ + +} + +-(void)downloadDidFinishWithData:(SPUDownloadData*)data +{ + switch (self.mode) { + case SPUDownloadModeTemporary: + if (data != nil) { + [self.delegate downloaderDidFinishWithTemporaryDownloadData:data]; + } else { + [self.delegate downloaderDidFailWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read temporary downloaded data from %@", self.downloadFilename]}]]; + } + break; + case SPUDownloadModePersistent: + [self.delegate downloaderDidFinishWithTemporaryDownloadData:nil]; + break; + } +} + +-(NSString*)getAndCleanTempDirectory +{ + NSString *rootPersistentDownloadCachePath = [[SPULocalCacheDirectory cachePathForBundleIdentifier:self.bundleIdentifier] stringByAppendingPathComponent:@"PersistentDownloads"]; + + [SPULocalCacheDirectory removeOldItemsInDirectory:rootPersistentDownloadCachePath]; + + NSString *tempDir = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootPersistentDownloadCachePath]; + if (tempDir == nil) { + // Okay, something's really broken with this user's file structure. + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.", tempDir] }]; + + [self.delegate downloaderDidFailWithError:error]; + + [self cancel]; + } + return tempDir; +} + +@end diff --git a/Sparkle/SPUDownloaderDelegate.h b/Sparkle/SPUDownloaderDelegate.h new file mode 100644 index 00000000..76e7e750 --- /dev/null +++ b/Sparkle/SPUDownloaderDelegate.h @@ -0,0 +1,38 @@ +// +// SPUDownloaderDelegate.h +// Sparkle +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif + +NS_ASSUME_NONNULL_BEGIN + +@class SPUDownloadData; + +@protocol SPUDownloaderDelegate + +// This is only invoked for persistent downloads +- (void)downloaderDidSetDestinationName:(NSString *)destinationName temporaryDirectory:(NSString *)temporaryDirectory; + +// Under rare cases, this may be called more than once, in which case the current progress should be reset back to 0 +// This is only invoked for persistent downloads +- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength; + +// This is only invoked for persistent downloads +- (void)downloaderDidReceiveDataOfLength:(uint64_t)length; + +// downloadData is nil if this is a persisent download, otherwise it's non-nil if it's a temporary download +- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)downloadData; + +- (void)downloaderDidFailWithError:(NSError *)error; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUDownloaderDeprecated.h b/Sparkle/SPUDownloaderDeprecated.h new file mode 100644 index 00000000..36302df4 --- /dev/null +++ b/Sparkle/SPUDownloaderDeprecated.h @@ -0,0 +1,13 @@ +// +// SPUDownloaderDeprecated.h +// Sparkle +// +// Created by Deadpikle on 12/20/17. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import "SPUDownloader.h" + +@interface SPUDownloaderDeprecated : SPUDownloader + +@end diff --git a/Sparkle/SPUDownloaderDeprecated.m b/Sparkle/SPUDownloaderDeprecated.m new file mode 100644 index 00000000..ae2a065c --- /dev/null +++ b/Sparkle/SPUDownloaderDeprecated.m @@ -0,0 +1,167 @@ +// +// SPUDownloaderDeprecated.m +// Sparkle +// +// Created by Deadpikle on 12/20/17. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import "SPUDownloaderDeprecated.h" +#import "SPUURLRequest.h" +#import "SPUDownloader_Private.h" +#import "SPUDownloadData.h" +#import "SPULocalCacheDirectory.h" +#import "SUErrors.h" + +#include "AppKitPrevention.h" + +@interface SPUDownloaderDeprecated () + +@property (nonatomic) NSURLDownload *download; +@property (nonatomic) NSURLResponse *response; + +@end + +@implementation SPUDownloaderDeprecated + +@synthesize download = _download; +@synthesize response = _response; + +- (void)startPersistentDownloadWithRequest:(SPUURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.download == nil && self.delegate != nil) { + // Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks + [[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason]; + self.disabledAutomaticTermination = YES; + + self.mode = SPUDownloadModePersistent; + self.desiredFilename = desiredFilename; + self.bundleIdentifier = bundleIdentifier; + + self.download = [[NSURLDownload alloc] initWithRequest:request.request delegate:self]; + } + }); +} + +- (void)startTemporaryDownloadWithRequest:(SPUURLRequest *)request +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.download == nil && self.delegate != nil) { + // Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks + [[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason]; + self.disabledAutomaticTermination = YES; + + self.mode = SPUDownloadModeTemporary; + self.download = [[NSURLDownload alloc] initWithRequest:request.request delegate:self]; + } + }); +} + +- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name +{ + if (self.mode == SPUDownloadModeTemporary) { + // Files downloaded in temporary mode should not last for very long, + // so it's ideal to place them in a system temporary directory + NSString *destinationFilename = NSTemporaryDirectory(); + if (destinationFilename) { + destinationFilename = [destinationFilename stringByAppendingPathComponent:name]; + + [self.download setDestination:destinationFilename allowOverwrite:NO]; + } + } else { + NSString *tempDir = [super getAndCleanTempDirectory]; + + if (tempDir != nil) { + NSString *downloadFileName = self.desiredFilename; + NSString *downloadFileNameDirectory = [tempDir stringByAppendingPathComponent:downloadFileName]; + + NSError *createError = nil; + if (![[NSFileManager defaultManager] createDirectoryAtPath:downloadFileNameDirectory withIntermediateDirectories:NO attributes:nil error:&createError]) { + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a download file name %@ directory inside temporary directory for the update download at %@.", downloadFileName, downloadFileNameDirectory] }]; + + [self.delegate downloaderDidFailWithError:error]; + } else { + [self.download setDestination:[downloadFileNameDirectory stringByAppendingPathComponent:name] allowOverwrite:YES]; + + [self.delegate downloaderDidSetDestinationName:name temporaryDirectory:downloadFileNameDirectory]; + } + } + } +} + +- (void)download:(NSURLDownload *)__unused aDownload didCreateDestination:(NSString *)path +{ + self.downloadFilename = path; +} + +- (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response +{ + self.response = response; + + if (self.mode == SPUDownloadModePersistent) { + // It might be tempting to send over the response object instead of the expected content length but this isn't a good idea + // For one, we are only ever concerned about the expected content length + // Another reason is that NSURLResponse doesn't support NSSecureCoding in older OS releases (eg: 10.8), which cause issues with XPC + [self.delegate downloaderDidReceiveExpectedContentLength:response.expectedContentLength]; + } +} + +- (void)download:(NSURLDownload *)__unused download didReceiveDataOfLength:(NSUInteger)length +{ + if (self.mode == SPUDownloadModePersistent) { + [self.delegate downloaderDidReceiveDataOfLength:length]; + } +} + +- (void)downloadDidFinish:(NSURLDownload *)__unused d +{ + [self downloadDidFinish]; +} + +- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error +{ + self.download = nil; + [self.delegate downloaderDidFailWithError:error]; + [self cleanup]; +} + +- (BOOL)download:(NSURLDownload *)__unused download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType +{ + // We don't want the download system to extract our gzips for persistent downloads + // Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug. + return (self.mode == SPUDownloadModeTemporary || [encodingType rangeOfString:@"gzip"].location == NSNotFound); +} + +- (void)downloadDidFinish +{ + assert(self.response != nil); + assert(self.downloadFilename != nil); + + SPUDownloadData *downloadData = nil; + if (self.mode == SPUDownloadModeTemporary) { + NSData *data = [NSData dataWithContentsOfFile:self.downloadFilename]; + if (data != nil) { + downloadData = [[SPUDownloadData alloc] initWithData:data textEncodingName:self.response.textEncodingName MIMEType:self.response.MIMEType]; + } + } + + self.download = nil; + + [super downloadDidFinishWithData:downloadData]; +} + +-(void)cleanup +{ + [self.download cancel]; + self.download = nil; + self.response = nil; + [super cleanup]; +} + +- (void)cancel +{ + [self cleanup]; +} + +@end diff --git a/Sparkle/SPUDownloaderProtocol.h b/Sparkle/SPUDownloaderProtocol.h new file mode 100644 index 00000000..ebe477fe --- /dev/null +++ b/Sparkle/SPUDownloaderProtocol.h @@ -0,0 +1,34 @@ +// +// SPUDownloaderProtocol.h +// PersistentDownloader +// +// Created by Mayur Pawashe on 4/1/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif + +NS_ASSUME_NONNULL_BEGIN + +@class SPUURLRequest; + +// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service. +@protocol SPUDownloaderProtocol + +- (void)startPersistentDownloadWithRequest:(SPUURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename; + +- (void)startTemporaryDownloadWithRequest:(SPUURLRequest *)request; + +- (void)downloadDidFinish; + +- (void)cleanup; + +- (void)cancel; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUDownloaderSession.h b/Sparkle/SPUDownloaderSession.h new file mode 100644 index 00000000..4bde75aa --- /dev/null +++ b/Sparkle/SPUDownloaderSession.h @@ -0,0 +1,20 @@ +// +// SPUDownloaderSession.h +// Sparkle +// +// Created by Deadpikle on 12/20/17. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif +#import "SPUDownloader.h" +#import "SPUDownloaderProtocol.h" + +NS_CLASS_AVAILABLE(NSURLSESSION_AVAILABLE, 7_0) +@interface SPUDownloaderSession : SPUDownloader + +@end diff --git a/Sparkle/SPUDownloaderSession.m b/Sparkle/SPUDownloaderSession.m new file mode 100644 index 00000000..219c4b22 --- /dev/null +++ b/Sparkle/SPUDownloaderSession.m @@ -0,0 +1,166 @@ +// +// SPUDownloaderSession.m +// Sparkle +// +// Created by Deadpikle on 12/20/17. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#import "SPUDownloaderSession.h" +#import "SPUURLRequest.h" +#import "SPUDownloader_Private.h" +#import "SPULocalCacheDirectory.h" +#import "SUErrors.h" +#import "SPUDownloadData.h" + +#include "AppKitPrevention.h" + +@interface SPUDownloaderSession () + +@property (nonatomic) NSURLSession *downloadSession; +@property (nonatomic) NSURLSessionDownloadTask *download; + +@end + +@implementation SPUDownloaderSession + +@synthesize downloadSession = _downloadSession; +@synthesize download = _download; + +- (void)startDownloadWithRequest:(SPUURLRequest *)request +{ + NSOperationQueue *queue = [NSOperationQueue mainQueue]; + self.downloadSession = [NSURLSession + sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] + delegate:self + delegateQueue:queue]; + self.download = [self.downloadSession downloadTaskWithRequest:request.request]; + [self.download resume]; +} + +- (void)startPersistentDownloadWithRequest:(SPUURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.download == nil && self.delegate != nil) { + // Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks + [[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason]; + self.disabledAutomaticTermination = YES; + + self.mode = SPUDownloadModePersistent; + self.desiredFilename = desiredFilename; + self.bundleIdentifier = bundleIdentifier; + + [self startDownloadWithRequest:request]; + } + }); +} + +- (void)startTemporaryDownloadWithRequest:(SPUURLRequest *)request +{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.download == nil && self.delegate != nil) { + // Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks + [[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason]; + self.disabledAutomaticTermination = YES; + + self.mode = SPUDownloadModeTemporary; + [self startDownloadWithRequest:request]; + } + }); +} + +- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *)__unused downloadTask didFinishDownloadingToURL:(NSURL *)location +{ + if (self.mode == SPUDownloadModeTemporary) { + self.downloadFilename = location.path; + [self downloadDidFinish]; // file is already in a system temp dir + } else { + NSString *tempDir = [super getAndCleanTempDirectory]; + + if (tempDir != nil) { + NSString *downloadFileName = self.desiredFilename; + NSString *downloadFileNameDirectory = [tempDir stringByAppendingPathComponent:downloadFileName]; + + NSError *createError = nil; + if (![[NSFileManager defaultManager] createDirectoryAtPath:downloadFileNameDirectory withIntermediateDirectories:NO attributes:nil error:&createError]) { + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a download file name %@ directory inside temporary directory for the update download at %@.", downloadFileName, downloadFileNameDirectory] }]; + + [self.delegate downloaderDidFailWithError:error]; + } else { + NSString *name = self.download.response.suggestedFilename; + if (!name) { + name = location.lastPathComponent; // This likely contains nothing useful to identify the file (e.g. CFNetworkDownload_87LVIz.tmp) + } + NSString *toPath = [downloadFileNameDirectory stringByAppendingPathComponent:name]; + NSString *fromPath = location.path; // suppress moveItemAtPath: non-null warning + NSError *error = nil; + if ([[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:&error]) { + self.downloadFilename = toPath; + [self.delegate downloaderDidSetDestinationName:name temporaryDirectory:downloadFileNameDirectory]; + [self downloadDidFinish]; + } else { + [self.delegate downloaderDidFailWithError:error]; + } + } + } + } +} + +- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *)__unused downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)__unused totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite +{ + + if (self.mode == SPUDownloadModePersistent && totalBytesExpectedToWrite > 0 && !self.receivedExpectedBytes) { + self.receivedExpectedBytes = YES; + [self.delegate downloaderDidReceiveExpectedContentLength:totalBytesExpectedToWrite]; + } + + if (self.mode == SPUDownloadModePersistent && bytesWritten >= 0) { + [self.delegate downloaderDidReceiveDataOfLength:(uint64_t)bytesWritten]; + } +} + +- (void)URLSession:(NSURLSession *)__unused session task:(NSURLSessionTask *)__unused task didCompleteWithError:(NSError *)error +{ + self.download = nil; + if (error) { + [self.delegate downloaderDidFailWithError:error]; + } + [self cleanup]; +} + +- (void)downloadDidFinish +{ + assert(self.downloadFilename != nil); + + SPUDownloadData *downloadData = nil; + if (self.mode == SPUDownloadModeTemporary) { + NSData *data = [NSData dataWithContentsOfFile:self.downloadFilename]; + if (data != nil) { + NSURLResponse *response = self.download.response; + assert(response != nil); + downloadData = [[SPUDownloadData alloc] initWithData:data textEncodingName:response.textEncodingName MIMEType:response.MIMEType]; + } + } + + self.download = nil; + + [super downloadDidFinishWithData:downloadData]; +} + +-(void)cleanup +{ + [self.download cancel]; + self.download = nil; + self.downloadSession = nil; + [super cleanup]; +} + +- (void)cancel +{ + [self cleanup]; +} + +// NSURLDownload has a [downlaod:shouldDecodeSourceDataOfMIMEType:] to determine if the data should be decoded. +// This does not exist for NSURLSessionDownloadTask and appears unnecessary. Data tasks will decode data, but not download tasks. + +@end diff --git a/Sparkle/SPUDownloader_Private.h b/Sparkle/SPUDownloader_Private.h new file mode 100644 index 00000000..af0464c8 --- /dev/null +++ b/Sparkle/SPUDownloader_Private.h @@ -0,0 +1,41 @@ +// +// SPUDownloader_Private.h +// Sparkle +// +// Created by Deadpikle on 12/20/17. +// Copyright © 2017 Sparkle Project. All rights reserved. +// + +#ifndef SPUDownloader_Private_h +#define SPUDownloader_Private_h + +#import "SPUDownloaderDelegate.h" + +typedef NS_ENUM(NSUInteger, SPUDownloadMode) +{ + SPUDownloadModePersistent, + SPUDownloadModeTemporary +}; + +static NSString *SUDownloadingReason = @"Downloading update related file"; + +@interface SPUDownloader () + +// Delegate is intentionally strongly referenced; see header +@property (nonatomic) id delegate; +@property (nonatomic, copy) NSString *bundleIdentifier; +@property (nonatomic, copy) NSString *desiredFilename; +@property (nonatomic, copy) NSString *downloadFilename; +@property (nonatomic) BOOL disabledAutomaticTermination; +@property (nonatomic) SPUDownloadMode mode; +@property (nonatomic) BOOL receivedExpectedBytes; + +// returns temp directory location if successful; if not successful, +// returns nil after sending error message to client and canceling download +-(NSString*)getAndCleanTempDirectory; + +-(void)downloadDidFinishWithData:(SPUDownloadData*)data; + +@end + +#endif /* SPUDownloader_Private_h */ diff --git a/Sparkle/SPULocalCacheDirectory.h b/Sparkle/SPULocalCacheDirectory.h new file mode 100644 index 00000000..eff88ba9 --- /dev/null +++ b/Sparkle/SPULocalCacheDirectory.h @@ -0,0 +1,35 @@ +// +// SULocalCacheDirectory.h +// Sparkle +// +// Created by Mayur Pawashe on 6/23/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SPULocalCacheDirectory : NSObject + +// Returns a path to a suitable cache directory to create specifically for Sparkle +// Intermediate directories to this path may not exist yet +// This path may depend on the type of running process, +// such that sandboxed vs non-sandboxed processes could yield different paths +// The caller should create a subdirectory from the path that is returned here so they don't have files that +// conflict with other callers. Once that subdirectory name is decided, the caller can remove old items inside it (using +removeOldItemsInDirectory:) +// and then create a unique temporary directory inside it (using +createUniqueDirectoryInDirectory:) ++ (NSString *)cachePathForBundleIdentifier:(NSString *)bundleIdentifier; + +// Remove old files inside a directory +// A caller may want to invoke this on a directory they own rather than remove and re-create an entire directory +// This does nothing if the supplied directory does not exist yet ++ (void)removeOldItemsInDirectory:(NSString *)directory; + +// Create a unique directory inside a parent directory +// The parent directory doesn't have to exist yet. If it doesn't exist, intermediate directories will be created. ++ (NSString * _Nullable)createUniqueDirectoryInDirectory:(NSString *)directory; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPULocalCacheDirectory.m b/Sparkle/SPULocalCacheDirectory.m new file mode 100644 index 00000000..c63f102f --- /dev/null +++ b/Sparkle/SPULocalCacheDirectory.m @@ -0,0 +1,80 @@ +// +// SULocalCacheDirectory.m +// Sparkle +// +// Created by Mayur Pawashe on 6/23/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPULocalCacheDirectory.h" +#import "SULog.h" + + +#include "AppKitPrevention.h" + +static NSTimeInterval OLD_ITEM_DELETION_INTERVAL = 86400 * 10; // 10 days + +@implementation SPULocalCacheDirectory + +// It is important to note this may return a different path whether invoked from a sanboxed vs non-sandboxed process, or from a different user +// For this reason, this method should not be a part of SUHost because its behavior depends on what kind of process it's being invoked from ++ (NSString *)cachePathForBundleIdentifier:(NSString *)bundleIdentifier +{ + NSURL *cacheURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL]; + assert(cacheURL != nil); + + NSString *resultPath = [[[cacheURL URLByAppendingPathComponent:bundleIdentifier] URLByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER] path]; + assert(resultPath != nil); + + return resultPath; +} + ++ (void)removeOldItemsInDirectory:(NSString *)directory +{ + NSMutableArray *filePathsToRemove = [NSMutableArray array]; + NSFileManager *fileManager = [NSFileManager defaultManager]; + if ([fileManager fileExistsAtPath:directory]) { + NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:directory]; + NSDate *currentDate = [NSDate date]; + for (NSString *filename in directoryEnumerator) + { + NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:[directory stringByAppendingPathComponent:filename] error:NULL]; + if (fileAttributes != nil) + { + NSDate *lastModificationDate = [fileAttributes objectForKey:NSFileModificationDate]; + if ([currentDate timeIntervalSinceDate:lastModificationDate] >= OLD_ITEM_DELETION_INTERVAL) + { + [filePathsToRemove addObject:[directory stringByAppendingPathComponent:filename]]; + } + } + + [directoryEnumerator skipDescendants]; + } + + for (NSString *filename in filePathsToRemove) + { + [fileManager removeItemAtPath:filename error:NULL]; + } + } +} + ++ (NSString * _Nullable)createUniqueDirectoryInDirectory:(NSString *)directory +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *createError = nil; + if (![fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&createError]) { + SULog(SULogLevelError, @"Failed to create directory with intermediate components at %@ with error %@", directory, createError); + return nil; + } + + NSString *templateString = [directory stringByAppendingPathComponent:@"XXXXXXXXX"]; + char buffer[PATH_MAX] = {0}; + if ([templateString getFileSystemRepresentation:buffer maxLength:sizeof(buffer)]) { + if (mkdtemp(buffer) != NULL) { + return [[NSString alloc] initWithUTF8String:buffer]; + } + } + return nil; +} + +@end diff --git a/Sparkle/SPUURLRequest.h b/Sparkle/SPUURLRequest.h new file mode 100644 index 00000000..69496147 --- /dev/null +++ b/Sparkle/SPUURLRequest.h @@ -0,0 +1,35 @@ +// +// SPUURLRequest.h +// Sparkle +// +// Created by Mayur Pawashe on 5/19/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif + +NS_ASSUME_NONNULL_BEGIN + +// A class that wraps NSURLRequest and implements NSSecureCoding +// This class exists because NSURLRequest did not support NSSecureCoding in macOS 10.8 +// I have not verified if NSURLRequest in 10.9 implements NSSecureCoding or not +@interface SPUURLRequest : NSObject + +// Creates a new URL request +// Only these properties are currently tracked: +// * URL +// * Cache policy +// * Timeout interval +// * HTTP header fields +// * networkServiceType ++ (instancetype)URLRequestWithRequest:(NSURLRequest *)request; + +@property (nonatomic, readonly) NSURLRequest *request; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUURLRequest.m b/Sparkle/SPUURLRequest.m new file mode 100644 index 00000000..fad9fcd5 --- /dev/null +++ b/Sparkle/SPUURLRequest.m @@ -0,0 +1,98 @@ +// +// SPUURLRequest.m +// Sparkle +// +// Created by Mayur Pawashe on 5/19/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPUURLRequest.h" + + +#include "AppKitPrevention.h" + +static NSString *SPUURLRequestURLKey = @"SPUURLRequestURL"; +static NSString *SPUURLRequestCachePolicyKey = @"SPUURLRequestCachePolicy"; +static NSString *SPUURLRequestTimeoutIntervalKey = @"SPUURLRequestTimeoutInterval"; +static NSString *SPUURLRequestHttpHeaderFieldsKey = @"SPUURLRequestHttpHeaderFields"; +static NSString *SPUURLRequestNetworkServiceTypeKey = @"SPUURLRequestNetworkServiceType"; + +@interface SPUURLRequest () + +@property (nonatomic, readonly) NSURL *url; +@property (nonatomic, readonly) NSURLRequestCachePolicy cachePolicy; +@property (nonatomic, readonly) NSTimeInterval timeoutInterval; +@property (nonatomic, readonly, nullable) NSDictionary *httpHeaderFields; +@property (nonatomic, readonly) NSURLRequestNetworkServiceType networkServiceType; + +@end + +@implementation SPUURLRequest + +@synthesize url = _url; +@synthesize cachePolicy = _cachePolicy; +@synthesize timeoutInterval = _timeoutInterval; +@synthesize httpHeaderFields = _httpHeaderFields; +@synthesize networkServiceType = _networkServiceType; + +- (instancetype)initWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval httpHeaderFields:(NSDictionary *)httpHeaderFields networkServiceType:(NSURLRequestNetworkServiceType)networkServiceType +{ + self = [super init]; + if (self != nil) { + _url = url; + _cachePolicy = cachePolicy; + _timeoutInterval = timeoutInterval; + _httpHeaderFields = httpHeaderFields; + _networkServiceType = networkServiceType; + } + return self; +} + ++ (instancetype)URLRequestWithRequest:(NSURLRequest *)request +{ + return [[[self class] alloc] initWithURL:request.URL cachePolicy:request.cachePolicy timeoutInterval:request.timeoutInterval httpHeaderFields:request.allHTTPHeaderFields networkServiceType:request.networkServiceType]; +} + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.url forKey:SPUURLRequestURLKey]; + [coder encodeInteger:self.cachePolicy forKey:SPUURLRequestCachePolicyKey]; + [coder encodeDouble:self.timeoutInterval forKey:SPUURLRequestTimeoutIntervalKey]; + [coder encodeInteger:self.networkServiceType forKey:SPUURLRequestNetworkServiceTypeKey]; + + if (self.httpHeaderFields != nil) { + [coder encodeObject:self.httpHeaderFields forKey:SPUURLRequestHttpHeaderFieldsKey]; + } +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + if (@available(macOS 10.8, *)) { + NSURL *url = [decoder decodeObjectOfClass:[NSURL class] forKey:SPUURLRequestURLKey]; + NSURLRequestCachePolicy cachePolicy = (NSURLRequestCachePolicy)[decoder decodeIntegerForKey:SPUURLRequestCachePolicyKey]; + NSTimeInterval timeoutInterval = [decoder decodeDoubleForKey:SPUURLRequestTimeoutIntervalKey]; + NSDictionary *httpHeaderFields = [decoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSDictionary class], [NSString class]]] forKey:SPUURLRequestHttpHeaderFieldsKey]; + NSURLRequestNetworkServiceType networkServiceType = (NSURLRequestNetworkServiceType)[decoder decodeIntegerForKey:SPUURLRequestNetworkServiceTypeKey]; + + return [self initWithURL:url cachePolicy:cachePolicy timeoutInterval:timeoutInterval httpHeaderFields:httpHeaderFields networkServiceType:networkServiceType]; + } else { + abort(); // Not used on 10.7 + } +} + +- (NSURLRequest *)request +{ + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.url cachePolicy:self.cachePolicy timeoutInterval:self.timeoutInterval]; + if (self.httpHeaderFields != nil) { + request.allHTTPHeaderFields = self.httpHeaderFields; + } + request.networkServiceType = self.networkServiceType; + return [request copy]; +} + +@end diff --git a/Sparkle/SUAppcast.h b/Sparkle/SUAppcast.h index d7363d0a..f2f43389 100644 --- a/Sparkle/SUAppcast.h +++ b/Sparkle/SUAppcast.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN @class SUAppcastItem; -SU_EXPORT @interface SUAppcast : NSObject +SU_EXPORT @interface SUAppcast : NSObject @property (copy, nullable) NSString *userAgentString; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 6783684d..d63a023c 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -12,6 +12,12 @@ #import "SULocalizations.h" #import "SUErrors.h" +#import "SPUURLRequest.h" +#import "SUOperatingSystem.h" +#import "SPUDownloadData.h" +#import "SPUDownloaderDelegate.h" +#import "SPUDownloaderDeprecated.h" +#import "SPUDownloaderSession.h" #include "AppKitPrevention.h" @@ -39,18 +45,18 @@ } @end -@interface SUAppcast () +@interface SUAppcast () + @property (strong) void (^completionBlock)(NSError *); -@property (copy) NSString *downloadFilename; -@property (strong) NSURLDownload *download; +@property (strong) SPUDownloader *download; @property (copy) NSArray *items; - (void)reportError:(NSError *)error; - (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes; + @end @implementation SUAppcast -@synthesize downloadFilename; @synthesize completionBlock; @synthesize userAgentString; @synthesize httpHeaders; @@ -79,49 +85,74 @@ [request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"]; - self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; -} - -- (void)download:(NSURLDownload *)__unused aDownload decideDestinationWithSuggestedFilename:(NSString *)filename -{ - NSString *destinationFilename = NSTemporaryDirectory(); - if (destinationFilename) - { - destinationFilename = [destinationFilename stringByAppendingPathComponent:filename]; - [self.download setDestination:destinationFilename allowOverwrite:NO]; + + if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 9, 0}]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" + self.download = [[SPUDownloaderSession alloc] initWithDelegate:self]; +#pragma clang diagnostic pop } + else { + self.download = [[SPUDownloaderDeprecated alloc] initWithDelegate:self]; + } + + SPUURLRequest *urlRequest = [SPUURLRequest URLRequestWithRequest:request]; + [self.download startTemporaryDownloadWithRequest:urlRequest]; } -- (void)download:(NSURLDownload *)__unused aDownload didCreateDestination:(NSString *)path +- (void)downloaderDidSetDestinationName:(NSString *)__unused destinationName temporaryDirectory:(NSString *)__unused temporaryDirectory { - self.downloadFilename = path; } -- (void)downloadDidFinish:(NSURLDownload *)__unused aDownload +- (void)downloaderDidReceiveExpectedContentLength:(int64_t)__unused expectedContentLength { - NSError *error = nil; - NSArray *appcastItems = [self parseAppcastItemsFromXMLFile:[NSURL fileURLWithPath:self.downloadFilename] error:&error]; +} - [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil]; - self.downloadFilename = nil; +- (void)downloaderDidReceiveDataOfLength:(uint64_t)__unused length +{ +} - if (appcastItems) { - self.items = appcastItems; - self.completionBlock(nil); - self.completionBlock = nil; - } else { - NSMutableDictionary *userInfo = [NSMutableDictionary - dictionaryWithObject: SULocalizedString(@"An error occurred while parsing the update feed.", nil) - forKey: NSLocalizedDescriptionKey]; - if (error) { - [userInfo setObject:error forKey:NSUnderlyingErrorKey]; +- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)downloadData +{ + if (downloadData != nil) { + NSError *parseError = nil; + NSArray *appcastItems = [self parseAppcastItemsFromXMLData:downloadData.data error:&parseError]; + + if (appcastItems != nil) { + self.items = appcastItems; + self.completionBlock(nil); + self.completionBlock = nil; + } else { + NSMutableDictionary *userInfo = [NSMutableDictionary + dictionaryWithObject: SULocalizedString(@"An error occurred while parsing the update feed.", nil) + forKey: NSLocalizedDescriptionKey]; + if (parseError != nil) { + [userInfo setObject:parseError forKey:NSUnderlyingErrorKey]; + } + [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain + code:SUAppcastParseError + userInfo:userInfo]]; } + } else { + SULog(SULogLevelError, @"Temp data download is null in SUAppcast"); + + NSDictionary *userInfo = [NSDictionary + dictionaryWithObject: SULocalizedString(@"An error occurred while downloading the update feed.", nil) + forKey: NSLocalizedDescriptionKey]; + [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain - code:SUAppcastParseError + code:SUDownloadError userInfo:userInfo]]; } } +- (void)downloaderDidFailWithError:(NSError *)error +{ + SULog(SULogLevelError, @"Encountered download feed error: %@", error); + + [self reportError:error]; +} + - (NSDictionary *)attributesOfNode:(NSXMLElement *)node { NSEnumerator *attributeEnum = [[node attributes] objectEnumerator]; @@ -152,17 +183,22 @@ } } --(NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp { +-(NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastURL error:(NSError *__autoreleasing*)errorp { + NSData *data = [NSData dataWithContentsOfURL:appcastURL]; + return [self parseAppcastItemsFromXMLData:data error:errorp]; +} + +-(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData error:(NSError *__autoreleasing*)errorp { if (errorp) { *errorp = nil; } - if (!appcastFile) { + if (!appcastData) { return nil; } NSUInteger options = NSXMLNodeLoadExternalEntitiesNever; // Prevent inclusion from file:// - NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:appcastFile options:options error:errorp]; + NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:appcastData options:options error:errorp]; if (nil == document) { return nil; } @@ -262,21 +298,6 @@ return appcastItems; } -- (void)download:(NSURLDownload *)__unused aDownload didFailWithError:(NSError *)error -{ - if (self.downloadFilename) { - [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil]; - } - self.downloadFilename = nil; - - [self reportError:error]; -} - -- (NSURLRequest *)download:(NSURLDownload *)__unused aDownload willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)__unused redirectResponse -{ - return request; -} - - (void)reportError:(NSError *)error { NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 9ed52c9e..5c861ddd 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -27,6 +27,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (strong, readonly) NSURL *fileURL; @property (nonatomic, readonly) uint64_t contentLength; @property (copy, readonly) NSString *versionString; +@property (copy, readonly) NSString *osString; @property (copy, readonly) NSString *displayVersionString; @property (copy, readonly) NSDictionary *deltaUpdates; @property (strong, readonly) NSURL *infoURL; @@ -37,6 +38,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; @property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate; +@property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; // Returns the dictionary provided in initWithDictionary; this might be useful later for extensions. diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 1f9ed7a1..c4293034 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -23,6 +23,7 @@ @property (copy, readwrite) NSString *maximumSystemVersion; @property (strong, readwrite) NSURL *fileURL; @property (copy, readwrite) NSString *versionString; +@property (copy, readwrite) NSString *osString; @property (copy, readwrite) NSString *displayVersionString; @property (copy, readwrite) NSDictionary *deltaUpdates; @property (strong, readwrite) NSURL *infoURL; @@ -43,6 +44,7 @@ @synthesize releaseNotesURL; @synthesize title; @synthesize versionString; +@synthesize osString; @synthesize propertiesDictionary; - (BOOL)isDeltaUpdate @@ -56,6 +58,11 @@ return [[self.propertiesDictionary objectForKey:SUAppcastElementTags] containsObject:SUAppcastElementCriticalUpdate]; } +- (BOOL)isMacOsUpdate +{ + return self.osString == nil || [self.osString isEqualToString:SUAppcastAttributeValueMacOS]; +} + - (BOOL)isInformationOnlyUpdate { return self.infoURL && !self.fileURL; @@ -150,8 +157,9 @@ } if (enclosure) { self.DSASignature = [enclosure objectForKey:SUAppcastAttributeDSASignature]; + self.osString = [enclosure objectForKey:SUAppcastAttributeOsType]; } - + self.versionString = newVersion; self.minimumSystemVersion = [dict objectForKey:SUAppcastElementMinimumSystemVersion]; self.maximumSystemVersion = [dict objectForKey:SUAppcastElementMaximumSystemVersion]; diff --git a/Sparkle/SUAutomaticUpdateAlert.m b/Sparkle/SUAutomaticUpdateAlert.m index 25d751c6..f0e7fea9 100644 --- a/Sparkle/SUAutomaticUpdateAlert.m +++ b/Sparkle/SUAutomaticUpdateAlert.m @@ -117,7 +117,7 @@ static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_B return touchBar; } -- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier +- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier API_AVAILABLE(macos(10.12.2)) { if ([identifier isEqualToString:SUAutomaticUpdateAlertTouchBarIndentifier]) { NSCustomTouchBarItem* item = [(NSCustomTouchBarItem *)[NSClassFromString(@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]; diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index bd83c4dd..26660c33 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -10,12 +10,14 @@ #define SUBASICUPDATEDRIVER_H #import "SUUpdateDriver.h" +#import "SPUDownloader.h" +#import "SPUDownloaderDelegate.h" -@class SUAppcast, SUAppcastItem, SUHost; -@interface SUBasicUpdateDriver : SUUpdateDriver +@class SUAppcast, SUAppcastItem, SUHost, SPUDownloadData; +@interface SUBasicUpdateDriver : SUUpdateDriver @property (strong, readonly) SUAppcastItem *updateItem; -@property (strong, readonly) NSURLDownload *download; +@property (strong, readonly) SPUDownloader *download; @property (copy, readonly) NSString *downloadPath; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; @@ -29,9 +31,12 @@ - (void)didNotFindUpdate; - (void)downloadUpdate; -- (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name; -- (void)downloadDidFinish:(NSURLDownload *)d; -- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error; +// SPUDownloaderDelegate +- (void)downloaderDidSetDestinationName:(NSString *)destinationName temporaryDirectory:(NSString *)temporaryDirectory; +- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength; +- (void)downloaderDidReceiveDataOfLength:(uint64_t)length; +- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData *)downloadData; +- (void)downloaderDidFailWithError:(NSError *)error; - (void)extractUpdate; - (void)failedToApplyDeltaUpdate; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index bd96b515..fe8c05dc 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -25,10 +25,14 @@ #import "SUAppcast.h" #import "SUAppcastItem.h" +#import "SPUURLRequest.h" +#import "SPUDownloaderDeprecated.h" +#import "SPUDownloaderSession.h" + @interface SUBasicUpdateDriver () @property (strong) SUAppcastItem *updateItem; -@property (strong) NSURLDownload *download; +@property (strong) SPUDownloader *download; @property (copy) NSString *downloadPath; @property (strong) SUAppcastItem *nonDeltaUpdateItem; @@ -115,12 +119,15 @@ + (BOOL)hostSupportsItem:(SUAppcastItem *)ui { + BOOL osOK = [ui isMacOsUpdate]; if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) && - ([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; } + ([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { + return osOK; + } BOOL minimumVersionOK = TRUE; BOOL maximumVersionOK = TRUE; - + id versionComparator = [[SUStandardVersionComparator alloc] init]; // Check minimum and maximum System Version @@ -131,7 +138,7 @@ maximumVersionOK = [versionComparator compareVersion:[ui maximumSystemVersion] toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending; } - return minimumVersionOK && maximumVersionOK; + return minimumVersionOK && maximumVersionOK && osOK; } - (BOOL)isItemNewer:(SUAppcastItem *)ui @@ -189,10 +196,10 @@ if ([self itemContainsValidUpdate:item]) { self.updateItem = item; - [self didFindValidUpdate]; + [self performSelectorOnMainThread:@selector(didFindValidUpdate) withObject:nil waitUntilDone:NO]; } else { self.updateItem = nil; - [self didNotFindUpdate]; + [self performSelectorOnMainThread:@selector(didNotFindUpdate) withObject:nil waitUntilDone:NO]; } } @@ -253,6 +260,9 @@ - (void)downloadUpdate { + NSString *bundleIdentifier = self.host.bundle.bundleIdentifier; + assert(bundleIdentifier != nil); + // Clear cache directory so that downloads can't possibly accumulate inside NSString *appCachePath = [self appCachePath]; if ([[NSFileManager defaultManager] fileExistsAtPath:appCachePath]) { @@ -272,43 +282,51 @@ willDownloadUpdate:self.updateItem withRequest:request]; } - self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + + if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 9, 0}]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" + self.download = [[SPUDownloaderSession alloc] initWithDelegate:self]; +#pragma clang diagnostic pop + } + else { + self.download = [[SPUDownloaderDeprecated alloc] initWithDelegate:self]; + } + SPUURLRequest *urlRequest = [SPUURLRequest URLRequestWithRequest:request]; + NSString *desiredFilename = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]]; + [self.download startPersistentDownloadWithRequest:urlRequest bundleIdentifier:bundleIdentifier desiredFilename:desiredFilename]; } -- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name + +- (void)downloaderDidSetDestinationName:(NSString *)destinationName temporaryDirectory:(NSString *)temporaryDirectory { - NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]]; - - NSString *appCachePath = [self appCachePath]; - - self.tempDir = [appCachePath stringByAppendingPathComponent:downloadFileName]; - int cnt = 1; - while ([[NSFileManager defaultManager] fileExistsAtPath:self.tempDir] && cnt <= 999) - { - self.tempDir = [appCachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]]; - } - - // Create the temporary directory if necessary. - BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:self.tempDir withIntermediateDirectories:YES attributes:nil error:NULL]; - if (!success) - { - // Okay, something's really broken with this user's file structure. - [self.download cancel]; - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.", self.tempDir] }]]; - } - - self.downloadPath = [self.tempDir stringByAppendingPathComponent:name]; - [self.download setDestination:self.downloadPath allowOverwrite:YES]; + self.tempDir = temporaryDirectory; + self.downloadPath = [temporaryDirectory stringByAppendingPathComponent:destinationName]; } -- (void)downloadDidFinish:(NSURLDownload *)__unused d +- (void)downloaderDidReceiveExpectedContentLength:(int64_t)__unused expectedContentLength { + // don't need to do anything here as there's no GUI with this driver (there can be with child classes) +} + +- (void)downloaderDidReceiveDataOfLength:(uint64_t)__unused length +{ + // don't need do anything here as there's no GUI with this driver (there can be with child classes) +} + +- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)__unused downloadData +{ + // finished. downloadData should be nil as this was a permanent download assert(self.updateItem); - + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updater:didDownloadUpdate:)]) { + [[updater delegate] updater:self.updater didDownloadUpdate:self.updateItem]; + } + [self extractUpdate]; } -- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error +- (void)downloaderDidFailWithError:(NSError *)error { NSURL *failingUrl = [error.userInfo objectForKey:NSURLErrorFailingURLErrorKey]; if (!failingUrl) { @@ -316,31 +334,24 @@ } id updater = self.updater; - + if ([[updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) { [[updater delegate] updater:self.updater - failedToDownloadUpdate:self.updateItem - error:error]; + failedToDownloadUpdate:self.updateItem + error:error]; } - + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ - NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), - NSUnderlyingErrorKey: error, - }]; + NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), + NSUnderlyingErrorKey: error, + }]; if (failingUrl) { [userInfo setObject:failingUrl forKey:NSURLErrorFailingURLErrorKey]; } - + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]]; } -- (BOOL)download:(NSURLDownload *)__unused download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType -{ - // We don't want the download system to extract our gzips. - // Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug. - return ([encodingType rangeOfString:@"gzip"].location == NSNotFound); -} - - (void)extractUpdate { id updater = self.updater; @@ -364,13 +375,20 @@ NSError *reason = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey: @"Failed to extract update."}]; [self unarchiverDidFailWithError:reason]; } else { + if ([[updater delegate] respondsToSelector:@selector(updater:willExtractUpdate:)]) { + [[updater delegate] updater:self.updater willExtractUpdate:self.updateItem]; + } + [unarchiver unarchiveWithCompletionBlock:^(NSError *err){ if (err) { [self unarchiverDidFailWithError:err]; return; } + if ([[updater delegate] respondsToSelector:@selector(updater:didExtractUpdate:)]) { + [[updater delegate] updater:self.updater didExtractUpdate:self.updateItem]; + } - [self unarchiverDidFinish:nil]; + [self performSelectorOnMainThread:@selector(unarchiverDidFinish:) withObject:nil waitUntilDone:NO]; } progressBlock:^(double progress) { [self unarchiver:nil extractedProgress:progress]; }]; @@ -574,6 +592,9 @@ } } + //Set relaunching flag. + [self.host setBool:YES forUserDefaultsKey:SUUpdateRelaunchingMarkerKey]; + [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], diff --git a/Sparkle/SUCodeSigningVerifier.h b/Sparkle/SUCodeSigningVerifier.h index bae76685..f034cd20 100644 --- a/Sparkle/SUCodeSigningVerifier.h +++ b/Sparkle/SUCodeSigningVerifier.h @@ -10,11 +10,13 @@ #define SUCODESIGNINGVERIFIER_H #import +#import "SUExport.h" -@interface SUCodeSigningVerifier : NSObject +SU_EXPORT @interface SUCodeSigningVerifier : NSObject + (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundlePath matchesSignatureAtBundleURL:(NSURL *)newBundlePath error:(NSError **)error; + (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundlePath error:(NSError **)error; + (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundlePath; ++ (NSDictionary *)codeSignatureInfoAtBundleURL:(NSURL *)bundlePath; @end #endif diff --git a/Sparkle/SUCodeSigningVerifier.m b/Sparkle/SUCodeSigningVerifier.m index 17ccf012..38af3baa 100644 --- a/Sparkle/SUCodeSigningVerifier.m +++ b/Sparkle/SUCodeSigningVerifier.m @@ -121,7 +121,22 @@ static id valueOrNSNull(id value) { return value ? value : [NSNull null]; } -+ (void)logSigningInfoForCode:(SecStaticCodeRef)code label:(NSString*)label { ++ (NSDictionary *)codeSignatureInfoAtBundleURL:(NSURL *)bundlePath { + NSDictionary *info = nil; + SecStaticCodeRef code = NULL; + OSStatus result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundlePath, kSecCSDefaultFlags, &code); + if (result != noErr) { + SULog(SULogLevelError, @"Failed to get static code %d", result); + goto finally; + } + info = [self codeSignatureInfoForCode:code]; + +finally: + if (code) CFRelease(code); + return info; +} + ++ (NSDictionary *)codeSignatureInfoForCode:(SecStaticCodeRef)code { CFDictionaryRef signingInfo = nil; const SecCSFlags flags = (SecCSFlags) (kSecCSSigningInformation | kSecCSRequirementInformation | kSecCSDynamicInformation | kSecCSContentInformation); if (SecCodeCopySigningInformation(code, flags, &signingInfo) == noErr) { @@ -133,8 +148,14 @@ static id valueOrNSNull(id value) { NSDictionary *infoPlist = [signingDict objectForKey:@"info-plist"]; [relevantInfo setObject:valueOrNSNull([infoPlist objectForKey:@"CFBundleShortVersionString"]) forKey:@"version"]; [relevantInfo setObject:valueOrNSNull([infoPlist objectForKey:(__bridge NSString *)kCFBundleVersionKey]) forKey:@"build"]; - SULog(SULogLevelDefault, @"%@: %@", label, relevantInfo); + return [relevantInfo copy]; } + return nil; +} + ++ (void)logSigningInfoForCode:(SecStaticCodeRef)code label:(NSString*)label { + NSDictionary *relevantInfo = [self codeSignatureInfoForCode:code]; + SULog(SULogLevelDefault, @"%@: %@", label, relevantInfo); } + (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundleURL diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index ae81a4b4..5ff8fb01 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -21,6 +21,8 @@ extern const NSTimeInterval SUDefaultUpdateCheckInterval; extern NSString *const SUBundleIdentifier; +extern NSString *const SUAppcastAttributeValueMacOS; + // ----------------------------------------------------------------------------- // Notifications: // ----------------------------------------------------------------------------- @@ -33,6 +35,7 @@ extern NSString *const SUTechnicalErrorInformationKey; extern NSString *const SUFeedURLKey; extern NSString *const SUHasLaunchedBeforeKey; +extern NSString *const SUUpdateRelaunchingMarkerKey; extern NSString *const SUShowReleaseNotesKey; extern NSString *const SUSkippedVersionKey; extern NSString *const SUScheduledCheckIntervalKey; @@ -63,6 +66,9 @@ extern NSString *const SUAppcastAttributeDeltaFrom; extern NSString *const SUAppcastAttributeDSASignature; extern NSString *const SUAppcastAttributeShortVersionString; extern NSString *const SUAppcastAttributeVersion; +extern NSString *const SUAppcastAttributeOsType; + + extern NSString *const SUAppcastElementCriticalUpdate; extern NSString *const SUAppcastElementDeltas; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 2fb83829..fc4e8e67 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -21,9 +21,12 @@ const NSTimeInterval SUDefaultUpdateCheckInterval = DEBUG ? 60 : (60 * 60 * 24); NSString *const SUBundleIdentifier = @SPARKLE_BUNDLE_IDENTIFIER; +NSString *const SUAppcastAttributeValueMacOS = @"macos"; + NSString *const SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation"; NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore"; +NSString *const SUUpdateRelaunchingMarkerKey = @"SUUpdateRelaunchingMarker"; NSString *const SUFeedURLKey = @"SUFeedURL"; NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes"; NSString *const SUSkippedVersionKey = @"SUSkippedVersion"; @@ -53,6 +56,7 @@ NSString *const SUAppcastAttributeDeltaFrom = @"sparkle:deltaFrom"; NSString *const SUAppcastAttributeDSASignature = @"sparkle:dsaSignature"; NSString *const SUAppcastAttributeShortVersionString = @"sparkle:shortVersionString"; NSString *const SUAppcastAttributeVersion = @"sparkle:version"; +NSString *const SUAppcastAttributeOsType = @"sparkle:os"; NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate"; NSString *const SUAppcastElementDeltas = @"sparkle:deltas"; diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index 8557d7fb..7d2e73ae 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -21,6 +21,8 @@ */ SU_EXPORT extern NSString *const SUSparkleErrorDomain; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wc++98-compat" typedef NS_ENUM(OSStatus, SUError) { // Appcast phase errors. SUAppcastParseError = 1000, @@ -49,5 +51,6 @@ typedef NS_ENUM(OSStatus, SUError) { // System phase errors SUSystemPowerOffError = 5000 }; +#pragma clang diagnostic pop #endif diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 7bf08747..1ab95cbf 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -109,20 +109,20 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { _auth = NULL; return NO; } - + AuthorizationItem rightItems[] = { // The right that allows us to run tools as root user {.name = kAuthorizationRightExecute, .valueLength = 0, .value = NULL, .flags = 0} }; - + AuthorizationRights rights = { .count = sizeof(rightItems) / sizeof(*rightItems), .items = rightItems }; - + AuthorizationFlags flags = (AuthorizationFlags)(kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights | kAuthorizationFlagPreAuthorize); - + // This will test if we can gain authorization for running utlities as root OSStatus copyStatus = AuthorizationCopyRights(_auth, &rights, kAuthorizationEmptyEnvironment, flags, NULL); if (copyStatus != errAuthorizationSuccess) { @@ -133,13 +133,13 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed granting authorization rights with status code %d.", copyStatus] }]; } } - + AuthorizationFree(_auth, kAuthorizationFlagDefaults); _auth = NULL; - + return NO; } - + return YES; } @@ -156,9 +156,9 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + char *arguments[] = { command, sourcePath, destinationPath, NULL }; - + char toolPath[PATH_MAX] = {0}; if (![_authorizationToolPath getFileSystemRepresentation:toolPath maxLength:sizeof(toolPath)]) { if (error != NULL) { @@ -166,7 +166,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + FILE *pipe = NULL; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" @@ -181,7 +181,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + uint32_t pidData = 0; if (fread(&pidData, sizeof(pidData), 1, pipe) < 1) { if (error != NULL) { @@ -190,7 +190,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { fclose(pipe); return NO; } - + if (lineCallback) { NSFileHandle *pipeHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileno(pipe) closeOnDealloc:NO]; [self parseLines:pipeHandle lineCallback:lineCallback]; @@ -198,21 +198,21 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { pid_t childPid = (int32_t)CFSwapInt32LittleToHost(pidData); int status = 0; - + pid_t waitResult; do { waitResult = waitpid(childPid, &status, 0); } while (waitResult == -1 && errno == EINTR); - + fclose(pipe); - + if (waitResult == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (error != NULL) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Failed to execute authorized executable with result %d and status (%d, %d, %d).", waitResult, status, WIFEXITED(status), WEXITSTATUS(status)] }]; } return NO; } - + return YES; } @@ -318,7 +318,9 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + + NSLog(@"Sparkle: Authorization required to remove quarantine %@", rootURL); + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpRemoveQuarantineCommand sourcePath:path destinationPath:NULL error:&executeError]; if (!success && error != NULL) { @@ -516,7 +518,9 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + + NSLog(@"Sparkle: Authorization required to copy %@ to %@", sourceURL, destinationURL); + NSError *executeError = nil; if (![self _authorizeAndExecuteCommand:SUFileOpCopyCommand sourcePath:sourcePath destinationPath:destinationPath error:&executeError]) { if (error != NULL) { @@ -609,6 +613,8 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } + NSLog(@"Sparkle: Authorization required to move %@ to %@", sourceURL, destinationURL); + char sourcePath[PATH_MAX] = {0}; if (![sourceURL.path getFileSystemRepresentation:sourcePath maxLength:sizeof(sourcePath)]) { if (error != NULL) { @@ -624,7 +630,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + NSError *executeError = nil; if (![self _authorizeAndExecuteCommand:SUFileOpMoveCommand sourcePath:sourcePath destinationPath:destinationPath error:&executeError]) { if (error != NULL) { @@ -654,11 +660,11 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + // We use fchown instead of chown because the latter can follow symbolic links BOOL success = fchown(fileDescriptor, ownerID.unsignedIntValue, groupID.unsignedIntValue) == 0; close(fileDescriptor); - + if (!success) { if (errno == EPERM) { if (needsAuth != NULL) { @@ -769,7 +775,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + char matchPath[PATH_MAX] = {0}; if (![matchURLPath getFileSystemRepresentation:matchPath maxLength:sizeof(matchPath)]) { if (error != NULL) { @@ -778,6 +784,8 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } + NSLog(@"Sparkle: Authorization required to change permissions of %@ to match %@", targetURL, matchURL); + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpChangeOwnerAndGroupCommand sourcePath:targetPath destinationPath:matchPath error:&executeError]; if (!success && error != NULL) { @@ -818,12 +826,12 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + // Using futimes() because utimes() follows symbolic links BOOL updatedTime = (futimes(fileDescriptor, NULL) == 0); - + close(fileDescriptor); - + if (updatedTime) { return YES; } @@ -834,7 +842,9 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + + NSLog(@"Sparkle: Authorization required to update timestamp of %@", targetURL); + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpUpdateModificationAndAccessTimeCommand sourcePath:path destinationPath:NULL error:&executeError]; if (!success && error != NULL) { @@ -877,6 +887,8 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } + NSLog(@"Sparkle: Authorization required to make directory %@", url); + char path[PATH_MAX] = {0}; if (![url.path getFileSystemRepresentation:path maxLength:sizeof(path)]) { if (error != NULL) { @@ -884,7 +896,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpMakeDirectoryCommand sourcePath:path destinationPath:NULL error:&executeError]; if (!success) { @@ -893,7 +905,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage, NSUnderlyingErrorKey: executeError }]; } } - + return success; } @@ -939,6 +951,8 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } + NSLog(@"Sparkle: Authorization required to delete %@", url); + char path[PATH_MAX] = {0}; if (![url.path getFileSystemRepresentation:path maxLength:sizeof(path)]) { if (error != NULL) { @@ -946,14 +960,14 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpRemoveCommand sourcePath:path destinationPath:NULL error:&executeError]; if (!success && error != NULL) { *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to remove %@ with authentication.", url.path.lastPathComponent], NSUnderlyingErrorKey: executeError }]; } - + return success; } @@ -966,7 +980,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + char path[PATH_MAX] = {0}; if (![packageURL.path getFileSystemRepresentation:path maxLength:sizeof(path)]) { if (error != NULL) { @@ -974,14 +988,16 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } return NO; } - + + NSLog(@"Sparkle: Authorization required to run pkg installer %@", packageURL); + NSError *executeError = nil; BOOL success = [self _authorizeAndExecuteCommand:SUFileOpInstallCommand sourcePath:path destinationPath:NULL lineCallback:^(NSString *line){ if ([line hasPrefix:@"installer:%"]) { progressBlock([[line substringFromIndex:11] doubleValue]/100.0); } } error:&executeError]; - + if (!success && error != NULL) { NSString* errorMessage = @"Failed to execute package installer."; *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey: errorMessage, NSUnderlyingErrorKey: executeError}]; diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index 7faa0a6d..ab417b8f 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -7,15 +7,29 @@ // #include "SULog.h" + #include +#include + +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 #include +#else + +typedef struct os_log_s *os_log_t; +#define os_log_create(subsystem, category) nil + +#define os_log(log, format, ...) +#define os_log_error(log, format, ...) + +#endif + +#include "AppKitPrevention.h" #import "SUOperatingSystem.h" // For converting constants to string literals using the preprocessor #define STRINGIFY(x) #x #define TO_STRING(x) STRINGIFY(x) -#include "AppKitPrevention.h" void SULog(SULogLevel level, NSString *format, ...) { @@ -30,6 +44,9 @@ void SULog(SULogLevel level, NSString *format, ...) NSBundle *mainBundle = [NSBundle mainBundle]; hasOSLogging = [SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 12, 0}]; +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101200 + hasOSLogging = NO; +#endif if (hasOSLogging) { const char *subsystem = SPARKLE_BUNDLE_IDENTIFIER; diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index a7fd0281..1c781634 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -50,14 +50,14 @@ { NSString *bundleVersion = [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; NSString *trimmedVersion = @""; - + if (bundleVersion != nil) { NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet]; [validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]]; - + trimmedVersion = [bundleVersion stringByTrimmingCharactersInSet:[validCharacters invertedSet]]; } - + return trimmedVersion.length > 0 ? trimmedVersion : nil; } @@ -77,7 +77,7 @@ } SUFileManager *fileManager = [SUFileManager fileManagerWithAuthorizationToolPath:fileOperationToolPath]; - + // Create a temporary directory for our new app that resides on our destination's volume NSString *preferredName = [installationURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingString:@" (Incomplete Update)"]; NSURL *installationDirectory = installationURL.URLByDeletingLastPathComponent; @@ -107,7 +107,7 @@ // Release our new app from quarantine, fix its owner and group IDs, and update its modification time while it's at our temporary destination // We must leave moving the app to its destination as the final step in installing it, so that // it's not possible our new app can be left in an incomplete state at the final destination - + NSError *quarantineError = nil; if (![fileManager releaseItemFromQuarantineAtRootURL:newTempURL error:&quarantineError]) { // Not big enough of a deal to fail the entire installation @@ -127,14 +127,14 @@ } return NO; } - + if (![fileManager changeOwnerAndGroupOfItemAtRootURL:newTempURL toMatchURL:oldURL error:error]) { // But this is big enough of a deal to fail SULog(SULogLevelError, @"Failed to change owner and group of new app at %@ to match old app at %@", newTempURL.path, oldURL.path); [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; return NO; } - + if (progress) { progress(5/10.0); } @@ -152,16 +152,16 @@ NSString *oldDestinationName = nil; if (SPARKLE_APPEND_VERSION_NUMBER) { NSString *oldBundleVersion = [self bundleVersionAppropriateForFilenameFromHost:host]; - + oldDestinationName = [oldURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingFormat:@" (%@)", oldBundleVersion != nil ? oldBundleVersion : @"old"]; } else { oldDestinationName = oldURL.lastPathComponent.stringByDeletingPathExtension; } - + NSString *oldURLExtension = oldURL.pathExtension; NSString *oldDestinationNameWithPathExtension = [oldDestinationName stringByAppendingPathExtension:oldURLExtension]; NSURL *oldURLDirectory = oldURL.URLByDeletingLastPathComponent; - + // Create a temporary directory for our old app that resides on its volume NSURL *tempOldDirectoryURL = [fileManager makeTemporaryDirectoryWithPreferredName:oldDestinationName appropriateForDirectoryURL:oldURLDirectory error:error]; if (tempOldDirectoryURL == nil) { @@ -178,11 +178,11 @@ NSURL *oldTempURL = [tempOldDirectoryURL URLByAppendingPathComponent:oldDestinationNameWithPathExtension]; if (![fileManager moveItemAtURL:oldURL toURL:oldTempURL error:error]) { SULog(SULogLevelError, @"Failed to move the old app at %@ to a temporary location at %@", oldURL.path, oldTempURL.path); - + // Just forget about our updated app on failure [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; [fileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; - + return NO; } @@ -193,14 +193,14 @@ // Move the new app to its final destination if (![fileManager moveItemAtURL:newTempURL toURL:installationURL error:error]) { SULog(SULogLevelError, @"Failed to move new app at %@ to final destination %@", newTempURL.path, installationURL.path); - + // Forget about our updated app on failure [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; - + // Attempt to restore our old app back the way it was on failure [fileManager moveItemAtURL:oldTempURL toURL:oldURL error:NULL]; [fileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; - + return NO; } @@ -210,7 +210,7 @@ // From here on out, we don't really need to bring up authorization if we haven't done so prior SUFileManager *constrainedFileManager = [fileManager fileManagerByPreservingAuthorizationRights]; - + // Cleanup [constrainedFileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; [constrainedFileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; @@ -225,20 +225,20 @@ - (BOOL)performInitialInstallation:(NSError * __autoreleasing *)error { BOOL allowDowngrades = SPARKLE_AUTOMATED_DOWNGRADES; - + // Prevent malicious downgrades if (!allowDowngrades) { NSString *hostVersion = [self.host version]; - + NSBundle *bundle = [NSBundle bundleWithPath:self.bundlePath]; SUHost *updateHost = [[SUHost alloc] initWithBundle:bundle]; NSString *updateVersion = [updateHost objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; - + id comparator = [[SUStandardVersionComparator alloc] init]; if (!updateVersion || [comparator compareVersion:hostVersion toVersion:updateVersion] == NSOrderedDescending) { if (error != NULL) { NSString *errorMessage = [NSString stringWithFormat:@"For security reasons, updates that downgrade version of the application are not allowed. Refusing to downgrade app from version %@ to %@. Aborting update.", hostVersion, updateVersion]; - + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; } return NO; diff --git a/Sparkle/SUStatus.xib b/Sparkle/SUStatus.xib index cb6a8084..56053034 100644 --- a/Sparkle/SUStatus.xib +++ b/Sparkle/SUStatus.xib @@ -1,9 +1,9 @@ - - + + - - - + + + @@ -15,7 +15,7 @@ - + @@ -55,7 +55,7 @@ - + + + + + + + + + + + + diff --git a/Sparkle/hu.lproj/SUUpdateAlert.xib b/Sparkle/hu.lproj/SUUpdateAlert.xib new file mode 100644 index 00000000..f5145923 --- /dev/null +++ b/Sparkle/hu.lproj/SUUpdateAlert.xib @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + NSNegateBoolean + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sparkle/hu.lproj/SUUpdatePermissionPrompt.xib b/Sparkle/hu.lproj/SUUpdatePermissionPrompt.xib new file mode 100644 index 00000000..27ea5b6b --- /dev/null +++ b/Sparkle/hu.lproj/SUUpdatePermissionPrompt.xib @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + visibleKey + visibleValue + displayValue + displayKey + + + + + + + + + + + + + + + Anonymous system profile information is used to help us plan future development work. Please contact us if you have any questions about this. + +This is the information that would be sent: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SUIncludeProfile + SUSendProfileInfo + + + + + + + diff --git a/Sparkle/hu.lproj/Sparkle.strings b/Sparkle/hu.lproj/Sparkle.strings new file mode 100644 index 00000000..a756c336 --- /dev/null +++ b/Sparkle/hu.lproj/Sparkle.strings @@ -0,0 +1,89 @@ +"%1$@ %2$@ has been downloaded and is ready to use! This is an important update; would you like to install it and relaunch %1$@ now?" = "A %1$@ %2$@ verziója letöltődött és készen áll a telepítésre! Ez egy fontos frissítés; szeretné most telepíteni, majd újraindítani a %1$@ alkalmazást?"; + +"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?" = "A %1$@ %2$@ verziója letöltődött és készen áll a telepítésre! Szeretné most telepíteni, majd újraindítani a %1$@ alkalmazást?"; + +"%1$@ can't be updated, because it was opened from a read-only or a temporary location. Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again." = "A programot nem lehet frissíteni, amikor egy csak olvasható kötetből (pl. lemezképfájl vagy optikai meghajtó) futtatja. Mozgassa a %1$@ alkalmazást az Alkalmazások mappába, indítsa újra onnan, majd próbálja újra a frissítést."; + +"%@ %@ is currently the newest version available." = "A %1$@ %2$@ a jelenleg elérhető legfrissebb verzió."; + +/* Description text for SUUpdateAlert when the update is downloadable. */ +"%@ %@ is now available--you have %@. Would you like to download it now?" = "A %1$@ %2$@ verziója már elérhető — az Ön jelenlegi verziója a %3$@. Szeretné most letölteni?"; + +/* Description text for SUUpdateAlert when the update informational with no download. */ +"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?" = "A %1$@ %2$@ verziója már elérhető — az Ön jelenlegi verziója a %3$@. Szeretne megtekinteni további információkat online?"; + +"%@ downloaded" = "%@ letöltve"; + +"%@ of %@" = "%1$@ / %2$@"; + +"A new version of %@ is available!" = "A %@ egy újabb verziója elérhető!"; + +"A new version of %@ is ready to install!" = "A %@ egy újabb verziója készen áll a telepítésre!"; + +"An error occurred in retrieving update information. Please try again later." = "Hiba történt a frissítések lekérdezésekor. Kérjük, próbálja újra később."; + +"An error occurred while downloading the update. Please try again later." = "Hiba történt a frissítés letöltése közben. Kérjük, próbálja újra később."; + +"An error occurred while extracting the archive. Please try again later." = "Hiba történt a frissítés kicsomagolása közben. Kérjük, próbálja újra később."; + +"An error occurred while installing the update. Please try again later." = "Hiba történt a frissítés telepítése közben. Kérjük, próbálja újra később."; + +"An error occurred while parsing the update feed." = "Hiba történt az elérhető frissítések beolvasásakor."; + +"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@." = "Hiba történt a %1$@ újraindítása közben, de az új verzió a %1$@ következő indításakor így is elérhető lesz."; + +"An important update to %@ is ready to install" = "A %@ egy fontos frissítése készen áll a telepítésre"; + +/* the unit for bytes */ +"B" = "B"; + +"Cancel" = "Mégsem"; + +"Cancel Update" = "Frissítés megszakítása"; + +"Checking for updates..." = "Frissítések keresése…"; + +/* Take care not to overflow the status window. */ +"Downloading update..." = "Frissítés letöltése…"; + +/* Take care not to overflow the status window. */ +"Extracting update..." = "Frissítés kicsomagolása…"; + +/* the unit for gigabytes */ +"GB" = "GB"; + +"Install and Relaunch" = "Telepítés és újraindítás"; + +/* Take care not to overflow the status window. */ +"Installing update..." = "Frissítés telepítése…"; + +/* the unit for kilobytes */ +"KB" = "KB"; + +/* Alternative name for "Install" button if we have a paid update or other update + without a download but with a URL. */ +"Learn More..." = "További információ…"; + +/* the unit for megabytes */ +"MB" = "MB"; + +/* OK button. */ +"OK" = "OK"; + +/* Status message on progress window once download has finished. */ +"Ready to Install" = "A telepítő készen áll"; + +/* Message that is optionally shown at startup to allow users to turn on/off update checks. 1=app name*/ +"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu." = "Szeretné, hogy a %1$@ ellenőrizze az elérhető frissítéseket induláskor? Ha nem, a frissítések keresését kézzel is elindíthatja a %1$@ menüből."; + +"The update is improperly signed." = "A frissítés aláírása sérült."; + +"Update Error!" = "Frissítési hiba!"; + +"Updating %@" = "%@ frissítése"; + +/* 'Error' message when the user checks for updates but is already current or the feed doesn't contain any updates. (not necessarily shown in UI). 1=app name */ +"You already have the newest version of %@." = "Ez a %@ jelenleg elérhető legfrissebb verziója."; + +/* Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates. */ +"You're up-to-date!" = "Nincs újabb verzió!"; diff --git a/Sparkle/is.lproj/SUAutomaticUpdateAlert.xib b/Sparkle/is.lproj/SUAutomaticUpdateAlert.xib index 867d7a18..2ebd717a 100644 --- a/Sparkle/is.lproj/SUAutomaticUpdateAlert.xib +++ b/Sparkle/is.lproj/SUAutomaticUpdateAlert.xib @@ -1,7 +1,8 @@ - + - + + diff --git a/Sparkle/is.lproj/SUUpdateAlert.xib b/Sparkle/is.lproj/SUUpdateAlert.xib index 13707e99..5b8fc42d 100644 --- a/Sparkle/is.lproj/SUUpdateAlert.xib +++ b/Sparkle/is.lproj/SUUpdateAlert.xib @@ -1,8 +1,9 @@ - + - - + + + @@ -26,7 +27,7 @@ - + diff --git a/Sparkle/is.lproj/SUUpdatePermissionPrompt.xib b/Sparkle/is.lproj/SUUpdatePermissionPrompt.xib index 2cac96f9..23d032c4 100644 --- a/Sparkle/is.lproj/SUUpdatePermissionPrompt.xib +++ b/Sparkle/is.lproj/SUUpdatePermissionPrompt.xib @@ -1,8 +1,8 @@ - - + + - - + + @@ -160,7 +160,7 @@ Gw - + @@ -201,7 +201,6 @@ Gw -