Updated Sparkle framework
|
@ -0,0 +1,45 @@
|
|||
AccessModifierOffset: -4
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackParameters: true
|
||||
BreakBeforeBinaryOperators: true
|
||||
BreakBeforeBraces: Linux
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
#DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ForEachMacros: foreach,Q_FOREACH
|
||||
IndentCaseLabels: true
|
||||
IndentFunctionDeclarationAfterType: true
|
||||
IndentWidth: 4
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
Language: Cpp
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
#PointerAlignment: Right
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
|
@ -1,5 +1,4 @@
|
|||
# Xcode
|
||||
build/*
|
||||
build/
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
|
@ -8,11 +7,30 @@ build/*
|
|||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
*.xcworkspace
|
||||
!default.xcworkspace
|
||||
xcuserdata/
|
||||
profile
|
||||
xcuserdata
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
*.xcuserstate
|
||||
|
||||
## Ignore incredibly annoying .DS_Store files
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear on external disk
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
language: objective-c
|
||||
script: make travis
|
|
@ -0,0 +1,294 @@
|
|||
# 1.8.0
|
||||
|
||||
* New SUDSAVerifier based on up-to-date OS X APIs (Zachary Waldowski)
|
||||
* Detailed error log for failed signature checks (Kornel Lesiński)
|
||||
* Converted Sparkle to ARC (C.W. Betts)
|
||||
* Converted ivars to properties. (Jake Petroules)
|
||||
* Cocoapod support (Xhacker Liu)
|
||||
* Quarantine removal on OS X 10.10 (C.W. Betts)
|
||||
* Updated Japanese localization (1024jp)
|
||||
* Added Greek localization
|
||||
|
||||
# 1.7.1
|
||||
|
||||
* Removed option to install unverified updates (Kornel Lesiński)
|
||||
* Added detailed log when code signing verification fails (Sam Deane)
|
||||
* Restored original Sparkle icon. (Jake Petroules)
|
||||
* Switched SUUpdateAlert.xib to AutoLayout (Kornel Lesiński)
|
||||
* Replace references to andymatuschak.org with sparkle-project.org. (Jake Petroules)
|
||||
* Several code cleanups, modernizations, fixed warnings and improved code formatting (Jake Petroules)
|
||||
* Make the repository significantly more organized. (Jake Petroules)
|
||||
* Xcode project: set organization name and class prefix. (Jake Petroules)
|
||||
* Link to Foundation and AppKit instead of Cocoa. (Jake Petroules)
|
||||
* Use new operatingSystemVersion API when available. (Jake Petroules)
|
||||
* Add .clang-format configuration file for source code formatting. (Jake Petroules)
|
||||
* Add a target to build Sparkle API documentation using Doxygen. (Jake Petroules)
|
||||
|
||||
# 1.7.0
|
||||
|
||||
* Dropped support for OS X 10.6. Sparkle now supports 10.7 and newer (including 10.10 Yosemite) on 64-bit Intel Macs (the last 32-bit Mac was released in 2006).
|
||||
* Removed use of deprecated functions (Zachary Waldowski)
|
||||
* Switched to modern Obj-C runtime and new literals syntax
|
||||
* Removed pre-10.7 code. (C.W. Betts)
|
||||
* Use more Blocks/libdispatch code. (C.W. Betts)
|
||||
* Cleaned up and improved security of `generate_keys`/`sign_update` scripts
|
||||
|
||||
# 1.6.1
|
||||
|
||||
* Removed archive password prompt (Kornel Lesiński)
|
||||
* (Re)fixes bug where URLs are naively double escaped (Andrew Madsen)
|
||||
* Fixed typo that caused crashes in BinaryDelta (Tamas Lustyik)
|
||||
* SUStandardVersionComparator.h is public (Vincent CARLIER)
|
||||
* Remove pre-10.6-specific code. (C.W. Betts)
|
||||
* Objective C 2 getters and setters. (C.W. Betts)
|
||||
* Define correct dependencies on locale scripts (Antonin Hildebrand)
|
||||
|
||||
# 1.6.0
|
||||
|
||||
* Cleaned up and deleted redundant strings files (Kornel Lesiński)
|
||||
* Modern Objective C syntax, properties where possible. (C.W. Betts)
|
||||
* Make SUAppcastDelegate a formal protocol. (C.W. Betts)
|
||||
* Fixed default font in release notes WebView (Kornel Lesiński)
|
||||
* Configurable name for finish_installation.app (Kornel Lesiński)
|
||||
* Removed code for 10.4 (Kornel Lesiński)
|
||||
* Convert all strings files to UTF-8 (UTF-16 must die) (Kornel Lesiński)
|
||||
* Removing GC target (Matt Thomas)
|
||||
* finish_installation.app and pkg files will not removed when we use *.pkg installer and restart system in the installer (Takayama Fumihiko)
|
||||
* Select Korean and Slovak for Sparkle.strings localization (Shon Frazier)
|
||||
* Updated the Romanian translation (Gabe)
|
||||
* pt-BR localization polishing (BR Lingo)
|
||||
* update zh_CN (61)
|
||||
* Shut up some warnings & make build with newer Xcode (Uli Kusterer)
|
||||
* Less unsafety with format strings (Uli Kusterer)
|
||||
* New icon (Rick Fillion)
|
||||
* fixed a 'content rectangle not entirely onscreen' warning (Simone Manganelli)
|
||||
* updated sends system profile to use info.plist if user defaults key isn't present (Jamie Pinkham)
|
||||
* Support for notifications on some updater events (Doug Russell)
|
||||
* Allow the delegate to trigger a silent install and relaunch (Matt Stevens)
|
||||
* Support silent relaunches (Matt Stevens)
|
||||
* Increment the sudden termination counter if installing on quit (Matt Stevens)
|
||||
* Prompts the user to update after a week (rather than a day) if he doesn't quit the app (Andy Matuschak)
|
||||
* Adding <sparkle:tags> appcast item element, <sparkle:criticalUpdate /> tag (Andy Matuschak)
|
||||
* We have this check box that says "Automatically download and install updates in the future." But we only download them automatically. We still ask permission again before installing them. (Andy Matuschak)
|
||||
|
||||
# 1.5.0-beta6
|
||||
|
||||
* Important Changes
|
||||
* Sparkle now requires DSA signatures on your updates. Check the documentation for more information on how to set that up if you don't already sign your updates. You can bypass this requirement if you deliver both your appcast and your updates over SSL.
|
||||
* Sparkle will no longer display release notes located at file:// URLs, since Javascript on such a page would be able to read files on your file system.
|
||||
* For security reasons, Sparkle will refuse to install updates which appear to "downgrade" the app.
|
||||
* SUUpdater now implements new keys: "automaticallyDownloadsUpdates", "lastUpdateCheckDate", and "sendsSystemProfile."
|
||||
* Fixed a bug that could prevent SUProbingUpdateDriver from working.
|
||||
* Fixed a bug that prevented the updaterWillRelaunchApplication: delegate method from getting called.
|
||||
* Fixed displaying release notes transmitted "loose" in the <description> key.
|
||||
* Fixed Sparkle compilation on 10.4 systems.
|
||||
* Fixed a bug that could cause window confusion if an app changed its LSUIElement at runtime.
|
||||
* Added support for Sparkle 1.1's behavior of disabling updates when the check interval is 0.
|
||||
* Sparkle can now handle appending parameters to URLs which already have parameters.
|
||||
* If an update's sparkle:shortVersionString is the same as the host's CFBundleShortVersionString, the sparkle:version and CFBundleVersion will be presented in parentheticals.
|
||||
|
||||
# 1.5.0-beta5
|
||||
|
||||
* Important Changes!
|
||||
* Made every Sparkle class private except for SUUpdater, SUAppcast, SUAppcastItem, and the SUVersionComparisonProtocol.
|
||||
* There is now a single SUUpdater singleton for every host bundle; instead of -[SUUpdater setHostBundle], you can use +[SUUpdater updaterForBundle].
|
||||
* Redefined the (entire) delegate protocol accordingly.
|
||||
* Renamed -[SUUpdater updatePreferencesChanged] to -[SUUpdater resetUpdateCycle]. This provides better semantics for non-apps, which need to start the update cycle manually.
|
||||
* -[SUUpdater checkForUpdatesWithDriver] is private. If you were using SUProbingUpdateDriver, you can now use -[SUUpdater checkForUpdateInformation] for a similar effect.
|
||||
* All the user defaults keys are now private; instead, SUUpdater is KVC-compliant for automaticallyChecksForUpdates, updateCheckInterval, and feedURL.
|
||||
* Reduced the size of the English-only framework by 25%.
|
||||
* System profiling information is now only submitted to the server once per week; this will help normalize your statistics across users with different interval preferences.
|
||||
* The feedParamatersForUpdater: delegate method now requires "displayKey" and "displayVersion" keys so that it can inform the user what's being sent.
|
||||
* Added a delegate method called pathToRelaunchForUpdater: which can be used for plugins to provide the path which should be used when relaunching the client after installing an update.
|
||||
* Added support for xml:lang to pick localized nodes in appcasts (for release notes, etc).
|
||||
* Fixed a bug which would cause the "checking for updates" window to not disappear in certain extraordinary error conditions.
|
||||
* Fixed a DSA signature checking bug for .tar.gz archives.
|
||||
* Sparkle now refuses to update on any read-only volume, not just dmgs.
|
||||
* Sparkle will clean up the host app's name and version before sending it as the user agent string; some non-ASCII characters were causing problems.
|
||||
* Added an Italian localization courtesy Michele Longhi.
|
||||
* Added a Swedish localization courtesy Daniel Bergman.
|
||||
* Fixes to the French localization courtesy Ronald Leroux and Yann Ricqueberg.
|
||||
* Fixes to the German localization courtesy Sven-S. Porst.
|
||||
* Fixes to the Russian localization courtesy Alexander Bykov and Anton Sotkov.
|
||||
* Fixed a number of issues related to archive format detection: I reverted back to extensions from UTIs.
|
||||
* Focus behavior fixes for LSUIElement apps.
|
||||
* The status window progress bar now animates even when indeterminate.
|
||||
* Major refactorings to improve functionality for non-app bundles.
|
||||
|
||||
# 1.5.0-beta4
|
||||
|
||||
* Fixed a critical bug which prevented non-.dmgs from unarchiving properly.
|
||||
* Added reporting of 64-bit capability to the profiling system.
|
||||
|
||||
# 1.5.0-beta3
|
||||
|
||||
* Added a new delegate method to SUUpdater.h to allow delegates to specify custom version comparators.
|
||||
* Added a German localization, courtesy the Camino localizer team: Dominik Tobschall, Tobias Stohr, and Friedemann Bochow.
|
||||
* Bug fixes:
|
||||
* Fixed a serious bug which could cause a server to be DDoS'd (or the host app to crash!) if an appcast fails to be parsed.
|
||||
* Fixed .tbz extraction if the archive was made with Stuffit.
|
||||
* Fixed support for .tar.bz2 and .tar.gz; Sparkle has to assume the archive is a tar when it sees "bz2" and "gz"; don't use those without tarring.
|
||||
* Fixed a typo which caused the shouldPromptForPermissionToCheckForUpdatesToHostBundle: method to not work in 1.5b2.
|
||||
* Fixed .zip extraction on Tiger (Apple changed the UTI between releases)
|
||||
* Fixed a crasher on Tiger.
|
||||
* Fixed display of the default app icon when the host app doesn't have an icon.
|
||||
* Sparkle now displays a sensible progress string and uses an indeterminate progress bar when the server doesn't report a file size.
|
||||
* Fixed some memory leaks.
|
||||
|
||||
# 1.5.0-beta2
|
||||
|
||||
* Compatibility Issues:
|
||||
* Most of the delegate method selectors have changed to scale better. See SUUpdater.h for changes; you'll likely have to make changes if you implement any delegate methods.
|
||||
* If you're using .tar.gz or .tar.bz2 archives, name them ".tbz" or ".tgz" instead; Sparkle now uses UTIs for archive detection, and it's not smart about double extensions.
|
||||
* I'm no longer supporting 10.3. This may or may not work on Panther—probably not.
|
||||
* Sparkle's no longer built for ppc64 by default. If you want to ship that, feel free to build your own, but this saves a few hundred k.
|
||||
* Enhancements:
|
||||
* Sparkle now detects if the preferences for automatic update checks or the time interval change mid-cycle.
|
||||
* If your product is a non-.app, you need to clue Sparkle in on the change by calling [[SUUpdater sharedUpdater] updatePreferencesChanged].
|
||||
* Added a cancel to the "checking for updates..." dialog.
|
||||
* Sparkle now cleans up all its litter in /tmp.
|
||||
* Made SUUpdater's delegate an IBOutlet so you can hook it up in IB.
|
||||
* Bug fixes:
|
||||
* Sparkle no longer crashes on non-GC hosts when the user cancels an update's downloads.
|
||||
* Sparkle no longer gets stuck in an inconsistent state or crashes when it can't parse the appcast on scheduled updates.
|
||||
* Added the sharedUpdater method to SUUpdater, as it should have been.
|
||||
* Fixed a bug where the "checking for updates..." window wouldn't go away if an error occurs while checking for updates.
|
||||
* Made the dual-mode build configuration actually use the .xcconfig which builds it with GC support. (oops!)
|
||||
* Fixed relaunching for prefpanes.
|
||||
* Sparkle no longer fails to install updates on Snow Leopard (though there's still an issue with trashing the old version of the app, but it seems to be a 10.6 bug)
|
||||
* Sparkle now handles redirects correctly under Tiger.
|
||||
* Fixed the installation path for non-.app bundles.
|
||||
* Fixed a bug which could crash Sparkle under non-English locales.
|
||||
* Fixed a weird race condition which could cause the relaunch tool to never notice that its target relaunched.
|
||||
* Fixed a bug where if the host app is inactive when an update occurs, the update alert sometimes doesn't become key.
|
||||
* Minor textual fixes.
|
||||
* Localizations:
|
||||
* Dutch: Maarten Van Coile
|
||||
* French: Yann Ricquebourg
|
||||
* Spanish: Ernesto Gomez Cereijo
|
||||
|
||||
# 1.5.0-beta1
|
||||
|
||||
* The most important things to know:
|
||||
* The 10.3 support is untested at best; sketchy at worst. Test with it thoroughly before you use it.
|
||||
* Sparkle now asks for permission to update on second launch; don't be surprised at that. You can change that behavior with a delegate method; read SUUpdater.h for more info.
|
||||
* We no longer distinguish between "check on startup" and "scheduled updates"; everything is scheduled, with the default being every day.
|
||||
* The test application is using the new profiling features, but that's only for demonstration: these are off by default. More on this later.
|
||||
* There are no localizations yet.
|
||||
* New features:
|
||||
* Sparkle now supports .pkgs. Just name the .pkg the name of the app and put in the update archive.
|
||||
* Sparkle now sends optional demographic profiling information; set SUEnableSystemProfiling to YES in your Info.plist and check out the GET data sent to your webserver when fetching the appcast. More on this in the documentation. The test application has this on so you can see the behavior.
|
||||
* Sparkle now supports updating non-.apps. Just call -setHostBundle: on the global SUUpdater to let it know what you're trying to update.
|
||||
* Sparkle now supports garbage collection in the host app. Use "Sparkle-with-GC.framework" for that, but be aware it's 10.5-only.
|
||||
* Sparkle is now 64-bit compatible, compiling both ppc64 and x86_64.
|
||||
* Sparkle now supports a sparkle:minimumSystemVersion key you can set on appcast items. It does what you think it does.
|
||||
* Sparkle now checks to see if the host app is running from a disk image and refuses to update if it is. (10.4+ only)
|
||||
* Added support for entities in enclosure paths.
|
||||
* The file size output is now formatted prettily.
|
||||
* Sparkle now gives visual indication that it's checking for updates when the update's user initiated. ie: it pops up a status controller saying "checking for updates..."
|
||||
* Added support for an SUPublicDSAKeyFile, so people don't have to copy/paste their entire key into their Info.plist. Set this key in your Info.plist to the filename of the key in your Resources directory.
|
||||
* Added an actually maintainable codebase.
|
||||
* Changes:
|
||||
* Sparkle version comparison is now dramatically less stupid and verified by a bunch of unit tests. If something doesn't work the way you think it should, add a test to SUVersionComparisonTest.m
|
||||
* Added a minimum to the check interval so that developers don't accidentally release their apps into the wild with 60-second test check intervals and have DOS-attack-like results. It's an hour now for release mode; feel free to change it.
|
||||
* The relaunching process now uses a separate helper app, which is a much more robust method.
|
||||
* Changed CFBundleShortVersionString behavior: Sparkle no longer uses Apple's about box style of displaying ShortVersionString (CFBundleVersion) when the latter is available.
|
||||
* No more MD5 checking. Use DSA: it's actually secure.
|
||||
* The abomination that was SUStatusChecker is dead. Use SUProbingUpdateDriver instead.
|
||||
* Bugfixes:
|
||||
* Fixed a huge bug with fully-automatic updating: before, if the user chose to relaunch later, the app would be running from the trash for a while. Now the buttons are "install and relaunch" or "install later."
|
||||
* Sparkle forces Spotlight to reindex the updated app so that it won't keep pointing to the one in the trash.
|
||||
* Sparkle trims whitespace from around DSA signatures; this could cause crashes before.
|
||||
* Fixed a bug where the user choosing to skip a version would inhibit future automatic updates until the next launch.
|
||||
* Fixed a bug that could occur when the app has a localized CFBundleName.
|
||||
* .dmgs now work on Leopard.
|
||||
* The status controller's button now sizes appropriately to the localization.
|
||||
* Sparkle now works correctly with LSUIElement apps: it focuses them before displaying the update alert.
|
||||
* Sparkle now deletes failed partial downloads.
|
||||
* The update alert no longer floats above everything in the app.
|
||||
* Fixed varied and sundry memory leaks.
|
||||
* A ton of other things that I've forgotten or were too small to mention!
|
||||
|
||||
# 1.1
|
||||
|
||||
* Optimized framework size: now only 1.4mb with all localizations and 384kb with only English (an English-only version is in the Extras folder).
|
||||
* Added a new SUStatusChecker class for programmatically determining if a new version is available (see the docs); thanks, Evan Schoenberg!
|
||||
* Added support for apps using SIGCHLD; thanks, Augie Fackler!
|
||||
* Added a zh_CN update from JT Lee
|
||||
* Added a Polish update from Piotr Chylinski
|
||||
* Fixed DMG support for images with /Applications symlinks.
|
||||
* Fixed a really stupid interval-checking bug that could cause repeated hits to the appcast.
|
||||
* Fixed a bug where the check interval would be inconsistent if a value of 0 was stored in the user defaults.
|
||||
|
||||
# 1.0
|
||||
|
||||
* Additions:
|
||||
* Added real version comparison courtesy Kevin Ballard: Sparkle now knows that 0.89 < 1.0a3 < 1.0.
|
||||
* Added many localizations courtesy David Kocher's localization team.
|
||||
* Added a much better installation mechanism courtesy Allan Odgaard.
|
||||
* Added a user agent string to the RSS fetch request.
|
||||
* Added support for CFBundleShortVersionString in addition to CFBundleVersion, and support for a sparkle:shortVersionString attribute on the enclosure.
|
||||
* Added support for CFBundleDisplayName if available.
|
||||
* Changes:
|
||||
* Automatic updating is now allowed by default, but only if DSA signing is on.
|
||||
* Pressing Escape or closing the update alert now reminds the user later.
|
||||
* Now when there's a stored check interval, Sparkle doesn't check immediately on startup the first time the app is launched because the user hasn't consented to it yet.
|
||||
* The update alert now remembers its size and floats.
|
||||
* Bug Fixes:
|
||||
* Fixed installation of DMGs with multiple files enclosed.
|
||||
* Fixed a nasty memory leak.
|
||||
* Fixed a bug wherein having no value for allowing automatic updates would display a checkbox for the updates but would not honor it.
|
||||
* Fixed a bug in zip extraction that occurred in Panther.
|
||||
* Fixed release notes caching.
|
||||
* Fixed a bug wherein Sparkle refused to authenticate the installation if the user had cancelled authentication previously in that session.
|
||||
* Fixed a weird bug that would cause a second help menu to appear on first launch.
|
||||
* Fixed a bug that could occur when changing the scheduled check interval.
|
||||
* Fixed a bug wherein the host app could crash if the user clicked Remind Me Later before the release notes finished loading.
|
||||
* Fixed a bug wherein the behavior was undefined if the user manually initiated a check when an automatic one was already taking place.
|
||||
* Fixed wrapping on the description field in the update alert.
|
||||
|
||||
# 1.0-beta3
|
||||
|
||||
* Fixed a nasty crasher that occurred often when the user was not connected to the internet.
|
||||
|
||||
# 1.0-beta2
|
||||
|
||||
* Major Improvements:
|
||||
* Fully automatic updating! (see the Documentation: this is beta and off by default)
|
||||
* Added support for DSA signatures (see the Documentation).
|
||||
* Added support for MD5 sum verification.
|
||||
* Added Security.framework-based authentication for installing to privileged directories.
|
||||
* Huge refactoring of the codebase: there's now a Sparkle Xcode project, Sparkle is now a framework, and everything is modular / abstracted. And no more code-generated interface.
|
||||
* Minor Improvements:
|
||||
* A SUUpdaterWillRestartNotification is sent out before restarting now.
|
||||
* Added key equivalents to alert panel buttons.
|
||||
* Error handling is much prettier now: technical messages are not presented to the user anymore.
|
||||
* There's now a test app for developers to see what Sparkle's like before using it.
|
||||
* Wrote new, pretty, extremely thorough documentation.
|
||||
* Bug Fixes:
|
||||
* Relaunch behavior is much improved and shouldn't fail in huge apps anymore.
|
||||
* Fixed a bug wherein a failing tar command could crash the host app.
|
||||
* Sparkle now looks at InfoPlist.strings in addition to Info.plist.
|
||||
* Fixed some stupid typos.
|
||||
|
||||
# 1.0-beta1
|
||||
|
||||
* Major New Features:
|
||||
* Sparkle now supports scheduled periodic updates—read the Readme for information on how to use it.
|
||||
* Sparkle now supports WebKit-based release notes (for CSS and full HTML), which it displays in the main update alert, not a separate panel. The Readme has much more information. Sparkle will, of course, fall back on NSTextView if the host app does not include WebKit.
|
||||
* Minor New Features:
|
||||
* Added support for .zip update archives.
|
||||
* Added support for .dmg update archives.
|
||||
* Implemented Remind Me Later to replace simple update cancellation.
|
||||
* Implemented Skip This Version functionality.
|
||||
* Added support for multiple feeds via the user defaults SUFeedURL key taking precedent over the one in Info.plist.
|
||||
* Added support for Sparkle's custom XML namespace, which is optional but may prove useful. See the Readme for more information.
|
||||
* Bug Fixes:
|
||||
* Sparkle will no longer enter an inconsistent state if the user tries to update again while one is already in progress.
|
||||
* Sparkle now uses CFBundleName to determine the application's name instead of the app's filename.
|
||||
* Sparkle no longer crashes if the user cancels during extraction.
|
||||
* Lots of code refactoring.
|
||||
|
||||
# 0.1
|
||||
|
||||
* Initial Release
|
|
@ -2,7 +2,3 @@
|
|||
|
||||
PRODUCT_NAME = BinaryDelta
|
||||
GCC_PREFIX_HEADER =
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=i386] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc64] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.5
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
|
|
|
@ -1,51 +1,62 @@
|
|||
// Common
|
||||
|
||||
PREBINDING = NO
|
||||
ZERO_LINK = NO
|
||||
CURRENT_PROJECT_VERSION = 1.5
|
||||
SDKROOT = macosx10.7
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc] = 10.4
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc64] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=i386] = 10.4
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.5
|
||||
GCC_C_LANGUAGE_STANDARD = c99
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES
|
||||
GCC_DEBUGGING_SYMBOLS = full
|
||||
FINISH_INSTALL_TOOL_NAME = Autoupdate
|
||||
|
||||
SPARKLE_VERSION_MAJOR = 1
|
||||
SPARKLE_VERSION_MINOR = 8
|
||||
SPARKLE_VERSION_PATCH = 0
|
||||
SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
||||
|
||||
CURRENT_PROJECT_VERSION = $(SPARKLE_VERSION)
|
||||
ALWAYS_SEARCH_USER_PATHS = NO
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES
|
||||
GCC_PREFIX_HEADER = $(SDKROOT)/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h
|
||||
GCC_FAST_OBJC_DISPATCH = YES
|
||||
GCC_ENABLE_PASCAL_STRINGS = NO
|
||||
ARCHS = ppc i386 x86_64
|
||||
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
|
||||
CLANG_LINK_OBJC_RUNTIME = NO
|
||||
ARCHS = $(ARCHS_STANDARD)
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.7
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS = FINISH_INSTALL_TOOL_NAME=$(FINISH_INSTALL_TOOL_NAME)
|
||||
CLANG_ENABLE_OBJC_ARC = YES
|
||||
|
||||
// Enable warnings
|
||||
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
|
||||
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
|
||||
GCC_WARN_SHADOW = YES
|
||||
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
|
||||
CLANG_WARN_EMPTY_BODY = YES
|
||||
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES
|
||||
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES
|
||||
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
|
||||
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES
|
||||
CLANG_WARN_OBJC_RECEIVER_WEAK = YES
|
||||
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
|
||||
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
|
||||
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES
|
||||
GCC_WARN_MISSING_PARENTHESES = YES
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
|
||||
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
|
||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES
|
||||
GCC_WARN_SIGN_COMPARE = YES
|
||||
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
|
||||
GCC_WARN_UNKNOWN_PRAGMAS = YES
|
||||
GCC_WARN_UNUSED_VARIABLE = YES
|
||||
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
|
||||
GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES
|
||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
|
||||
GCC_WARN_PEDANTIC = YES
|
||||
GCC_WARN_SHADOW = YES
|
||||
GCC_WARN_SIGN_COMPARE = YES
|
||||
GCC_WARN_STRICT_SELECTOR_MATCH = YES
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES
|
||||
GCC_WARN_UNKNOWN_PRAGMAS = YES
|
||||
GCC_WARN_UNUSED_FUNCTION = YES
|
||||
GCC_WARN_UNUSED_LABEL = YES
|
||||
GCC_WARN_UNUSED_VALUE = YES
|
||||
GCC_WARN_UNUSED_PARAMETER = YES
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES
|
||||
WARNING_CFLAGS = -Wall -Wno-unused-parameter -Werror -Wundef -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-format-attribute -Wpacked -Wredundant-decls -Winline -Wdisabled-optimization -Winvalid-pch
|
||||
GCC_WARN_UNUSED_VARIABLE = YES
|
||||
|
||||
// These should be removed once the conversion to ARC is complete
|
||||
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-empty-translation-unit -Wno-unused-macros -Wno-gnu-statement-expression -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak $(WARNING_CFLAGS_EXTRA)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
|
||||
// Debug only
|
||||
|
||||
GCC_OPTIMIZATION_LEVEL = 0
|
||||
DEBUG_INFORMATION_FORMAT = dwarf
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
SPARKLE_EXTRA_DEBUG_10_5_ONLY = -fstack-protector -D_FORTIFY_SOURCE=2
|
||||
SPARKLE_EXTRA_DEBUG = -DDEBUG
|
||||
OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG)
|
||||
|
||||
// Add $(SPARKLE_EXTRA_DEBUG_10_5_ONLY) to SPARKLE_EXTRA_DEBUG if your deployment is 10.5 or greater.
|
||||
ONLY_ACTIVE_ARCH = YES
|
||||
COPY_PHASE_STRIP = NO
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
|
||||
// Release only
|
||||
|
||||
GCC_OPTIMIZATION_LEVEL = s
|
||||
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
DEAD_CODE_STRIPPING = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = NO
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
// Framework only
|
||||
|
||||
INSTALL_PATH = @loader_path/../Frameworks
|
||||
DYLIB_COMPATIBILITY_VERSION = 1.5
|
||||
DYLIB_CURRENT_VERSION = 1.5
|
||||
DYLIB_COMPATIBILITY_VERSION = 1.6
|
||||
DYLIB_CURRENT_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
||||
PRODUCT_NAME = Sparkle
|
||||
WRAPPER_EXTENSION = framework
|
||||
FRAMEWORK_VERSION = A
|
||||
INFOPLIST_FILE = Info.plist
|
||||
GCC_PREFIX_HEADER = Sparkle.pch
|
||||
INFOPLIST_FILE = Sparkle/Sparkle-Info.plist
|
||||
GCC_PREFIX_HEADER = Sparkle/Sparkle.pch
|
||||
SKIP_INSTALL = YES
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
|
|
|
@ -1,9 +1,2 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
STRIP_INSTALLED_PRODUCT = YES
|
||||
DEPLOYMENT_POSTPROCESSING = YES
|
||||
STRIPFLAGS = -u -r
|
||||
STRIP_STYLE = non-global
|
||||
SEPARATE_STRIP = YES
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
// Relaunch Tool only
|
||||
|
||||
PRODUCT_NAME = finish_installation
|
||||
INFOPLIST_FILE = Sparkle/Autoupdate/Autoupdate-Info.plist
|
||||
PRODUCT_NAME = $(FINISH_INSTALL_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
GCC_PREFIX_HEADER = Sparkle/Autoupdate/Autoupdate.pch
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
// Test Application only
|
||||
|
||||
INFOPLIST_FILE = Test Application/Test Application-Info.plist
|
||||
INFOPLIST_FILE = TestApplication/TestApplication-Info.plist
|
||||
PRODUCT_NAME = Sparkle Test App
|
||||
WRAPPER_EXTENSION = app
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
CLANG_ENABLE_OBJC_ARC = NO
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigTestApp.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigTestApp.xcconfig"
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
// Unit Test only
|
||||
|
||||
INFOPLIST_FILE = Tests/Sparkle Unit Tests-Info.plist
|
||||
OTHER_LDFLAGS = -framework Cocoa -framework SenTestingKit
|
||||
INFOPLIST_FILE = Tests/SparkleTests-Info.plist
|
||||
PRODUCT_NAME = Sparkle Unit Tests
|
||||
WRAPPER_EXTENSION = octest
|
||||
FRAMEWORK_SEARCH_PATHS = $(DEVELOPER_LIBRARY_DIR)/Frameworks
|
||||
GCC_PREFIX_HEADER = $(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.6
|
||||
WRAPPER_EXTENSION = xctest
|
||||
WARNING_CFLAGS = $(inherited) -Wno-variadic-macros -Wno-gnu-zero-variadic-macro-arguments
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ "$ACTION" = "" ] ; then
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging"
|
||||
rm -f "Sparkle-$CURRENT_PROJECT_VERSION.tar.bz2"
|
||||
|
||||
mkdir -p "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp "$SRCROOT/CHANGELOG" "$SRCROOT/LICENSE" "$SRCROOT/Resources/SampleAppcast.xml" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$SRCROOT/bin" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp "$CONFIGURATION_BUILD_DIR/BinaryDelta" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/BinaryDelta.dSYM" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.framework" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.framework.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
|
||||
cd "$CONFIGURATION_BUILD_DIR/staging"
|
||||
# Sorted file list groups similar files together, which improves tar compression
|
||||
find . \! -type d | rev | sort | rev | tar cjvf "../Sparkle-$CURRENT_PROJECT_VERSION.tar.bz2" --files-from=-
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging"
|
||||
fi
|
|
@ -0,0 +1 @@
|
|||
html
|
|
@ -0,0 +1,20 @@
|
|||
PROJECT_NAME = Sparkle
|
||||
PROJECT_NUMBER = 1.7.1
|
||||
PROJECT_BRIEF = "A software update framework for OS X"
|
||||
PROJECT_LOGO = Resources/Images.xcassets/AppIcon.appiconset/icon_32x32@2x.png
|
||||
|
||||
RECURSIVE = YES
|
||||
INPUT = Sparkle
|
||||
OUTPUT_DIRECTORY = Documentation
|
||||
|
||||
GENERATE_HTML = YES
|
||||
GENERATE_LATEX = NO
|
||||
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST = YES
|
||||
GENERATE_TODOLIST = YES
|
||||
|
||||
ALPHABETICAL_INDEX = YES
|
||||
|
||||
QT_AUTOBRIEF = YES
|
||||
WARN_IF_UNDOCUMENTED = NO
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ "$ACTION" = "" ] ; then
|
||||
if which -s doxygen ; then
|
||||
doxygen Documentation/Doxyfile
|
||||
else
|
||||
echo "warning: Doxygen not found in PATH"
|
||||
fi
|
||||
elif [ "$ACTION" = "clean" ] ; then
|
||||
rm -rf "$SRCROOT/Documentation/html"
|
||||
fi
|
|
@ -0,0 +1,54 @@
|
|||
© 2006-2013 Andy Matuschak
|
||||
© 2009-2013 Elgato Systems GmbH.
|
||||
© 2011-2014 Kornel Lesiński
|
||||
© 2014 C.W. Betts
|
||||
© 2014 Petroules Corporation, Sparkle Project contributors
|
||||
© 2014 Big Nerd Ranch
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
=================
|
||||
EXTERNAL LICENSES
|
||||
=================
|
||||
|
||||
bspatch.c and bsdiff.c, from bsdiff 4.3 <http://www.daemonology.net/bsdiff/>: © 2003-2005 Colin Percival.
|
||||
SUDSAVerifier.m: © 2011 Mark Hamlin.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted providing that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,7 +1,21 @@
|
|||
.PHONY: all localizable-strings
|
||||
.PHONY: all localizable-strings release build test travis
|
||||
|
||||
BUILDDIR := $(shell mktemp -d "$(TMPDIR)/Sparkle.XXXXXX")
|
||||
|
||||
localizable-strings:
|
||||
rm en.lproj/Sparkle.strings || TRUE
|
||||
genstrings -o en.lproj -s SULocalizedString *.m *.h
|
||||
mv en.lproj/Localizable.strings en.lproj/Sparkle.strings
|
||||
rm -f Sparkle/en.lproj/Sparkle.strings
|
||||
genstrings -o Sparkle/en.lproj -s SULocalizedString Sparkle/*.m Sparkle/*.h
|
||||
iconv -f UTF-16 -t UTF-8 < Sparkle/en.lproj/Localizable.strings > Sparkle/en.lproj/Sparkle.strings
|
||||
rm Sparkle/en.lproj/Localizable.strings
|
||||
|
||||
release:
|
||||
xcodebuild -scheme Distribution -configuration Release -derivedDataPath "$(BUILDDIR)"
|
||||
open -R "$(BUILDDIR)/Build/Products/Release/Sparkle-"*.tar.bz2
|
||||
|
||||
build:
|
||||
xcodebuild clean build
|
||||
|
||||
test:
|
||||
xcodebuild -target 'Sparkle Unit Tests' -scheme 'Sparkle' test
|
||||
|
||||
travis: test
|
||||
|
|
|
@ -1,40 +1,30 @@
|
|||
# Sparkle
|
||||
# Sparkle <img src="Resources/Sparkle.png" width=48 height=48 alt=""/>
|
||||
is an easy-to-use software update framework for Cocoa developers.
|
||||
|
||||
* True self-updating--no work required from the user.
|
||||
[![Build Status](https://travis-ci.org/sparkle-project/Sparkle.svg?branch=master)](https://travis-ci.org/sparkle-project/Sparkle)
|
||||
|
||||
* Displays release notes to the user via WebKit.
|
||||
## Changes since 1.5b
|
||||
|
||||
* Up-to-date with 10.10 SDK and Xcode 6. Supports OS X 10.7+.
|
||||
* Cleaned up and modernized code, using ARC and Autolayout.
|
||||
* Merged bugfixes, security fixes and some features from multiple Sparkle forks.
|
||||
* Truly automatic background updates (no UI at all) when user agreed to "Automatically download and install updates in the future."
|
||||
* Ability to mark updates as critical.
|
||||
* Progress and status notifications for the host app.
|
||||
* Name of finish_installation.app can be configured to match your app's name.
|
||||
|
||||
## Features
|
||||
|
||||
* True self-updating—the user can choose to automatically download and install all updates.
|
||||
* Displays a detailed progress window to the user.
|
||||
|
||||
* Supports authentication for installing in secure locations.
|
||||
|
||||
* Really, really easy to install.
|
||||
|
||||
* Uses appcasts for release information.
|
||||
|
||||
* The user can choose to automatically download and install all updates.
|
||||
|
||||
* Seamless integration—there's no mention of Sparkle; your icons and app name are used.
|
||||
|
||||
* Supports DSA signatures for ultra-secure updates.
|
||||
|
||||
* Sparkle requires no code in your app, so it's trivial to upgrade or remove the module.
|
||||
|
||||
## New in Sparkle 1.5:
|
||||
|
||||
* Optionally sends user demographic information to the server when checking for updates.
|
||||
|
||||
* Dual-mode garbage collection support for any memory management style.
|
||||
|
||||
* Supports Apple code signing and DSA signatures for ultra-secure updates.
|
||||
* Easy to install. Sparkle requires no code in your app, so it's trivial to upgrade or remove the framework.
|
||||
* Uses appcasts for release information. Appcasts are supported by 3rd party update-tracking programs and websites.
|
||||
* Displays release notes to the user via WebKit.
|
||||
* Sparkle doesn't bug the user until second launch for better first impressions.
|
||||
|
||||
* Sparkle can install .pkg files for more complicated products.
|
||||
|
||||
* Supports bundles, preference panes, plugins, and other non-.app software.
|
||||
|
||||
* Supports branches due to minimum OS version requirements.
|
||||
|
||||
* Seamless integration—there's no mention of Sparkle; your icons and app name are used.
|
||||
* Deep delegate support to make Sparkle work exactly as you need.
|
||||
|
||||
* Tons of other stuff! [Read more about what's new.](http://andymatuschak.org/articles/2008/05/31/sparkle-15b1-now-available/ "Sparkle 1.5b1: now available!")
|
||||
* Optionally sends system information to the server when checking for updates.
|
||||
* Supports bundles, preference panes, plugins, and other non-.app software. Can install .pkg files for more complicated products.
|
||||
* Supports branches due to minimum OS version requirements.
|
||||
|
|
65
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/Contents.json
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_256x256.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_128x128.png
vendored
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_128x128@2x.png
vendored
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_16x16.png
vendored
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_16x16@2x.png
vendored
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_256x256.png
vendored
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_32x32.png
vendored
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
Frameworks/Sparkle/Resources/Images.xcassets/AppIcon.appiconset/icon_32x32@2x.png
vendored
Normal file
After Width: | Height: | Size: 11 KiB |
|
@ -0,0 +1,228 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>ADP2,1</key>
|
||||
<string>Developer Transition Kit</string>
|
||||
<key>iMac1,1</key>
|
||||
<string>iMac G3 (Rev A-D)</string>
|
||||
<key>iMac4,1</key>
|
||||
<string>iMac (Core Duo)</string>
|
||||
<key>iMac4,2</key>
|
||||
<string>iMac for Education (17 inch, Core Duo)</string>
|
||||
<key>iMac5,1</key>
|
||||
<string>iMac (Core 2 Duo, 17 or 20 inch, SuperDrive)</string>
|
||||
<key>iMac5,2</key>
|
||||
<string>iMac (Core 2 Duo, 17 inch, Combo Drive)</string>
|
||||
<key>iMac6,1</key>
|
||||
<string>iMac (Core 2 Duo, 24 inch, SuperDrive)</string>
|
||||
<key>iMac8,1</key>
|
||||
<string>iMac (Core 2 Duo, 20 or 24 inch, Early 2008 )</string>
|
||||
<key>iMac9,1</key>
|
||||
<string>iMac (Core 2 Duo, 20 or 24 inch, Early or Mid 2009 )</string>
|
||||
<key>iMac10,1</key>
|
||||
<string>iMac (Core 2 Duo, 21.5 or 27 inch, Late 2009 )</string>
|
||||
<key>iMac11,1</key>
|
||||
<string>iMac (Core i5 or i7, 27 inch Late 2009)</string>
|
||||
<key>iMac11,2</key>
|
||||
<string>iMac (Core i3 or i5, 27 inch Mid 2010)</string>
|
||||
<key>iMac11,3</key>
|
||||
<string>iMac (Core i5 or i7, 27 inch Mid 2010)</string>
|
||||
<key>iMac12,1</key>
|
||||
<string>iMac (Core i3 or i5 or i7, 21.5 inch Mid 2010 or Late 2011)</string>
|
||||
<key>iMac12,2</key>
|
||||
<string>iMac (Core i5 or i7, 27 inch Mid 2011)</string>
|
||||
<key>iMac13,1</key>
|
||||
<string>iMac (Core i3 or i5 or i7, 21.5 inch Late 2012 or Early 2013)</string>
|
||||
<key>iMac13,2</key>
|
||||
<string>iMac (Core i5 or i7, 27 inch Late 2012)</string>
|
||||
<key>iMac14,1</key>
|
||||
<string>iMac (Core i5, 21.5 inch Late 2013)</string>
|
||||
<key>iMac14,2</key>
|
||||
<string>iMac (Core i5 or i7, 27 inch Late 2013)</string>
|
||||
<key>iMac14,3</key>
|
||||
<string>iMac (Core i5 or i7, 21.5 inch Late 2013)</string>
|
||||
<key>MacBook1,1</key>
|
||||
<string>MacBook (Core Duo)</string>
|
||||
<key>MacBook2,1</key>
|
||||
<string>MacBook (Core 2 Duo)</string>
|
||||
<key>MacBook4,1</key>
|
||||
<string>MacBook (Core 2 Duo Feb 2008)</string>
|
||||
<key>MacBook5,1</key>
|
||||
<string>MacBook (Core 2 Duo, Late 2008, Unibody)</string>
|
||||
<key>MacBook5,2</key>
|
||||
<string>MacBook (Core 2 Duo, Early 2009, White)</string>
|
||||
<key>MacBook6,1</key>
|
||||
<string>MacBook (Core 2 Duo, Late 2009, Unibody)</string>
|
||||
<key>MacBook7,1</key>
|
||||
<string>MacBook (Core 2 Duo, Mid 2010, White)</string>
|
||||
<key>MacBookAir1,1</key>
|
||||
<string>MacBook Air (Core 2 Duo, 13 inch, Early 2008)</string>
|
||||
<key>MacBookAir2,1</key>
|
||||
<string>MacBook Air (Core 2 Duo, 13 inch, Mid 2009)</string>
|
||||
<key>MacBookAir3,1</key>
|
||||
<string>MacBook Air (Core 2 Duo, 11 inch, Late 2010)</string>
|
||||
<key>MacBookAir3,2</key>
|
||||
<string>MacBook Air (Core 2 Duo, 13 inch, Late 2010)</string>
|
||||
<key>MacBookAir4,1</key>
|
||||
<string>MacBook Air (Core i5 or i7, 11 inch, Mid 2011)</string>
|
||||
<key>MacBookAir4,2</key>
|
||||
<string>MacBook Air (Core i5 or i7, 13 inch, Mid 2011)</string>
|
||||
<key>MacBookAir5,1</key>
|
||||
<string>MacBook Air (Core i5 or i7, 11 inch, Mid 2012)</string>
|
||||
<key>MacBookAir5,2</key>
|
||||
<string>MacBook Air (Core i5 or i7, 13 inch, Mid 2012)</string>
|
||||
<key>MacBookAir6,1</key>
|
||||
<string>MacBook Air (Core i5 or i7, 11 inch, Mid 2013 or Early 2014)</string>
|
||||
<key>MacBookAir6,2</key>
|
||||
<string>MacBook Air (Core i5 or i7, 13 inch, Mid 2013 or Early 2014)</string>
|
||||
<key>MacBookPro1,1</key>
|
||||
<string>MacBook Pro Core Duo (15-inch)</string>
|
||||
<key>MacBookPro1,2</key>
|
||||
<string>MacBook Pro Core Duo (17-inch)</string>
|
||||
<key>MacBookPro2,1</key>
|
||||
<string>MacBook Pro Core 2 Duo (17-inch)</string>
|
||||
<key>MacBookPro2,2</key>
|
||||
<string>MacBook Pro Core 2 Duo (15-inch)</string>
|
||||
<key>MacBookPro3,1</key>
|
||||
<string>MacBook Pro Core 2 Duo (15-inch LED, Core 2 Duo)</string>
|
||||
<key>MacBookPro3,2</key>
|
||||
<string>MacBook Pro Core 2 Duo (17-inch HD, Core 2 Duo)</string>
|
||||
<key>MacBookPro4,1</key>
|
||||
<string>MacBook Pro (Core 2 Duo Feb 2008)</string>
|
||||
<key>Macmini1,1</key>
|
||||
<string>Mac Mini (Core Solo/Duo)</string>
|
||||
<key>MacPro1,1</key>
|
||||
<string>Mac Pro (four-core)</string>
|
||||
<key>MacPro2,1</key>
|
||||
<string>Mac Pro (eight-core)</string>
|
||||
<key>MacPro3,1</key>
|
||||
<string>Mac Pro (January 2008 4- or 8- core "Harpertown")</string>
|
||||
<key>MacPro4,1</key>
|
||||
<string>Mac Pro (March 2009)</string>
|
||||
<key>MacPro5,1</key>
|
||||
<string>Mac Pro (August 2010)</string>
|
||||
<key>PowerBook1,1</key>
|
||||
<string>PowerBook G3</string>
|
||||
<key>PowerBook2,1</key>
|
||||
<string>iBook G3</string>
|
||||
<key>PowerBook2,2</key>
|
||||
<string>iBook G3 (FireWire)</string>
|
||||
<key>PowerBook2,3</key>
|
||||
<string>iBook G3</string>
|
||||
<key>PowerBook2,4</key>
|
||||
<string>iBook G3</string>
|
||||
<key>PowerBook3,1</key>
|
||||
<string>PowerBook G3 (FireWire)</string>
|
||||
<key>PowerBook3,2</key>
|
||||
<string>PowerBook G4</string>
|
||||
<key>PowerBook3,3</key>
|
||||
<string>PowerBook G4 (Gigabit Ethernet)</string>
|
||||
<key>PowerBook3,4</key>
|
||||
<string>PowerBook G4 (DVI)</string>
|
||||
<key>PowerBook3,5</key>
|
||||
<string>PowerBook G4 (1GHz / 867MHz)</string>
|
||||
<key>PowerBook4,1</key>
|
||||
<string>iBook G3 (Dual USB, Late 2001)</string>
|
||||
<key>PowerBook4,2</key>
|
||||
<string>iBook G3 (16MB VRAM)</string>
|
||||
<key>PowerBook4,3</key>
|
||||
<string>iBook G3 Opaque 16MB VRAM, 32MB VRAM, Early 2003)</string>
|
||||
<key>PowerBook5,1</key>
|
||||
<string>PowerBook G4 (17 inch)</string>
|
||||
<key>PowerBook5,2</key>
|
||||
<string>PowerBook G4 (15 inch FW 800)</string>
|
||||
<key>PowerBook5,3</key>
|
||||
<string>PowerBook G4 (17-inch 1.33GHz)</string>
|
||||
<key>PowerBook5,4</key>
|
||||
<string>PowerBook G4 (15 inch 1.5/1.33GHz)</string>
|
||||
<key>PowerBook5,5</key>
|
||||
<string>PowerBook G4 (17-inch 1.5GHz)</string>
|
||||
<key>PowerBook5,6</key>
|
||||
<string>PowerBook G4 (15 inch 1.67GHz/1.5GHz)</string>
|
||||
<key>PowerBook5,7</key>
|
||||
<string>PowerBook G4 (17-inch 1.67GHz)</string>
|
||||
<key>PowerBook5,8</key>
|
||||
<string>PowerBook G4 (Double layer SD, 15 inch)</string>
|
||||
<key>PowerBook5,9</key>
|
||||
<string>PowerBook G4 (Double layer SD, 17 inch)</string>
|
||||
<key>PowerBook6,1</key>
|
||||
<string>PowerBook G4 (12 inch)</string>
|
||||
<key>PowerBook6,2</key>
|
||||
<string>PowerBook G4 (12 inch, DVI)</string>
|
||||
<key>PowerBook6,3</key>
|
||||
<string>iBook G4</string>
|
||||
<key>PowerBook6,4</key>
|
||||
<string>PowerBook G4 (12 inch 1.33GHz)</string>
|
||||
<key>PowerBook6,5</key>
|
||||
<string>iBook G4 (Early-Late 2004)</string>
|
||||
<key>PowerBook6,7</key>
|
||||
<string>iBook G4 (Mid 2005)</string>
|
||||
<key>PowerBook6,8</key>
|
||||
<string>PowerBook G4 (12 inch 1.5GHz)</string>
|
||||
<key>PowerMac1,1</key>
|
||||
<string>Power Macintosh G3 (Blue & White)</string>
|
||||
<key>PowerMac1,2</key>
|
||||
<string>Power Macintosh G4 (PCI Graphics)</string>
|
||||
<key>PowerMac10,1</key>
|
||||
<string>Mac Mini G4</string>
|
||||
<key>PowerMac10,2</key>
|
||||
<string>Mac Mini (Late 2005)</string>
|
||||
<key>PowerMac11,2</key>
|
||||
<string>Power Macintosh G5 (Late 2005)</string>
|
||||
<key>PowerMac12,1</key>
|
||||
<string>iMac G5 (iSight)</string>
|
||||
<key>PowerMac2,1</key>
|
||||
<string>iMac G3 (Slot-loading CD-ROM)</string>
|
||||
<key>PowerMac2,2</key>
|
||||
<string>iMac G3 (Summer 2000)</string>
|
||||
<key>PowerMac3,1</key>
|
||||
<string>Power Macintosh G4 (AGP Graphics)</string>
|
||||
<key>PowerMac3,2</key>
|
||||
<string>Power Macintosh G4 (AGP Graphics)</string>
|
||||
<key>PowerMac3,3</key>
|
||||
<string>Power Macintosh G4 (Gigabit Ethernet)</string>
|
||||
<key>PowerMac3,4</key>
|
||||
<string>Power Macintosh G4 (Digital Audio)</string>
|
||||
<key>PowerMac3,5</key>
|
||||
<string>Power Macintosh G4 (Quick Silver)</string>
|
||||
<key>PowerMac3,6</key>
|
||||
<string>Power Macintosh G4 (Mirrored Drive Door)</string>
|
||||
<key>PowerMac4,1</key>
|
||||
<string>iMac G3 (Early/Summer 2001)</string>
|
||||
<key>PowerMac4,2</key>
|
||||
<string>iMac G4 (Flat Panel)</string>
|
||||
<key>PowerMac4,4</key>
|
||||
<string>eMac</string>
|
||||
<key>PowerMac4,5</key>
|
||||
<string>iMac G4 (17-inch Flat Panel)</string>
|
||||
<key>PowerMac5,1</key>
|
||||
<string>Power Macintosh G4 Cube</string>
|
||||
<key>PowerMac6,1</key>
|
||||
<string>iMac G4 (USB 2.0)</string>
|
||||
<key>PowerMac6,3</key>
|
||||
<string>iMac G4 (20-inch Flat Panel)</string>
|
||||
<key>PowerMac6,4</key>
|
||||
<string>eMac (USB 2.0, 2005)</string>
|
||||
<key>PowerMac7,2</key>
|
||||
<string>Power Macintosh G5</string>
|
||||
<key>PowerMac7,3</key>
|
||||
<string>Power Macintosh G5</string>
|
||||
<key>PowerMac8,1</key>
|
||||
<string>iMac G5</string>
|
||||
<key>PowerMac8,2</key>
|
||||
<string>iMac G5 (Ambient Light Sensor)</string>
|
||||
<key>PowerMac9,1</key>
|
||||
<string>Power Macintosh G5 (Late 2005)</string>
|
||||
<key>RackMac1,1</key>
|
||||
<string>Xserve G4</string>
|
||||
<key>RackMac1,2</key>
|
||||
<string>Xserve G4 (slot-loading, cluster node)</string>
|
||||
<key>RackMac3,1</key>
|
||||
<string>Xserve G5</string>
|
||||
<key>Xserve1,1</key>
|
||||
<string>Xserve (Intel Xeon)</string>
|
||||
<key>Xserve2,1</key>
|
||||
<string>Xserve (January 2008 quad-core)</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel>
|
||||
<title>Your Great App's Changelog</title>
|
||||
<link>http://you.com/app/appcast.xml</link>
|
||||
<description>Most recent changes with links to updates.</description>
|
||||
<language>en</language>
|
||||
<item>
|
||||
<title>Version 2.0 (2 bugs fixed; 3 new features)</title>
|
||||
<sparkle:releaseNotesLink>
|
||||
http://you.com/app/2.0.html
|
||||
</sparkle:releaseNotesLink>
|
||||
<pubDate>Wed, 09 Jan 2006 19:20:11 +0000</pubDate>
|
||||
<enclosure url="http://you.com/app/Your%20Great%20App%202.0.zip" sparkle:version="2.0" length="1623481" type="application/octet-stream" sparkle:dsaSignature="BAFJW4B6B1K1JyW30nbkBwainOzrN6EQuAh" />
|
||||
<sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Version 1.5 (8 bugs fixed; 2 new features)</title>
|
||||
<sparkle:releaseNotesLink>
|
||||
http://you.com/app/1.5.html
|
||||
</sparkle:releaseNotesLink>
|
||||
<pubDate>Wed, 01 Jan 2006 12:20:11 +0000</pubDate>
|
||||
<enclosure url="http://you.com/app/Your%20Great%20App%201.5.zip" sparkle:version="1.5" length="1472893" type="application/octet-stream" sparkle:dsaSignature="234818feCa1JyW30nbkBwainOzrN6EQuAh" />
|
||||
<sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
|
||||
</item>
|
||||
|
||||
<!-- Now here's an example of a version with a weird internal version number (like an SVN revision) but a human-readable external one. -->
|
||||
<item>
|
||||
<title>Version 1.4 (5 bugs fixed; 2 new features)</title>
|
||||
<sparkle:releaseNotesLink>
|
||||
http://you.com/app/1.4.html
|
||||
</sparkle:releaseNotesLink>
|
||||
<pubDate>Wed, 25 Dec 2005 12:20:11 +0000</pubDate>
|
||||
<enclosure url="http://you.com/app/Your%20Great%20App%201.4.zip" sparkle:version="241" sparkle:shortVersionString="1.4" sparkle:dsaSignature="MC0CFBfeCa1JyW30nbkBwainOzrN6EQuAh=" length="1472349" type="application/octet-stream" />
|
||||
<sparkle:minimumSystemVersion>10.7</sparkle:minimumSystemVersion>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,26 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "Sparkle"
|
||||
s.version = "1.7.1"
|
||||
s.summary = "A software update framework for OS X"
|
||||
s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers."
|
||||
s.homepage = "https://github.com/sparkle-project/Sparkle"
|
||||
s.license = {
|
||||
:type => 'MIT',
|
||||
:file => 'LICENSE'
|
||||
}
|
||||
s.authors = {
|
||||
'Andy Matuschak' => 'andy@andymatuschak.org',
|
||||
'Kornel Lesiński' => 'pornel@pornel.net',
|
||||
'C.W. Betts' => 'computers57@hotmail.com',
|
||||
'Jake Petroules' => 'jake.petroules@petroules.com',
|
||||
}
|
||||
|
||||
s.platform = :osx
|
||||
s.source = { :http => "https://github.com/sparkle-project/Sparkle/releases/download/#{s.version}/Sparkle-#{s.version}.zip" }
|
||||
|
||||
s.public_header_files = 'Sparkle.framework/Headers/*.h'
|
||||
s.vendored_framework = 'Sparkle.framework'
|
||||
s.resources = 'Sparkle.framework'
|
||||
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}/Sparkle"' }
|
||||
s.requires_arc = false
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0450"
|
||||
version = "1.3">
|
||||
LastUpgradeVersion = "0600"
|
||||
version = "2.0">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
|
@ -20,34 +20,6 @@
|
|||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "61B5F90109C4CEE200B25A18"
|
||||
BuildableName = "Sparkle Test App.app"
|
||||
BlueprintName = "Sparkle Test App"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "5D06E8CF0FD68C7C005AE3F6"
|
||||
BuildableName = "BinaryDelta"
|
||||
BlueprintName = "BinaryDelta"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
|
@ -61,7 +33,7 @@
|
|||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "612279D80DB5470200AB99EA"
|
||||
BuildableName = "Sparkle Unit Tests.octest"
|
||||
BuildableName = "Sparkle Unit Tests.xctest"
|
||||
BlueprintName = "Sparkle Unit Tests"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
|
@ -70,31 +42,32 @@
|
|||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "61B5F90109C4CEE200B25A18"
|
||||
BuildableName = "Sparkle Test App.app"
|
||||
BlueprintName = "Sparkle Test App"
|
||||
BlueprintIdentifier = "8DC2EF4F0486A6940098B216"
|
||||
BuildableName = "Sparkle.framework"
|
||||
BlueprintName = "Sparkle"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
selectedDebuggerIdentifier = ""
|
||||
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "YES"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugXPCServices = "NO"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "61B5F90109C4CEE200B25A18"
|
||||
BuildableName = "Sparkle Test App.app"
|
||||
BlueprintName = "Sparkle Test App"
|
||||
BlueprintIdentifier = "8DC2EF4F0486A6940098B216"
|
||||
BuildableName = "Sparkle.framework"
|
||||
BlueprintName = "Sparkle"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
|
@ -103,8 +76,16 @@
|
|||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
ignoresPersistentStateOnLaunch = "YES"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "8DC2EF4F0486A6940098B216"
|
||||
BuildableName = "Sparkle.framework"
|
||||
BlueprintName = "Sparkle"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>LSBackgroundOnly</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>LSUIElement</key>
|
||||
<string>1</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,223 @@
|
|||
#import <AppKit/AppKit.h>
|
||||
#import "SUInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
#import "SUStatusController.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*!
|
||||
* If the Installation takes longer than this time the Application Icon is shown in the Dock so that the user has some feedback.
|
||||
*/
|
||||
static const NSTimeInterval SUInstallationTimeLimit = 5;
|
||||
|
||||
/*!
|
||||
* Time this app uses to recheck if the parent has already died.
|
||||
*/
|
||||
static const NSTimeInterval SUParentQuitCheckInterval = .25;
|
||||
|
||||
@interface TerminationListener : NSObject <SUInstallerDelegate>
|
||||
|
||||
@property (assign) const char *hostpath;
|
||||
@property (assign) const char *executablepath;
|
||||
@property (assign) pid_t parentprocessid;
|
||||
@property (assign) const char *folderpath;
|
||||
|
||||
@property (copy) NSString *selfPath;
|
||||
@property (copy) NSString *installationPath;
|
||||
@property (strong) NSTimer *watchdogTimer;
|
||||
@property (strong) NSTimer *longInstallationTimer;
|
||||
@property (strong) SUHost *host;
|
||||
@property (assign) BOOL shouldRelaunch;
|
||||
@property (assign) BOOL shouldShowUI;
|
||||
|
||||
- (void)parentHasQuit;
|
||||
|
||||
- (void)relaunch;
|
||||
- (void)install;
|
||||
|
||||
- (void)showAppIconInDock:(NSTimer *)aTimer;
|
||||
- (void)watchdog:(NSTimer *)aTimer;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TerminationListener
|
||||
|
||||
@synthesize hostpath;
|
||||
@synthesize executablepath;
|
||||
@synthesize parentprocessid;
|
||||
@synthesize folderpath;
|
||||
|
||||
@synthesize selfPath;
|
||||
@synthesize installationPath;
|
||||
@synthesize watchdogTimer;
|
||||
@synthesize longInstallationTimer;
|
||||
@synthesize host;
|
||||
@synthesize shouldRelaunch;
|
||||
@synthesize shouldShowUI;
|
||||
|
||||
- (instancetype)initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath:(const char *)infolderpath shouldRelaunch:(BOOL)relaunch shouldShowUI:(BOOL)showUI selfPath:(NSString *)inSelfPath
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
hostpath = inhostpath;
|
||||
executablepath = execpath;
|
||||
parentprocessid = ppid;
|
||||
folderpath = infolderpath;
|
||||
selfPath = inSelfPath;
|
||||
shouldRelaunch = relaunch;
|
||||
shouldShowUI = showUI;
|
||||
|
||||
BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already
|
||||
|
||||
if (alreadyTerminated)
|
||||
[self parentHasQuit];
|
||||
else
|
||||
watchdogTimer = [NSTimer scheduledTimerWithTimeInterval:SUParentQuitCheckInterval target:self selector:@selector(watchdog:) userInfo:nil repeats:YES];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[longInstallationTimer invalidate];
|
||||
}
|
||||
|
||||
|
||||
- (void)parentHasQuit
|
||||
{
|
||||
[self.watchdogTimer invalidate];
|
||||
self.longInstallationTimer = [NSTimer scheduledTimerWithTimeInterval:SUInstallationTimeLimit
|
||||
target: self selector: @selector(showAppIconInDock:)
|
||||
userInfo:nil repeats:NO];
|
||||
|
||||
if (self.folderpath)
|
||||
[self install];
|
||||
else
|
||||
[self relaunch];
|
||||
}
|
||||
|
||||
- (void)watchdog:(NSTimer *)__unused aTimer
|
||||
{
|
||||
if (![NSRunningApplication runningApplicationWithProcessIdentifier:self.parentprocessid]) {
|
||||
[self parentHasQuit];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showAppIconInDock:(NSTimer *)__unused aTimer
|
||||
{
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
}
|
||||
|
||||
|
||||
- (void)relaunch __attribute__((noreturn))
|
||||
{
|
||||
if (self.shouldRelaunch)
|
||||
{
|
||||
NSString *appPath = nil;
|
||||
if (!self.folderpath || strcmp(self.executablepath, self.hostpath) != 0)
|
||||
appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:self.executablepath length:strlen(self.executablepath)];
|
||||
else
|
||||
appPath = self.installationPath;
|
||||
[[NSWorkspace sharedWorkspace] openFile:appPath];
|
||||
}
|
||||
|
||||
if (self.folderpath)
|
||||
{
|
||||
NSError *theError = nil;
|
||||
if (![SUPlainInstaller _removeFileAtPath:[SUInstaller updateFolder] error:&theError])
|
||||
SULog(@"Couldn't remove update folder: %@.", theError);
|
||||
}
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.selfPath error:NULL];
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
- (void)install
|
||||
{
|
||||
NSBundle *theBundle = [NSBundle bundleWithPath:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:self.hostpath length:strlen(self.hostpath)]];
|
||||
self.host = [[SUHost alloc] initWithBundle:theBundle];
|
||||
self.installationPath = [[self.host installationPath] copy];
|
||||
|
||||
if (self.shouldShowUI) {
|
||||
SUStatusController *statusCtl = [[SUStatusController alloc] initWithHost:self.host]; // We quit anyway after we've installed, so leak this for now.
|
||||
[statusCtl setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:Nil isDefault:NO];
|
||||
[statusCtl beginActionWithTitle:SULocalizedString(@"Installing update...", @"")
|
||||
maxProgressValue: 0 statusText: @""];
|
||||
[statusCtl showWindow:self];
|
||||
}
|
||||
|
||||
[SUInstaller installFromUpdateFolder:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:self.folderpath length:strlen(self.folderpath)]
|
||||
overHost:self.host
|
||||
installationPath:self.installationPath
|
||||
delegate:self
|
||||
versionComparator:[SUStandardVersionComparator defaultComparator]];
|
||||
}
|
||||
|
||||
- (void)installerFinishedForHost:(SUHost *)__unused aHost
|
||||
{
|
||||
[self relaunch];
|
||||
}
|
||||
|
||||
- (void)installerForHost:(SUHost *)__unused host failedWithError:(NSError *)error __attribute__((noreturn))
|
||||
{
|
||||
if (self.shouldShowUI)
|
||||
NSRunAlertPanel(@"", @"%@", @"OK", @"", @"", [error localizedDescription]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
if (argc < 5 || argc > 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@autoreleasepool {
|
||||
//ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
//TransformProcessType( &psn, kProcessTransformToForegroundApplication );
|
||||
|
||||
#if 0 // Cmdline tool
|
||||
NSString* selfPath = nil;
|
||||
if (argv[0][0] == '/') {
|
||||
selfPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation: argv[0] length: strlen(argv[0])];
|
||||
}
|
||||
else
|
||||
{
|
||||
selfPath = [[NSFileManager defaultManager] currentDirectoryPath];
|
||||
selfPath = [selfPath stringByAppendingPathComponent: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: argv[0] length: strlen(argv[0])]];
|
||||
}
|
||||
#else
|
||||
NSString *selfPath = [[NSBundle mainBundle] bundlePath];
|
||||
#endif
|
||||
|
||||
BOOL shouldShowUI = (argc > 6) ? !!atoi(argv[6]) : YES;
|
||||
if (shouldShowUI)
|
||||
{
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
[NSApplication sharedApplication];
|
||||
TerminationListener *termListen = [[TerminationListener alloc] initWithHostPath:(argc > 1) ? argv[1] : NULL
|
||||
executablePath:(argc > 2) ? argv[2] : NULL
|
||||
parentProcessId:(argc > 3) ? atoi(argv[3]) : 0
|
||||
folderPath:(argc > 4) ? argv[4] : NULL
|
||||
shouldRelaunch:(argc > 5) ? !!atoi(argv[5]) : YES
|
||||
shouldShowUI:shouldShowUI
|
||||
selfPath:selfPath];
|
||||
|
||||
[termListen class];
|
||||
[[NSApplication sharedApplication] run];
|
||||
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// Sparkle.pch
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/23/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#define SPARKLE_BUNDLE [NSBundle mainBundle]
|
||||
#define SULocalizedString(key,comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", SPARKLE_BUNDLE, comment)
|
||||
#define SUAbstractFail() NSAssert2(nil, @"Can't call %@ on an instance of %@; this is an abstract method!", __PRETTY_FUNCTION__, [self class]);
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUConstants.h"
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// SUAppcast.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/12/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUAPPCAST_H
|
||||
#define SUAPPCAST_H
|
||||
|
||||
@protocol SUAppcastDelegate;
|
||||
|
||||
@class SUAppcastItem;
|
||||
@interface SUAppcast : NSObject <NSURLDownloadDelegate>
|
||||
|
||||
@property (weak) id<SUAppcastDelegate> delegate;
|
||||
@property (copy) NSString *userAgentString;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url;
|
||||
|
||||
@property (readonly, copy) NSArray *items;
|
||||
@end
|
||||
|
||||
@protocol SUAppcastDelegate <NSObject>
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
|
||||
- (void)appcast:(SUAppcast *)appcast failedToLoadWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,261 @@
|
|||
//
|
||||
// SUAppcast.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/12/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@interface NSXMLElement (SUAppcastExtensions)
|
||||
@property (readonly, copy) NSDictionary *attributesAsDictionary;
|
||||
@end
|
||||
|
||||
@implementation NSXMLElement (SUAppcastExtensions)
|
||||
- (NSDictionary *)attributesAsDictionary
|
||||
{
|
||||
NSEnumerator *attributeEnum = [[self attributes] objectEnumerator];
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
|
||||
for (NSXMLNode *attribute in attributeEnum) {
|
||||
dictionary[[attribute name]] = [attribute stringValue];
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface SUAppcast () <NSURLDownloadDelegate>
|
||||
@property (copy) NSString *downloadFilename;
|
||||
@property (strong) NSURLDownload *download;
|
||||
@property (copy) NSArray *items;
|
||||
- (void)reportError:(NSError *)error;
|
||||
- (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes;
|
||||
@end
|
||||
|
||||
@implementation SUAppcast
|
||||
|
||||
@synthesize downloadFilename;
|
||||
@synthesize delegate;
|
||||
@synthesize userAgentString;
|
||||
@synthesize download;
|
||||
@synthesize items;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url
|
||||
{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
|
||||
if (self.userAgentString) {
|
||||
[request setValue:self.userAgentString forHTTPHeaderField:@"User-Agent"];
|
||||
}
|
||||
|
||||
[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];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused aDownload didCreateDestination:(NSString *)path
|
||||
{
|
||||
self.downloadFilename = path;
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)__unused aDownload
|
||||
{
|
||||
NSError *error = nil;
|
||||
|
||||
NSXMLDocument *document = nil;
|
||||
BOOL failed = NO;
|
||||
NSArray *xmlItems = nil;
|
||||
NSMutableArray *appcastItems = [NSMutableArray array];
|
||||
|
||||
if (self.downloadFilename)
|
||||
{
|
||||
NSUInteger options = 0;
|
||||
options = NSXMLNodeLoadExternalEntitiesSameOriginOnly;
|
||||
document = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:self.downloadFilename] options:options error:&error];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil];
|
||||
self.downloadFilename = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
failed = YES;
|
||||
}
|
||||
|
||||
if (nil == document)
|
||||
{
|
||||
failed = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlItems = [document nodesForXPath:@"/rss/channel/item" error:&error];
|
||||
if (nil == xmlItems)
|
||||
{
|
||||
failed = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed == NO)
|
||||
{
|
||||
|
||||
NSEnumerator *nodeEnum = [xmlItems objectEnumerator];
|
||||
NSXMLNode *node;
|
||||
NSMutableDictionary *nodesDict = [NSMutableDictionary dictionary];
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||
|
||||
while (failed == NO && (node = [nodeEnum nextObject]))
|
||||
{
|
||||
// First, we'll "index" all the first-level children of this appcast item so we can pick them out by language later.
|
||||
if ([[node children] count])
|
||||
{
|
||||
node = [node childAtIndex:0];
|
||||
while (nil != node)
|
||||
{
|
||||
NSString *name = [node name];
|
||||
if (name)
|
||||
{
|
||||
NSMutableArray *nodes = nodesDict[name];
|
||||
if (nodes == nil)
|
||||
{
|
||||
nodes = [NSMutableArray array];
|
||||
nodesDict[name] = nodes;
|
||||
}
|
||||
[nodes addObject:node];
|
||||
}
|
||||
node = [node nextSibling];
|
||||
}
|
||||
}
|
||||
|
||||
for (NSString *name in nodesDict)
|
||||
{
|
||||
node = [self bestNodeInNodes:nodesDict[name]];
|
||||
if ([name isEqualToString:@"enclosure"])
|
||||
{
|
||||
// enclosure is flattened as a separate dictionary for some reason
|
||||
NSDictionary *encDict = [(NSXMLElement *)node attributesAsDictionary];
|
||||
dict[@"enclosure"] = encDict;
|
||||
|
||||
}
|
||||
else if ([name isEqualToString:@"pubDate"])
|
||||
{
|
||||
// pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString
|
||||
NSDate *date = [NSDate dateWithNaturalLanguageString:[node stringValue]];
|
||||
if (date)
|
||||
dict[name] = date;
|
||||
}
|
||||
else if ([name isEqualToString:@"sparkle:deltas"])
|
||||
{
|
||||
NSMutableArray *deltas = [NSMutableArray array];
|
||||
NSEnumerator *childEnum = [[node children] objectEnumerator];
|
||||
for (NSXMLNode *child in childEnum) {
|
||||
if ([[child name] isEqualToString:@"enclosure"])
|
||||
[deltas addObject:[(NSXMLElement *)child attributesAsDictionary]];
|
||||
}
|
||||
dict[@"deltas"] = deltas;
|
||||
}
|
||||
else if (name != nil)
|
||||
{
|
||||
// add all other values as strings
|
||||
NSString *theValue = [[node stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
if (theValue != nil) {
|
||||
dict[name] = theValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSString *errString;
|
||||
SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict failureReason:&errString];
|
||||
if (anItem)
|
||||
{
|
||||
[appcastItems addObject:anItem];
|
||||
}
|
||||
else
|
||||
{
|
||||
SULog(@"Sparkle Updater: Failed to parse appcast item: %@.\nAppcast dictionary was: %@", errString, dict);
|
||||
}
|
||||
[nodesDict removeAllObjects];
|
||||
[dict removeAllObjects];
|
||||
}
|
||||
}
|
||||
|
||||
if ([appcastItems count])
|
||||
{
|
||||
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
|
||||
[appcastItems sortUsingDescriptors:@[sort]];
|
||||
self.items = appcastItems;
|
||||
}
|
||||
|
||||
if (failed)
|
||||
{
|
||||
[self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while parsing the update feed.", nil) }]];
|
||||
}
|
||||
else if ([self.delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
|
||||
{
|
||||
[self.delegate appcastDidFinishLoading:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (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
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(appcast:failedToLoadWithError:)])
|
||||
{
|
||||
[self.delegate appcast:self failedToLoadWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred in retrieving update information. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes
|
||||
{
|
||||
// We use this method to pick out the localized version of a node when one's available.
|
||||
if ([nodes count] == 1)
|
||||
return nodes[0];
|
||||
else if ([nodes count] == 0)
|
||||
return nil;
|
||||
|
||||
NSMutableArray *languages = [NSMutableArray array];
|
||||
NSString *lang;
|
||||
NSUInteger i;
|
||||
for (NSXMLElement *node in nodes) {
|
||||
lang = [[node attributeForName:@"xml:lang"] stringValue];
|
||||
[languages addObject:(lang ? lang : @"")];
|
||||
}
|
||||
lang = [NSBundle preferredLocalizationsFromArray:languages][0];
|
||||
i = [languages indexOfObject:([languages containsObject:lang] ? lang : @"")];
|
||||
if (i == NSNotFound) {
|
||||
i = 0;
|
||||
}
|
||||
return nodes[i];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// SUAppcastItem.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/12/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUAPPCASTITEM_H
|
||||
#define SUAPPCASTITEM_H
|
||||
|
||||
@interface SUAppcastItem : NSObject
|
||||
@property (copy, readonly) NSString *title;
|
||||
@property (copy, readonly) NSDate *date;
|
||||
@property (copy, readonly) NSString *itemDescription;
|
||||
@property (strong, readonly) NSURL *releaseNotesURL;
|
||||
@property (copy, readonly) NSString *DSASignature;
|
||||
@property (copy, readonly) NSString *minimumSystemVersion;
|
||||
@property (copy, readonly) NSString *maximumSystemVersion;
|
||||
@property (strong, readonly) NSURL *fileURL;
|
||||
@property (copy, readonly) NSString *versionString;
|
||||
@property (copy, readonly) NSString *displayVersionString;
|
||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
||||
@property (strong, readonly) NSURL *infoURL;
|
||||
|
||||
// Initializes with data from a dictionary provided by the RSS class.
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict;
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString **)error;
|
||||
|
||||
@property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate;
|
||||
@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate;
|
||||
|
||||
// Returns the dictionary provided in initWithDictionary; this might be useful later for extensions.
|
||||
@property (readonly, copy) NSDictionary *propertiesDictionary;
|
||||
|
||||
- (NSURL *)infoURL;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,180 @@
|
|||
//
|
||||
// SUAppcastItem.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/12/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@interface SUAppcastItem ()
|
||||
@property (copy, readwrite) NSString *title;
|
||||
@property (copy, readwrite) NSDate *date;
|
||||
@property (copy, readwrite) NSString *itemDescription;
|
||||
@property (strong, readwrite) NSURL *releaseNotesURL;
|
||||
@property (copy, readwrite) NSString *DSASignature;
|
||||
@property (copy, readwrite) NSString *minimumSystemVersion;
|
||||
@property (copy, readwrite) NSString *maximumSystemVersion;
|
||||
@property (strong, readwrite) NSURL *fileURL;
|
||||
@property (copy, readwrite) NSString *versionString;
|
||||
@property (copy, readwrite) NSString *displayVersionString;
|
||||
@property (copy, readwrite) NSDictionary *deltaUpdates;
|
||||
@property (strong, readwrite) NSURL *infoURL;
|
||||
@property (readwrite, copy) NSDictionary *propertiesDictionary;
|
||||
@end
|
||||
|
||||
@implementation SUAppcastItem
|
||||
@synthesize date;
|
||||
@synthesize deltaUpdates;
|
||||
@synthesize displayVersionString;
|
||||
@synthesize DSASignature;
|
||||
@synthesize fileURL;
|
||||
@synthesize infoURL;
|
||||
@synthesize itemDescription;
|
||||
@synthesize maximumSystemVersion;
|
||||
@synthesize minimumSystemVersion;
|
||||
@synthesize releaseNotesURL;
|
||||
@synthesize title;
|
||||
@synthesize versionString;
|
||||
@synthesize propertiesDictionary;
|
||||
|
||||
- (BOOL)isDeltaUpdate
|
||||
{
|
||||
return self.propertiesDictionary[@"enclosure"][@"sparkle:deltaFrom"] != nil;
|
||||
}
|
||||
|
||||
- (BOOL)isCriticalUpdate
|
||||
{
|
||||
return [self.propertiesDictionary[@"sparkle:tags"] containsObject:@"sparkle:criticalUpdate"];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict
|
||||
{
|
||||
return [self initWithDictionary:dict failureReason:nil];
|
||||
}
|
||||
|
||||
- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString *__autoreleasing *)error
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
id enclosure = dict[@"enclosure"];
|
||||
|
||||
// Try to find a version string.
|
||||
// Finding the new version number from the RSS feed is a little bit hacky. There are two ways:
|
||||
// 1. A "sparkle:version" attribute on the enclosure tag, an extension from the RSS spec.
|
||||
// 2. If there isn't a version attribute, Sparkle will parse the path in the enclosure, expecting
|
||||
// that it will look like this: http://something.com/YourApp_0.5.zip. It'll read whatever's between the last
|
||||
// underscore and the last period as the version number. So name your packages like this: APPNAME_VERSION.extension.
|
||||
// The big caveat with this is that you can't have underscores in your version strings, as that'll confuse Sparkle.
|
||||
// Feel free to change the separator string to a hyphen or something more suited to your needs if you like.
|
||||
NSString *newVersion = enclosure[@"sparkle:version"];
|
||||
if (newVersion == nil) {
|
||||
newVersion = dict[@"sparkle:version"]; // Get version from the item, in case it's a download-less item (i.e. paid upgrade).
|
||||
}
|
||||
if (newVersion == nil) // no sparkle:version attribute anywhere?
|
||||
{
|
||||
SULog(@"warning: <enclosure> for URL '%@' is missing sparkle:version attribute. Version comparison may be unreliable. Please always specify sparkle:version", enclosure[@"url"]);
|
||||
|
||||
// Separate the url by underscores and take the last component, as that'll be closest to the end,
|
||||
// then we remove the extension. Hopefully, this will be the version.
|
||||
NSArray *fileComponents = [enclosure[@"url"] componentsSeparatedByString:@"_"];
|
||||
if ([fileComponents count] > 1) {
|
||||
newVersion = [[fileComponents lastObject] stringByDeletingPathExtension];
|
||||
}
|
||||
}
|
||||
|
||||
if (!newVersion) {
|
||||
if (error) {
|
||||
*error = @"Feed item lacks sparkle:version attribute, and version couldn't be deduced from file name (would have used last component of a file name like AppName_1.3.4.zip)";
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict];
|
||||
self.title = dict[@"title"];
|
||||
self.date = dict[@"pubDate"];
|
||||
self.itemDescription = dict[@"description"];
|
||||
|
||||
NSString *theInfoURL = dict[@"link"];
|
||||
if (theInfoURL) {
|
||||
if (![theInfoURL isKindOfClass:[NSString class]]) {
|
||||
SULog(@"SUAppcastItem -initWithDictionary: Info URL is not of valid type.");
|
||||
} else {
|
||||
self.infoURL = [NSURL URLWithString:theInfoURL];
|
||||
}
|
||||
}
|
||||
|
||||
// Need an info URL or an enclosure URL. Former to show "More Info"
|
||||
// page, latter to download & install:
|
||||
if (!enclosure && !theInfoURL) {
|
||||
if (error) {
|
||||
*error = @"No enclosure in feed item";
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *enclosureURLString = enclosure[@"url"];
|
||||
if (!enclosureURLString && !theInfoURL) {
|
||||
if (error) {
|
||||
*error = @"Feed item's enclosure lacks URL";
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (enclosureURLString) {
|
||||
NSString *fileURLString = [[enclosureURLString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
self.fileURL = [NSURL URLWithString:fileURLString];
|
||||
}
|
||||
if (enclosure) {
|
||||
self.DSASignature = enclosure[@"sparkle:dsaSignature"];
|
||||
}
|
||||
|
||||
self.versionString = newVersion;
|
||||
self.minimumSystemVersion = dict[@"sparkle:minimumSystemVersion"];
|
||||
self.maximumSystemVersion = dict[@"sparkle:maximumSystemVersion"];
|
||||
|
||||
NSString *shortVersionString = enclosure[@"sparkle:shortVersionString"];
|
||||
if (nil == shortVersionString) {
|
||||
shortVersionString = dict[@"sparkle:shortVersionString"]; // fall back on the <item>
|
||||
}
|
||||
|
||||
if (shortVersionString) {
|
||||
self.displayVersionString = shortVersionString;
|
||||
} else {
|
||||
self.displayVersionString = self.versionString;
|
||||
}
|
||||
|
||||
// Find the appropriate release notes URL.
|
||||
if (dict[@"sparkle:releaseNotesLink"]) {
|
||||
self.releaseNotesURL = [NSURL URLWithString:dict[@"sparkle:releaseNotesLink"]];
|
||||
} else if ([self.itemDescription hasPrefix:@"http://"] || [self.itemDescription hasPrefix:@"https://"]) { // if the description starts with http:// or https:// use that.
|
||||
self.releaseNotesURL = [NSURL URLWithString:self.itemDescription];
|
||||
} else {
|
||||
self.releaseNotesURL = nil;
|
||||
}
|
||||
|
||||
if (dict[@"deltas"]) {
|
||||
NSMutableDictionary *deltas = [NSMutableDictionary dictionary];
|
||||
NSArray *deltaDictionaries = dict[@"deltas"];
|
||||
for (NSDictionary *deltaDictionary in deltaDictionaries) {
|
||||
NSMutableDictionary *fakeAppCastDict = [dict mutableCopy];
|
||||
[fakeAppCastDict removeObjectForKey:@"deltas"];
|
||||
fakeAppCastDict[@"enclosure"] = deltaDictionary;
|
||||
SUAppcastItem *deltaItem = [[[self class] alloc] initWithDictionary:fakeAppCastDict];
|
||||
|
||||
deltas[deltaDictionary[@"sparkle:deltaFrom"]] = deltaItem;
|
||||
}
|
||||
self.deltaUpdates = deltas;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// SUAutomaticUpdateAlert.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/18/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUAUTOMATICUPDATEALERT_H
|
||||
#define SUAUTOMATICUPDATEALERT_H
|
||||
|
||||
#import "SUWindowController.h"
|
||||
|
||||
@protocol SUAutomaticUpdateAlertDelegate;
|
||||
|
||||
typedef NS_ENUM(NSInteger, SUAutomaticInstallationChoice) {
|
||||
SUInstallNowChoice,
|
||||
SUInstallLaterChoice,
|
||||
SUDoNotInstallChoice
|
||||
};
|
||||
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUAutomaticUpdateAlert : SUWindowController
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id<SUAutomaticUpdateAlertDelegate>)delegate;
|
||||
- (IBAction)installNow:sender;
|
||||
- (IBAction)installLater:sender;
|
||||
- (IBAction)doNotInstall:sender;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUAutomaticUpdateAlertDelegate <NSObject>
|
||||
- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(SUAutomaticInstallationChoice)choice;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// SUAutomaticUpdateAlert.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/18/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
|
||||
@interface SUAutomaticUpdateAlert ()
|
||||
@property (strong) SUAppcastItem *updateItem;
|
||||
@property (weak) id<SUAutomaticUpdateAlertDelegate> delegate;
|
||||
@property (strong) SUHost *host;
|
||||
@end
|
||||
|
||||
@implementation SUAutomaticUpdateAlert
|
||||
@synthesize delegate;
|
||||
@synthesize host;
|
||||
@synthesize updateItem;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id<SUAutomaticUpdateAlertDelegate>)del
|
||||
{
|
||||
self = [super initWithHost:aHost windowNibName:@"SUAutomaticUpdateAlert"];
|
||||
if (self)
|
||||
{
|
||||
self.updateItem = item;
|
||||
self.delegate = del;
|
||||
self.host = aHost;
|
||||
[self setShouldCascadeWindows:NO];
|
||||
[[self window] center];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; }
|
||||
|
||||
- (IBAction)installNow:(id)__unused sender
|
||||
{
|
||||
[self close];
|
||||
[self.delegate automaticUpdateAlert:self finishedWithChoice:SUInstallNowChoice];
|
||||
}
|
||||
|
||||
- (IBAction)installLater:(id)__unused sender
|
||||
{
|
||||
[self close];
|
||||
[self.delegate automaticUpdateAlert:self finishedWithChoice:SUInstallLaterChoice];
|
||||
}
|
||||
|
||||
- (IBAction)doNotInstall:(id)__unused sender
|
||||
{
|
||||
[self close];
|
||||
[self.delegate automaticUpdateAlert:self finishedWithChoice:SUDoNotInstallChoice];
|
||||
}
|
||||
|
||||
- (NSImage *)applicationIcon
|
||||
{
|
||||
return [self.host icon];
|
||||
}
|
||||
|
||||
- (NSString *)titleText
|
||||
{
|
||||
if ([self.updateItem isCriticalUpdate])
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [self.host name]];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [self.host name]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)descriptionText
|
||||
{
|
||||
if ([self.updateItem isCriticalUpdate])
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"%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?", nil), [self.host name], [self.updateItem displayVersionString]];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [self.host name], [self.updateItem displayVersionString]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// SUAutomaticUpdateDriver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/6/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUAUTOMATICUPDATEDRIVER_H
|
||||
#define SUAUTOMATICUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate, SUAutomaticUpdateAlertDelegate>
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,189 @@
|
|||
//
|
||||
// SUAutomaticUpdateDriver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/6/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUAutomaticUpdateDriver.h"
|
||||
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
// If the user hasn't quit in a week, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise.
|
||||
static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24 * 7;
|
||||
|
||||
@interface SUUpdateDriver ()
|
||||
|
||||
@property (getter=isInterruptible) BOOL interruptible;
|
||||
|
||||
@end
|
||||
|
||||
@interface SUAutomaticUpdateDriver ()
|
||||
|
||||
@property (assign) BOOL postponingInstallation;
|
||||
@property (assign) BOOL showErrors;
|
||||
@property (assign) BOOL willUpdateOnTermination;
|
||||
@property (strong) SUAutomaticUpdateAlert *alert;
|
||||
@property (strong) NSTimer *showUpdateAlertTimer;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUAutomaticUpdateDriver
|
||||
|
||||
@synthesize postponingInstallation;
|
||||
@synthesize showErrors;
|
||||
@synthesize willUpdateOnTermination;
|
||||
@synthesize alert;
|
||||
@synthesize showUpdateAlertTimer;
|
||||
|
||||
- (void)showUpdateAlert
|
||||
{
|
||||
self.interruptible = NO;
|
||||
self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host delegate:self];
|
||||
|
||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
||||
// there may be no way for the application to be activated to make it visible again.
|
||||
if ([self.host isBackgroundApplication])
|
||||
{
|
||||
[[self.alert window] setHidesOnDeactivate:NO];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
if ([NSApp isActive])
|
||||
[[self.alert window] makeKeyAndOrderFront:self];
|
||||
else
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
|
||||
// Sudden termination is available on 10.6+
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
[processInfo disableSuddenTermination];
|
||||
|
||||
self.willUpdateOnTermination = YES;
|
||||
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)])
|
||||
{
|
||||
BOOL relaunch = YES;
|
||||
BOOL showUI = NO;
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)]];
|
||||
[invocation setSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)];
|
||||
[invocation setArgument:&relaunch atIndex:2];
|
||||
[invocation setArgument:&showUI atIndex:3];
|
||||
[invocation setTarget:self];
|
||||
|
||||
[updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation];
|
||||
}
|
||||
|
||||
// If this is marked as a critical update, we'll prompt the user to install it right away.
|
||||
if ([self.updateItem isCriticalUpdate])
|
||||
{
|
||||
[self showUpdateAlert];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.showUpdateAlertTimer = [NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO];
|
||||
|
||||
// At this point the driver is idle, allow it to be interrupted for user-initiated update checks.
|
||||
self.interruptible = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stopUpdatingOnTermination
|
||||
{
|
||||
if (self.willUpdateOnTermination)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
[processInfo enableSuddenTermination];
|
||||
|
||||
self.willUpdateOnTermination = NO;
|
||||
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)])
|
||||
[updaterDelegate updater:self.updater didCancelInstallUpdateOnQuit:self.updateItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)invalidateShowUpdateAlertTimer
|
||||
{
|
||||
[self.showUpdateAlertTimer invalidate];
|
||||
self.showUpdateAlertTimer = nil;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self stopUpdatingOnTermination];
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
{
|
||||
[self stopUpdatingOnTermination];
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
[super abortUpdate];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification
|
||||
{
|
||||
[[self.alert window] makeKeyAndOrderFront:self];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSApplicationDidBecomeActiveNotification" object:NSApp];
|
||||
}
|
||||
|
||||
- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)__unused aua finishedWithChoice:(SUAutomaticInstallationChoice)choice
|
||||
{
|
||||
switch (choice)
|
||||
{
|
||||
case SUInstallNowChoice:
|
||||
[self stopUpdatingOnTermination];
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
break;
|
||||
|
||||
case SUInstallLaterChoice:
|
||||
self.postponingInstallation = YES;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
// We're already waiting on quit, just indicate that we're idle.
|
||||
self.interruptible = YES;
|
||||
break;
|
||||
|
||||
case SUDoNotInstallChoice:
|
||||
[self.host setObject:[self.updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
|
||||
[self abortUpdate];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)shouldInstallSynchronously { return self.postponingInstallation; }
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
if (relaunch) {
|
||||
[self stopUpdatingOnTermination];
|
||||
}
|
||||
|
||||
self.showErrors = YES;
|
||||
[super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)__unused note
|
||||
{
|
||||
[self installWithToolAndRelaunch:NO];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if (self.showErrors)
|
||||
[super abortUpdateWithError:error];
|
||||
else
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// SUBasicUpdateDriver.h
|
||||
// Sparkle,
|
||||
//
|
||||
// Created by Andy Matuschak on 4/23/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBASICUPDATEDRIVER_H
|
||||
#define SUBASICUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUpdateDriver.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUAppcast.h"
|
||||
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate, SUUnarchiverDelegate, SUAppcastDelegate>
|
||||
|
||||
@property (strong, readonly) SUAppcastItem *updateItem;
|
||||
@property (strong, readonly) NSURLDownload *download;
|
||||
@property (copy, readonly) NSString *downloadPath;
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host;
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui;
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui;
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui;
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui;
|
||||
- (void)didFindValidUpdate;
|
||||
- (void)didNotFindUpdate;
|
||||
|
||||
- (void)downloadUpdate;
|
||||
- (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name;
|
||||
- (void)downloadDidFinish:(NSURLDownload *)d;
|
||||
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error;
|
||||
|
||||
- (void)extractUpdate;
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)ua;
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)ua;
|
||||
- (void)failedToApplyDeltaUpdate;
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch;
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
|
||||
- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error;
|
||||
|
||||
- (void)cleanUpDownload;
|
||||
|
||||
- (void)abortUpdate;
|
||||
- (void)abortUpdateWithError:(NSError *)error;
|
||||
- (void)terminateApp;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,451 @@
|
|||
//
|
||||
// SUBasicUpdateDriver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/23/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUUpdater_Private.h"
|
||||
|
||||
#ifdef FINISH_INSTALL_TOOL_NAME
|
||||
// FINISH_INSTALL_TOOL_NAME expands to unquoted Autoupdate
|
||||
#define QUOTE_NS_STRING2(str) @"" #str
|
||||
#define QUOTE_NS_STRING1(str) QUOTE_NS_STRING2(str)
|
||||
#define FINISH_INSTALL_TOOL_NAME_STRING QUOTE_NS_STRING1(FINISH_INSTALL_TOOL_NAME)
|
||||
#else
|
||||
#error FINISH_INSTALL_TOOL_NAME not defined
|
||||
#endif
|
||||
|
||||
@interface SUBasicUpdateDriver ()
|
||||
|
||||
@property (strong) SUAppcastItem *updateItem;
|
||||
@property (strong) NSURLDownload *download;
|
||||
@property (copy) NSString *downloadPath;
|
||||
|
||||
@property (strong) SUAppcastItem *nonDeltaUpdateItem;
|
||||
@property (copy) NSString *tempDir;
|
||||
@property (copy) NSString *relaunchPath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUBasicUpdateDriver
|
||||
|
||||
@synthesize updateItem;
|
||||
@synthesize download;
|
||||
@synthesize downloadPath;
|
||||
|
||||
@synthesize nonDeltaUpdateItem;
|
||||
@synthesize tempDir;
|
||||
@synthesize relaunchPath;
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
|
||||
{
|
||||
[super checkForUpdatesAtURL:URL host:aHost];
|
||||
if ([aHost isRunningOnReadOnlyVolume])
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
SUAppcast *appcast = [[SUAppcast alloc] init];
|
||||
|
||||
[appcast setDelegate:self];
|
||||
[appcast setUserAgentString:[self.updater userAgentString]];
|
||||
[appcast fetchAppcastFromURL:URL];
|
||||
}
|
||||
|
||||
- (id<SUVersionComparison>)versionComparator
|
||||
{
|
||||
id<SUVersionComparison> comparator = nil;
|
||||
|
||||
// Give the delegate a chance to provide a custom version comparator
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) {
|
||||
comparator = [[self.updater delegate] versionComparatorForUpdater:self.updater];
|
||||
}
|
||||
|
||||
// If we don't get a comparator from the delegate, use the default comparator
|
||||
if (!comparator) {
|
||||
comparator = [SUStandardVersionComparator defaultComparator];
|
||||
}
|
||||
|
||||
return comparator;
|
||||
}
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui
|
||||
{
|
||||
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
}
|
||||
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui
|
||||
{
|
||||
if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) &&
|
||||
([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; }
|
||||
|
||||
BOOL minimumVersionOK = TRUE;
|
||||
BOOL maximumVersionOK = TRUE;
|
||||
|
||||
// Check minimum and maximum System Version
|
||||
if ([ui minimumSystemVersion] != nil && ![[ui minimumSystemVersion] isEqualToString:@""]) {
|
||||
minimumVersionOK = [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedDescending;
|
||||
}
|
||||
if ([ui maximumSystemVersion] != nil && ![[ui maximumSystemVersion] isEqualToString:@""]) {
|
||||
maximumVersionOK = [[SUStandardVersionComparator defaultComparator] compareVersion:[ui maximumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedAscending;
|
||||
}
|
||||
|
||||
return minimumVersionOK && maximumVersionOK;
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
|
||||
{
|
||||
NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey];
|
||||
if (skippedVersion == nil) { return NO; }
|
||||
return [[self versionComparator] compareVersion:[ui versionString] toVersion:skippedVersion] != NSOrderedDescending;
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
|
||||
{
|
||||
return ui && [self hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui];
|
||||
}
|
||||
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac
|
||||
{
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) {
|
||||
[[self.updater delegate] updater:self.updater didFinishLoadingAppcast:ac];
|
||||
}
|
||||
|
||||
NSDictionary *userInfo = (ac != nil) ? @{ SUUpdaterAppcastNotificationKey: ac } : nil;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:self.updater userInfo:userInfo];
|
||||
|
||||
SUAppcastItem *item = nil;
|
||||
|
||||
// Now we have to find the best valid update in the appcast.
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it?
|
||||
{
|
||||
item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:self.updater];
|
||||
}
|
||||
else // If not, we'll take care of it ourselves.
|
||||
{
|
||||
// Find the first update we can actually use.
|
||||
NSEnumerator *updateEnumerator = [[ac items] objectEnumerator];
|
||||
do {
|
||||
item = [updateEnumerator nextObject];
|
||||
} while (item && ![self hostSupportsItem:item]);
|
||||
|
||||
if (binaryDeltaSupported()) {
|
||||
SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]];
|
||||
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
|
||||
self.nonDeltaUpdateItem = item;
|
||||
item = deltaUpdateItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([self itemContainsValidUpdate:item]) {
|
||||
self.updateItem = item;
|
||||
[self didFindValidUpdate];
|
||||
} else {
|
||||
self.updateItem = nil;
|
||||
[self didNotFindUpdate];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)appcast:(SUAppcast *)__unused ac failedToLoadWithError:(NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
||||
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
||||
object:self.updater
|
||||
userInfo:@{ SUUpdaterAppcastItemNotificationKey: self.updateItem }];
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
|
||||
[[self.updater delegate] updaterDidNotFindUpdate:self.updater];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain
|
||||
code:SUNoUpdateError
|
||||
userInfo:@{
|
||||
NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", "'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)"), self.host.name]
|
||||
}]];
|
||||
}
|
||||
|
||||
- (void)downloadUpdate
|
||||
{
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]];
|
||||
[request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"];
|
||||
self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name
|
||||
{
|
||||
NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]];
|
||||
|
||||
|
||||
self.tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:downloadFileName];
|
||||
int cnt = 1;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:self.tempDir] && cnt <= 999)
|
||||
{
|
||||
self.tempDir = [[self.host appSupportPath] 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];
|
||||
}
|
||||
|
||||
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
|
||||
{
|
||||
NSString *newBundlePath = [SUInstaller appPathInUpdateFolder:extractedPath forHost:self.host];
|
||||
|
||||
if (newBundlePath) {
|
||||
if ([SUCodeSigningVerifier hostApplicationIsCodeSigned]) {
|
||||
NSError *error = nil;
|
||||
if ([SUCodeSigningVerifier codeSignatureIsValidAtPath:newBundlePath error:&error]) {
|
||||
return YES;
|
||||
} else {
|
||||
SULog(@"Code signature check on update failed: %@. Sparkle will use DSA signature instead.", error);
|
||||
}
|
||||
} else {
|
||||
SULog(@"The host app is not signed using Apple Code Signing, and therefore cannot verify updates this way. Sparkle will use DSA signature instead.");
|
||||
}
|
||||
}
|
||||
|
||||
if (DSASignature) {
|
||||
return [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey];
|
||||
} else {
|
||||
SULog(@"The appcast item for the update has no DSA signature. The update will be rejected, because both DSA and Apple Code Signing verification failed.");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)__unused d
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
[self extractUpdate];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
|
||||
}
|
||||
|
||||
- (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
|
||||
{
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHost:self.host];
|
||||
if (!unarchiver)
|
||||
{
|
||||
SULog(@"Error: No valid unarchiver for %@!", self.downloadPath);
|
||||
[self unarchiverDidFail:nil];
|
||||
return;
|
||||
}
|
||||
[unarchiver setDelegate:self];
|
||||
[unarchiver start];
|
||||
}
|
||||
|
||||
- (void)failedToApplyDeltaUpdate
|
||||
{
|
||||
// When a delta update fails to apply we fall back on updating via a full install.
|
||||
self.updateItem = self.nonDeltaUpdateItem;
|
||||
self.nonDeltaUpdateItem = nil;
|
||||
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
if ([self.updateItem isDeltaUpdate]) {
|
||||
[self failedToApplyDeltaUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) }]];
|
||||
}
|
||||
|
||||
- (BOOL)shouldInstallSynchronously { return NO; }
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch
|
||||
{
|
||||
// Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them.
|
||||
[self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch];
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
if (![self validateUpdateDownloadedToPath:self.downloadPath extractedToPath:self.tempDir DSASignature:self.updateItem.DSASignature publicDSAKey:self.host.publicDSAKey])
|
||||
{
|
||||
NSDictionary *userInfo = @{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: SULocalizedString(@"The update is improperly signed.", nil),
|
||||
};
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:userInfo]];
|
||||
return;
|
||||
}
|
||||
|
||||
if (![self.updater mayUpdateAndRestart])
|
||||
{
|
||||
[self abortUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the host app an opportunity to postpone the install and relaunch.
|
||||
static BOOL postponedOnce = NO;
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if (!postponedOnce && [updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)])
|
||||
{
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]];
|
||||
[invocation setSelector:@selector(installWithToolAndRelaunch:)];
|
||||
[invocation setArgument:&relaunch atIndex:2];
|
||||
[invocation setTarget:self];
|
||||
postponedOnce = YES;
|
||||
if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) {
|
||||
[updaterDelegate updater:self.updater willInstallUpdate:self.updateItem];
|
||||
}
|
||||
|
||||
NSString *const finishInstallToolName = FINISH_INSTALL_TOOL_NAME_STRING;
|
||||
|
||||
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
NSString *relaunchPathToCopy = [SPARKLE_BUNDLE pathForResource:finishInstallToolName ofType:@"app"];
|
||||
if (relaunchPathToCopy != nil)
|
||||
{
|
||||
NSString *targetPath = [[self.host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:[targetPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:@{} error:&error];
|
||||
|
||||
if ([SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error])
|
||||
self.relaunchPath = targetPath;
|
||||
else
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]}]];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)])
|
||||
[updaterDelegate updaterWillRelaunchApplication:self.updater];
|
||||
|
||||
if(!self.relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath])
|
||||
{
|
||||
// Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]], NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", self.relaunchPath]}]];
|
||||
// We intentionally don't abandon the update here so that the host won't initiate another.
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *pathToRelaunch = [self.host bundlePath];
|
||||
if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) {
|
||||
pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater];
|
||||
}
|
||||
NSString *relaunchToolPath = [[self.relaunchPath stringByAppendingPathComponent:@"/Contents/MacOS"] stringByAppendingPathComponent:finishInstallToolName];
|
||||
[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath],
|
||||
pathToRelaunch,
|
||||
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
|
||||
self.tempDir,
|
||||
relaunch ? @"1" : @"0",
|
||||
showUI ? @"1" : @"0"]];
|
||||
[self terminateApp];
|
||||
}
|
||||
|
||||
- (void)terminateApp
|
||||
{
|
||||
[NSApp terminate:self];
|
||||
}
|
||||
|
||||
- (void)cleanUpDownload
|
||||
{
|
||||
if (self.tempDir != nil) // tempDir contains downloadPath, so we implicitly delete both here.
|
||||
{
|
||||
BOOL success = NO;
|
||||
NSError *error = nil;
|
||||
success = [[NSFileManager defaultManager] removeItemAtPath:self.tempDir error:&error]; // Clean up the copied relauncher
|
||||
if (!success)
|
||||
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[self.tempDir stringByDeletingLastPathComponent] destination:@"" files:@[[self.tempDir lastPathComponent]] tag:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error
|
||||
{
|
||||
if (aHost != self.host) { return; }
|
||||
NSError *dontThrow = nil;
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.relaunchPath error:&dontThrow]; // Clean up the copied relauncher
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
{
|
||||
[self cleanUpDownload];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
self.updateItem = nil;
|
||||
[super abortUpdate];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if ([error code] != SUNoUpdateError) { // Let's not bother logging this.
|
||||
SULog(@"Error: %@ %@", [error localizedDescription], [error localizedFailureReason]);
|
||||
}
|
||||
if (self.download) {
|
||||
[self.download cancel];
|
||||
}
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// SUBinaryDeltaApply.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTAAPPLY_H
|
||||
#define SUBINARYDELTAAPPLY_H
|
||||
|
||||
@class NSString;
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,101 @@
|
|||
//
|
||||
// SUBinaryDeltaApply.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#include <bspatch.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
static void applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
{
|
||||
NSString *patchFile = temporaryFilename(@"apply-binary-delta");
|
||||
xar_extract_tofile(x, file, [patchFile fileSystemRepresentation]);
|
||||
const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]};
|
||||
bspatch(4, (char **)argv);
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile)
|
||||
{
|
||||
xar_t x = xar_open([patchFile UTF8String], READ);
|
||||
if (!x) {
|
||||
fprintf(stderr, "Unable to open %s. Giving up.\n", [patchFile UTF8String]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSString *expectedBeforeHash = nil;
|
||||
NSString *expectedAfterHash = nil;
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (!strcmp(xar_subdoc_name(subdoc), "binary-delta-attributes")) {
|
||||
const char *value = 0;
|
||||
xar_subdoc_prop_get(subdoc, "before-sha1", &value);
|
||||
if (value)
|
||||
expectedBeforeHash = @(value);
|
||||
|
||||
xar_subdoc_prop_get(subdoc, "after-sha1", &value);
|
||||
if (value)
|
||||
expectedAfterHash = @(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!expectedBeforeHash || !expectedAfterHash) {
|
||||
fprintf(stderr, "Unable to find before-sha1 or after-sha1 metadata in delta. Giving up.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Verifying source... ");
|
||||
NSString *beforeHash = hashOfTree(source);
|
||||
|
||||
if (![beforeHash isEqualToString:expectedBeforeHash]) {
|
||||
fprintf(stderr, "Source doesn't have expected hash (%s != %s). Giving up.\n", [expectedBeforeHash UTF8String], [beforeHash UTF8String]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nCopying files... ");
|
||||
removeTree(destination);
|
||||
copyTree(source, destination);
|
||||
|
||||
fprintf(stderr, "\nPatching... ");
|
||||
xar_file_t file;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (file = xar_file_first(x, iter); file; file = xar_file_next(iter)) {
|
||||
NSString *path = @(xar_get_path(file));
|
||||
NSString *sourceFilePath = [source stringByAppendingPathComponent:path];
|
||||
NSString *destinationFilePath = [destination stringByAppendingPathComponent:path];
|
||||
|
||||
const char *value;
|
||||
if (!xar_prop_get(file, "delete", &value) || !xar_prop_get(file, "delete-then-extract", &value)) {
|
||||
removeTree(destinationFilePath);
|
||||
if (!xar_prop_get(file, "delete", &value))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!xar_prop_get(file, "binary-delta", &value))
|
||||
applyBinaryDeltaToFile(x, file, sourceFilePath, destinationFilePath);
|
||||
else
|
||||
xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]);
|
||||
}
|
||||
xar_close(x);
|
||||
|
||||
fprintf(stderr, "\nVerifying destination... ");
|
||||
NSString *afterHash = hashOfTree(destination);
|
||||
|
||||
if (![afterHash isEqualToString:expectedAfterHash]) {
|
||||
fprintf(stderr, "Destination doesn't have expected hash (%s != %s). Giving up.\n", [expectedAfterHash UTF8String], [afterHash UTF8String]);
|
||||
removeTree(destination);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// SUBinaryDeltaCommon.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTACOMMON_H
|
||||
#define SUBINARYDELTACOMMON_H
|
||||
|
||||
#include <fts.h>
|
||||
|
||||
@class NSString;
|
||||
@class NSData;
|
||||
|
||||
extern int binaryDeltaSupported(void);
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
extern NSData *hashOfFile(FTSENT *ent);
|
||||
extern NSString *hashOfTree(NSString *path);
|
||||
extern void removeTree(NSString *path);
|
||||
extern void copyTree(NSString *source, NSString *dest);
|
||||
extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path);
|
||||
NSString *temporaryFilename(NSString *base);
|
||||
NSString *stringWithFileSystemRepresentation(const char*);
|
||||
#endif
|
|
@ -0,0 +1,168 @@
|
|||
//
|
||||
// SUBinaryDeltaCommon.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
int binaryDeltaSupported(void)
|
||||
{
|
||||
// OS X 10.4 didn't include libxar, so we link against it weakly.
|
||||
// This checks whether libxar is available at runtime.
|
||||
return xar_close != 0;
|
||||
}
|
||||
|
||||
int compareFiles(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcoll((*a)->fts_name, (*b)->fts_name);
|
||||
}
|
||||
|
||||
NSString *pathRelativeToDirectory(NSString *directory, NSString *path)
|
||||
{
|
||||
NSUInteger directoryLength = [directory length];
|
||||
if ([path hasPrefix:directory])
|
||||
return [path substringFromIndex:directoryLength];
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
NSString *stringWithFileSystemRepresentation(const char *input) {
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
return [fm stringWithFileSystemRepresentation:input length:strlen(input)];
|
||||
}
|
||||
|
||||
NSString *temporaryFilename(NSString *base)
|
||||
{
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
const char *fsrepr = [template fileSystemRepresentation];
|
||||
|
||||
const size_t buffer_len = strlen(fsrepr) + 1;
|
||||
char *buffer = (char *)malloc(buffer_len);
|
||||
strlcpy(buffer, fsrepr, buffer_len);
|
||||
|
||||
// mkstemp() can't be used, beause it returns a file descriptor, and XAR API requires a filename
|
||||
NSString *ret = stringWithFileSystemRepresentation(mktemp(buffer));
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void _hashOfBuffer(unsigned char *hash, const char* buffer, ssize_t bufferLength)
|
||||
{
|
||||
assert(bufferLength >= 0 && bufferLength <= UINT32_MAX);
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
CC_SHA1_Update(&hashContext, buffer, (CC_LONG)bufferLength);
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
}
|
||||
|
||||
static void _hashOfFile(unsigned char* hash, FTSENT *ent)
|
||||
{
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
char linkDestination[MAXPATHLEN + 1];
|
||||
ssize_t linkDestinationLength = readlink(ent->fts_path, linkDestination, MAXPATHLEN);
|
||||
if (linkDestinationLength < 0) {
|
||||
perror("readlink");
|
||||
return;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, linkDestination, linkDestinationLength);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->fts_info == FTS_F) {
|
||||
int fileDescriptor = open(ent->fts_path, O_RDONLY);
|
||||
if (fileDescriptor == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
|
||||
ssize_t fileSize = ent->fts_statp->st_size;
|
||||
if (fileSize == 0) {
|
||||
_hashOfBuffer(hash, NULL, 0);
|
||||
close(fileDescriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
void *buffer = mmap(0, (size_t)fileSize, PROT_READ, MAP_FILE | MAP_PRIVATE, fileDescriptor, 0);
|
||||
if (buffer == (void*)-1) {
|
||||
close(fileDescriptor);
|
||||
perror("mmap");
|
||||
return;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, buffer, fileSize);
|
||||
munmap(buffer, (size_t)fileSize);
|
||||
close(fileDescriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->fts_info == FTS_D)
|
||||
memset(hash, 0xdd, CC_SHA1_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
NSData *hashOfFile(FTSENT *ent)
|
||||
{
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
_hashOfFile(fileHash, ent);
|
||||
return [NSData dataWithBytes:fileHash length:CC_SHA1_DIGEST_LENGTH];
|
||||
}
|
||||
|
||||
NSString *hashOfTree(NSString *path)
|
||||
{
|
||||
const char *sourcePaths[] = {[path fileSystemRepresentation], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return nil;
|
||||
}
|
||||
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL)
|
||||
continue;
|
||||
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
_hashOfFile(fileHash, ent);
|
||||
CC_SHA1_Update(&hashContext, fileHash, sizeof(fileHash));
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(path, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
const char *relativePathBytes = [relativePath fileSystemRepresentation];
|
||||
CC_SHA1_Update(&hashContext, relativePathBytes, (CC_LONG)strlen(relativePathBytes));
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
|
||||
char hexHash[CC_SHA1_DIGEST_LENGTH * 2 + 1];
|
||||
size_t i;
|
||||
for (i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
|
||||
sprintf(hexHash + i * 2, "%02x", hash[i]);
|
||||
|
||||
return @(hexHash);
|
||||
}
|
||||
|
||||
void removeTree(NSString *path)
|
||||
{
|
||||
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
|
||||
}
|
||||
|
||||
void copyTree(NSString *source, NSString *dest)
|
||||
{
|
||||
[[NSFileManager defaultManager] copyItemAtPath:source toPath:dest error:nil];
|
||||
}
|
|
@ -0,0 +1,266 @@
|
|||
//
|
||||
// SUBinaryDeltaTool.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#define _DARWIN_NO_64_BIT_INODE 1
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include "SUBinaryDeltaApply.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
extern int bsdiff(int argc, const char **argv);
|
||||
|
||||
@interface CreateBinaryDeltaOperation : NSOperation
|
||||
@property (copy) NSString *relativePath;
|
||||
@property (strong) NSString *resultPath;
|
||||
@property (strong) NSString *_fromPath;
|
||||
@property (strong) NSString *_toPath;
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree;
|
||||
@end
|
||||
|
||||
@implementation CreateBinaryDeltaOperation
|
||||
@synthesize relativePath = _relativePath;
|
||||
@synthesize resultPath = _resultPath;
|
||||
@synthesize _fromPath = _fromPath;
|
||||
@synthesize _toPath = _toPath;
|
||||
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
self.relativePath = relativePath;
|
||||
self._fromPath = [oldTree stringByAppendingPathComponent:relativePath];
|
||||
self._toPath = [newTree stringByAppendingPathComponent:relativePath];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
NSString *temporaryFile = temporaryFilename(@"BinaryDelta");
|
||||
const char *argv[] = {"/usr/bin/bsdiff", [self._fromPath fileSystemRepresentation], [self._toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation]};
|
||||
int result = bsdiff(4, argv);
|
||||
if (!result)
|
||||
self.resultPath = temporaryFile;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static NSDictionary *infoForFile(FTSENT *ent)
|
||||
{
|
||||
NSData *hash = hashOfFile(ent);
|
||||
NSNumber *size = @0;
|
||||
if (ent->fts_info != FTS_D) {
|
||||
size = @(ent->fts_statp->st_size);
|
||||
}
|
||||
return @{@"hash": hash, @"type": @(ent->fts_info), @"size": size};
|
||||
}
|
||||
|
||||
static NSString *absolutePath(NSString *path)
|
||||
{
|
||||
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
|
||||
return [[url absoluteURL] path];
|
||||
}
|
||||
|
||||
static NSString *temporaryPatchFile(NSString *patchFile)
|
||||
{
|
||||
NSString *path = absolutePath(patchFile);
|
||||
NSString *directory = [path stringByDeletingLastPathComponent];
|
||||
NSString *file = [path lastPathComponent];
|
||||
return [NSString stringWithFormat:@"%@/.%@.tmp", directory, file];
|
||||
}
|
||||
|
||||
static BOOL shouldSkipDeltaCompression(NSString * __unused key, NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
unsigned long long fileSize = [newInfo[@"size"] unsignedLongLongValue];
|
||||
if (fileSize < 4096) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (!originalInfo) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([originalInfo[@"type"] unsignedShortValue] != [newInfo[@"type"] unsignedShortValue]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
static BOOL shouldDeleteThenExtract(NSString * __unused key, NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
if (!originalInfo) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([originalInfo[@"type"] unsignedShortValue] != [newInfo[@"type"] unsignedShortValue]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (argc != 5) {
|
||||
usage:
|
||||
fprintf(stderr, "Usage: BinaryDelta [create | apply] before-tree after-tree patch-file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
NSString *command = @(argv[1]);
|
||||
NSString *oldPath = stringWithFileSystemRepresentation(argv[2]);
|
||||
NSString *newPath = stringWithFileSystemRepresentation(argv[3]);
|
||||
NSString *patchFile = stringWithFileSystemRepresentation(argv[4]);
|
||||
|
||||
if ([command isEqualToString:@"apply"]) {
|
||||
int result = applyBinaryDelta(oldPath, newPath, patchFile);
|
||||
return result;
|
||||
}
|
||||
if (![command isEqualToString:@"create"]) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
NSMutableDictionary *originalTreeState = [NSMutableDictionary dictionary];
|
||||
|
||||
const char *sourcePaths[] = {[oldPath fileSystemRepresentation], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Processing %s...", [oldPath UTF8String]);
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *key = pathRelativeToDirectory(oldPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (![key length]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
originalTreeState[key] = info;
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *beforeHash = hashOfTree(oldPath);
|
||||
|
||||
NSMutableDictionary *newTreeState = [NSMutableDictionary dictionary];
|
||||
for (NSString *key in originalTreeState)
|
||||
{
|
||||
newTreeState[key] = [NSNull null];
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nProcessing %s... ", [newPath UTF8String]);
|
||||
sourcePaths[0] = [newPath fileSystemRepresentation];
|
||||
fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *key = pathRelativeToDirectory(newPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (![key length]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
NSDictionary *oldInfo = originalTreeState[key];
|
||||
|
||||
if ([info isEqual:oldInfo])
|
||||
[newTreeState removeObjectForKey:key];
|
||||
else
|
||||
newTreeState[key] = info;
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *afterHash = hashOfTree(newPath);
|
||||
|
||||
fprintf(stderr, "\nGenerating delta... ");
|
||||
|
||||
NSString *temporaryFile = temporaryPatchFile(patchFile);
|
||||
xar_t x = xar_open([temporaryFile fileSystemRepresentation], WRITE);
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
xar_subdoc_t attributes = xar_subdoc_new(x, "binary-delta-attributes");
|
||||
xar_subdoc_prop_set(attributes, "before-sha1", [beforeHash UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, "after-sha1", [afterHash UTF8String]);
|
||||
|
||||
NSOperationQueue *deltaQueue = [[NSOperationQueue alloc] init];
|
||||
NSMutableArray *deltaOperations = [NSMutableArray array];
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wselector"
|
||||
// Xcode 5.1.1: compare: is clearly declared, must warn due to a compiler bug?
|
||||
NSArray *keys = [[newTreeState allKeys] sortedArrayUsingSelector:@selector(compare:)];
|
||||
#pragma clang diagnostic pop
|
||||
for (NSString* key in keys) {
|
||||
id value = [newTreeState valueForKey:key];
|
||||
|
||||
if ([value isEqual:[NSNull null]]) {
|
||||
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, "delete", "true");
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *originalInfo = originalTreeState[key];
|
||||
NSDictionary *newInfo = newTreeState[key];
|
||||
if (shouldSkipDeltaCompression(key, originalInfo, newInfo)) {
|
||||
NSString *path = [newPath stringByAppendingPathComponent:key];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [key fileSystemRepresentation], [path fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
if (shouldDeleteThenExtract(key, originalInfo, newInfo)) {
|
||||
xar_prop_set(newFile, "delete-then-extract", "true");
|
||||
}
|
||||
} else {
|
||||
CreateBinaryDeltaOperation *operation = [[CreateBinaryDeltaOperation alloc] initWithRelativePath:key oldTree:oldPath newTree:newPath];
|
||||
[deltaQueue addOperation:operation];
|
||||
[deltaOperations addObject:operation];
|
||||
}
|
||||
}
|
||||
|
||||
[deltaQueue waitUntilAllOperationsAreFinished];
|
||||
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [[operation relativePath] fileSystemRepresentation], [resultPath fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, "binary-delta", "true");
|
||||
unlink([resultPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
xar_close(x);
|
||||
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
link([temporaryFile fileSystemRepresentation], [patchFile fileSystemRepresentation]);
|
||||
unlink([temporaryFile fileSystemRepresentation]);
|
||||
fprintf(stderr, "Done!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// SUBinaryDeltaUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-03.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTAUNARCHIVER_H
|
||||
#define SUBINARYDELTAUNARCHIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUnarchiver.h"
|
||||
|
||||
@interface SUBinaryDeltaUnarchiver : SUUnarchiver
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// SUBinaryDeltaUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-03.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUBinaryDeltaUnarchiver.h"
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "SUHost.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
|
||||
@implementation SUBinaryDeltaUnarchiver
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return binaryDeltaSupported() && [[path pathExtension] isEqualToString:@"delta"];
|
||||
}
|
||||
|
||||
- (void)applyBinaryDelta
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSString *sourcePath = [[self.updateHost bundle] bundlePath];
|
||||
NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
int result = applyBinaryDelta(sourcePath, targetPath, self.archivePath);
|
||||
if (!result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
});
|
||||
}
|
||||
else {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfFailure];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self applyBinaryDelta];
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self registerImplementation:self];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// SUCodeSigningVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef SUCODESIGNINGVERIFIER_H
|
||||
#define SUCODESIGNINGVERIFIER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error;
|
||||
+ (BOOL)hostApplicationIsCodeSigned;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,117 @@
|
|||
//
|
||||
// SUCodeSigningVerifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#include <Security/CodeSigning.h>
|
||||
#include <Security/SecCode.h>
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecRequirementRef requirement = NULL;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
SecCodeRef hostCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
CFErrorRef cfError = NULL;
|
||||
if (error) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to copy host code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to copy designated requirement. Code Signing OSStatus code: %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:destinationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle for update");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle executableURL], kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, kSecCSDefaultFlags | kSecCSCheckAllArchitectures, requirement, &cfError);
|
||||
|
||||
if (cfError) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
if (error) *error = tmpError;
|
||||
}
|
||||
|
||||
if (result != noErr) {
|
||||
if (result == errSecCSUnsigned) {
|
||||
SULog(@"The host app is signed, but the new version of the app is not signed using Apple Code Signing. Please ensure that the new app is signed and that archiving did not corrupt the signature.");
|
||||
}
|
||||
if (result == errSecCSReqFailed) {
|
||||
CFStringRef requirementString = nil;
|
||||
if (SecRequirementCopyString(requirement, kSecCSDefaultFlags, &requirementString) == noErr) {
|
||||
SULog(@"Code signature of the new version doesn't match the old version: %@. Please ensure that old and new app is signed using exactly the same certificate.", requirementString);
|
||||
CFRelease(requirementString);
|
||||
}
|
||||
|
||||
[self logSigningInfoForCode:hostCode label:@"host info"];
|
||||
[self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
}
|
||||
}
|
||||
|
||||
finally:
|
||||
if (hostCode) CFRelease(hostCode);
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
static id valueOrNSNull(id value) {
|
||||
return value ? value : [NSNull null];
|
||||
}
|
||||
|
||||
+ (void)logSigningInfoForCode:(SecStaticCodeRef)code label:(NSString*)label {
|
||||
CFDictionaryRef signingInfo = nil;
|
||||
const SecCSFlags flags = kSecCSSigningInformation | kSecCSRequirementInformation | kSecCSDynamicInformation | kSecCSContentInformation;
|
||||
if (SecCodeCopySigningInformation(code, flags, &signingInfo) == noErr) {
|
||||
NSDictionary *signingDict = CFBridgingRelease(signingInfo);
|
||||
NSMutableDictionary *relevantInfo = [NSMutableDictionary dictionary];
|
||||
for (NSString *key in @[@"format", @"identifier", @"requirements", @"teamid", @"signing-time"]) {
|
||||
relevantInfo[key] = valueOrNSNull(signingDict[key]);
|
||||
}
|
||||
NSDictionary *infoPlist = signingDict[@"info-plist"];
|
||||
relevantInfo[@"version"] = valueOrNSNull(infoPlist[@"CFBundleShortVersionString"]);
|
||||
relevantInfo[@"build"] = valueOrNSNull(infoPlist[@"CFBundleVersion"]);
|
||||
SULog(@"%@: %@", label, relevantInfo);
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)hostApplicationIsCodeSigned
|
||||
{
|
||||
OSStatus result;
|
||||
SecCodeRef hostCode = NULL;
|
||||
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
if (result != 0) return NO;
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
|
||||
if (hostCode) CFRelease(hostCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,87 @@
|
|||
//
|
||||
// SUConstants.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SUCONSTANTS_H
|
||||
#define SUCONSTANTS_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Preprocessor flags:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Sparkle usually doesn't allow downgrades as they're usually accidental, but
|
||||
// if your app has a downgrade function or URL handler, turn this on:
|
||||
#define PERMIT_AUTOMATED_DOWNGRADES 0
|
||||
|
||||
// If your app file on disk is named "MyApp 1.1b4", Sparkle usually updates it
|
||||
// in place, giving you an app named 1.1b4 that is actually 1.2. Turn the
|
||||
// following on to always reset the name back to "MyApp":
|
||||
#define NORMALIZE_INSTALLED_APP_NAME 0
|
||||
|
||||
|
||||
#define TRY_TO_APPEND_VERSION_NUMBER 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Notifications:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUTechnicalErrorInformationKey;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// PList keys::
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUFeedURLKey;
|
||||
extern NSString *const SUHasLaunchedBeforeKey;
|
||||
extern NSString *const SUShowReleaseNotesKey;
|
||||
extern NSString *const SUSkippedVersionKey;
|
||||
extern NSString *const SUScheduledCheckIntervalKey;
|
||||
extern NSString *const SULastCheckTimeKey;
|
||||
extern NSString *const SUExpectsDSASignatureKey;
|
||||
extern NSString *const SUPublicDSAKeyKey;
|
||||
extern NSString *const SUPublicDSAKeyFileKey;
|
||||
extern NSString *const SUAutomaticallyUpdateKey;
|
||||
extern NSString *const SUAllowsAutomaticUpdatesKey;
|
||||
extern NSString *const SUEnableAutomaticChecksKey;
|
||||
extern NSString *const SUEnableAutomaticChecksKeyOld;
|
||||
extern NSString *const SUEnableSystemProfilingKey;
|
||||
extern NSString *const SUSendProfileInfoKey;
|
||||
extern NSString *const SULastProfileSubmitDateKey;
|
||||
extern NSString *const SUPromptUserOnFirstLaunchKey;
|
||||
extern NSString *const SUKeepDownloadOnFailedInstallKey;
|
||||
extern NSString *const SUDefaultsDomainKey;
|
||||
extern NSString *const SUFixedHTMLDisplaySizeKey __attribute__((deprecated("This key is obsolete and has no effect.")));
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Errors:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUSparkleErrorDomain;
|
||||
// Appcast phase errors.
|
||||
extern OSStatus SUAppcastParseError;
|
||||
extern OSStatus SUNoUpdateError;
|
||||
extern OSStatus SUAppcastError;
|
||||
extern OSStatus SURunningFromDiskImageError;
|
||||
|
||||
// Downlaod phase errors.
|
||||
extern OSStatus SUTemporaryDirectoryError;
|
||||
|
||||
// Extraction phase errors.
|
||||
extern OSStatus SUUnarchivingError;
|
||||
extern OSStatus SUSignatureError;
|
||||
|
||||
// Installation phase errors.
|
||||
extern OSStatus SUFileCopyFailure;
|
||||
extern OSStatus SUAuthenticationFailure;
|
||||
extern OSStatus SUMissingUpdateError;
|
||||
extern OSStatus SUMissingInstallerToolError;
|
||||
extern OSStatus SURelaunchError;
|
||||
extern OSStatus SUInstallationError;
|
||||
extern OSStatus SUDowngradeError;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// SUConstants.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
NSString *const SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation";
|
||||
|
||||
NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore";
|
||||
NSString *const SUFeedURLKey = @"SUFeedURL";
|
||||
NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes";
|
||||
NSString *const SUSkippedVersionKey = @"SUSkippedVersion";
|
||||
NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval";
|
||||
NSString *const SULastCheckTimeKey = @"SULastCheckTime";
|
||||
NSString *const SUExpectsDSASignatureKey = @"SUExpectsDSASignature";
|
||||
NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey";
|
||||
NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile";
|
||||
NSString *const SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate";
|
||||
NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates";
|
||||
NSString *const SUEnableSystemProfilingKey = @"SUEnableSystemProfiling";
|
||||
NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks";
|
||||
NSString *const SUEnableAutomaticChecksKeyOld = @"SUCheckAtStartup";
|
||||
NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo";
|
||||
NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate";
|
||||
NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch";
|
||||
NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize";
|
||||
NSString *const SUKeepDownloadOnFailedInstallKey = @"SUKeepDownloadOnFailedInstall";
|
||||
NSString *const SUDefaultsDomainKey = @"SUDefaultsDomain";
|
||||
|
||||
NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain";
|
||||
OSStatus SUAppcastParseError = 1000;
|
||||
OSStatus SUNoUpdateError = 1001;
|
||||
OSStatus SUAppcastError = 1002;
|
||||
OSStatus SURunningFromDiskImageError = 1003;
|
||||
|
||||
OSStatus SUTemporaryDirectoryError = 2000;
|
||||
|
||||
OSStatus SUUnarchivingError = 3000;
|
||||
OSStatus SUSignatureError = 3001;
|
||||
|
||||
OSStatus SUFileCopyFailure = 4000;
|
||||
OSStatus SUAuthenticationFailure = 4001;
|
||||
OSStatus SUMissingUpdateError = 4002;
|
||||
OSStatus SUMissingInstallerToolError = 4003;
|
||||
OSStatus SURelaunchError = 4004;
|
||||
OSStatus SUInstallationError = 4005;
|
||||
OSStatus SUDowngradeError = 4006;
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// SUDSAVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
// Includes code by Zach Waldowski on 10/18/13.
|
||||
// Copyright 2014 Big Nerd Ranch. Licensed under MIT.
|
||||
//
|
||||
// Includes code from Plop by Mark Hamlin.
|
||||
// Copyright 2011 Mark Hamlin. Licensed under BSD.
|
||||
//
|
||||
|
||||
#ifndef SUDSAVERIFIER_H
|
||||
#define SUDSAVERIFIER_H
|
||||
|
||||
@interface SUDSAVerifier : NSObject
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString;
|
||||
|
||||
- (instancetype)initWithPublicKeyData:(NSData *)data;
|
||||
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signature:(NSData *)signature;
|
||||
- (BOOL)verifyStream:(NSInputStream *)stream signature:(NSData *)signature;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,156 @@
|
|||
//
|
||||
// SUDSAVerifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
// Includes code by Zach Waldowski on 10/18/13.
|
||||
// Copyright 2014 Big Nerd Ranch. Licensed under MIT.
|
||||
//
|
||||
// Includes code from Plop by Mark Hamlin.
|
||||
// Copyright 2011 Mark Hamlin. Licensed under BSD.
|
||||
//
|
||||
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SULog.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@implementation SUDSAVerifier {
|
||||
SecKeyRef _secKey;
|
||||
}
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString
|
||||
{
|
||||
if (!encodedSignature) {
|
||||
SULog(@"There is no DSA signature to check");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
SUDSAVerifier *verifier = [[self alloc] initWithPublicKeyData:[pkeyString dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
|
||||
if (!verifier) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSString *strippedSignature = [encodedSignature stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
||||
NSData *signature = [[NSData alloc] initWithBase64Encoding:strippedSignature];
|
||||
return [verifier verifyFileAtPath:path signature:signature];
|
||||
}
|
||||
|
||||
- (instancetype)initWithPublicKeyData:(NSData *)data
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (!self || !data.length) {
|
||||
SULog(@"Could not read public DSA key");
|
||||
return nil;
|
||||
}
|
||||
|
||||
SecExternalFormat format = kSecFormatOpenSSL;
|
||||
SecExternalItemType itemType = kSecItemTypePublicKey;
|
||||
CFArrayRef items = NULL;
|
||||
|
||||
OSStatus status = SecItemImport((__bridge CFDataRef)data, NULL, &format, &itemType, 0, NULL, NULL, &items);
|
||||
if (status != errSecSuccess || !items) {
|
||||
if (items) {
|
||||
CFRelease(items);
|
||||
}
|
||||
SULog(@"Public DSA key could not be imported: %d", status);
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (format == kSecFormatOpenSSL && itemType == kSecItemTypePublicKey && CFArrayGetCount(items) == 1) {
|
||||
_secKey = (SecKeyRef)CFRetain(CFArrayGetValueAtIndex(items, 0));
|
||||
}
|
||||
|
||||
CFRelease(items);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if (_secKey) {
|
||||
CFRelease(_secKey);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signature:(NSData *)signature
|
||||
{
|
||||
if (!path.length) {
|
||||
return NO;
|
||||
}
|
||||
NSInputStream *dataInputStream = [NSInputStream inputStreamWithFileAtPath:path];
|
||||
return [self verifyStream:dataInputStream signature:signature];
|
||||
}
|
||||
|
||||
- (BOOL)verifyStream:(NSInputStream *)stream signature:(NSData *)signature
|
||||
{
|
||||
if (!stream || !signature) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
__block SecGroupTransformRef group = SecTransformCreateGroupTransform();
|
||||
__block SecTransformRef dataReadTransform = NULL;
|
||||
__block SecTransformRef dataDigestTransform = NULL;
|
||||
__block SecTransformRef dataVerifyTransform = NULL;
|
||||
__block CFErrorRef error = NULL;
|
||||
|
||||
BOOL (^cleanup)(void) = ^{
|
||||
if (group) CFRelease(group);
|
||||
if (dataReadTransform) CFRelease(dataReadTransform);
|
||||
if (dataDigestTransform) CFRelease(dataDigestTransform);
|
||||
if (dataVerifyTransform) CFRelease(dataVerifyTransform);
|
||||
if (error) CFRelease(error);
|
||||
return NO;
|
||||
};
|
||||
|
||||
dataReadTransform = SecTransformCreateReadTransformWithReadStream((__bridge CFReadStreamRef)stream);
|
||||
if (!dataReadTransform) {
|
||||
SULog(@"File containing update archive could not be read (failed to create SecTransform for input stream)");
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, CC_SHA1_DIGEST_LENGTH, NULL);
|
||||
if (!dataDigestTransform) {
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
dataVerifyTransform = SecVerifyTransformCreate(_secKey, (__bridge CFDataRef)signature, &error);
|
||||
if (!dataVerifyTransform || error) {
|
||||
SULog(@"Could not understand format of the sugnature: %@; Signature data: %@", error, signature);
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error);
|
||||
if (error) {
|
||||
SULog(@"%@", error);
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataVerifyTransform, kSecTransformInputAttributeName, group, &error);
|
||||
if (error) {
|
||||
SULog(@"%@", error);
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
NSNumber *result = CFBridgingRelease(SecTransformExecute(group, &error));
|
||||
if (error) {
|
||||
SULog(@"DSA signature verification failed: %@", error);
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
if (!result.boolValue) {
|
||||
SULog(@"DSA signature does not match. Data of the update file being checked is different than data that has been signed, or the public key and the private key are not from the same set.");
|
||||
}
|
||||
|
||||
cleanup();
|
||||
return result.boolValue;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// SUDiskImageUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUDISKIMAGEUNARCHIVER_H
|
||||
#define SUDISKIMAGEUNARCHIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUnarchiver.h"
|
||||
|
||||
@interface SUDiskImageUnarchiver : SUUnarchiver
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,168 @@
|
|||
//
|
||||
// SUDiskImageUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUDiskImageUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
#import "SULog.h"
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
@implementation SUDiskImageUnarchiver
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return [[path pathExtension] isEqualToString:@"dmg"];
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMG
|
||||
{
|
||||
@autoreleasepool {
|
||||
[self extractDMGWithPassword:nil];
|
||||
}
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMGWithPassword:(NSString *)__unused password
|
||||
{
|
||||
@autoreleasepool {
|
||||
BOOL mountedSuccessfully = NO;
|
||||
|
||||
SULog(@"Extracting %@ as a DMG", self.archivePath);
|
||||
|
||||
// get a unique mount point path
|
||||
NSString *mountPoint = nil;
|
||||
FSRef tmpRef;
|
||||
NSFileManager *manager;
|
||||
NSError *error;
|
||||
NSArray *contents;
|
||||
// We have to declare these before a goto to prevent an error under ARC.
|
||||
// No, we cannot have them in the dispatch_async calls, as the goto "jump enters
|
||||
// lifetime of block which strongly captures a variable"
|
||||
dispatch_block_t delegateFailure = ^{
|
||||
[self notifyDelegateOfFailure];
|
||||
};
|
||||
dispatch_block_t delegateSuccess = ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
};
|
||||
do
|
||||
{
|
||||
// Using NSUUID would make creating UUIDs be done in Cocoa,
|
||||
// and thus managed under ARC. Sadly, the class is in 10.8 and later.
|
||||
CFUUIDRef uuid = CFUUIDCreate(NULL);
|
||||
if (uuid)
|
||||
{
|
||||
NSString *uuidString = CFBridgingRelease(CFUUIDCreateString(NULL, uuid));
|
||||
if (uuidString)
|
||||
{
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:uuidString];
|
||||
}
|
||||
CFRelease(uuid);
|
||||
}
|
||||
}
|
||||
while (noErr == FSPathMakeRefWithOptions((UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL));
|
||||
|
||||
NSData *promptData = nil;
|
||||
promptData = [NSData dataWithBytes:"yes\n" length:4];
|
||||
|
||||
NSArray *arguments = @[@"attach", self.archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen"];
|
||||
|
||||
NSData *output = nil;
|
||||
NSInteger taskResult = -1;
|
||||
@try
|
||||
{
|
||||
NTSynchronousTask *task = [[NTSynchronousTask alloc] init];
|
||||
|
||||
[task run:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:promptData];
|
||||
|
||||
taskResult = [task result];
|
||||
output = [[task output] copy];
|
||||
}
|
||||
@catch (NSException *)
|
||||
{
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
if (taskResult != 0)
|
||||
{
|
||||
NSString *resultStr = output ? [[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding] : nil;
|
||||
SULog(@"hdiutil failed with code: %ld data: <<%@>>", (long)taskResult, resultStr);
|
||||
goto reportError;
|
||||
}
|
||||
mountedSuccessfully = YES;
|
||||
|
||||
// Now that we've mounted it, we need to copy out its contents.
|
||||
manager = [[NSFileManager alloc] init];
|
||||
contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error];
|
||||
if (error)
|
||||
{
|
||||
SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
for (NSString *item in contents)
|
||||
{
|
||||
NSString *fromPath = [mountPoint stringByAppendingPathComponent:item];
|
||||
NSString *toPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item];
|
||||
|
||||
// We skip any files in the DMG which are not readable.
|
||||
if (![manager isReadableFileAtPath:fromPath]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath);
|
||||
|
||||
if (![manager copyItemAtPath:fromPath toPath:toPath error:&error])
|
||||
{
|
||||
SULog(@"Couldn't copy item: %@ : %@", error, error.userInfo ? error.userInfo : @"");
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), delegateSuccess);
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
dispatch_async(dispatch_get_main_queue(), delegateFailure);
|
||||
|
||||
finally:
|
||||
if (mountedSuccessfully)
|
||||
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]];
|
||||
else
|
||||
SULog(@"Can't mount DMG %@", self.archivePath);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self extractDMG];
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self registerImplementation:self];
|
||||
}
|
||||
|
||||
- (BOOL)isEncrypted:(NSData *)resultData
|
||||
{
|
||||
BOOL result = NO;
|
||||
if(resultData)
|
||||
{
|
||||
NSString *data = [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding];
|
||||
|
||||
if ((data != nil) && !NSEqualRanges([data rangeOfString:@"passphrase-count"], NSMakeRange(NSNotFound, 0)))
|
||||
{
|
||||
result = YES;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// SUHost.h
|
||||
// Sparkle
|
||||
//
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@interface SUHost : NSObject
|
||||
|
||||
@property (strong, readonly) NSBundle *bundle;
|
||||
|
||||
+ (NSString *)systemVersionString;
|
||||
|
||||
- (instancetype)initWithBundle:(NSBundle *)aBundle;
|
||||
@property (readonly, copy) NSString *bundlePath;
|
||||
@property (readonly, copy) NSString *appSupportPath;
|
||||
@property (readonly, copy) NSString *installationPath;
|
||||
@property (readonly, copy) NSString *name;
|
||||
@property (readonly, copy) NSString *version;
|
||||
@property (readonly, copy) NSString *displayVersion;
|
||||
@property (readonly, copy) NSImage *icon;
|
||||
@property (getter=isRunningOnReadOnlyVolume, readonly) BOOL runningOnReadOnlyVolume;
|
||||
@property (getter=isBackgroundApplication, readonly) BOOL backgroundApplication;
|
||||
@property (readonly, copy) NSString *publicDSAKey;
|
||||
@property (readonly, copy) NSArray *systemProfile;
|
||||
|
||||
- (id)objectForInfoDictionaryKey:(NSString *)key;
|
||||
- (BOOL)boolForInfoDictionaryKey:(NSString *)key;
|
||||
- (id)objectForUserDefaultsKey:(NSString *)defaultName;
|
||||
- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName;
|
||||
- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName;
|
||||
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName;
|
||||
- (id)objectForKey:(NSString *)key;
|
||||
- (BOOL)boolForKey:(NSString *)key;
|
||||
@end
|
|
@ -0,0 +1,276 @@
|
|||
//
|
||||
// SUHost.m
|
||||
// Sparkle
|
||||
//
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUHost.h"
|
||||
|
||||
#import "SUConstants.h"
|
||||
#import "SUSystemProfiler.h"
|
||||
#include <sys/mount.h> // For statfs for isRunningOnReadOnlyVolume
|
||||
#import "SULog.h"
|
||||
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000
|
||||
typedef struct {
|
||||
NSInteger majorVersion;
|
||||
NSInteger minorVersion;
|
||||
NSInteger patchVersion;
|
||||
} NSOperatingSystemVersion;
|
||||
@interface NSProcessInfo ()
|
||||
- (NSOperatingSystemVersion)operatingSystemVersion;
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface SUHost ()
|
||||
|
||||
@property (strong, readwrite) NSBundle *bundle;
|
||||
@property (copy) NSString *defaultsDomain;
|
||||
@property (assign) BOOL usesStandardUserDefaults;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUHost
|
||||
|
||||
@synthesize bundle;
|
||||
@synthesize defaultsDomain;
|
||||
@synthesize usesStandardUserDefaults;
|
||||
|
||||
- (instancetype)initWithBundle:(NSBundle *)aBundle
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
if (aBundle == nil) aBundle = [NSBundle mainBundle];
|
||||
self.bundle = aBundle;
|
||||
if (![self.bundle bundleIdentifier]) {
|
||||
SULog(@"Error: the bundle being updated at %@ has no CFBundleIdentifier! This will cause preference read/write to not work properly.", self.bundle);
|
||||
}
|
||||
|
||||
self.defaultsDomain = [self.bundle objectForInfoDictionaryKey:SUDefaultsDomainKey];
|
||||
if (!self.defaultsDomain) {
|
||||
self.defaultsDomain = [self.bundle bundleIdentifier];
|
||||
}
|
||||
|
||||
// If we're using the main bundle's defaults we'll use the standard user defaults mechanism, otherwise we have to get CF-y.
|
||||
usesStandardUserDefaults = !self.defaultsDomain || [self.defaultsDomain isEqualToString:[[NSBundle mainBundle] bundleIdentifier]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self bundlePath], [self installationPath]]; }
|
||||
|
||||
- (NSString *)bundlePath
|
||||
{
|
||||
return [self.bundle bundlePath];
|
||||
}
|
||||
|
||||
- (NSString *)appSupportPath
|
||||
{
|
||||
NSArray *appSupportPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSString *appSupportPath = nil;
|
||||
if (!appSupportPaths || [appSupportPaths count] == 0)
|
||||
{
|
||||
SULog(@"Failed to find app support directory! Using ~/Library/Application Support...");
|
||||
appSupportPath = [@"~/Library/Application Support" stringByExpandingTildeInPath];
|
||||
}
|
||||
else {
|
||||
appSupportPath = appSupportPaths[0];
|
||||
}
|
||||
appSupportPath = [appSupportPath stringByAppendingPathComponent:[self name]];
|
||||
appSupportPath = [appSupportPath stringByAppendingPathComponent:@".Sparkle"];
|
||||
return appSupportPath;
|
||||
}
|
||||
|
||||
- (NSString *)installationPath
|
||||
{
|
||||
#if NORMALIZE_INSTALLED_APP_NAME
|
||||
// We'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name.
|
||||
NSString *normalizedAppPath = [[[self.bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [self.bundle objectForInfoDictionaryKey:@"CFBundleName"], [[self.bundle bundlePath] pathExtension]]];
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[[[self.bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [self.bundle objectForInfoDictionaryKey:@"CFBundleName"], [[self.bundle bundlePath] pathExtension]]]]) {
|
||||
return normalizedAppPath;
|
||||
}
|
||||
#endif
|
||||
return [self.bundle bundlePath];
|
||||
}
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
NSString *name = [self.bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||
if (name) return name;
|
||||
|
||||
name = [self objectForInfoDictionaryKey:@"CFBundleName"];
|
||||
if (name) return name;
|
||||
|
||||
return [[[NSFileManager defaultManager] displayNameAtPath:[self.bundle bundlePath]] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
- (NSString *)version
|
||||
{
|
||||
NSString *version = [self.bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
|
||||
if (!version || [version isEqualToString:@""])
|
||||
[NSException raise:@"SUNoVersionException" format:@"This host (%@) has no CFBundleVersion! This attribute is required.", [self bundlePath]];
|
||||
return version;
|
||||
}
|
||||
|
||||
- (NSString *)displayVersion
|
||||
{
|
||||
NSString *shortVersionString = [self.bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
if (shortVersionString)
|
||||
return shortVersionString;
|
||||
else
|
||||
return [self version]; // Fall back on the normal version string.
|
||||
}
|
||||
|
||||
- (NSImage *)icon
|
||||
{
|
||||
// Cache the application icon.
|
||||
NSString *iconPath = [self.bundle pathForResource:[self.bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:@"icns"];
|
||||
// According to the OS X docs, "CFBundleIconFile - This key identifies the file containing
|
||||
// the icon for the bundle. The filename you specify does not need to include the .icns
|
||||
// extension, although it may."
|
||||
//
|
||||
// However, if it *does* include the '.icns' the above method fails (tested on OS X 10.3.9) so we'll also try:
|
||||
if (!iconPath) {
|
||||
iconPath = [self.bundle pathForResource:[self.bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:nil];
|
||||
}
|
||||
NSImage *icon = [[NSImage alloc] initWithContentsOfFile:iconPath];
|
||||
// Use a default icon if none is defined.
|
||||
if (!icon) {
|
||||
BOOL isMainBundle = (self.bundle == [NSBundle mainBundle]);
|
||||
|
||||
NSString *fileType = isMainBundle ? (NSString *)kUTTypeApplication : (NSString *)kUTTypeBundle;
|
||||
icon = [[NSWorkspace sharedWorkspace] iconForFileType:fileType];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
- (BOOL)isRunningOnReadOnlyVolume
|
||||
{
|
||||
struct statfs statfs_info;
|
||||
statfs([[self.bundle bundlePath] fileSystemRepresentation], &statfs_info);
|
||||
return (statfs_info.f_flags & MNT_RDONLY);
|
||||
}
|
||||
|
||||
- (BOOL)isBackgroundApplication
|
||||
{
|
||||
return ([[NSApplication sharedApplication] activationPolicy] == NSApplicationActivationPolicyAccessory);
|
||||
}
|
||||
|
||||
- (NSString *)publicDSAKey
|
||||
{
|
||||
// Maybe the key is just a string in the Info.plist.
|
||||
NSString *key = [self.bundle objectForInfoDictionaryKey:SUPublicDSAKeyKey];
|
||||
if (key) { return key; }
|
||||
|
||||
// More likely, we've got a reference to a Resources file by filename:
|
||||
NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey];
|
||||
if (!keyFilename) { return nil; }
|
||||
NSError *ignoreErr = nil;
|
||||
return [NSString stringWithContentsOfFile:[self.bundle pathForResource:keyFilename ofType:nil] encoding:NSASCIIStringEncoding error:&ignoreErr];
|
||||
}
|
||||
|
||||
- (NSArray *)systemProfile
|
||||
{
|
||||
return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:self];
|
||||
}
|
||||
|
||||
- (id)objectForInfoDictionaryKey:(NSString *)key
|
||||
{
|
||||
return [self.bundle objectForInfoDictionaryKey:key];
|
||||
}
|
||||
|
||||
- (BOOL)boolForInfoDictionaryKey:(NSString *)key
|
||||
{
|
||||
return [[self objectForInfoDictionaryKey:key] boolValue];
|
||||
}
|
||||
|
||||
- (id)objectForUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
if (!defaultName || !self.defaultsDomain) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistrationDomain, so anything
|
||||
// passed into -[NSUserDefaults registerDefaults:] is ignored. The following line falls
|
||||
// back to using NSUserDefaults, but only if the host bundle is the main bundle.
|
||||
if (self.usesStandardUserDefaults) {
|
||||
return [[NSUserDefaults standardUserDefaults] objectForKey:defaultName];
|
||||
}
|
||||
|
||||
CFPropertyListRef obj = CFPreferencesCopyAppValue((__bridge CFStringRef)defaultName, (__bridge CFStringRef)self.defaultsDomain);
|
||||
return CFBridgingRelease(obj);
|
||||
}
|
||||
|
||||
- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
if (self.usesStandardUserDefaults)
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:defaultName];
|
||||
}
|
||||
else
|
||||
{
|
||||
CFPreferencesSetValue((__bridge CFStringRef)defaultName, (__bridge CFPropertyListRef)(value), (__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
CFPreferencesSynchronize((__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
if (self.usesStandardUserDefaults) {
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:defaultName];
|
||||
}
|
||||
|
||||
BOOL value;
|
||||
CFPropertyListRef plr = CFPreferencesCopyAppValue((__bridge CFStringRef)defaultName, (__bridge CFStringRef)self.defaultsDomain);
|
||||
if (plr == NULL) {
|
||||
value = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (BOOL)CFBooleanGetValue((CFBooleanRef)plr);
|
||||
CFRelease(plr);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
if (self.usesStandardUserDefaults)
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] setBool:value forKey:defaultName];
|
||||
}
|
||||
else
|
||||
{
|
||||
CFPreferencesSetValue((__bridge CFStringRef)defaultName, (__bridge CFBooleanRef) @(value), (__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
CFPreferencesSynchronize((__bridge CFStringRef)self.defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
}
|
||||
}
|
||||
|
||||
- (id)objectForKey:(NSString *)key {
|
||||
return [self objectForUserDefaultsKey:key] ? [self objectForUserDefaultsKey:key] : [self objectForInfoDictionaryKey:key];
|
||||
}
|
||||
|
||||
- (BOOL)boolForKey:(NSString *)key {
|
||||
return [self objectForUserDefaultsKey:key] ? [self boolForUserDefaultsKey:key] : [self boolForInfoDictionaryKey:key];
|
||||
}
|
||||
|
||||
+ (NSString *)systemVersionString
|
||||
{
|
||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090 // Present in 10.9 despite NS_AVAILABLE's claims
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wselector"
|
||||
// Xcode 5.1.1: operatingSystemVersion is clearly declared, must warn due to a compiler bug?
|
||||
if (![NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)])
|
||||
#pragma clang diagnostic pop
|
||||
{
|
||||
NSURL *coreServices = [[NSFileManager defaultManager] URLForDirectory:NSCoreServiceDirectory inDomain:NSSystemDomainMask appropriateForURL:nil create:NO error:nil];
|
||||
return [NSDictionary dictionaryWithContentsOfURL:[coreServices URLByAppendingPathComponent:@"SystemVersion.plist"]][@"ProductVersion"];
|
||||
}
|
||||
#endif
|
||||
NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion];
|
||||
return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion, (long)version.minorVersion, (long)version.patchVersion];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// SUInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUINSTALLER_H
|
||||
#define SUINSTALLER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@protocol SUInstallerDelegate;
|
||||
|
||||
@class SUHost;
|
||||
@interface SUInstaller : NSObject
|
||||
|
||||
+ (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host;
|
||||
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator;
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:(id<SUInstallerDelegate>)delegate;
|
||||
+ (NSString *)updateFolder;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUInstallerDelegate <NSObject>
|
||||
- (void)installerFinishedForHost:(SUHost *)host;
|
||||
- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,181 @@
|
|||
//
|
||||
// SUInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUInstaller.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPackageInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
|
||||
@implementation SUInstaller
|
||||
|
||||
static NSString *sUpdateFolder = nil;
|
||||
|
||||
+ (NSString *)updateFolder
|
||||
{
|
||||
return sUpdateFolder;
|
||||
}
|
||||
|
||||
+ (BOOL)isAliasFolderAtPath:(NSString *)path
|
||||
{
|
||||
FSRef fileRef;
|
||||
OSStatus err = noErr;
|
||||
Boolean aliasFileFlag = false, folderFlag = false;
|
||||
NSURL *fileURL = [NSURL fileURLWithPath:path];
|
||||
|
||||
if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef))
|
||||
err = coreFoundationUnknownErr;
|
||||
|
||||
if (noErr == err)
|
||||
err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag);
|
||||
|
||||
if (noErr == err)
|
||||
return !!(aliasFileFlag && folderFlag);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr
|
||||
{
|
||||
// Search subdirectories for the application
|
||||
NSString *currentFile,
|
||||
*newAppDownloadPath = nil,
|
||||
*bundleFileName = [[host bundlePath] lastPathComponent],
|
||||
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
||||
BOOL isPackage = NO;
|
||||
NSString *fallbackPackagePath = nil;
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder];
|
||||
|
||||
sUpdateFolder = inUpdateFolder;
|
||||
|
||||
while ((currentFile = [dirEnum nextObject]))
|
||||
{
|
||||
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
||||
if ([[currentFile lastPathComponent] isEqualToString:bundleFileName] ||
|
||||
[[currentFile lastPathComponent] isEqualToString:alternateBundleFileName]) // We found one!
|
||||
{
|
||||
isPackage = NO;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
else if ([[currentFile pathExtension] isEqualToString:@"pkg"] ||
|
||||
[[currentFile pathExtension] isEqualToString:@"mpkg"])
|
||||
{
|
||||
if ([[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]])
|
||||
{
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
||||
fallbackPackagePath = currentPath;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
||||
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
||||
if(incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]])
|
||||
{
|
||||
isPackage = NO;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Some DMGs have symlinks into /Applications! That's no good!
|
||||
if ([self isAliasFolderAtPath:currentPath])
|
||||
[dirEnum skipDescendents];
|
||||
}
|
||||
|
||||
// We don't have a valid path. Try to use the fallback package.
|
||||
|
||||
if (newAppDownloadPath == nil && fallbackPackagePath != nil)
|
||||
{
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = fallbackPackagePath;
|
||||
}
|
||||
|
||||
if (isPackagePtr) *isPackagePtr = isPackage;
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
+ (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage];
|
||||
return isPackage ? nil : path;
|
||||
}
|
||||
|
||||
+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage];
|
||||
|
||||
if (newAppDownloadPath == nil)
|
||||
{
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] delegate:delegate];
|
||||
}
|
||||
else
|
||||
{
|
||||
[(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class])performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)mdimportInstallationPath:(NSString *)installationPath
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!
|
||||
|
||||
SULog(@"mdimporting");
|
||||
|
||||
NSTask *mdimport = [[NSTask alloc] init];
|
||||
[mdimport setLaunchPath:@"/usr/bin/mdimport"];
|
||||
[mdimport setArguments:@[installationPath]];
|
||||
@try
|
||||
{
|
||||
[mdimport launch];
|
||||
[mdimport waitUntilExit];
|
||||
}
|
||||
@catch (NSException *launchException)
|
||||
{
|
||||
// No big deal.
|
||||
SULog(@"Error: %@", [launchException description]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define SUNotifyDictHostKey @"SUNotifyDictHost"
|
||||
#define SUNotifyDictErrorKey @"SUNotifyDictError"
|
||||
#define SUNotifyDictDelegateKey @"SUNotifyDictDelegate"
|
||||
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:(id<SUInstallerDelegate>)delegate
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
[self mdimportInstallationPath:installationPath];
|
||||
if ([delegate respondsToSelector:@selector(installerFinishedForHost:)]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[delegate installerFinishedForHost:host];
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[delegate installerForHost:host failedWithError:error];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* SULog.h
|
||||
* EyeTV
|
||||
*
|
||||
* Created by Uli Kusterer on 12/03/2009.
|
||||
* Copyright 2008 Elgato Systems GmbH. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Log output for troubleshooting Sparkle failures on end-user machines.
|
||||
Your tech support will hug you if you tell them about this.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Headers:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Prototypes:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SUClearLog(void);
|
||||
void SULog(NSString *format, ...) NS_FORMAT_FUNCTION(1, 2);
|
||||
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* SULog.m
|
||||
* EyeTV
|
||||
*
|
||||
* Created by Uli Kusterer on 12/03/2009.
|
||||
* Copyright 2009 Elgato Systems GmbH. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Headers:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "SULog.h"
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constants:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define LOG_FILE_PATH @"~/Library/Logs/SparkleUpdateLog.log"
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SUClearLog:
|
||||
// Erase the log at the start of an update. We don't want to litter the
|
||||
// user's hard disk with logging data that's mostly unused, so each app
|
||||
// should clear the log before it starts updating, so only the most recent
|
||||
// update is kept around.
|
||||
//
|
||||
// TAKES:
|
||||
// sender - Object that sent this message, typically of type X.
|
||||
//
|
||||
// GIVES:
|
||||
// param - who owns the returned value?
|
||||
// result - same here.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SUClearLog(void)
|
||||
{
|
||||
FILE *logfile = fopen([[LOG_FILE_PATH stringByExpandingTildeInPath] fileSystemRepresentation], "w");
|
||||
if (logfile) {
|
||||
fclose(logfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SULog:
|
||||
// Like NSLog, but logs to one specific log file. Each line is prefixed
|
||||
// with the current date and time, to help in regressing issues.
|
||||
//
|
||||
// TAKES:
|
||||
// format - NSLog/printf-style format string.
|
||||
// ... - More parameters depending on format string's contents.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SULog(NSString *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
NSString *theStr = [[NSString alloc] initWithFormat:format arguments:ap];
|
||||
NSLog(@"Sparkle: %@", theStr);
|
||||
|
||||
FILE *logfile = fopen([[LOG_FILE_PATH stringByExpandingTildeInPath] fileSystemRepresentation], "a");
|
||||
if (logfile) {
|
||||
theStr = [NSString stringWithFormat:@"%@: %@\n", [NSDate date], theStr];
|
||||
NSData *theData = [theStr dataUsingEncoding:NSUTF8StringEncoding];
|
||||
fwrite([theData bytes], 1, [theData length], logfile);
|
||||
fclose(logfile);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// SUPackageInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPACKAGEINSTALLER_H
|
||||
#define SUPACKAGEINSTALLER_H
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
|
||||
@interface SUPackageInstaller : SUPlainInstaller
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// SUPackageInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUPackageInstaller.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUConstants.h"
|
||||
|
||||
@implementation SUPackageInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)__unused comparator
|
||||
{
|
||||
// Run installer using the "open" command to ensure it is launched in front of current application.
|
||||
// -W = wait until the app has quit.
|
||||
// -n = Open another instance if already open.
|
||||
// -b = app bundle identifier
|
||||
NSString *command = @"/usr/bin/open";
|
||||
NSArray *args = @[@"-W", @"-n", @"-b", @"com.apple.installer", path];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:command]) {
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find Apple's installer tool!" }];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
NSTask *installer = [NSTask launchedTaskWithLaunchPath:command arguments:args];
|
||||
[installer waitUntilExit];
|
||||
|
||||
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self finishInstallationToPath:installationPath withResult:YES host:host error:nil delegate:delegate];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// SUPipedUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPIPEDUNARCHIVER_H
|
||||
#define SUPIPEDUNARCHIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUnarchiver.h"
|
||||
|
||||
@interface SUPipedUnarchiver : SUUnarchiver
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,151 @@
|
|||
//
|
||||
// SUPipedUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 6/16/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUPipedUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "SULog.h"
|
||||
|
||||
|
||||
@implementation SUPipedUnarchiver
|
||||
|
||||
+ (SEL)selectorConformingToTypeOfPath:(NSString *)path
|
||||
{
|
||||
static NSDictionary *typeSelectorDictionary;
|
||||
if (!typeSelectorDictionary)
|
||||
typeSelectorDictionary = @{ @".zip": @"extractZIP",
|
||||
@".tar": @"extractTAR",
|
||||
@".tar.gz": @"extractTGZ",
|
||||
@".tgz": @"extractTGZ",
|
||||
@".tar.bz2": @"extractTBZ",
|
||||
@".tbz": @"extractTBZ" };
|
||||
|
||||
NSString *lastPathComponent = [path lastPathComponent];
|
||||
for (NSString *currentType in typeSelectorDictionary)
|
||||
{
|
||||
if ([currentType length] > [lastPathComponent length]) continue;
|
||||
if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType])
|
||||
return NSSelectorFromString(typeSelectorDictionary[currentType]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[NSThread detachNewThreadSelector:[[self class] selectorConformingToTypeOfPath:self.archivePath] toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return ([self selectorConformingToTypeOfPath:path] != nil);
|
||||
}
|
||||
|
||||
// This method abstracts the types that use a command line tool piping data from stdin.
|
||||
- (void)extractArchivePipingDataToCommand:(NSString *)command
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
@autoreleasepool {
|
||||
FILE *fp = NULL, *cmdFP = NULL;
|
||||
char *oldDestinationString = NULL;
|
||||
// We have to declare these before a goto to prevent an error under ARC.
|
||||
// No, we cannot have them in the dispatch_async calls, as the goto "jump enters
|
||||
// lifetime of block which strongly captures a variable"
|
||||
dispatch_block_t delegateSuccess = ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
};
|
||||
dispatch_block_t delegateFailure = ^{
|
||||
[self notifyDelegateOfFailure];
|
||||
};
|
||||
|
||||
SULog(@"Extracting %@ using '%@'", self.archivePath, command);
|
||||
|
||||
// Get the file size.
|
||||
NSNumber *fs = [[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil][NSFileSize];
|
||||
if (fs == nil) goto reportError;
|
||||
|
||||
// Thank you, Allan Odgaard!
|
||||
// (who wrote the following extraction alg.)
|
||||
fp = fopen([self.archivePath fileSystemRepresentation], "r");
|
||||
if (!fp) goto reportError;
|
||||
|
||||
oldDestinationString = getenv("DESTINATION");
|
||||
setenv("DESTINATION", [[self.archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], 1);
|
||||
cmdFP = popen([command fileSystemRepresentation], "w");
|
||||
size_t written;
|
||||
if (!cmdFP) goto reportError;
|
||||
|
||||
char buf[32 * 1024];
|
||||
size_t len;
|
||||
while((len = fread(buf, 1, 32*1024, fp)))
|
||||
{
|
||||
written = fwrite(buf, 1, len, cmdFP);
|
||||
if( written < len )
|
||||
{
|
||||
pclose(cmdFP);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfExtractedLength:len];
|
||||
});
|
||||
}
|
||||
pclose(cmdFP);
|
||||
|
||||
if (ferror(fp)) {
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), delegateSuccess);
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
dispatch_async(dispatch_get_main_queue(), delegateFailure);
|
||||
|
||||
finally:
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (oldDestinationString)
|
||||
setenv("DESTINATION", oldDestinationString, 1);
|
||||
else
|
||||
unsetenv("DESTINATION");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)extractTAR
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -xC \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
- (void)extractTGZ
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -zxC \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
- (void)extractTBZ
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -jxC \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
- (void)extractZIP
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"ditto -x -k - \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self registerImplementation:self];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// SUPlainInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPLAININSTALLER_H
|
||||
#define SUPLAININSTALLER_H
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SUPlainInstaller : SUInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// SUPlainInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 4/10/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
@implementation SUPlainInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator
|
||||
{
|
||||
// Prevent malicious downgrades:
|
||||
#if !PERMIT_AUTOMATED_DOWNGRADES
|
||||
if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]] == NSOrderedDescending)
|
||||
{
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
NSError *error = nil;
|
||||
NSString *oldPath = [host bundlePath];
|
||||
NSString *tempName = [self temporaryNameForPath:[host installationPath]];
|
||||
|
||||
BOOL result = [self copyPathWithAuthentication:path overPath:installationPath temporaryName:tempName error:&error];
|
||||
|
||||
if (result) {
|
||||
BOOL haveOld = [[NSFileManager defaultManager] fileExistsAtPath:oldPath];
|
||||
BOOL differentFromNew = ![oldPath isEqualToString:installationPath];
|
||||
if (haveOld && differentFromNew) {
|
||||
[self _movePathToTrash:oldPath]; // On success, trash old copy if there's still one due to renaming.
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self finishInstallationToPath:installationPath withResult:result host:host error:error delegate:delegate];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// SUPlainInstallerInternals.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/9/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPLAININSTALLERINTERNALS_H
|
||||
#define SUPLAININSTALLERINTERNALS_H
|
||||
|
||||
#import "SUPlainInstaller.h"
|
||||
|
||||
@interface SUPlainInstaller (Internals)
|
||||
+ (NSString *)temporaryNameForPath:(NSString *)path;
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)error;
|
||||
+ (void)_movePathToTrash:(NSString *)path;
|
||||
+ (BOOL)_removeFileAtPath:(NSString *)path error:(NSError **)error;
|
||||
+ (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError **)error;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,619 @@
|
|||
//
|
||||
// SUPlainInstallerInternals.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/9/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <Security/Security.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000
|
||||
extern NSString *const NSURLQuarantinePropertiesKey WEAK_IMPORT_ATTRIBUTE;
|
||||
#endif
|
||||
|
||||
static inline void PerformOnMainThreadSync(dispatch_block_t theBlock)
|
||||
{
|
||||
if ([NSThread isMainThread]) {
|
||||
theBlock();
|
||||
} else {
|
||||
dispatch_sync(dispatch_get_main_queue(), theBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@interface SUPlainInstaller (MMExtendedAttributes)
|
||||
// Removes the directory tree rooted at |root| from the file quarantine.
|
||||
// The quarantine was introduced on OS X 10.5 and is described at:
|
||||
//
|
||||
// http://developer.apple.com/releasenotes/Carbon/RN-LaunchServices/index.html
|
||||
//#apple_ref/doc/uid/TP40001369-DontLinkElementID_2
|
||||
//
|
||||
// If |root| is not a directory, then it alone is removed from the quarantine.
|
||||
// Symbolic links, including |root| if it is a symbolic link, will not be
|
||||
// traversed.
|
||||
//
|
||||
// Ordinarily, the quarantine is managed by calling LSSetItemAttribute
|
||||
// to set the kLSItemQuarantineProperties attribute to a dictionary specifying
|
||||
// the quarantine properties to be applied. However, it does not appear to be
|
||||
// possible to remove an item from the quarantine directly through any public
|
||||
// Launch Services calls. Instead, this method takes advantage of the fact
|
||||
// that the quarantine is implemented in part by setting an extended attribute,
|
||||
// "com.apple.quarantine", on affected files. Removing this attribute is
|
||||
// sufficient to remove files from the quarantine.
|
||||
+ (void)releaseFromQuarantine:(NSString *)root;
|
||||
@end
|
||||
|
||||
// Authorization code based on generous contribution from Allan Odgaard. Thanks, Allan!
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // this is terrible; will fix later probably
|
||||
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char *executablePath, AuthorizationFlags options, const char *const *arguments)
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL);
|
||||
BOOL returnValue = YES;
|
||||
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, (char* const*)arguments, NULL) == errAuthorizationSuccess)
|
||||
{
|
||||
int status;
|
||||
pid_t pid = wait(&status);
|
||||
if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
returnValue = NO;
|
||||
}
|
||||
else
|
||||
returnValue = NO;
|
||||
|
||||
signal(SIGCHLD, oldSigChildHandler);
|
||||
return returnValue;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@implementation SUPlainInstaller (Internals)
|
||||
|
||||
+ (NSString *)temporaryNameForPath:(NSString *)path
|
||||
{
|
||||
// Let's try to read the version number so the filename will be more meaningful.
|
||||
NSString *postFix;
|
||||
NSString *version;
|
||||
if ((version = [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]) && ![version isEqualToString:@""])
|
||||
{
|
||||
NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
postFix = [version stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
else
|
||||
postFix = @"old";
|
||||
NSString *prefix = [[path stringByDeletingPathExtension] stringByAppendingFormat:@" (%@)", postFix];
|
||||
NSString *tempDir = [prefix stringByAppendingPathExtension:[path pathExtension]];
|
||||
// Now let's make sure we get a unique path.
|
||||
unsigned int cnt = 2;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
|
||||
tempDir = [NSString stringWithFormat:@"%@ %u.%@", prefix, cnt++, [path pathExtension]];
|
||||
return [tempDir lastPathComponent];
|
||||
}
|
||||
|
||||
+ (NSString *)_temporaryCopyNameForPath:(NSString *)path didFindTrash:(BOOL *)outDidFindTrash
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
NSString *tempDir = nil;
|
||||
|
||||
UInt8 trashPath[MAXPATHLEN + 1] = { 0 };
|
||||
FSRef trashRef, pathRef;
|
||||
FSVolumeRefNum vSrcRefNum = kFSInvalidVolumeRefNum;
|
||||
FSCatalogInfo catInfo;
|
||||
memset(&catInfo, 0, sizeof(catInfo));
|
||||
OSStatus err = FSPathMakeRef((UInt8 *)[path fileSystemRepresentation], &pathRef, NULL);
|
||||
if( err == noErr )
|
||||
{
|
||||
err = FSGetCatalogInfo(&pathRef, kFSCatInfoVolume, &catInfo, NULL, NULL, NULL);
|
||||
vSrcRefNum = catInfo.volume;
|
||||
}
|
||||
if (err == noErr)
|
||||
err = FSFindFolder(vSrcRefNum, kTrashFolderType, kCreateFolder, &trashRef);
|
||||
if (err == noErr)
|
||||
err = FSGetCatalogInfo(&trashRef, kFSCatInfoVolume, &catInfo, NULL, NULL, NULL);
|
||||
if (err == noErr && vSrcRefNum != catInfo.volume)
|
||||
err = nsvErr; // Couldn't find a trash folder on same volume as given path. Docs say this may happen in the future.
|
||||
if (err == noErr)
|
||||
err = FSRefMakePath(&trashRef, trashPath, MAXPATHLEN);
|
||||
if (err == noErr)
|
||||
tempDir = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:(char *)trashPath length:strlen((char *)trashPath)];
|
||||
if (outDidFindTrash)
|
||||
*outDidFindTrash = (tempDir != nil);
|
||||
if (!tempDir)
|
||||
tempDir = [path stringByDeletingLastPathComponent];
|
||||
|
||||
// Let's try to read the version number so the filename will be more meaningful.
|
||||
#if TRY_TO_APPEND_VERSION_NUMBER
|
||||
NSString *postFix = nil;
|
||||
NSString *version = nil;
|
||||
if ((version = [[NSBundle bundleWithPath: path] objectForInfoDictionaryKey:@"CFBundleVersion"]) && ![version isEqualToString:@""])
|
||||
{
|
||||
NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
postFix = [version stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
else {
|
||||
postFix = @"old";
|
||||
}
|
||||
NSString *prefix = [NSString stringWithFormat:@"%@ (%@)", [[path lastPathComponent] stringByDeletingPathExtension], postFix];
|
||||
#else
|
||||
NSString *prefix = [[path lastPathComponent] stringByDeletingPathExtension];
|
||||
#endif
|
||||
NSString *tempName = [prefix stringByAppendingPathExtension:[path pathExtension]];
|
||||
tempDir = [tempDir stringByAppendingPathComponent:tempName];
|
||||
|
||||
// Now let's make sure we get a unique path.
|
||||
int cnt = 2;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 9999) {
|
||||
tempDir = [[tempDir stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d.%@", prefix, cnt++, [path pathExtension]]];
|
||||
}
|
||||
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
+ (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst temporaryPath:(NSString *)tmp error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char *srcPath = [src fileSystemRepresentation];
|
||||
const char *tmpPath = [tmp fileSystemRepresentation];
|
||||
const char *dstPath = [dst fileSystemRepresentation];
|
||||
|
||||
struct stat dstSB;
|
||||
if (stat(dstPath, &dstSB) != 0) // Doesn't exist yet, try containing folder.
|
||||
{
|
||||
const char *dstDirPath = [[dst stringByDeletingLastPathComponent] fileSystemRepresentation];
|
||||
if( stat(dstDirPath, &dstSB) != 0 )
|
||||
{
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Stat on %@ during authenticated file copy failed.", dst];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while (authStat == errAuthorizationDenied) {
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess) {
|
||||
res = YES;
|
||||
|
||||
char uidgid[42];
|
||||
snprintf(uidgid, sizeof(uidgid), "%u:%u",
|
||||
dstSB.st_uid, dstSB.st_gid);
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home with "mv" in case it's moved across filesystems: if
|
||||
// that happens, "mv" actually performs a copy and may result
|
||||
// in the application being quarantined. It also needs to be
|
||||
// done before "chown" changes ownership, because the ownership
|
||||
// change will almost certainly make it impossible to change
|
||||
// attributes to release the files from the quarantine.
|
||||
if (res)
|
||||
{
|
||||
SULog(@"releaseFromQuarantine");
|
||||
PerformOnMainThreadSync(^{
|
||||
[self releaseFromQuarantine:src];
|
||||
});
|
||||
}
|
||||
|
||||
if (res) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination.
|
||||
{
|
||||
const char *coParams[] = { "-R", uidgid, srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams);
|
||||
if (!res)
|
||||
SULog(@"chown -R %s %s failed.", uidgid, srcPath);
|
||||
}
|
||||
|
||||
BOOL haveDst = [[NSFileManager defaultManager] fileExistsAtPath:dst];
|
||||
if (res && haveDst) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char *rmParams[] = { "-rf", tmpPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams);
|
||||
if (!res)
|
||||
SULog(@"rm failed");
|
||||
}
|
||||
|
||||
if (res && haveDst) // Move old exe to tmp path.
|
||||
{
|
||||
const char *mvParams[] = { "-f", dstPath, tmpPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams);
|
||||
if (!res)
|
||||
SULog(@"mv 1 failed");
|
||||
}
|
||||
|
||||
if (res) // Move new exe to old exe's path.
|
||||
{
|
||||
const char *mvParams2[] = { "-f", srcPath, dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams2);
|
||||
if (!res)
|
||||
SULog(@"mv 2 failed");
|
||||
}
|
||||
|
||||
// if( res && haveDst /*&& !foundTrash*/ ) // If we managed to put the old exe in the trash, leave it there for the user to delete or recover.
|
||||
// { // ... Otherwise we better delete it, wouldn't want dozens of old versions lying around next to the new one.
|
||||
// const char* rmParams2[] = { "-rf", tmpPath, NULL };
|
||||
// res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams2 );
|
||||
// }
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home with "mv" in case it's moved across filesystems: if
|
||||
// that happens, "mv" actually performs a copy and may result
|
||||
// in the application being quarantined.
|
||||
if (res)
|
||||
{
|
||||
SULog(@"releaseFromQuarantine after installing");
|
||||
PerformOnMainThreadSync(^{
|
||||
[self releaseFromQuarantine:dst];
|
||||
});
|
||||
}
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file copy from %@ to %@ failed.", src, dst];
|
||||
if (error != nil)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != nil)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't get permission to authenticate." }];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
+ (BOOL)_movePathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char *srcPath = [src fileSystemRepresentation];
|
||||
const char *dstPath = [dst fileSystemRepresentation];
|
||||
const char *dstContainerPath = [[dst stringByDeletingLastPathComponent] fileSystemRepresentation];
|
||||
|
||||
struct stat dstSB;
|
||||
stat(dstContainerPath, &dstSB);
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while( authStat == errAuthorizationDenied )
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
char uidgid[42];
|
||||
snprintf(uidgid, sizeof(uidgid), "%d:%d",
|
||||
dstSB.st_uid, dstSB.st_gid);
|
||||
|
||||
if (res) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination.
|
||||
{
|
||||
const char *coParams[] = { "-R", uidgid, srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams);
|
||||
if (!res)
|
||||
SULog(@"Can't set permissions");
|
||||
}
|
||||
|
||||
BOOL haveDst = [[NSFileManager defaultManager] fileExistsAtPath:dst];
|
||||
if (res && haveDst) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char *rmParams[] = { "-rf", dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams);
|
||||
if (!res)
|
||||
SULog(@"Can't remove destination file");
|
||||
}
|
||||
|
||||
if (res) // Move!.
|
||||
{
|
||||
const char *mvParams[] = { "-f", srcPath, dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams);
|
||||
if (!res)
|
||||
SULog(@"Can't move source file");
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file move from %@ to %@ failed.", src, dst];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't get permission to authenticate." }];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char *srcPath = [src fileSystemRepresentation];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while( authStat == errAuthorizationDenied )
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
if (res) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char *rmParams[] = { "-rf", srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams);
|
||||
if (!res)
|
||||
SULog(@"Can't remove destination file");
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file remove from %@ failed.", src];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't get permission to authenticate." }];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
+ (BOOL)_removeFileAtPath:(NSString *)path error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
BOOL success = YES;
|
||||
if( ![[NSFileManager defaultManager] removeItemAtPath: path error: NULL] )
|
||||
{
|
||||
success = [self _removeFileAtPathWithForcedAuthentication:path error:error];
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
+ (void)_movePathToTrash:(NSString *)path
|
||||
{
|
||||
//SULog(@"Moving %@ to the trash.", path);
|
||||
NSInteger tag = 0;
|
||||
if (![[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[path stringByDeletingLastPathComponent] destination:@"" files:@[[path lastPathComponent]] tag:&tag])
|
||||
{
|
||||
BOOL didFindTrash = NO;
|
||||
NSString *trashPath = [self _temporaryCopyNameForPath:path didFindTrash:&didFindTrash];
|
||||
if( didFindTrash )
|
||||
{
|
||||
NSError *err = nil;
|
||||
if (![self _movePathWithForcedAuthentication:path toPath:trashPath error:&err]) {
|
||||
SULog(@"Error: couldn't move %@ to the trash (%@). %@", path, trashPath, err);
|
||||
}
|
||||
}
|
||||
else {
|
||||
SULog(@"Error: couldn't move %@ to the trash. This is often a sign of a permissions error.", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)__unused tmp error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
FSRef srcRef, dstRef, dstDirRef, tmpDirRef;
|
||||
OSStatus err;
|
||||
BOOL hadFileAtDest = NO, didFindTrash = NO;
|
||||
NSString *tmpPath = [self _temporaryCopyNameForPath:dst didFindTrash:&didFindTrash];
|
||||
|
||||
// Make FSRef for destination:
|
||||
err = FSPathMakeRefWithOptions((UInt8 *)[dst fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &dstRef, NULL);
|
||||
hadFileAtDest = (err == noErr); // There is a file at the destination, move it aside. If we normalized the name, we might not get here, so don't error.
|
||||
if( hadFileAtDest )
|
||||
{
|
||||
if (0 != access([dst fileSystemRepresentation], W_OK) || 0 != access([[dst stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK))
|
||||
{
|
||||
return [self _copyPathWithForcedAuthentication:src toPath:dst temporaryPath:tmpPath error:error];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 != access([[dst stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK)
|
||||
|| 0 != access([[[dst stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK))
|
||||
{
|
||||
return [self _copyPathWithForcedAuthentication:src toPath:dst temporaryPath:tmpPath error:error];
|
||||
}
|
||||
}
|
||||
|
||||
if( hadFileAtDest )
|
||||
{
|
||||
err = FSPathMakeRef((UInt8 *)[[tmpPath stringByDeletingLastPathComponent] fileSystemRepresentation], &tmpDirRef, NULL);
|
||||
if (err != noErr)
|
||||
FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &tmpDirRef, NULL);
|
||||
}
|
||||
|
||||
err = FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &dstDirRef, NULL);
|
||||
|
||||
if (err == noErr && hadFileAtDest)
|
||||
{
|
||||
NSFileManager *manager = [[NSFileManager alloc] init];
|
||||
BOOL success = [manager moveItemAtPath:dst toPath:tmpPath error:error];
|
||||
if (!success && hadFileAtDest)
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] }];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
err = FSPathMakeRef((UInt8 *)[src fileSystemRepresentation], &srcRef, NULL);
|
||||
if (err == noErr)
|
||||
{
|
||||
NSFileManager *manager = [[NSFileManager alloc] init];
|
||||
BOOL success = [manager copyItemAtPath:src toPath:dst error:error];
|
||||
if (!success)
|
||||
{
|
||||
// We better move the old version back to its old location
|
||||
if (hadFileAtDest) {
|
||||
success = [manager moveItemAtPath:tmpPath toPath:dst error:error];
|
||||
}
|
||||
if (!success && error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] }];
|
||||
return NO;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home in case it's moved across filesystems: if that
|
||||
// happens, the move is actually a copy, and it may result
|
||||
// in the application being quarantined.
|
||||
PerformOnMainThreadSync(^{
|
||||
[self releaseFromQuarantine:dst];
|
||||
});
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <sys/xattr.h>
|
||||
|
||||
@implementation SUPlainInstaller (MMExtendedAttributes)
|
||||
|
||||
+ (int)removeXAttr:(NSString *)name
|
||||
fromFile:(NSString *)file
|
||||
options:(int)options
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char *path = NULL;
|
||||
const char *attr = [name cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
@try {
|
||||
path = [file fileSystemRepresentation];
|
||||
}
|
||||
@catch (id) {
|
||||
// -[NSString fileSystemRepresentation] throws an exception if it's
|
||||
// unable to convert the string to something suitable. Map that to
|
||||
// EDOM, "argument out of domain", which sort of conveys that there
|
||||
// was a conversion failure.
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return removexattr(path, attr, options);
|
||||
}
|
||||
|
||||
+ (void)releaseFromQuarantine:(NSString *)root
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
|
||||
if (!&NSURLQuarantinePropertiesKey) {
|
||||
NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties;
|
||||
const int removeXAttrOptions = XATTR_NOFOLLOW;
|
||||
|
||||
[self removeXAttr:quarantineAttribute
|
||||
fromFile:root
|
||||
options:removeXAttrOptions];
|
||||
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
// root-level symbolic link.
|
||||
NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil];
|
||||
NSString *rootType = rootAttributes[NSFileType];
|
||||
|
||||
if (rootType == NSFileTypeDirectory) {
|
||||
// The NSDirectoryEnumerator will avoid recursing into any contained
|
||||
// symbolic links, so no further type checks are needed.
|
||||
NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtPath:root];
|
||||
NSString *file = nil;
|
||||
while ((file = [directoryEnumerator nextObject])) {
|
||||
[self removeXAttr:quarantineAttribute
|
||||
fromFile:[root stringByAppendingPathComponent:file]
|
||||
options:removeXAttrOptions];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
NSURL *rootURL = [NSURL fileURLWithPath:root];
|
||||
[rootURL setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL];
|
||||
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
// root-level symbolic link.
|
||||
NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil];
|
||||
NSString *rootType = rootAttributes[NSFileType];
|
||||
|
||||
if (rootType == NSFileTypeDirectory) {
|
||||
// The NSDirectoryEnumerator will avoid recursing into any contained
|
||||
// symbolic links, so no further type checks are needed.
|
||||
NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtURL:rootURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil];
|
||||
|
||||
for (NSURL *file in directoryEnumerator) {
|
||||
[file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// SUProbingUpdateDriver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/7/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPROBINGUPDATEDRIVER_H
|
||||
#define SUPROBINGUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
|
||||
// This replaces the old SUStatusChecker.
|
||||
@interface SUProbingUpdateDriver : SUBasicUpdateDriver
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// SUProbingUpdateDriver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/7/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUProbingUpdateDriver.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
@implementation SUProbingUpdateDriver
|
||||
|
||||
// Stop as soon as we have an answer! Since the superclass implementations are not called, we are responsible for notifying the delegate.
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:didFindValidUpdate:)])
|
||||
[updaterDelegate updater:self.updater didFindValidUpdate:self.updateItem];
|
||||
NSDictionary *userInfo = (self.updateItem != nil) ? @{ SUUpdaterAppcastItemNotificationKey: self.updateItem } : nil;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:self.updater userInfo:userInfo];
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
|
||||
if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
|
||||
[updaterDelegate updaterDidNotFindUpdate:self.updater];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
|
||||
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// SUScheduledUpdateDriver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/6/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUSCHEDULEDUPDATEDRIVER_H
|
||||
#define SUSCHEDULEDUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUIBasedUpdateDriver.h"
|
||||
|
||||
@interface SUScheduledUpdateDriver : SUUIBasedUpdateDriver
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// SUScheduledUpdateDriver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/6/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUScheduledUpdateDriver.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@interface SUScheduledUpdateDriver ()
|
||||
|
||||
@property (assign) BOOL showErrors;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUScheduledUpdateDriver
|
||||
|
||||
@synthesize showErrors;
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
self.showErrors = YES; // We only start showing errors after we present the UI for the first time.
|
||||
[super didFindValidUpdate];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
|
||||
if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
|
||||
[updaterDelegate updaterDidNotFindUpdate:self.updater];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
|
||||
|
||||
[self abortUpdate]; // Don't tell the user that no update was found; this was a scheduled update.
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if (self.showErrors)
|
||||
[super abortUpdateWithError:error];
|
||||
else
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// SUStandardVersionComparator.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 12/21/07.
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUSTANDARDVERSIONCOMPARATOR_H
|
||||
#define SUSTANDARDVERSIONCOMPARATOR_H
|
||||
|
||||
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
/*!
|
||||
Sparkle's default version comparator.
|
||||
|
||||
This comparator is adapted from MacPAD, by Kevin Ballard.
|
||||
It's "dumb" in that it does essentially string comparison,
|
||||
in components split by character type.
|
||||
*/
|
||||
@interface SUStandardVersionComparator : NSObject <SUVersionComparison>
|
||||
|
||||
/*!
|
||||
Returns a singleton instance of the comparator.
|
||||
*/
|
||||
+ (SUStandardVersionComparator *)defaultComparator;
|
||||
|
||||
/*!
|
||||
Compares version strings through textual analysis.
|
||||
|
||||
See the implementation for more details.
|
||||
*/
|
||||
- (NSComparisonResult)compareVersion:(NSString *)versionA toVersion:(NSString *)versionB;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,170 @@
|
|||
//
|
||||
// SUStandardVersionComparator.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 12/21/07.
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
|
||||
@implementation SUStandardVersionComparator
|
||||
|
||||
+ (SUStandardVersionComparator *)defaultComparator
|
||||
{
|
||||
static SUStandardVersionComparator *defaultComparator = nil;
|
||||
if (defaultComparator == nil) {
|
||||
defaultComparator = [[SUStandardVersionComparator alloc] init];
|
||||
}
|
||||
return defaultComparator;
|
||||
}
|
||||
|
||||
typedef NS_ENUM(NSInteger, SUCharacterType) {
|
||||
kNumberType,
|
||||
kStringType,
|
||||
kSeparatorType,
|
||||
};
|
||||
|
||||
- (SUCharacterType)typeOfCharacter:(NSString *)character
|
||||
{
|
||||
if ([character isEqualToString:@"."]) {
|
||||
return kSeparatorType;
|
||||
} else if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:[character characterAtIndex:0]]) {
|
||||
return kNumberType;
|
||||
} else if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[character characterAtIndex:0]]) {
|
||||
return kSeparatorType;
|
||||
} else if ([[NSCharacterSet punctuationCharacterSet] characterIsMember:[character characterAtIndex:0]]) {
|
||||
return kSeparatorType;
|
||||
} else {
|
||||
return kStringType;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)splitVersionString:(NSString *)version
|
||||
{
|
||||
NSString *character;
|
||||
NSMutableString *s;
|
||||
NSUInteger i, n;
|
||||
SUCharacterType oldType, newType;
|
||||
NSMutableArray *parts = [NSMutableArray array];
|
||||
if ([version length] == 0) {
|
||||
// Nothing to do here
|
||||
return parts;
|
||||
}
|
||||
s = [[version substringToIndex:1] mutableCopy];
|
||||
oldType = [self typeOfCharacter:s];
|
||||
n = [version length] - 1;
|
||||
for (i = 1; i <= n; ++i) {
|
||||
character = [version substringWithRange:NSMakeRange(i, 1)];
|
||||
newType = [self typeOfCharacter:character];
|
||||
if (oldType != newType || oldType == kSeparatorType) {
|
||||
// We've reached a new segment
|
||||
NSString *aPart = [[NSString alloc] initWithString:s];
|
||||
[parts addObject:aPart];
|
||||
[s setString:character];
|
||||
} else {
|
||||
// Add character to string and continue
|
||||
[s appendString:character];
|
||||
}
|
||||
oldType = newType;
|
||||
}
|
||||
|
||||
// Add the last part onto the array
|
||||
[parts addObject:[NSString stringWithString:s]];
|
||||
return parts;
|
||||
}
|
||||
|
||||
- (NSComparisonResult)compareVersion:(NSString *)versionA toVersion:(NSString *)versionB
|
||||
{
|
||||
NSArray *partsA = [self splitVersionString:versionA];
|
||||
NSArray *partsB = [self splitVersionString:versionB];
|
||||
|
||||
NSString *partA, *partB;
|
||||
NSUInteger i, n;
|
||||
long long valueA, valueB;
|
||||
SUCharacterType typeA, typeB;
|
||||
|
||||
n = MIN([partsA count], [partsB count]);
|
||||
for (i = 0; i < n; ++i) {
|
||||
partA = partsA[i];
|
||||
partB = partsB[i];
|
||||
|
||||
typeA = [self typeOfCharacter:partA];
|
||||
typeB = [self typeOfCharacter:partB];
|
||||
|
||||
// Compare types
|
||||
if (typeA == typeB) {
|
||||
// Same type; we can compare
|
||||
if (typeA == kNumberType) {
|
||||
valueA = [partA longLongValue];
|
||||
valueB = [partB longLongValue];
|
||||
if (valueA > valueB) {
|
||||
return NSOrderedDescending;
|
||||
} else if (valueA < valueB) {
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
} else if (typeA == kStringType) {
|
||||
NSComparisonResult result = [partA compare:partB];
|
||||
if (result != NSOrderedSame) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not the same type? Now we have to do some validity checking
|
||||
if (typeA != kStringType && typeB == kStringType) {
|
||||
// typeA wins
|
||||
return NSOrderedDescending;
|
||||
} else if (typeA == kStringType && typeB != kStringType) {
|
||||
// typeB wins
|
||||
return NSOrderedAscending;
|
||||
} else {
|
||||
// One is a number and the other is a period. The period is invalid
|
||||
if (typeA == kNumberType) {
|
||||
return NSOrderedDescending;
|
||||
} else {
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// The versions are equal up to the point where they both still have parts
|
||||
// Lets check to see if one is larger than the other
|
||||
if ([partsA count] != [partsB count]) {
|
||||
// Yep. Lets get the next part of the larger
|
||||
// n holds the index of the part we want.
|
||||
NSString *missingPart;
|
||||
SUCharacterType missingType;
|
||||
NSComparisonResult shorterResult, largerResult;
|
||||
|
||||
if ([partsA count] > [partsB count]) {
|
||||
missingPart = partsA[n];
|
||||
shorterResult = NSOrderedAscending;
|
||||
largerResult = NSOrderedDescending;
|
||||
} else {
|
||||
missingPart = partsB[n];
|
||||
shorterResult = NSOrderedDescending;
|
||||
largerResult = NSOrderedAscending;
|
||||
}
|
||||
|
||||
missingType = [self typeOfCharacter:missingPart];
|
||||
// Check the type
|
||||
if (missingType == kStringType) {
|
||||
// It's a string. Shorter version wins
|
||||
return shorterResult;
|
||||
} else {
|
||||
// It's a number/period. Larger version wins
|
||||
return largerResult;
|
||||
}
|
||||
}
|
||||
|
||||
// The 2 strings are identical
|
||||
return NSOrderedSame;
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -0,0 +1,94 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<dependencies>
|
||||
<deployment defaultVersion="1070" identifier="macosx"/>
|
||||
<development version="5100" identifier="xcode"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SUStatusController">
|
||||
<connections>
|
||||
<outlet property="actionButton" destination="12" id="34"/>
|
||||
<outlet property="progressBar" destination="11" id="49"/>
|
||||
<outlet property="window" destination="5" id="25"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application"/>
|
||||
<window title="Set in Code" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="5" userLabel="Window">
|
||||
<windowStyleMask key="styleMask" titled="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="200" y="222" width="400" height="107"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1178"/>
|
||||
<value key="minSize" type="size" width="213" height="107"/>
|
||||
<view key="contentView" id="6">
|
||||
<rect key="frame" x="0.0" y="0.0" width="400" height="107"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<imageView id="7">
|
||||
<rect key="frame" x="24" y="28" width="64" height="64"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="axesIndependently" image="NSApplicationIcon" id="53"/>
|
||||
<connections>
|
||||
<binding destination="-2" name="value" keyPath="applicationIcon" id="9"/>
|
||||
</connections>
|
||||
</imageView>
|
||||
<textField verticalHuggingPriority="750" id="8">
|
||||
<rect key="frame" x="106" y="75" width="277" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Status Text (set by loc. string in code)" id="54">
|
||||
<font key="font" metaFont="systemBold"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<binding destination="-2" name="value" keyPath="title" id="26"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<progressIndicator verticalHuggingPriority="750" maxValue="100" bezeled="NO" indeterminate="YES" style="bar" id="11">
|
||||
<rect key="frame" x="107" y="47" width="275" height="20"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<connections>
|
||||
<binding destination="-2" name="maxValue" keyPath="maxProgressValue" id="13"/>
|
||||
<binding destination="-2" name="value" keyPath="progressValue" previousBinding="13" id="27"/>
|
||||
</connections>
|
||||
</progressIndicator>
|
||||
<button verticalHuggingPriority="750" id="12">
|
||||
<rect key="frame" x="272.00000009349748" y="12" width="114" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Button" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="55">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="-2" name="title" keyPath="buttonTitle" id="21"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField verticalHuggingPriority="750" id="16">
|
||||
<rect key="frame" x="106" y="22" width="167" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Small System Font Text" id="56">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<binding destination="-2" name="hidden" keyPath="statusText" id="33">
|
||||
<dictionary key="options">
|
||||
<string key="NSValueTransformerName">NSIsNil</string>
|
||||
</dictionary>
|
||||
</binding>
|
||||
<binding destination="-2" name="value" keyPath="statusText" id="17"/>
|
||||
</connections>
|
||||
</textField>
|
||||
</subviews>
|
||||
</view>
|
||||
<connections>
|
||||
<binding destination="-2" name="title" keyPath="windowTitle" id="24"/>
|
||||
</connections>
|
||||
</window>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="NSApplicationIcon" width="128" height="128"/>
|
||||
</resources>
|
||||
</document>
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// SUStatusController.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/14/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUSTATUSCONTROLLER_H
|
||||
#define SUSTATUSCONTROLLER_H
|
||||
|
||||
#import "SUWindowController.h"
|
||||
|
||||
@class SUHost;
|
||||
@interface SUStatusController : SUWindowController
|
||||
@property (weak) IBOutlet NSButton *actionButton;
|
||||
@property (weak) IBOutlet NSProgressIndicator *progressBar;
|
||||
|
||||
@property (copy) NSString *statusText;
|
||||
@property double progressValue;
|
||||
@property (nonatomic) double maxProgressValue;
|
||||
@property (getter=isButtonEnabled) BOOL buttonEnabled;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host;
|
||||
|
||||
// Pass 0 for the max progress value to get an indeterminate progress bar.
|
||||
// Pass nil for the status text to not show it.
|
||||
- (void)beginActionWithTitle:(NSString *)title maxProgressValue:(double)maxProgressValue statusText:(NSString *)statusText;
|
||||
|
||||
// If isDefault is YES, the button's key equivalent will be \r.
|
||||
- (void)setButtonTitle:(NSString *)buttonTitle target:(id)target action:(SEL)action isDefault:(BOOL)isDefault;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,120 @@
|
|||
//
|
||||
// SUStatusController.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/14/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUStatusController.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
@interface SUStatusController ()
|
||||
@property (copy) NSString *title, *buttonTitle;
|
||||
@property (strong) SUHost *host;
|
||||
@end
|
||||
|
||||
@implementation SUStatusController
|
||||
@synthesize progressValue;
|
||||
@synthesize maxProgressValue;
|
||||
@synthesize statusText;
|
||||
@synthesize title;
|
||||
@synthesize buttonTitle;
|
||||
@synthesize host;
|
||||
@synthesize actionButton;
|
||||
@synthesize progressBar;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)aHost
|
||||
{
|
||||
self = [super initWithHost:aHost windowNibName:@"SUStatus"];
|
||||
if (self)
|
||||
{
|
||||
self.host = aHost;
|
||||
[self setShouldCascadeWindows:NO];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; }
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
if ([self.host isBackgroundApplication]) {
|
||||
[[self window] setLevel:NSFloatingWindowLevel];
|
||||
}
|
||||
|
||||
[[self window] center];
|
||||
[[self window] setFrameAutosaveName:@"SUStatusFrame"];
|
||||
[self.progressBar setUsesThreadedAnimation:YES];
|
||||
}
|
||||
|
||||
- (NSString *)windowTitle
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [self.host name]];
|
||||
}
|
||||
|
||||
- (NSImage *)applicationIcon
|
||||
{
|
||||
return [self.host icon];
|
||||
}
|
||||
|
||||
- (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText
|
||||
{
|
||||
self.title = aTitle;
|
||||
|
||||
self.maxProgressValue = aMaxProgressValue;
|
||||
self.statusText = aStatusText;
|
||||
}
|
||||
|
||||
- (void)setButtonTitle:(NSString *)aButtonTitle target:(id)target action:(SEL)action isDefault:(BOOL)isDefault
|
||||
{
|
||||
self.buttonTitle = aButtonTitle;
|
||||
|
||||
[self window];
|
||||
[self.actionButton sizeToFit];
|
||||
// Except we're going to add 15 px for padding.
|
||||
[self.actionButton setFrameSize:NSMakeSize([self.actionButton frame].size.width + 15, [self.actionButton frame].size.height)];
|
||||
// Now we have to move it over so that it's always 15px from the side of the window.
|
||||
[self.actionButton setFrameOrigin:NSMakePoint([[self window] frame].size.width - 15 - [self.actionButton frame].size.width, [self.actionButton frame].origin.y)];
|
||||
// Redisplay superview to clean up artifacts
|
||||
[[self.actionButton superview] display];
|
||||
|
||||
[self.actionButton setTarget:target];
|
||||
[self.actionButton setAction:action];
|
||||
[self.actionButton setKeyEquivalent:isDefault ? @"\r" : @""];
|
||||
|
||||
// 06/05/2008 Alex: Avoid a crash when cancelling during the extraction
|
||||
[self setButtonEnabled:(target != nil)];
|
||||
}
|
||||
|
||||
- (BOOL)progressBarShouldAnimate
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setButtonEnabled:(BOOL)enabled
|
||||
{
|
||||
[self.actionButton setEnabled:enabled];
|
||||
}
|
||||
|
||||
- (BOOL)isButtonEnabled
|
||||
{
|
||||
return [self.actionButton isEnabled];
|
||||
}
|
||||
|
||||
- (void)setMaxProgressValue:(double)value
|
||||
{
|
||||
if (value < 0.0) value = 0.0;
|
||||
maxProgressValue = value;
|
||||
[self setProgressValue:0.0];
|
||||
[self.progressBar setIndeterminate:(value == 0.0)];
|
||||
[self.progressBar startAnimation:self];
|
||||
[self.progressBar setUsesThreadedAnimation:YES];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// SUSystemProfiler.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 12/22/07.
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUSYSTEMPROFILER_H
|
||||
#define SUSYSTEMPROFILER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SUHost;
|
||||
@interface SUSystemProfiler : NSObject
|
||||
+ (SUSystemProfiler *)sharedSystemProfiler;
|
||||
- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,156 @@
|
|||
//
|
||||
// SUSystemProfiler.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 12/22/07.
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
// Adapted from Sparkle+, by Tom Harrington.
|
||||
//
|
||||
|
||||
#import "SUSystemProfiler.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
@implementation SUSystemProfiler
|
||||
+ (SUSystemProfiler *)sharedSystemProfiler
|
||||
{
|
||||
static SUSystemProfiler *sharedSystemProfiler = nil;
|
||||
if (!sharedSystemProfiler) {
|
||||
sharedSystemProfiler = [[self alloc] init];
|
||||
}
|
||||
return sharedSystemProfiler;
|
||||
}
|
||||
|
||||
- (NSDictionary *)modelTranslationTable
|
||||
{
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUModelTranslation" ofType:@"plist"];
|
||||
return [[NSDictionary alloc] initWithContentsOfFile:path];
|
||||
}
|
||||
|
||||
- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host
|
||||
{
|
||||
NSDictionary *modelTranslation = [self modelTranslationTable];
|
||||
|
||||
// Gather profile information and append it to the URL.
|
||||
NSMutableArray *profileArray = [NSMutableArray array];
|
||||
NSArray *profileDictKeys = @[@"key", @"displayKey", @"value", @"displayValue"];
|
||||
int error = 0;
|
||||
int value = 0;
|
||||
size_t length = sizeof(value);
|
||||
|
||||
// OS version
|
||||
NSString *currentSystemVersion = [SUHost systemVersionString];
|
||||
if (currentSystemVersion != nil) {
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"osVersion", @"OS Version", currentSystemVersion, currentSystemVersion] forKeys:profileDictKeys]];
|
||||
}
|
||||
|
||||
// CPU type (decoder info for values found here is in mach/machine.h)
|
||||
error = sysctlbyname("hw.cputype", &value, &length, NULL, 0);
|
||||
int cpuType = -1;
|
||||
if (error == 0) {
|
||||
cpuType = value;
|
||||
NSString *visibleCPUType;
|
||||
switch (value) {
|
||||
case CPU_TYPE_X86: visibleCPUType = @"Intel"; break;
|
||||
case CPU_TYPE_POWERPC: visibleCPUType = @"PowerPC"; break;
|
||||
default: visibleCPUType = @"Unknown"; break;
|
||||
}
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cputype", @"CPU Type", @(value), visibleCPUType] forKeys:profileDictKeys]];
|
||||
}
|
||||
error = sysctlbyname("hw.cpu64bit_capable", &value, &length, NULL, 0);
|
||||
if (error != 0) {
|
||||
error = sysctlbyname("hw.optional.x86_64", &value, &length, NULL, 0); //x86 specific
|
||||
}
|
||||
if (error != 0) {
|
||||
error = sysctlbyname("hw.optional.64bitops", &value, &length, NULL, 0); //PPC specific
|
||||
}
|
||||
|
||||
BOOL is64bit = NO;
|
||||
|
||||
if (error == 0) {
|
||||
is64bit = value == 1;
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cpu64bit", @"CPU is 64-Bit?", @(is64bit), is64bit ? @"Yes" : @"No"] forKeys:profileDictKeys]];
|
||||
}
|
||||
error = sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
NSString *visibleCPUSubType;
|
||||
if (cpuType == 7) {
|
||||
// Intel
|
||||
// TODO: other Intel processors, like Core i7, i5, i3, Xeon?
|
||||
visibleCPUSubType = is64bit ? @"Intel Core 2" : @"Intel Core"; // If anyone knows how to tell a Core Duo from a Core Solo, please email tph@atomicbird.com
|
||||
} else if (cpuType == 18) {
|
||||
// PowerPC
|
||||
switch (value) {
|
||||
case 9: visibleCPUSubType=@"G3"; break;
|
||||
case 10: case 11: visibleCPUSubType=@"G4"; break;
|
||||
case 100: visibleCPUSubType=@"G5"; break;
|
||||
default: visibleCPUSubType=@"Other"; break;
|
||||
}
|
||||
} else {
|
||||
visibleCPUSubType = @"Other";
|
||||
}
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cpusubtype", @"CPU Subtype", @(value), visibleCPUSubType] forKeys:profileDictKeys]];
|
||||
}
|
||||
error = sysctlbyname("hw.model", NULL, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
char *cpuModel = (char *)malloc(sizeof(char) * length);
|
||||
if (cpuModel != NULL) {
|
||||
error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
NSString *rawModelName = @(cpuModel);
|
||||
NSString *visibleModelName = modelTranslation[rawModelName];
|
||||
if (visibleModelName == nil) {
|
||||
visibleModelName = rawModelName;
|
||||
}
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"model", @"Mac Model", rawModelName, visibleModelName] forKeys:profileDictKeys]];
|
||||
}
|
||||
free(cpuModel);
|
||||
}
|
||||
}
|
||||
|
||||
// Number of CPUs
|
||||
error = sysctlbyname("hw.ncpu", &value, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"ncpu", @"Number of CPUs", @(value), @(value)] forKeys:profileDictKeys]];
|
||||
}
|
||||
|
||||
// User preferred language
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
NSArray *languages = [defs objectForKey:@"AppleLanguages"];
|
||||
if ([languages count] > 0) {
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"lang", @"Preferred Language", languages[0], languages[0]] forKeys:profileDictKeys]];
|
||||
}
|
||||
|
||||
// Application sending the request
|
||||
NSString *appName = [host name];
|
||||
if (appName) {
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"appName", @"Application Name", appName, appName] forKeys:profileDictKeys]];
|
||||
}
|
||||
NSString *appVersion = [host version];
|
||||
if (appVersion) {
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"appVersion", @"Application Version", appVersion, appVersion] forKeys:profileDictKeys]];
|
||||
}
|
||||
|
||||
// Number of displays?
|
||||
|
||||
// CPU speed
|
||||
unsigned long hz;
|
||||
size_t hz_size = sizeof(unsigned long);
|
||||
if (sysctlbyname("hw.cpufrequency", &hz, &hz_size, NULL, 0) == 0) {
|
||||
unsigned long mhz = hz / 1000000;
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"cpuFreqMHz", @"CPU Speed (GHz)", @(mhz), @(mhz / 1000.)] forKeys:profileDictKeys]];
|
||||
}
|
||||
|
||||
// amount of RAM
|
||||
unsigned long bytes;
|
||||
size_t bytes_size = sizeof(unsigned long);
|
||||
if (sysctlbyname("hw.memsize", &bytes, &bytes_size, NULL, 0) == 0) {
|
||||
double megabytes = bytes / (1024. * 1024.);
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:@[@"ramMB", @"Memory (MB)", @(megabytes), @(megabytes)] forKeys:profileDictKeys]];
|
||||
}
|
||||
|
||||
return profileArray;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// SUUIBasedUpdateDriver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/5/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUUIBASEDUPDATEDRIVER_H
|
||||
#define SUUIBASEDUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUUpdateAlert.h"
|
||||
|
||||
@class SUStatusController;
|
||||
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate, SUUpdateAlertDelegate>
|
||||
|
||||
- (void)showModalAlert:(NSAlert *)alert;
|
||||
- (IBAction)cancelDownload:(id)sender;
|
||||
- (void)installAndRestart:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,240 @@
|
|||
//
|
||||
// SUUIBasedUpdateDriver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/5/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUIBasedUpdateDriver.h"
|
||||
|
||||
#import "SUUpdateAlert.h"
|
||||
#import "SUUpdater_Private.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUStatusController.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
@interface SUUIBasedUpdateDriver ()
|
||||
|
||||
@property (strong) SUStatusController *statusController;
|
||||
@property (strong) SUUpdateAlert *updateAlert;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUUIBasedUpdateDriver
|
||||
|
||||
@synthesize statusController;
|
||||
@synthesize updateAlert;
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host];
|
||||
[self.updateAlert setDelegate:self];
|
||||
|
||||
id<SUVersionDisplay> versDisp = nil;
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) {
|
||||
versDisp = [[self.updater delegate] versionDisplayerForUpdater:self.updater];
|
||||
}
|
||||
[self.updateAlert setVersionDisplayer:versDisp];
|
||||
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
||||
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
||||
}
|
||||
|
||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
||||
// there may be no way for the application to be activated to make it visible again.
|
||||
if ([self.host isBackgroundApplication])
|
||||
{
|
||||
[[self.updateAlert window] setHidesOnDeactivate:NO];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
// Only show the update alert if the app is active; otherwise, we'll wait until it is.
|
||||
if ([NSApp isActive])
|
||||
[[self.updateAlert window] makeKeyAndOrderFront:self];
|
||||
else
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
|
||||
[[self.updater delegate] updaterDidNotFindUpdate:self.updater];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
|
||||
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.")
|
||||
defaultButton:SULocalizedString(@"OK", nil)
|
||||
alternateButton:nil
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
|
||||
[self showModalAlert:alert];
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification
|
||||
{
|
||||
[[self.updateAlert window] makeKeyAndOrderFront:self];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSApplicationDidBecomeActiveNotification" object:NSApp];
|
||||
}
|
||||
|
||||
- (void)updateAlert:(SUUpdateAlert *)__unused alert finishedWithChoice:(SUUpdateAlertChoice)choice
|
||||
{
|
||||
self.updateAlert = nil;
|
||||
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
|
||||
switch (choice)
|
||||
{
|
||||
case SUInstallUpdateChoice:
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO];
|
||||
[self.statusController showWindow:self];
|
||||
[self downloadUpdate];
|
||||
break;
|
||||
|
||||
case SUOpenInfoURLChoice:
|
||||
[[NSWorkspace sharedWorkspace] openURL:[self.updateItem infoURL]];
|
||||
[self abortUpdate];
|
||||
break;
|
||||
|
||||
case SUSkipThisVersionChoice:
|
||||
[self.host setObject:[self.updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
|
||||
[self abortUpdate];
|
||||
break;
|
||||
|
||||
case SURemindMeLaterChoice:
|
||||
[self abortUpdate];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response
|
||||
{
|
||||
[self.statusController setMaxProgressValue:[response expectedContentLength]];
|
||||
}
|
||||
|
||||
- (NSString *)humanReadableSizeFromDouble:(double)value
|
||||
{
|
||||
if (value < 1000) {
|
||||
return [NSString stringWithFormat:@"%.0lf %@", value, SULocalizedString(@"B", @"the unit for bytes")];
|
||||
}
|
||||
|
||||
if (value < 1000 * 1000) {
|
||||
return [NSString stringWithFormat:@"%.0lf %@", value / 1000.0, SULocalizedString(@"KB", @"the unit for kilobytes")];
|
||||
}
|
||||
|
||||
if (value < 1000 * 1000 * 1000) {
|
||||
return [NSString stringWithFormat:@"%.1lf %@", value / 1000.0 / 1000.0, SULocalizedString(@"MB", @"the unit for megabytes")];
|
||||
}
|
||||
|
||||
return [NSString stringWithFormat:@"%.2lf %@", value / 1000.0 / 1000.0 / 1000.0, SULocalizedString(@"GB", @"the unit for gigabytes")];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didReceiveDataOfLength:(NSUInteger)length
|
||||
{
|
||||
[self.statusController setProgressValue:[self.statusController progressValue] + (double)length];
|
||||
if ([self.statusController maxProgressValue] > 0.0)
|
||||
[self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self humanReadableSizeFromDouble:[self.statusController progressValue]], [self humanReadableSizeFromDouble:[self.statusController maxProgressValue]]]];
|
||||
else
|
||||
[self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self humanReadableSizeFromDouble:[self.statusController progressValue]]]];
|
||||
}
|
||||
|
||||
- (IBAction)cancelDownload:(id)__unused sender
|
||||
{
|
||||
if (self.download)
|
||||
[self.download cancel];
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
- (void)extractUpdate
|
||||
{
|
||||
// Now we have to extract the downloaded archive.
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonEnabled:NO];
|
||||
[super extractUpdate];
|
||||
}
|
||||
|
||||
- (void)unarchiver:(SUUnarchiver *)__unused ua extractedLength:(unsigned long)length
|
||||
{
|
||||
// We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress.
|
||||
if ([self.statusController maxProgressValue] == 0.0)
|
||||
{
|
||||
NSDictionary *attributes;
|
||||
attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.downloadPath error:nil];
|
||||
[self.statusController setMaxProgressValue:[attributes[NSFileSize] doubleValue]];
|
||||
}
|
||||
[self.statusController setProgressValue:[self.statusController progressValue] + (double)length];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil];
|
||||
[self.statusController setProgressValue:1.0]; // Fill the bar.
|
||||
[self.statusController setButtonEnabled:YES];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Install and Relaunch", nil) target:self action:@selector(installAndRestart:) isDefault:YES];
|
||||
[[self.statusController window] makeKeyAndOrderFront:self];
|
||||
[NSApp requestUserAttention:NSInformationalRequest];
|
||||
}
|
||||
|
||||
- (void)installAndRestart:(id)__unused sender
|
||||
{
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch
|
||||
{
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
[self.statusController setButtonEnabled:NO];
|
||||
[super installWithToolAndRelaunch:relaunch];
|
||||
}
|
||||
|
||||
- (void)terminateApp
|
||||
{
|
||||
// if a user chooses to NOT relaunch the app (as is the case with WebKit
|
||||
// when it asks you if you are sure you want to close the app with multiple
|
||||
// tabs open), the status window still stays on the screen and obscures
|
||||
// other windows; with this fix, it doesn't
|
||||
|
||||
if (self.statusController) {
|
||||
[self.statusController close];
|
||||
self.statusController = nil;
|
||||
}
|
||||
|
||||
[super terminateApp];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"Update Error!", nil) defaultButton:SULocalizedString(@"Cancel Update", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", [error localizedDescription]];
|
||||
[self showModalAlert:alert];
|
||||
[super abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
{
|
||||
if (self.statusController)
|
||||
{
|
||||
[self.statusController close];
|
||||
self.statusController = nil;
|
||||
}
|
||||
[super abortUpdate];
|
||||
}
|
||||
|
||||
- (void)showModalAlert:(NSAlert *)alert
|
||||
{
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) {
|
||||
[[self.updater delegate] updaterWillShowModalAlert:self.updater];
|
||||
}
|
||||
|
||||
// When showing a modal alert we need to ensure that background applications
|
||||
// are focused to inform the user since there is no dock icon to notify them.
|
||||
if ([self.host isBackgroundApplication]) { [NSApp activateIgnoringOtherApps:YES]; }
|
||||
|
||||
[alert setIcon:[self.host icon]];
|
||||
[alert runModal];
|
||||
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)])
|
||||
[[self.updater delegate] updaterDidShowModalAlert:self.updater];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// SUUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUUNARCHIVER_H
|
||||
#define SUUNARCHIVER_H
|
||||
|
||||
@class SUHost;
|
||||
@protocol SUUnarchiverDelegate;
|
||||
|
||||
@interface SUUnarchiver : NSObject
|
||||
|
||||
@property (copy, readonly) NSString *archivePath;
|
||||
@property (weak, readonly) SUHost *updateHost;
|
||||
@property (weak) id<SUUnarchiverDelegate> delegate;
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host;
|
||||
|
||||
- (void)start;
|
||||
@end
|
||||
|
||||
@protocol SUUnarchiverDelegate <NSObject>
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver;
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)unarchiver;
|
||||
@optional
|
||||
- (void)unarchiver:(SUUnarchiver *)unarchiver extractedLength:(unsigned long)length;
|
||||
@end
|
||||
|
||||
#endif
|
|
@ -0,0 +1,93 @@
|
|||
//
|
||||
// SUUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
|
||||
@implementation SUUnarchiver
|
||||
|
||||
@synthesize archivePath;
|
||||
@synthesize updateHost;
|
||||
@synthesize delegate;
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host
|
||||
{
|
||||
for (id current in [self unarchiverImplementations])
|
||||
{
|
||||
if ([current canUnarchivePath:path]) {
|
||||
return [[current alloc] initWithPath:path host:host];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; }
|
||||
|
||||
- (void)start
|
||||
{
|
||||
// No-op
|
||||
}
|
||||
|
||||
- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
archivePath = [path copy];
|
||||
updateHost = host;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)__unused path
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)notifyDelegateOfExtractedLength:(size_t)length
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiver:extractedLength:)]) {
|
||||
[self.delegate unarchiver:self extractedLength:length];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyDelegateOfSuccess
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiverDidFinish:)]) {
|
||||
[self.delegate unarchiverDidFinish:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyDelegateOfFailure
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiverDidFail:)]) {
|
||||
[self.delegate unarchiverDidFail:self];
|
||||
}
|
||||
}
|
||||
|
||||
static NSMutableArray *gUnarchiverImplementations;
|
||||
|
||||
+ (void)registerImplementation:(Class)implementation
|
||||
{
|
||||
if (!gUnarchiverImplementations) {
|
||||
gUnarchiverImplementations = [[NSMutableArray alloc] init];
|
||||
}
|
||||
[gUnarchiverImplementations addObject:implementation];
|
||||
}
|
||||
|
||||
+ (NSArray *)unarchiverImplementations
|
||||
{
|
||||
return [NSArray arrayWithArray:gUnarchiverImplementations];
|
||||
}
|
||||
|
||||
@end
|