Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62ee3fa6b1 | ||
|
|
d79643b458 | ||
|
|
08ad834d3f | ||
|
|
65ccd10a9c | ||
|
|
045875ae08 | ||
|
|
f5f5c517a5 | ||
|
|
3a1e60890e | ||
|
|
ba30bb137d | ||
|
|
d9e7ec2cf9 | ||
|
|
30d8815213 | ||
|
|
8a7857ba59 | ||
|
|
45345c0a44 | ||
|
|
bf11f076dc | ||
|
|
38ec6273fb | ||
|
|
a728f9a712 | ||
|
|
19ff4dce3d | ||
|
|
e649d2f4e1 | ||
|
|
80cb274d4c | ||
|
|
5a1732fdd8 | ||
|
|
fbd4272819 | ||
|
|
e6891906ef | ||
|
|
b4b8ac9e12 | ||
|
|
5593774b34 | ||
|
|
f343053e67 | ||
|
|
211f930059 | ||
|
|
7677f2d4ac | ||
|
|
e4c65a32de | ||
|
|
ef62c4ef15 | ||
|
|
e3990c0e42 | ||
|
|
d9e9a1bcee | ||
|
|
253de444e6 | ||
|
|
dd3aca874b | ||
|
|
90f35f87dc | ||
|
|
4149bf0103 | ||
|
|
af366b8b8c | ||
|
|
756023500c | ||
|
|
7f6cbe4577 | ||
|
|
c94eac3673 | ||
|
|
acea9b0d1d | ||
|
|
3b15ab08e1 | ||
|
|
02d5d44ffd | ||
|
|
1daba4d60f | ||
|
|
910f6a5966 | ||
|
|
5ed577fe78 | ||
|
|
d37bea0e67 | ||
|
|
5ca9c2fbbe | ||
|
|
bc1dc3ebf1 | ||
|
|
b9f6e9c8ae | ||
|
|
a30d745158 | ||
|
|
aa916f4bfe | ||
|
|
b820e4f288 | ||
|
|
2beaa9602c | ||
|
|
4953a96658 | ||
|
|
d47560283c | ||
|
|
b57ca4769c | ||
|
|
01b1ce7b9c | ||
|
|
32e59c6ea4 | ||
|
|
941a65f78f | ||
|
|
bd046ab1ad | ||
|
|
ebfb5f82b2 | ||
|
|
8039ce9862 | ||
|
|
26818ca11d | ||
|
|
1dcb87cc44 | ||
|
|
313daa4711 | ||
|
|
86278a2f32 | ||
|
|
a91749781d | ||
|
|
b52291cfc6 | ||
|
|
d5d9824b6c | ||
|
|
d487361cb9 | ||
|
|
5e906948f3 | ||
|
|
48ab89338b | ||
|
|
1c09a01ef9 | ||
|
|
4094dc3e83 | ||
|
|
d25e96f220 | ||
|
|
12531b635d | ||
|
|
bb645e9832 | ||
|
|
e24212f797 | ||
|
|
6b97e4a533 | ||
|
|
3956a27bd0 | ||
|
|
8a4578fe4d | ||
|
|
3c7b0805e1 | ||
|
|
d81139830e | ||
|
|
b6b704ea55 | ||
|
|
77fc6ca681 | ||
|
|
46c22e2bbf | ||
|
|
92d7b9f68f | ||
|
|
6b6b6b2405 | ||
|
|
b854b01e6a | ||
|
|
61e16cf276 | ||
|
|
e7088fc788 | ||
|
|
54aa6f2cc2 | ||
|
|
acf758e485 | ||
|
|
ceedfba634 | ||
|
|
addedeac13 | ||
|
|
eedb0ff0dd | ||
|
|
67a7bc3d62 | ||
|
|
65d7c38ab6 | ||
|
|
5b786043c2 | ||
|
|
ca23238d59 | ||
|
|
fc1870cbd2 | ||
|
|
659aec4eaf | ||
|
|
88a197a7f0 | ||
|
|
9119d287ab | ||
|
|
7797a8f58c | ||
|
|
1f0da95e59 | ||
|
|
84a2feb0ad | ||
|
|
bbe75fc6f2 | ||
|
|
9c8e08b7ae | ||
|
|
371c51fe5a | ||
|
|
feb2ad4b64 | ||
|
|
1e75acb963 | ||
|
|
b3c69f8b8c | ||
|
|
5cd9bdccf6 | ||
|
|
12eede4123 | ||
|
|
9633a57c6c | ||
|
|
ab389260be | ||
|
|
abf70ab8dc | ||
|
|
67ebc6ff74 | ||
|
|
1e14f7d7b6 | ||
|
|
5bd4c1ecb6 | ||
|
|
406f3da615 | ||
|
|
302eb082d6 | ||
|
|
16b75653dc | ||
|
|
fc8176a229 | ||
|
|
502c7fb6db | ||
|
|
71f747aec1 | ||
|
|
aebb767cfb | ||
|
|
04b1514452 | ||
|
|
22f9c96a1f | ||
|
|
78b08a0bee | ||
|
|
6fc58a1025 | ||
|
|
dbd2b9b30a |
No files matched your search
@@ -28,13 +28,6 @@ Icon
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# With Carthage, if Sparkle is included as a Git submodule (e.g. with the
|
||||
# --use-submodules option), the main module's .gitignore can't reach all the
|
||||
# way inside the submodule to ignore the added Carthage/Build symlink, and Git
|
||||
# keeps complaining about untracked changes in the submodule forever, which
|
||||
# is very annoying. To avoid that issue, ignore here in Sparkle instead.
|
||||
Carthage/Build
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
language: objective-c
|
||||
osx_image: xcode8.2
|
||||
osx_image: xcode7
|
||||
before_install:
|
||||
- brew update
|
||||
- brew install macmade/tap/xcode-coveralls
|
||||
script: make ci
|
||||
after_success: xcode-coveralls --exclude /Applications --exclude Tests --exclude Vendor build/Build/Intermediates/Sparkle.build/Coverage/Sparkle.build/Objects-normal/x86_64
|
||||
@@ -1,150 +1,25 @@
|
||||
# 1.17.0
|
||||
|
||||
* Added Touch Bar support (Bi11)
|
||||
* Upgraded SULog to use logging APIs that Apple provides built-in (Zorg)
|
||||
* Skip buttons are disabled if the update is marked as critical (Kornel Lesiński)
|
||||
* Background updates ask OS for lower-priority networking (Kornel Lesiński)
|
||||
* Refactorings to sync with upcoming 2.0
|
||||
* Added kqueue based termination listener (Zorg)
|
||||
* Added AppKit prevention guards to modules that shouldn't import it (Zorg)
|
||||
* Added Obj-C generics where applicable (Zorg)
|
||||
* Made SUBundleIcon & SUApplicationInfo take SUHost, not NSBundle (Zorg)
|
||||
* Improved -[SUHost objectForInfoDictionaryKey:] (Zorg)
|
||||
* Detect and fail if any two-way dependencies exist in the project (Zorg)
|
||||
* generate_appcast:
|
||||
* fixed handling of multiple directories in an archive
|
||||
* percent encode the filename used in the delta url (Brett Walker)
|
||||
* Update Sparkle.strings (BR Lingo)
|
||||
* Improved handling of non-ASCII names in delta archives (Kornel Lesiński)
|
||||
* Don't touch Info.plist unless git version changes (Václav Slavík)
|
||||
|
||||
# 1.16.0
|
||||
|
||||
* Guided package installs are now the default for updating packages (Zorg)
|
||||
- `pkg` installers won't show any UI. If you require the old behavior of showing a full installer window, rename the `*.pkg` file to `*.sparkle_interactive.pkg`
|
||||
* Previous version of the app is now deleted instead of staying in the trash (Zorg)
|
||||
* Added `generate_appcast` helper tool (Kornel Lesiński)
|
||||
* Made manual check resume pending automatic updates instead of starting a new update (Kornel Lesiński)
|
||||
* Started using `length` value from RSS if HTTP doesn't give one (Zorg)
|
||||
* Hidden automatic updates checkbox for information only updates (Bi11)
|
||||
* Added progressbar for DMG and binary delta extraction (Kornel Lesiński)
|
||||
* Fixed showing of download status if we attempt a 2nd download (Zorg)
|
||||
* Refactorings to sync with upcoming 2.0
|
||||
* Decoupled and simplified installation code using protocols (Zorg)
|
||||
* Added nullability annotations (Zorg)
|
||||
* Allowed delegate methods that return an object to return nil (Zorg)
|
||||
* Decreased responsibility of SUHost and moved code into other components (Zorg)
|
||||
* Removed Sparkle.pch and many file #includes (Zorg)
|
||||
|
||||
# 1.15.0
|
||||
|
||||
* A new icon! Thanks to 1024jp
|
||||
* Show alert when an update is sent over insecure HTTP with no DSA key (Zorg)
|
||||
- If you can't use HTTPS, you must at least sign updates with a DSA key.
|
||||
* Improved binary delta implementation (Zorg)
|
||||
* Added improved -validateMenuItem: as a method in SUUpdater.h for public use (Zorg)
|
||||
* Removed reachability preflight check (Zorg)
|
||||
* Clear update caches directory before downloading new update (Zorg)
|
||||
* Check the bundle's parent directory for writability too (Zorg)
|
||||
* Don't follow symbolic links for file operations (Zorg)
|
||||
* Don't bring up an authorized dialog during cleanup (Zorg)
|
||||
* Made Sparkle look for the highest compatible version regardless of timestamps (Zorg)
|
||||
* Fixed compatibility with 10.7
|
||||
* Fixed crash on 10.7 - subscript operator not available (kleuter)
|
||||
* Fixed warnings caused by -Wpartial-availability (Zorg)
|
||||
* Fixed german l10n. (Sebastian Volland)
|
||||
* Error code for download errors (Kornel Lesiński)
|
||||
* Update last update check date when the update driver finishes (Zorg)
|
||||
* Scale app icon up if needed in Software Update window (Nicholas Riley)
|
||||
* Don't register for termination notifications more than once (Zorg)
|
||||
* Don't terminate the app if we're already terminating (Zorg)
|
||||
* Removed SUEnableAutomaticChecksKeyOld and SUCheckAtStartup constants (Eitot)
|
||||
* Updated Sparkle framework headers to use modules if modules are available (B. Kevin Hardman)
|
||||
* Fixed warnings, fixed uses of SULocalizedString (Jerry Krinock)
|
||||
* Improved signing verifier to take any host and s/application/bundle/ (Zorg)
|
||||
* Improved Spotlight updates after delta extraction (Zorg)
|
||||
|
||||
# 1.14.0 (Mar 11, 2016)
|
||||
|
||||
* Disable javascript by default and make it opt-in (Zorg)
|
||||
* URL-encoding of appcast URLs is preserved (Kornel Lesiński)
|
||||
* Delegate is asked for fallback updates if delta update fails (Kornel Lesiński)
|
||||
* Fixed crash on 10.7 - subscript operator not available (kleuter)
|
||||
* Fixed check of feed URL before delegate had a chance to set it (Kornel Lesiński)
|
||||
* Re-added support for password-protected dmg images (Andrew K. Boyd)
|
||||
* Added warning about ATS blocking (Kornel Lesiński)
|
||||
* Translation fixes for pt-BR. (vitu)
|
||||
* Add some Japanese lozalized strings (1024jp)
|
||||
* Made test app available in all languages #695 (LIU Dongyuan / 柳东原)
|
||||
* Czech localizations update (Frantisek Erben)
|
||||
* Removed a test resource from the framework bundle (Karl Moskowski)
|
||||
* Test if the updated app is the frontmost one (Zorg)
|
||||
* UI Tests for the Test Application (Zorg)
|
||||
|
||||
# 1.13.1 (Jan 31, 2016)
|
||||
|
||||
Important security fixes:
|
||||
|
||||
* Prevent inclusion of local files via file:// XML entities
|
||||
* Disable redirects to non-HTTP URLs in release notes webview
|
||||
|
||||
# 1.13.0 (Dec 18, 2015)
|
||||
|
||||
* Changed framework's bundle ID from `org.andymatuschak.Sparkle` to `org.sparkle-project.Sparkle`.
|
||||
|
||||
# 1.12.0 (Dec 13, 2015)
|
||||
|
||||
* Rewritten file operations for updating an app (Zorg)
|
||||
- Ensuring atomic move operations, robust error handling.
|
||||
- Faster.
|
||||
- Using modern APIs where possible (no FSPathMakeRef, FSGetCatalogInfo, FSFindFolder, etc.)
|
||||
- Strong documentation, easier to read code.
|
||||
* Automatic updates won't be installed if the system is about to shut off (Zorg)
|
||||
* Deprecated serving over HTTP without DSA (Zorg)
|
||||
- Note that Apple has deprecated insecure HTTP in macOS 10.11
|
||||
* Improved Autoupdate application (Zorg)
|
||||
* Do all the installation work after the runloop is set up
|
||||
* TerminationListener only does termination listening now
|
||||
* Handle cases where host path is not installation path and host path is not desired executable path
|
||||
* Don't show Autoupdate dock icon if we shouldn't show UI
|
||||
* Update modification & access time for new update
|
||||
* Added installUpdatesIfAvailable (Ian Langworth)
|
||||
* Removed extensions from shell scripts (Jake Petroules)
|
||||
* Rewritten test app so it works again, and from a local web server (Zorg)
|
||||
* Replaced use of Python with built-in web server (Kevin Wojniak)
|
||||
* Set LD_RUNPATH_SEARCH_PATHS in Podspec (Jake Petroules)
|
||||
* Don't install automatic updates if the system might shut off (Zorg)
|
||||
* Don't show Autoupdate dock icon if we shouldn't show UI (Zorg)
|
||||
* Updated layout constraints when removing release notes (Zorg)
|
||||
* Improved BinaryDelta error handling & logging (Zorg)
|
||||
* Refactored quarantine removal (Zorg)
|
||||
* Fixed German localization (1024jp)
|
||||
* Updated zh_CN translation (LIU Dongyuan / 柳东原)
|
||||
* Updated Mac models list until July 2015 (Gabriel Ulici)
|
||||
* Updated Polish translation (Kornel Lesiński)
|
||||
* Updated Xcode project languages for which we have translations (Jake Petroules)
|
||||
* Updated XIB files (Kornel Lesiński)
|
||||
* Use NSByteCountFormatter if available (Jake Petroules)
|
||||
* Declared protocols on SUUpdateAlert for the 10.11 SDK (Daniel Jalkut)
|
||||
* Silenced warning about casting away const-ness and -Wassign-enum (Daniel Jalkut)
|
||||
* Added script to generate a report comparing the Sparkle.strings files (Kevin Wojniak)
|
||||
* Check for empty strings (as well as nil) in SUHost's -name method (Karl Moskowski)
|
||||
* Don't follow symlinks for checking file existence (Zorg)
|
||||
* Unit tests in Swift (Zorg, Jake Petroules)
|
||||
* Fixed framework imports (Felix Schulze)
|
||||
* Fixed issues with copying files from different mounted drives (Zorg)
|
||||
* Disallowed automatic updates when user can't write to the bundle (Zorg)
|
||||
* Set the task working directories instead of changing the process working directory (Kevin Wojniak)
|
||||
|
||||
# 1.11.1 (Nov 9, 2015)
|
||||
|
||||
* Don't install automatic updates when system is about to shut down
|
||||
|
||||
# 1.11.0 (Aug 24, 2015)
|
||||
# 1.11.0
|
||||
|
||||
* Big improvements to code signing and DSA verification
|
||||
- Sparkle now checks not only whether an update is correctly signed, but also whether the updated version will be able to verify future updates. Updates now must either use DSA keys correctly, or not try to use them at all. Same goes for Apple Code Signing.
|
||||
- Rely on code signing and the DSA key in the new app instead of appcast. If the new app has a public DSA key, then the appcast item must have a DSA signature for the app, even if the app is code signed. (Zorg)
|
||||
* Deprecated serving over http without DSA (Zorg)
|
||||
* Removed extensions from shell scripts (Jake Petroules)
|
||||
* Improved Autoupdate application (Zorg)
|
||||
* Do all the installation work after the runloop is set up
|
||||
* TerminationListener only does termination listening now
|
||||
* Handle cases where host path is not installation path and host path is not desired executable path
|
||||
* Set LD_RUNPATH_SEARCH_PATHS in Podspec. (Jake Petroules)
|
||||
* Updated layout constraints when removing release notes (Zorg)
|
||||
* Fix German localization (1024jp)
|
||||
* Updated zh_CN translation (LIU Dongyuan / 柳东原)
|
||||
* Updated Mac models list until July 2015 (Gabriel Ulici)
|
||||
* Updated Xcode project languages for which we have translations (Jake Petroules)
|
||||
* Use NSByteCountFormatter if available (Jake Petroules)
|
||||
* Declared protocols on SUUpdateAlert for the 10.11 SDK (Daniel Jalkut)
|
||||
* Silenced warning about casting away const-ness and -Wassign-enum (Daniel Jalkut)
|
||||
* Rewritten test app so it works again, and from a local web server (Zorg)
|
||||
* Added script to generate a report comparing the Sparkle.strings files (Kevin Wojniak)
|
||||
* More verbose error message when DSA keys don't match (Kornel Lesiński)
|
||||
* Added delegate methods for pre-download and immediately post-failed-download (Isaac Greenspan)
|
||||
* Fix Lucida Grande is always used for release notes (LIU Dongyuan / 柳东原)
|
||||
@@ -158,7 +33,7 @@ Important security fixes:
|
||||
* Added logging of appcast/download URL on error (Kornel Lesiński)
|
||||
* More robust reading of Autoupdate.app path from Sparkle bundle
|
||||
|
||||
# 1.10.0 (Apr 26, 2015)
|
||||
# 1.10.0
|
||||
|
||||
* Massive improvements to the BinaryDelta tool (Zorg)
|
||||
- Ability to track file permissions (Zorg)
|
||||
@@ -174,7 +49,7 @@ Important security fixes:
|
||||
* Stdout used for non error outputs (JDuquennoy)
|
||||
* French locale update (Kent Sutherland)
|
||||
|
||||
# 1.9.0 (Jan 26, 2015)
|
||||
# 1.9.0
|
||||
|
||||
* Added SUUpdater delegate method for failures. (Benjamin Gordon)
|
||||
* Make the error definitions public (C.W. Betts)
|
||||
@@ -184,7 +59,7 @@ Important security fixes:
|
||||
* Use Library/Caches rather than app support directory (Kornel Lesiński)
|
||||
* Check for a modal window being onscreen before trying to put up the Sparkle prompt (Alf Watt)
|
||||
* Fixed crashes on 10.7 (Chris Campbell, Ger Teunis)
|
||||
* Fixed Sparkle tags parsing (Tamás Lustyik)
|
||||
* Fixed Sparkle tags parsing (Tamás Lustyik)
|
||||
* SULog code cleanups (Kevin Wojniak)
|
||||
* Make sure CFBundleVersion is a semantic version number. (Jake Petroules)
|
||||
* Replace typedef enums with typedef NS_ENUM to make Swift happier (C.W. Betts)
|
||||
@@ -197,18 +72,18 @@ Important security fixes:
|
||||
* Turkish localization fixes (Emir)
|
||||
* Proofing of Ukrainian localization (Vera Tkachenko)
|
||||
|
||||
# 1.8.0 (Jul 26, 2014)
|
||||
# 1.8.0
|
||||
|
||||
* New SUDSAVerifier based on up-to-date macOS APIs (Zachary Waldowski)
|
||||
* 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 macOS 10.10 (C.W. Betts)
|
||||
* Quarantine removal on OS X 10.10 (C.W. Betts)
|
||||
* Updated Japanese localization (1024jp)
|
||||
* Added Greek localization
|
||||
|
||||
# 1.7.1 (Jul 2, 2014)
|
||||
# 1.7.1
|
||||
|
||||
* Removed option to install unverified updates (Kornel Lesiński)
|
||||
* Added detailed log when code signing verification fails (Sam Deane)
|
||||
@@ -225,7 +100,7 @@ Important security fixes:
|
||||
|
||||
# 1.7.0
|
||||
|
||||
* Dropped support for macOS 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).
|
||||
* 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)
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at kornel+sparkle@geekhood.net. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
@@ -1,8 +1,7 @@
|
||||
// Common
|
||||
|
||||
SPARKLE_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle
|
||||
SPARKLE_BUNDLE_IDENTIFIER = org.andymatuschak.Sparkle
|
||||
SPARKLE_RELAUNCH_TOOL_NAME = Autoupdate
|
||||
SPARKLE_FILEOP_TOOL_NAME = fileop
|
||||
|
||||
SPARKLE_APPEND_VERSION_NUMBER = 1
|
||||
|
||||
@@ -16,13 +15,15 @@ SPARKLE_AUTOMATED_DOWNGRADES = 0
|
||||
SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
||||
|
||||
SPARKLE_VERSION_MAJOR = 1
|
||||
SPARKLE_VERSION_MINOR = 17
|
||||
SPARKLE_VERSION_MINOR = 12
|
||||
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
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES
|
||||
GCC_PREFIX_HEADER = Sparkle/Sparkle.pch
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = YES
|
||||
GCC_INLINES_ARE_PRIVATE_EXTERN = YES
|
||||
ARCHS = $(ARCHS_STANDARD)
|
||||
@@ -30,15 +31,12 @@ MACOSX_DEPLOYMENT_TARGET = 10.7
|
||||
PRODUCT_NAME = ${TARGET_NAME}
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier}
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_FILEOP_TOOL_NAME=\"$(SPARKLE_FILEOP_TOOL_NAME)\"
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\"
|
||||
|
||||
CLANG_ENABLE_OBJC_ARC = YES
|
||||
GCC_ENABLE_PASCAL_STRINGS = NO
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
COMBINE_HIDPI_IMAGES = NO;
|
||||
|
||||
// Enable warnings
|
||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
|
||||
@@ -53,6 +51,7 @@ 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
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES
|
||||
@@ -88,4 +87,4 @@ CLANG_ENABLE_MODULES[sdk=macosx10.8] = NO
|
||||
WARNING_CFLAGS_EXTRA = -Wno-custom-atomic-properties -Wno-implicit-atomic-properties
|
||||
|
||||
// Turn on all warnings, then disable a few which are almost impossible to avoid
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import $(WARNING_CFLAGS_EXTRA)
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wno-auto-import $(WARNING_CFLAGS_EXTRA)
|
||||
@@ -3,6 +3,7 @@
|
||||
// Debug only
|
||||
|
||||
GCC_OPTIMIZATION_LEVEL = 0
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
DEBUG_INFORMATION_FORMAT = dwarf
|
||||
ENABLE_TESTABILITY = YES
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Common
|
||||
|
||||
ARCHS = x86_64
|
||||
VALID_ARCHS = x86_64
|
||||
@@ -0,0 +1,4 @@
|
||||
// Common
|
||||
|
||||
ARCHS = ppc i386 x86_64
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Release only
|
||||
|
||||
GCC_OPTIMIZATION_LEVEL = s
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Ofast
|
||||
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
// Fileop tool only
|
||||
|
||||
PRODUCT_NAME = $(SPARKLE_FILEOP_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
@@ -9,5 +9,5 @@ INFOPLIST_FILE = Sparkle/Sparkle-Info.plist
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BUILDING_SPARKLE=1
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
SKIP_INSTALL = YES
|
||||
DEFINES_MODULE = YES
|
||||
DEFINES_MODULE = NO
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${SPARKLE_BUNDLE_IDENTIFIER}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Generate Appcast only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
SWIFT_OBJC_BRIDGING_HEADER = generate_appcast/Appcast-Bridging-Header.h
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
PRODUCT_NAME = generate_appcast
|
||||
@@ -1,4 +0,0 @@
|
||||
// Generate Appcast Debug
|
||||
|
||||
#include "ConfigGenerateAppcast.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -1,4 +0,0 @@
|
||||
// Generate Appcast Release
|
||||
|
||||
#include "ConfigGenerateAppcast.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -0,0 +1,10 @@
|
||||
// Sandbox Service only
|
||||
|
||||
WRAPPER_EXTENSION = xpc
|
||||
MACH_O_TYPE = mh_execute
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.7
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.7
|
||||
|
||||
GCC_WARN_SHADOW = NO
|
||||
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = NO
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigService.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -DDEBUG
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigService.xcconfig"
|
||||
@@ -1 +0,0 @@
|
||||
SWIFT_VERSION = 3.0
|
||||
@@ -1 +0,0 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Onone
|
||||
@@ -1 +0,0 @@
|
||||
SWIFT_OPTIMIZATION_LEVEL = -Owholemodule
|
||||
@@ -5,3 +5,4 @@ WRAPPER_EXTENSION = app
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
LD_RUNPATH_SEARCH_PATHS = @executable_path/../Frameworks
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.SparkleTestApp
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) CODE_SIGN_IDENTITY="$(CODE_SIGN_IDENTITY)"
|
||||
@@ -1,13 +0,0 @@
|
||||
// UI Test only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
INFOPLIST_FILE = UITests/UITests-Info.plist
|
||||
WRAPPER_EXTENSION = xctest
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
|
||||
FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR)
|
||||
LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks
|
||||
|
||||
TEST_TARGET_NAME = Sparkle Test App
|
||||
USES_XCTRUNNER = YES
|
||||
@@ -1,4 +0,0 @@
|
||||
#include "ConfigUITest.xcconfig"
|
||||
|
||||
GCC_GENERATE_TEST_COVERAGE_FILES = NO
|
||||
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "ConfigUITest.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "ConfigUITest.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -1,7 +1,5 @@
|
||||
// Unit Test only
|
||||
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
INFOPLIST_FILE = Tests/SparkleTests-Info.plist
|
||||
WRAPPER_EXTENSION = xctest
|
||||
OTHER_CFLAGS = $(inherited) -iframework"$(DEVELOPER_FRAMEWORKS_DIR)" -iframework"$(PLATFORM_DIR)/Developer/Library/Frameworks"
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
#include "ConfigSwiftDebug.xcconfig"
|
||||
@@ -1,2 +1 @@
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
#include "ConfigSwiftRelease.xcconfig"
|
||||
@@ -2,13 +2,6 @@
|
||||
set -e
|
||||
|
||||
if [ "$ACTION" = "" ] ; then
|
||||
# Sanity check that the Podspec version matches the Sparkle version
|
||||
spec_version=$(printf "require 'cocoapods'\nspec = %s\nprint spec.version" "$(cat "$SRCROOT/Sparkle.podspec")" | LANG=en_US.UTF-8 ruby)
|
||||
if [ "$spec_version" != "$CURRENT_PROJECT_VERSION" ] ; then
|
||||
echo "podspec version '$spec_version' does not match the current project version '$CURRENT_PROJECT_VERSION'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf "$CONFIGURATION_BUILD_DIR/staging"
|
||||
rm -f "Sparkle-$CURRENT_PROJECT_VERSION.tar.bz2"
|
||||
|
||||
@@ -16,7 +9,6 @@ if [ "$ACTION" = "" ] ; then
|
||||
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 "$CONFIGURATION_BUILD_DIR/generate_appcast" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.framework" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
|
||||
@@ -24,7 +16,6 @@ if [ "$ACTION" = "" ] ; then
|
||||
# because missing dSYMs in a release build SHOULD trigger a build failure
|
||||
if [ "$CONFIGURATION" = "Release" ] ; then
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/BinaryDelta.dSYM" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/generate_appcast.dSYM" "$CONFIGURATION_BUILD_DIR/staging/bin"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle Test App.app.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
cp -R "$CONFIGURATION_BUILD_DIR/Sparkle.framework.dSYM" "$CONFIGURATION_BUILD_DIR/staging"
|
||||
fi
|
||||
|
||||
@@ -13,28 +13,16 @@ if [ -z "$SRCROOT" ] || \
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version="$CURRENT_PROJECT_VERSION"
|
||||
|
||||
# Get version in format 1.x.x-commits-hash
|
||||
gitversion=$( cd "$SRCROOT"; git describe --tags --match '[12].*' || true )
|
||||
if [ -z "$gitversion" ] ; then
|
||||
echo "$0: Can't find a Git hash!" 1>&2
|
||||
# Get the current Git master hash
|
||||
version=$(cd "$SRCROOT" ; git show-ref --abbrev heads/master | awk '{print $1}')
|
||||
if [ -z "$version" ] ; then
|
||||
echo "$0: Can't find a Git hash!" 1>&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# remove everything before the first "-" to keep the hash part only
|
||||
versionsuffix=${gitversion#*-};
|
||||
if [ "$versionsuffix" != "$gitversion" ]; then
|
||||
version="$version $versionsuffix"
|
||||
fi
|
||||
version="$CURRENT_PROJECT_VERSION git-$version"
|
||||
|
||||
# and use it to set the CFBundleShortVersionString value
|
||||
export PATH="$PATH:/usr/libexec"
|
||||
|
||||
if [ -f "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" ] ; then
|
||||
oldversion=$(PlistBuddy -c "Print :CFBundleShortVersionString" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH")
|
||||
fi
|
||||
if [ "$version" != "$oldversion" ] ; then
|
||||
PlistBuddy -c "Set :CFBundleShortVersionString '$version'" \
|
||||
"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
|
||||
fi
|
||||
PlistBuddy -c "Set :CFBundleShortVersionString '$version'" \
|
||||
"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
|
||||
@@ -1,6 +1,6 @@
|
||||
PROJECT_NAME = Sparkle
|
||||
PROJECT_NUMBER = 1.14.0
|
||||
PROJECT_BRIEF = "A software update framework for macOS"
|
||||
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
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
Copyright (c) 2006-2013 Andy Matuschak.
|
||||
Copyright (c) 2009-2013 Elgato Systems GmbH.
|
||||
Copyright (c) 2011-2014 Kornel Lesiński.
|
||||
Copyright (c) 2015-2017 Mayur Pawashe.
|
||||
Copyright (c) 2014 C.W. Betts.
|
||||
Copyright (c) 2014 Petroules Corporation.
|
||||
Copyright (c) 2014 Big Nerd Ranch.
|
||||
|
||||
@@ -13,18 +13,12 @@ localizable-strings:
|
||||
release:
|
||||
xcodebuild -scheme Distribution -configuration Release -derivedDataPath "$(BUILDDIR)" build
|
||||
open -R "$(BUILDDIR)/Build/Products/Release/Sparkle-"*.tar.bz2
|
||||
cat Sparkle.podspec
|
||||
@echo "Don't forget to update CocoaPods! pod trunk push"
|
||||
|
||||
build:
|
||||
xcodebuild clean build
|
||||
|
||||
test:
|
||||
xcodebuild -scheme Distribution -configuration Debug test
|
||||
./objc_dep/objc_dep.py -t .
|
||||
|
||||
uitest:
|
||||
xcodebuild -scheme UITests -configuration Debug test
|
||||
|
||||
ci:
|
||||
for i in {7..9} ; do \
|
||||
@@ -32,7 +26,7 @@ ci:
|
||||
( rm -rf build && xcodebuild -sdk "macosx10.$$i" -scheme Distribution -configuration Coverage -derivedDataPath build ) || exit 1 ; \
|
||||
fi ; \
|
||||
done
|
||||
for i in {10..12} ; do \
|
||||
for i in {10..11} ; do \
|
||||
if xcrun --sdk "macosx10.$$i" --show-sdk-path 2> /dev/null ; then \
|
||||
( rm -rf build && xcodebuild -sdk "macosx10.$$i" -scheme Distribution -configuration Coverage -derivedDataPath build test ) || exit 1 ; \
|
||||
fi ; \
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# To update the icon run make -f Makefile-icon
|
||||
# Requires:
|
||||
# autoconf, automake, libtool, pkg-config, pngquant
|
||||
|
||||
ICONDIR=./Resources/Images.xcassets/AppIcon.appiconset
|
||||
OPTIMIZEDICONS=$(ICONDIR)/optimized_16x16.png $(ICONDIR)/optimized_32x32.png $(ICONDIR)/optimized_128x128.png $(ICONDIR)/optimized_512x512.png
|
||||
DESTICON=Resources/AppIcon.icns
|
||||
|
||||
all: $(DESTICON)
|
||||
|
||||
libicns:
|
||||
git clone https://github.com/pornel/libicns.git
|
||||
|
||||
libicns/Makefile: libicns
|
||||
( cd libicns && autoreconf -vif && ./configure )
|
||||
|
||||
libicns/icnsutils/png2icns: libicns/Makefile
|
||||
( cd libicns && make -j8 )
|
||||
|
||||
optimized_%.png: icon_%.png
|
||||
pngquant -s1 -f -o $@ $<
|
||||
|
||||
$(DESTICON): libicns/icnsutils/png2icns $(OPTIMIZEDICONS)
|
||||
./libicns/icnsutils/png2icns $@ $(OPTIMIZEDICONS)
|
||||
@@ -1,45 +1,41 @@
|
||||
# Sparkle [](https://travis-ci.org/sparkle-project/Sparkle) [](https://github.com/Carthage/Carthage) []() <a href="https://www.stackpath.com/?utm_source=sparkle-github&utm_medium=badge&utm_campaign=readme"><img src="https://img.shields.io/badge/sponsored%20by-StackPath-orange.svg" alt="sponsored by: StackPath"></a>
|
||||
# Sparkle [](https://travis-ci.org/sparkle-project/Sparkle) <a href='https://app.ship.io/dashboard#/jobs/8814/history' target='_blank'><img src='https://app.ship.io/jobs/V3PoCLcN5ft5Pnq0/build_status.png' height='20' /></a> [](https://coveralls.io/github/sparkle-project/Sparkle?branch=master)
|
||||
|
||||
Secure and reliable software update framework for Cocoa developers.
|
||||
An easy-to-use software update framework for Cocoa developers.
|
||||
|
||||
<img src="Resources/Screenshot.png" width="732" alt="Sparkle shows familiar update window with release notes">
|
||||
|
||||
## Features
|
||||
|
||||
* Seamless. There's no mention of Sparkle; your icons and app name are used.
|
||||
* Secure. Updates are verified using DSA signatures and Apple Code Signing.
|
||||
* Fast. Supports delta updates which only patch files that have changed.
|
||||
* Easy to install. Sparkle requires no code in your app, and only needs static files on a web server.
|
||||
* Supports bundles, preference panes, plugins, and other non-.app software. Can install .pkg files for more complicated products.
|
||||
* Handles permissions, quarantine and automatically asks for authentication if needed.
|
||||
* Uses RSS-based appcasts for release information. Appcasts are a de-facto standard supported by 3rd party update-tracking programs and websites.
|
||||
* Sparkle stays hidden until second launch for better first impressions.
|
||||
* Truly self-updating — the user can choose to automatically download and install all updates in the background.
|
||||
<img src="Resources/Screenshot.png" width="715" alt="Sparkle shows familiar update window with release notes">
|
||||
|
||||
## Changes since 1.5b
|
||||
|
||||
* Compatibilty with macOS Sierra.
|
||||
* Up-to-date with 10.12 SDK and Xcode 8 (supports macOS 10.7+).
|
||||
* Important security fixes.
|
||||
* Up-to-date with 10.11 SDK and Xcode 7. 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."
|
||||
* Upgraded and more reliable binary delta and code signing verification.
|
||||
* 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.
|
||||
* Upgraded and more reliable binary delta and code signing verification.
|
||||
|
||||
## Requirements
|
||||
## Features
|
||||
|
||||
* Runtime: macOS 10.7 or greater
|
||||
* Build: Xcode 7 and 10.8 SDK or greater
|
||||
* HTTPS server for serving updates (see [App Transport Security](http://sparkle-project.org/documentation/app-transport-security/))
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
|
||||
## Usage
|
||||
## Developers
|
||||
|
||||
See [getting started guide](https://sparkle-project.org/documentation/). No code is necessary, but a bit of Xcode configuration is required.
|
||||
Building Sparkle requires Xcode 5 or above.
|
||||
|
||||
## Development
|
||||
|
||||
### API symbols
|
||||
### API
|
||||
|
||||
Sparkle is built with `-fvisibility=hidden -fvisibility-inlines-hidden` which means no symbols are exported by default.
|
||||
If you are adding a symbol to the public API you must decorate the declaration with the `SU_EXPORT` macro (grep the source code for examples).
|
||||
@@ -49,11 +45,3 @@ If you are adding a symbol to the public API you must decorate the declaration w
|
||||
`cd` to the root of the Sparkle source tree and run `make release`. Sparkle-*VERSION*.tar.bz2 will be created in a temporary directory and revealed in Finder after the build has completed.
|
||||
|
||||
Alternatively, build the Distribution scheme in the Xcode UI.
|
||||
|
||||
### Code of Conduct
|
||||
|
||||
We pledge to have an open and welcoming environment. See our [Code of Conduct](CODE_OF_CONDUCT.md).
|
||||
|
||||
## Project Sponsor
|
||||
|
||||
[StackPath](https://www.stackpath.com/?utm_source=sparkle-github&utm_medium=link&utm_campaign=readme-footer)
|
||||
@@ -43,21 +43,18 @@
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_256x256@2x.png",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_512x512.png",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_512x512@2x.png",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
|
||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 827 B After Width: | Height: | Size: 754 B |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 130 KiB |
|
Before Width: | Height: | Size: 368 KiB |
@@ -47,13 +47,7 @@
|
||||
<key>iMac14,4</key>
|
||||
<string>iMac (Core i5, 21.5 inch Mid 2014)</string>
|
||||
<key>iMac15,1</key>
|
||||
<string>iMac (Retina 5K Core i5 or i7, 27 inch Late 2014 or Mid 2015)</string>
|
||||
<key>iMac16,1</key>
|
||||
<string>iMac (Core i5, 21,5 inch Late 2015)</string>
|
||||
<key>iMac16,2</key>
|
||||
<string>iMac (Retina 4K Core i5 or i7, 21.5 inch Late 2015)</string>
|
||||
<key>iMac17,1</key>
|
||||
<string>iMac (Retina 5K Core i5 or i7, 27 inch Late 2015)</string>
|
||||
<string>iMac (Retina 5K Core i5 or i7, 27 inch 2014 or 2015)</string>
|
||||
<key>MacBook1,1</key>
|
||||
<string>MacBook (Core Duo)</string>
|
||||
<key>MacBook2,1</key>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<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>
|
||||
|
||||
|
Before Width: | Height: | Size: 228 KiB After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,5 @@
|
||||
<?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/>
|
||||
</plist>
|
||||
@@ -1,29 +1,26 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Sparkle"
|
||||
s.version = "1.17.0"
|
||||
s.summary = "A software update framework for macOS"
|
||||
s.version = "1.11.0"
|
||||
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 = "http://sparkle-project.org"
|
||||
s.documentation_url = "http://sparkle-project.org/documentation/"
|
||||
s.screenshot = "http://sparkle-project.org/images/screenshot-noshadow@2x.png"
|
||||
s.license = {
|
||||
:type => 'MIT',
|
||||
:file => 'LICENSE'
|
||||
}
|
||||
s.authors = {
|
||||
'Mayur Pawashe' => 'zorgiepoo@gmail.com',
|
||||
'Kornel Lesiński' => 'pornel@pornel.net',
|
||||
'Jake Petroules' => 'jake.petroules@petroules.com',
|
||||
'C.W. Betts' => 'computers57@hotmail.com',
|
||||
'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, '10.7'
|
||||
s.source = { :http => "https://github.com/sparkle-project/Sparkle/releases/download/#{s.version}/Sparkle-#{s.version}.tar.bz2" }
|
||||
s.source_files = 'Sparkle.framework/Versions/A/Headers/*.h'
|
||||
|
||||
s.public_header_files = 'Sparkle.framework/Versions/A/Headers/*.h'
|
||||
s.vendored_frameworks = 'Sparkle.framework'
|
||||
s.vendored_framework = 'Sparkle.framework'
|
||||
s.resources = 'Sparkle.framework'
|
||||
s.xcconfig = {
|
||||
'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}/Sparkle"',
|
||||
'LD_RUNPATH_SEARCH_PATHS' => '@loader_path/../Frameworks'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0830"
|
||||
LastUpgradeVersion = "0640"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,74 +14,81 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "5AA96C541E0AE0DB00CA4346"
|
||||
BuildableName = "generate_appcast"
|
||||
BlueprintName = "generate_appcast"
|
||||
BlueprintIdentifier = "331726961B4D5F27008B2D77"
|
||||
BuildableName = "libDevMateSparkle.a"
|
||||
BlueprintName = "DevMateSparkle_lib"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "331726A01B4D5F27008B2D77"
|
||||
BuildableName = "DevMateSparkle_libTests.xctest"
|
||||
BlueprintName = "DevMateSparkle_libTests"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
buildConfiguration = "Debug">
|
||||
<Testables>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "5AA96C541E0AE0DB00CA4346"
|
||||
BuildableName = "generate_appcast"
|
||||
BlueprintName = "generate_appcast"
|
||||
BlueprintIdentifier = "331726961B4D5F27008B2D77"
|
||||
BuildableName = "libDevMateSparkle.a"
|
||||
BlueprintName = "DevMateSparkle_lib"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Debug"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "331726961B4D5F27008B2D77"
|
||||
BuildableName = "libDevMateSparkle.a"
|
||||
BlueprintName = "DevMateSparkle_lib"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Release"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "5AA96C541E0AE0DB00CA4346"
|
||||
BuildableName = "generate_appcast"
|
||||
BlueprintName = "generate_appcast"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<CommandLineArguments>
|
||||
</CommandLineArguments>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
buildConfiguration = "Release"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "5AA96C541E0AE0DB00CA4346"
|
||||
BuildableName = "generate_appcast"
|
||||
BlueprintName = "generate_appcast"
|
||||
BlueprintIdentifier = "331726961B4D5F27008B2D77"
|
||||
BuildableName = "libDevMateSparkle.a"
|
||||
BlueprintName = "DevMateSparkle_lib"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0830"
|
||||
LastUpgradeVersion = "0700"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0830"
|
||||
LastUpgradeVersion = "0700"
|
||||
version = "2.0">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0830"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "726B2B5C1C645FC900388755"
|
||||
BuildableName = "UI Tests.xctest"
|
||||
BlueprintName = "UI Tests"
|
||||
ReferencedContainer = "container:Sparkle.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// AppKitPrevention.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 1/17/17.
|
||||
// Copyright © 2017 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
// #include (not #import) this header to prevent AppKit from being imported
|
||||
// Note this should be your LAST #include in your implementation file
|
||||
|
||||
// If this error is triggered, you can have Xcode indicate to you which source file including this header caused the issue
|
||||
|
||||
// One may wonder for certain targets where AppKit is banned completely, why just not link AppKit instead.
|
||||
// Well, Xcode has thing called auto-linking that I don't trust very much.
|
||||
// Even after trying to disable the setting, I've had targets able to link to AppKit without AppKit being specified in the list of linked libraries.
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a core or daemon-safe module and should NOT import AppKit
|
||||
#endif
|
||||
@@ -28,7 +28,5 @@
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>${ASSETCATALOG_COMPILER_APPICON_NAME}.icns</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,28 +1,77 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SULocalizations.h"
|
||||
#import "SUErrors.h"
|
||||
#import <AppKit/AppKit.h>
|
||||
#import "SUInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
#import "SUStatusController.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SULog.h"
|
||||
#import "SUInstallerProtocol.h"
|
||||
#import "TerminationListener.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
/*!
|
||||
* Time this app uses to recheck if the parent has already died.
|
||||
*/
|
||||
static const NSTimeInterval SUParentQuitCheckInterval = .25;
|
||||
|
||||
@interface TerminationListener : NSObject
|
||||
|
||||
- (instancetype)initWithProcessId:(pid_t)pid;
|
||||
|
||||
@end
|
||||
|
||||
@interface TerminationListener ()
|
||||
|
||||
@property (nonatomic, assign) pid_t processIdentifier;
|
||||
@property (nonatomic, strong) NSTimer *watchdogTimer;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TerminationListener
|
||||
|
||||
@synthesize processIdentifier = _processIdentifier;
|
||||
@synthesize watchdogTimer = _watchdogTimer;
|
||||
|
||||
- (instancetype)initWithProcessId:(pid_t)pid
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.processIdentifier = pid;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)cleanupWithCompletion:(void (^)(void))completionBlock
|
||||
{
|
||||
[self.watchdogTimer invalidate];
|
||||
completionBlock();
|
||||
completionBlock = nil;
|
||||
}
|
||||
|
||||
- (void)startListeningWithCompletion:(void (^)(void))completionBlock
|
||||
{
|
||||
BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already
|
||||
if (alreadyTerminated)
|
||||
[self cleanupWithCompletion:completionBlock];
|
||||
else
|
||||
self.watchdogTimer = [NSTimer scheduledTimerWithTimeInterval:SUParentQuitCheckInterval target:self selector:@selector(watchdog:) userInfo:completionBlock repeats:YES];
|
||||
}
|
||||
|
||||
- (void)watchdog:(NSTimer *)timer
|
||||
{
|
||||
if (![NSRunningApplication runningApplicationWithProcessIdentifier:self.processIdentifier]) {
|
||||
[self cleanupWithCompletion:timer.userInfo];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*!
|
||||
* 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;
|
||||
|
||||
/*!
|
||||
* Terminate the application after a delay from launching the new update to avoid OS activation issues
|
||||
* This delay should be be high enough to increase the likelihood that our updated app will be launched up front,
|
||||
* but should be low enough so that the user doesn't ponder why the updater hasn't finished terminating yet
|
||||
*/
|
||||
static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
|
||||
@interface AppInstaller : NSObject <NSApplicationDelegate>
|
||||
|
||||
/*
|
||||
@@ -48,8 +97,6 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
@property (nonatomic, assign) BOOL shouldRelaunch;
|
||||
@property (nonatomic, assign) BOOL shouldShowUI;
|
||||
|
||||
@property (nonatomic, assign) BOOL isTerminating;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppInstaller
|
||||
@@ -61,7 +108,6 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
@synthesize relaunchPath = _relaunchPath;
|
||||
@synthesize shouldRelaunch = _shouldRelaunch;
|
||||
@synthesize shouldShowUI = _shouldShowUI;
|
||||
@synthesize isTerminating = _isTerminating;
|
||||
|
||||
- (instancetype)initWithHostPath:(NSString *)hostPath relaunchPath:(NSString *)relaunchPath parentProcessId:(pid_t)parentProcessId updateFolderPath:(NSString *)updateFolderPath shouldRelaunch:(BOOL)shouldRelaunch shouldShowUI:(BOOL)shouldShowUI
|
||||
{
|
||||
@@ -71,8 +117,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
|
||||
self.hostPath = hostPath;
|
||||
self.relaunchPath = relaunchPath;
|
||||
SULog(SULogLevelDefault, @"PID to listen: %d", parentProcessId);
|
||||
self.terminationListener = [[TerminationListener alloc] initWithProcessIdentifier:@(parentProcessId)];
|
||||
self.terminationListener = [[TerminationListener alloc] initWithProcessId:parentProcessId];
|
||||
self.updateFolderPath = updateFolderPath;
|
||||
self.shouldRelaunch = shouldRelaunch;
|
||||
self.shouldShowUI = shouldShowUI;
|
||||
@@ -82,148 +127,81 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification __unused *)notification
|
||||
{
|
||||
[self.terminationListener startListeningWithCompletion:^(BOOL terminationSuccess) {
|
||||
[self.terminationListener startListeningWithCompletion:^{
|
||||
self.terminationListener = nil;
|
||||
|
||||
if (!terminationSuccess) {
|
||||
SULog(SULogLevelError, @"Failed to listen for application termination");
|
||||
// Continue on with the installation anyway?
|
||||
}
|
||||
|
||||
if (self.shouldShowUI) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUInstallationTimeLimit * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!self.isTerminating) {
|
||||
// Show app icon in the dock
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
}
|
||||
});
|
||||
}
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUInstallationTimeLimit * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
// Show app icon in the dock
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
});
|
||||
|
||||
[self install];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)showError:(NSError *)error
|
||||
{
|
||||
if (self.shouldShowUI) {
|
||||
NSAlert *alert = [[NSAlert alloc] init];
|
||||
alert.messageText = @"";
|
||||
alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]];
|
||||
[alert runModal];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)install
|
||||
{
|
||||
NSBundle *theBundle = [NSBundle bundleWithPath:self.hostPath];
|
||||
SUHost *host = [[SUHost alloc] initWithBundle:theBundle];
|
||||
NSString *installationPath = [[host installationPath] copy];
|
||||
|
||||
NSString *fileOperationToolPath = [[[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@""SPARKLE_FILEOP_TOOL_NAME];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileOperationToolPath]) {
|
||||
SULog(SULogLevelError, @"Potential Installation Error: File operation tool path %@ is not found", fileOperationToolPath);
|
||||
}
|
||||
|
||||
NSError *retrieveInstallerError = nil;
|
||||
id<SUInstallerProtocol> installer = [SUInstaller installerForHost:host fileOperationToolPath:fileOperationToolPath updateDirectory:self.updateFolderPath error:&retrieveInstallerError];
|
||||
if (installer == nil) {
|
||||
SULog(SULogLevelError, @"Retrieved Installer Error: %@", retrieveInstallerError);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (self.shouldShowUI && [installer canInstallSilently]) {
|
||||
if (self.shouldShowUI) {
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:host];
|
||||
[self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:Nil isDefault:NO];
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"")
|
||||
maxProgressValue:100 statusText: @""];
|
||||
maxProgressValue: 0 statusText: @""];
|
||||
[self.statusController showWindow:self];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
NSError *initialInstallationError = nil;
|
||||
if (![installer performInitialInstallation:&initialInstallationError]) {
|
||||
SULog(SULogLevelError, @"Failed to perform initial installation with error: %@", initialInstallationError);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self showError:initialInstallationError];
|
||||
exit(EXIT_FAILURE);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
void(^progressBlock)(double) = ^(double progress){
|
||||
dispatch_async(dispatch_get_main_queue(), ^(){
|
||||
self.statusController.progressValue = progress * 100.0;
|
||||
});
|
||||
};
|
||||
|
||||
NSError *finalInstallationError = nil;
|
||||
if (![installer performFinalInstallationProgressBlock:progressBlock error:&finalInstallationError]) {
|
||||
NSError *underlyingError = [finalInstallationError.userInfo objectForKey:NSUnderlyingErrorKey];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (underlyingError == nil || underlyingError.code != SUInstallationCancelledError) {
|
||||
SULog(SULogLevelError, @"Failed to perform final installation Error: %@", finalInstallationError);
|
||||
[self showError:finalInstallationError];
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *installationPath = [installer installationPath];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSString *pathToRelaunch = nil;
|
||||
// If the relaunch path is the same as the host bundle path, use the installation path from the installer which may be normalized
|
||||
// Otherwise use the requested relaunch path in all other cases
|
||||
if ([self.relaunchPath.pathComponents isEqualToArray:host.bundlePath.pathComponents]) {
|
||||
pathToRelaunch = installationPath;
|
||||
} else {
|
||||
pathToRelaunch = self.relaunchPath;
|
||||
}
|
||||
[self cleanupAndTerminateWithPathToRelaunch:pathToRelaunch];
|
||||
});
|
||||
});
|
||||
[SUInstaller installFromUpdateFolder:self.updateFolderPath
|
||||
overHost:host
|
||||
installationPath:installationPath
|
||||
versionComparator:[SUStandardVersionComparator defaultComparator]
|
||||
completionHandler:^(NSError *error) {
|
||||
if (error) {
|
||||
if (self.shouldShowUI) {
|
||||
NSAlert *alert = [[NSAlert alloc] init];
|
||||
alert.messageText = @"";
|
||||
alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]];
|
||||
[alert runModal];
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
NSString *pathToRelaunch = nil;
|
||||
// If the installation path differs from the host path, we give higher precedence for it than
|
||||
// if the desired relaunch path differs from the host path
|
||||
if (![installationPath.pathComponents isEqualToArray:self.hostPath.pathComponents] || [self.relaunchPath.pathComponents isEqualToArray:self.hostPath.pathComponents]) {
|
||||
pathToRelaunch = installationPath;
|
||||
} else {
|
||||
pathToRelaunch = self.relaunchPath;
|
||||
}
|
||||
[self cleanupAndTerminateWithPathToRelaunch:pathToRelaunch];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)cleanupAndTerminateWithPathToRelaunch:(NSString *)relaunchPath
|
||||
- (void)cleanupAndTerminateWithPathToRelaunch:(NSString *)relaunchPath __attribute__((noreturn))
|
||||
{
|
||||
self.isTerminating = YES;
|
||||
|
||||
dispatch_block_t cleanupAndExit = ^{
|
||||
NSError *theError = nil;
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:self.updateFolderPath error:&theError]) {
|
||||
SULog(SULogLevelError, @"Couldn't remove update folder: %@.", theError);
|
||||
}
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:[[NSBundle mainBundle] bundlePath] error:NULL];
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
};
|
||||
|
||||
if (self.shouldRelaunch) {
|
||||
// The auto updater can terminate before the newly updated app is finished launching
|
||||
// If that happens, the OS may not make the updated app active and frontmost
|
||||
// (Or it does become frontmost, but the OS backgrounds it afterwards.. It's some kind of timing/activation issue that doesn't occur all the time)
|
||||
// The only remedy I've been able to find is waiting an arbitrary delay before exiting our application
|
||||
|
||||
// Don't use -launchApplication: because we may not be launching an application. Eg: it could be a system prefpane
|
||||
if (![[NSWorkspace sharedWorkspace] openFile:relaunchPath]) {
|
||||
SULog(SULogLevelError, @"Failed to launch %@", relaunchPath);
|
||||
NSError *error = nil;
|
||||
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:relaunchPath]
|
||||
options:NSWorkspaceLaunchNewInstance
|
||||
configuration:@{}
|
||||
error:&error];
|
||||
if (error.code != noErr)
|
||||
{
|
||||
SULog(@"%ld - %@", error.code, error.localizedDescription);
|
||||
}
|
||||
|
||||
[self.statusController close];
|
||||
|
||||
// Don't even think about hiding the app icon from the dock if we've already shown it
|
||||
// Transforming the app back to a background one has a backfiring effect, decreasing the likelihood
|
||||
// that the updated app will be brought up front
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUTerminationTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
cleanupAndExit();
|
||||
});
|
||||
} else {
|
||||
cleanupAndExit();
|
||||
}
|
||||
|
||||
NSError *theError = nil;
|
||||
if (![SUPlainInstaller _removeFileAtPath:self.updateFolderPath error:&theError])
|
||||
SULog(@"Couldn't remove update folder: %@.", theError);
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:[[NSBundle mainBundle] bundlePath] error:NULL];
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -239,19 +217,29 @@ int main(int __unused argc, const char __unused *argv[])
|
||||
|
||||
NSApplication *application = [NSApplication sharedApplication];
|
||||
|
||||
BOOL shouldShowUI = (args.count > 6) ? [[args objectAtIndex:6] boolValue] : YES;
|
||||
BOOL shouldShowUI = (args.count > 6) ? [args[6] boolValue] : YES;
|
||||
if (shouldShowUI) {
|
||||
[application activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostPath:[args objectAtIndex:1]
|
||||
relaunchPath:[args objectAtIndex:2]
|
||||
parentProcessId:[[args objectAtIndex:3] intValue]
|
||||
updateFolderPath:[args objectAtIndex:4]
|
||||
shouldRelaunch:(args.count > 5) ? [[args objectAtIndex:5] boolValue] : YES
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostPath:args[1]
|
||||
relaunchPath:args[2]
|
||||
parentProcessId:[args[3] intValue]
|
||||
updateFolderPath:args[4]
|
||||
shouldRelaunch:(args.count > 5) ? [args[5] boolValue] : YES
|
||||
shouldShowUI:shouldShowUI];
|
||||
NSConnection *connection = [[NSConnection alloc] init];
|
||||
[connection setRootObject:appInstaller];
|
||||
if (![connection registerName:[NSString stringWithFormat:@"Sparkle-%@", [NSBundle bundleWithPath:appInstaller.hostPath].bundleIdentifier]])
|
||||
{
|
||||
SULog(@"%@ server: could not register server. Is one already running?\n", args.firstObject);
|
||||
}
|
||||
|
||||
[application setDelegate:appInstaller];
|
||||
[application run];
|
||||
|
||||
// Ensure connection is not deallocated by ARC before caling -[NSApplication run]
|
||||
[connection class];
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
//
|
||||
// TerminationListener.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TerminationListener : NSObject
|
||||
|
||||
- (instancetype)initWithProcessIdentifier:(NSNumber * _Nullable)processIdentifier;
|
||||
|
||||
@property (nonatomic, readonly) BOOL terminated;
|
||||
|
||||
// If the process identifier provided was nil, then the completion block will invoke immediately with a YES success
|
||||
- (void)startListeningWithCompletion:(void (^)(BOOL success))completionBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,131 +0,0 @@
|
||||
//
|
||||
// TerminationListener.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/7/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TerminationListener.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface TerminationListener ()
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSNumber *processIdentifier;
|
||||
@property (nonatomic) BOOL watchedTermination;
|
||||
@property (nonatomic, copy) void (^completionBlock)(BOOL);
|
||||
|
||||
@end
|
||||
|
||||
@implementation TerminationListener
|
||||
|
||||
@synthesize completionBlock = _completionBlock;
|
||||
@synthesize processIdentifier = _processIdentifier;
|
||||
@synthesize watchedTermination = _watchedTermination;
|
||||
|
||||
- (instancetype)initWithProcessIdentifier:(NSNumber * _Nullable)processIdentifier
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_processIdentifier = processIdentifier;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)terminated
|
||||
{
|
||||
return (self.watchedTermination || self.processIdentifier == nil) ? YES : (kill(self.processIdentifier.intValue, 0) != 0);
|
||||
}
|
||||
|
||||
- (void)invokeCompletionWithSuccess:(BOOL)success
|
||||
{
|
||||
if (self.completionBlock != nil) {
|
||||
self.completionBlock(success);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startListeningWithCompletion:(void (^)(BOOL))completionBlock
|
||||
{
|
||||
self.completionBlock = completionBlock;
|
||||
|
||||
if (self.processIdentifier == nil) {
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
// Use kqueues to determine when the process will terminate
|
||||
// As described in https://developer.apple.com/library/mac/technotes/tn2050/_index.html#//apple_ref/doc/uid/DTS10003081-CH1-SUBSECTION10
|
||||
// By using kqueues, we can stay away from using AppKit in case we ever decide to abandon it
|
||||
|
||||
pid_t processIdentifier = self.processIdentifier.intValue;
|
||||
int queue = kqueue();
|
||||
if (queue == -1) {
|
||||
SULog(SULogLevelError, @"Failed to create kqueue() due to error %d: %@", errno, @(strerror(errno)));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
struct kevent changes;
|
||||
EV_SET(&changes, processIdentifier, EVFILT_PROC, EV_ADD | EV_RECEIPT, NOTE_EXIT, 0, NULL);
|
||||
|
||||
if (kevent(queue, &changes, 1, &changes, 1, NULL) == -1) {
|
||||
SULog(SULogLevelError, @"Failed to invoke kevent() due to error %d: %@", errno, @(strerror(errno)));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
// We will assume this terminationListener will never be deallocated
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-qual"
|
||||
CFFileDescriptorContext context = { 0, (void *)CFBridgingRetain(self), NULL, NULL, NULL };
|
||||
#pragma clang diagnostic pop
|
||||
CFFileDescriptorRef noteExitKQueueRef = CFFileDescriptorCreate(NULL, queue, true, noteExitKQueueCallback, &context);
|
||||
if (noteExitKQueueRef == NULL) {
|
||||
SULog(SULogLevelError, @"Failed to create file descriptor via CFFileDescriptorCreate()");
|
||||
CFRelease((__bridge CFTypeRef)(self));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
CFRunLoopSourceRef runLoopSource = CFFileDescriptorCreateRunLoopSource(NULL, noteExitKQueueRef, 0);
|
||||
if (runLoopSource == NULL) {
|
||||
SULog(SULogLevelError, @"Failed to create runLoopSource via CFFileDescriptorCreateRunLoopSource()");
|
||||
CFRelease((__bridge CFTypeRef)(self));
|
||||
[self invokeCompletionWithSuccess:NO];
|
||||
return;
|
||||
}
|
||||
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopDefaultMode);
|
||||
CFRelease(runLoopSource);
|
||||
|
||||
CFFileDescriptorEnableCallBacks(noteExitKQueueRef, kCFFileDescriptorReadCallBack);
|
||||
|
||||
// Make sure we didn't set the listener callback to a dead PID
|
||||
// If we did, we could hang forever. To avoid this, we check if the process has terminated *after* we set up the callback
|
||||
// If we tried to do this check before setting the callback, we could run into an issue where the process can terminate after our check
|
||||
// but before setting the callback
|
||||
if ([self terminated]) {
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
}
|
||||
}
|
||||
|
||||
static void noteExitKQueueCallback(CFFileDescriptorRef file, CFOptionFlags __unused callBackTypes, void *info)
|
||||
{
|
||||
struct kevent event;
|
||||
kevent(CFFileDescriptorGetNativeDescriptor(file), NULL, 0, &event, 1, NULL);
|
||||
|
||||
TerminationListener *self = CFBridgingRelease(info);
|
||||
self.watchedTermination = YES;
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -2,21 +2,21 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
func die(_ msg: String) {
|
||||
print("ERROR: \(msg)")
|
||||
func die(msg: String) {
|
||||
println("ERROR: \(msg)")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
extension XMLElement {
|
||||
extension NSXMLElement {
|
||||
convenience init(name: String, attributes: [String: String], stringValue string: String? = nil) {
|
||||
self.init(name: name, stringValue: string)
|
||||
setAttributesWith(attributes)
|
||||
setAttributesWithDictionary(attributes)
|
||||
}
|
||||
}
|
||||
|
||||
let ud = UserDefaults.standard
|
||||
let sparkleRoot = ud.object(forKey: "root") as? String
|
||||
let htmlPath = ud.object(forKey: "htmlPath") as? String
|
||||
let ud = NSUserDefaults.standardUserDefaults()
|
||||
let sparkleRoot = ud.objectForKey("root") as? String
|
||||
let htmlPath = ud.objectForKey("htmlPath") as? String
|
||||
if sparkleRoot == nil || htmlPath == nil {
|
||||
die("Missing arguments")
|
||||
}
|
||||
@@ -28,37 +28,37 @@ if enStringsDict == nil {
|
||||
}
|
||||
let enStringsDictKeys = enStringsDict!.allKeys
|
||||
|
||||
let dirPath = NSString(string: sparkleRoot! + "/Sparkle")
|
||||
let dirContents = try! FileManager.default.contentsOfDirectory(atPath: dirPath as String)
|
||||
let dirPath = sparkleRoot! + "/Sparkle"
|
||||
let dirContents = NSFileManager.defaultManager().contentsOfDirectoryAtPath(dirPath, error: nil) as! [String]
|
||||
let css =
|
||||
"body { font-family: sans-serif; font-size: 10pt; }" +
|
||||
"h1 { font-size: 12pt; }" +
|
||||
".missing { background-color: #FFBABA; color: #D6010E; white-space: pre; }" +
|
||||
".unused { background-color: #BDE5F8; color: #00529B; white-space: pre; }" +
|
||||
".unlocalized { background-color: #FEEFB3; color: #9F6000; white-space: pre; }"
|
||||
var html = XMLDocument(rootElement: XMLElement(name: "html"))
|
||||
html.dtd = XMLDTD()
|
||||
html.dtd!.name = html.rootElement()!.name
|
||||
var html = NSXMLDocument(rootElement: NSXMLElement(name: "html"))
|
||||
html.DTD = NSXMLDTD()
|
||||
html.DTD!.name = html.rootElement()!.name
|
||||
html.characterEncoding = "UTF-8"
|
||||
html.documentContentKind = XMLDocument.ContentKind.xhtml
|
||||
var body = XMLElement(name: "body")
|
||||
var head = XMLElement(name: "head")
|
||||
html.documentContentKind = NSXMLDocumentContentKind.XHTMLKind
|
||||
var body = NSXMLElement(name: "body")
|
||||
var head = NSXMLElement(name: "head")
|
||||
html.rootElement()!.addChild(head)
|
||||
html.rootElement()!.addChild(body)
|
||||
head.addChild(XMLElement(name: "meta", attributes: ["charset": html.characterEncoding!]))
|
||||
head.addChild(XMLElement(name: "title", stringValue: "Sparkle Localizations Report"))
|
||||
head.addChild(XMLElement(name: "style", stringValue: css))
|
||||
head.addChild(NSXMLElement(name: "meta", attributes: ["charset": html.characterEncoding!]))
|
||||
head.addChild(NSXMLElement(name: "title", stringValue: "Sparkle Localizations Report"))
|
||||
head.addChild(NSXMLElement(name: "style", stringValue: css))
|
||||
|
||||
let locale = Locale.current
|
||||
let locale = NSLocale.currentLocale()
|
||||
for dirEntry in dirContents {
|
||||
if NSString(string: dirEntry).pathExtension != "lproj" || dirEntry == "en.lproj" {
|
||||
if dirEntry.pathExtension != "lproj" || dirEntry == "en.lproj" {
|
||||
continue
|
||||
}
|
||||
|
||||
let lang = (locale as NSLocale).displayName(forKey: NSLocale.Key.languageCode, value: NSString(string: dirEntry).deletingPathExtension)
|
||||
body.addChild(XMLElement(name: "h1", stringValue: "\(dirEntry) (\(lang!))"))
|
||||
let lang = locale.displayNameForKey(NSLocaleLanguageCode, value: dirEntry.stringByDeletingPathExtension)
|
||||
body.addChild(NSXMLElement(name: "h1", stringValue: "\(dirEntry) (\(lang!))"))
|
||||
|
||||
let stringsPath = NSString(string: dirPath.appendingPathComponent(dirEntry)).appendingPathComponent("Sparkle.strings")
|
||||
let stringsPath = dirPath.stringByAppendingPathComponent(dirEntry).stringByAppendingPathComponent("Sparkle.strings")
|
||||
let stringsDict = NSDictionary(contentsOfFile: stringsPath)
|
||||
if stringsDict == nil {
|
||||
die("Invalid strings file \(dirEntry)")
|
||||
@@ -70,10 +70,10 @@ for dirEntry in dirContents {
|
||||
var unused: [String] = []
|
||||
|
||||
for key in enStringsDictKeys {
|
||||
let str = stringsDict?.object(forKey: key) as? String
|
||||
let str = stringsDict?.objectForKey(key) as? String
|
||||
if str == nil {
|
||||
missing.append(key as! String)
|
||||
} else if let enStr = enStringsDict?.object(forKey: key) as? String {
|
||||
} else if let enStr = enStringsDict?.objectForKey(key) as? String {
|
||||
if enStr == str {
|
||||
unlocalized.append(key as! String)
|
||||
}
|
||||
@@ -82,7 +82,7 @@ for dirEntry in dirContents {
|
||||
|
||||
let stringsDictKeys = stringsDict!.allKeys
|
||||
for key in stringsDictKeys {
|
||||
if enStringsDict?.object(forKey: key) == nil {
|
||||
if enStringsDict?.objectForKey(key) == nil {
|
||||
unused.append(key as! String)
|
||||
}
|
||||
}
|
||||
@@ -90,12 +90,12 @@ for dirEntry in dirContents {
|
||||
let sorter = { (s1: String, s2: String) -> Bool in
|
||||
return s1 < s2
|
||||
}
|
||||
missing.sort(by: sorter)
|
||||
unlocalized.sort(by: sorter)
|
||||
unused.sort(by: sorter)
|
||||
missing.sort(sorter)
|
||||
unlocalized.sort(sorter)
|
||||
unused.sort(sorter)
|
||||
|
||||
let addRow = { (prefix: String, cssClass: String, key: String) -> Void in
|
||||
body.addChild(XMLElement(name: "span", attributes: ["class": cssClass], stringValue: [prefix, key].joined(separator: " ") + "\n"))
|
||||
body.addChild(NSXMLElement(name: "span", attributes: ["class": cssClass], stringValue: " ".join([prefix, key]) + "\n"))
|
||||
}
|
||||
|
||||
for key in missing {
|
||||
@@ -110,6 +110,6 @@ for dirEntry in dirContents {
|
||||
}
|
||||
|
||||
var err: NSError?
|
||||
if !((try? html.xmlData.write(to: URL(fileURLWithPath: htmlPath!), options: [.atomic])) != nil) {
|
||||
die("Can't write report: \(err!)")
|
||||
if !html.XMLData.writeToFile(htmlPath!, atomically: true) {
|
||||
die("Can't write report: \(err)")
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// DevMateSparkle.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 10/1/14.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef Sparkle_DevMateSparkle_h
|
||||
#define Sparkle_DevMateSparkle_h
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
// If you are using your own copy of Sparkle.framework just define
|
||||
// USED_CUSTOM_SPARKLE_FRAMEWORK macro.
|
||||
#ifndef USED_CUSTOM_SPARKLE_FRAMEWORK
|
||||
|
||||
#define SUUpdater DM_SUUpdater
|
||||
#define SUUpdaterQueue DM_SUUpdaterQueue
|
||||
#define SUAppcast DM_SUAppcast
|
||||
#define SUAppcastItem DM_SUAppcastItem
|
||||
#define SUUpdaterDelegate DM_SUUpdaterDelegate
|
||||
#define SUUpdaterDelegate_DevMateInteraction DM_SUUpdaterDelegate_DevMateInteraction
|
||||
#define SUVersionComparison DM_SUVersionComparison
|
||||
#define SUStandardVersionComparator DM_SUStandardVersionComparator
|
||||
#define SUVersionDisplay DM_SUVersionDisplay
|
||||
|
||||
#import <DevMateSparkle/SUExport.h>
|
||||
#import <DevMateSparkle/SUUpdater.h>
|
||||
#import <DevMateSparkle/SUUpdaterQueue.h>
|
||||
#import <DevMateSparkle/SUAppcast.h>
|
||||
#import <DevMateSparkle/SUAppcastItem.h>
|
||||
#import <DevMateSparkle/SUVersionComparisonProtocol.h>
|
||||
#import <DevMateSparkle/SUStandardVersionComparator.h>
|
||||
#import <DevMateSparkle/SUVersionDisplayProtocol.h>
|
||||
#import <DevMateSparkle/SUErrors.h>
|
||||
|
||||
#endif // USED_CUSTOM_SPARKLE_FRAMEWORK
|
||||
|
||||
#endif // Sparkle_DevMateSparkle_h
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// DevMateSparkle.pch
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 10/1/14.
|
||||
//
|
||||
//
|
||||
|
||||
#define SUUpdater DM_SUUpdater
|
||||
#define SUUpdaterQueue DM_SUUpdaterQueue
|
||||
#define SUAppcast DM_SUAppcast
|
||||
#define SUAppcastItem DM_SUAppcastItem
|
||||
#define SUUpdaterDelegate DM_SUUpdaterDelegate
|
||||
#define SUUpdaterDelegate_DevMateInteraction DM_SUUpdaterDelegate_DevMateInteraction
|
||||
#define SUVersionComparison DM_SUVersionComparison
|
||||
#define SUStandardVersionComparator DM_SUStandardVersionComparator
|
||||
#define SUVersionDisplay DM_SUVersionDisplay
|
||||
|
||||
#define SUPackageInstaller DM_SUPackageInstaller
|
||||
#define SUDSAVerifier DM_SUDSAVerifier
|
||||
#define SUUpdateAlert DM_SUUpdateAlert
|
||||
#define SUUIBasedUpdateDriver DM_SUUIBasedUpdateDriver
|
||||
#define SUSystemProfiler DM_SUSystemProfiler
|
||||
#define SUXPCInstaller DM_SUXPCInstaller
|
||||
#define SUPlainInstaller DM_SUPlainInstaller
|
||||
#define SUUpdatePermissionPrompt DM_SUUpdatePermissionPrompt
|
||||
#define SUUnarchiver DM_SUUnarchiver
|
||||
#define SUUserInitiatedUpdateDriver DM_SUUserInitiatedUpdateDriver
|
||||
#define SUUpdateDriver DM_SUUpdateDriver
|
||||
#define SUProbingUpdateDriver DM_SUProbingUpdateDriver
|
||||
#define SUAutomaticUpdateAlert DM_SUAutomaticUpdateAlert
|
||||
#define SUBasicUpdateDriver DM_SUBasicUpdateDriver
|
||||
#define SUWindowController DM_SUWindowController
|
||||
#define SUStatusController DM_SUStatusController
|
||||
#define SUHost DM_SUHost
|
||||
#define SUPipedUnarchiver DM_SUPipedUnarchiver
|
||||
#define SUAutomaticUpdateDriver DM_SUAutomaticUpdateDriver
|
||||
#define SUCodeSigningVerifier DM_SUCodeSigningVerifier
|
||||
#define SUBinaryDeltaUnarchiver DM_SUBinaryDeltaUnarchiver
|
||||
#define SUDelegateProxy DM_SUDelegateProxy
|
||||
#define SUInstaller DM_SUInstaller
|
||||
#define SUScheduledUpdateDriver DM_SUScheduledUpdateDriver
|
||||
#define SUDiskImageUnarchiver DM_SUDiskImageUnarchiver
|
||||
#define SUGuidedPackageInstaller DM_SUGuidedPackageInstaller
|
||||
#define NTSynchronousTask DM_NTSynchronousTask
|
||||
#define SUUpdaterWorking DM_SUUpdater // Used in SUUpdaterLoader.m file
|
||||
#define SUUpdaterLoader DM_SUUpdaterLoader
|
||||
|
||||
#import "Sparkle.pch"
|
||||
|
||||
@@ -3,22 +3,29 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>XPCService</key>
|
||||
<dict>
|
||||
<key>ServiceType</key>
|
||||
<string>Application</string>
|
||||
<key>JoinExistingSession</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,4 @@
|
||||
//
|
||||
// Prefix header for all source files of the 'Downloading XPC Service' target in the 'Downloading XPC Service' project
|
||||
//
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// SUDSDownloader.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 8/1/13.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#define DEBUG_LOGGING_ENABLED defined(DEBUG) && 1
|
||||
|
||||
@class SUDSDownloader;
|
||||
|
||||
typedef void (^SUDSDownloadDidBegin)(SUDSDownloader *downloader);
|
||||
typedef void (^SUDSDownloadDidFinish)(SUDSDownloader *downloader);
|
||||
typedef void (^SUDSDownloadDidFail)(SUDSDownloader *downloader, NSError *error);
|
||||
typedef void (^SUDSDownloadDidReceiveResponse)(SUDSDownloader *downloader, NSURLResponse *response);
|
||||
typedef void (^SUDSDownloadDidReceiveData)(SUDSDownloader *downloader, NSUInteger dataLength);
|
||||
typedef void (^SUDSDownloadDidCreateDestination)(SUDSDownloader *downloader, NSString *destinationPath);
|
||||
typedef BOOL (^SUDSDownloadShouldDecodeSourceData)(SUDSDownloader *downloader, NSString *MIMEType);
|
||||
|
||||
typedef struct SUDSDownloaderCallBacks
|
||||
{
|
||||
SUDSDownloadDidBegin downloadDidBegin;
|
||||
SUDSDownloadDidFinish downloadDidFinish;
|
||||
SUDSDownloadDidFail downloadDidFail;
|
||||
|
||||
SUDSDownloadDidReceiveResponse downloadDidReceiveResponse;
|
||||
SUDSDownloadDidReceiveData downloadDidReceiveData;
|
||||
SUDSDownloadDidCreateDestination downloadDidCreateDestination;
|
||||
|
||||
SUDSDownloadShouldDecodeSourceData downloadShouldDecodeSourceData;
|
||||
} SUDSDownloaderCallBacks;
|
||||
|
||||
FOUNDATION_EXTERN SUDSDownloaderCallBacks SUDSCopyDownloaderCallBacks(SUDSDownloaderCallBacks callBacks);
|
||||
FOUNDATION_EXTERN void SUDSReleaseDownloaderCallBacks(SUDSDownloaderCallBacks callBacks);
|
||||
|
||||
@interface SUDSDownloader : NSObject <NSURLDownloadDelegate>
|
||||
{
|
||||
@private
|
||||
NSURLRequest *_request;
|
||||
NSString *_destFilePath;
|
||||
SUDSDownloaderCallBacks _callBacks;
|
||||
|
||||
NSURLDownload *_download;
|
||||
}
|
||||
|
||||
- (id)initWithURLRequest:(NSURLRequest *)request destinationPath:(NSString *)filePath;
|
||||
+ (id)downloaderWithURLRequest:(NSURLRequest *)request destinationPath:(NSString *)filePath;
|
||||
|
||||
- (NSURLRequest *)request;
|
||||
- (NSString *)destinationPath;
|
||||
- (void)setCallBacks:(SUDSDownloaderCallBacks)callBacks;
|
||||
|
||||
- (void)startDownload;
|
||||
- (void)stopDownload;
|
||||
- (BOOL)isInProgress;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,210 @@
|
||||
//
|
||||
// SUDSDownloader.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 8/1/13.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SUDSDownloader.h"
|
||||
|
||||
SUDSDownloaderCallBacks SUDSCopyDownloaderCallBacks(SUDSDownloaderCallBacks callBacks)
|
||||
{
|
||||
SUDSDownloaderCallBacks callBacksCopy = {0};
|
||||
|
||||
if (callBacks.downloadDidBegin)
|
||||
callBacksCopy.downloadDidBegin = Block_copy(callBacks.downloadDidBegin);
|
||||
if (callBacks.downloadDidFinish)
|
||||
callBacksCopy.downloadDidFinish = Block_copy(callBacks.downloadDidFinish);
|
||||
if (callBacks.downloadDidFail)
|
||||
callBacksCopy.downloadDidFail = Block_copy(callBacks.downloadDidFail);
|
||||
if (callBacks.downloadDidReceiveData)
|
||||
callBacksCopy.downloadDidReceiveData = Block_copy(callBacks.downloadDidReceiveData);
|
||||
if (callBacks.downloadDidCreateDestination)
|
||||
callBacksCopy.downloadDidCreateDestination = Block_copy(callBacks.downloadDidCreateDestination);
|
||||
if (callBacks.downloadDidReceiveResponse)
|
||||
callBacksCopy.downloadDidReceiveResponse = Block_copy(callBacks.downloadDidReceiveResponse);
|
||||
if (callBacks.downloadShouldDecodeSourceData)
|
||||
callBacksCopy.downloadShouldDecodeSourceData = Block_copy(callBacks.downloadShouldDecodeSourceData);
|
||||
|
||||
return callBacksCopy;
|
||||
}
|
||||
|
||||
void SUDSReleaseDownloaderCallBacks(SUDSDownloaderCallBacks callBacks)
|
||||
{
|
||||
if (callBacks.downloadDidBegin)
|
||||
Block_release(callBacks.downloadDidBegin);
|
||||
if (callBacks.downloadDidFinish)
|
||||
Block_release(callBacks.downloadDidFinish);
|
||||
if (callBacks.downloadDidFail)
|
||||
Block_release(callBacks.downloadDidFail);
|
||||
if (callBacks.downloadDidReceiveData)
|
||||
Block_release(callBacks.downloadDidReceiveData);
|
||||
if (callBacks.downloadDidCreateDestination)
|
||||
Block_release(callBacks.downloadDidCreateDestination);
|
||||
if (callBacks.downloadDidReceiveResponse)
|
||||
Block_release(callBacks.downloadDidReceiveResponse);
|
||||
if (callBacks.downloadShouldDecodeSourceData)
|
||||
Block_release(callBacks.downloadShouldDecodeSourceData);
|
||||
}
|
||||
|
||||
@implementation SUDSDownloader
|
||||
|
||||
- (id)initWithURLRequest:(NSURLRequest *)request destinationPath:(NSString *)filePath
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_request = [request retain];
|
||||
_destFilePath = [filePath copy];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (id)downloaderWithURLRequest:(NSURLRequest *)request destinationPath:(NSString *)filePath
|
||||
{
|
||||
return [[[[self class] alloc] initWithURLRequest:request destinationPath:filePath] autorelease];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self stopDownload];
|
||||
|
||||
[_request release];
|
||||
[_destFilePath release];
|
||||
SUDSReleaseDownloaderCallBacks(_callBacks);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSURLRequest *)request
|
||||
{
|
||||
return _request;
|
||||
}
|
||||
|
||||
- (NSString *)destinationPath
|
||||
{
|
||||
return _destFilePath;
|
||||
}
|
||||
|
||||
- (void)setCallBacks:(SUDSDownloaderCallBacks)callBacks
|
||||
{
|
||||
SUDSDownloaderCallBacks oldCallBacks = _callBacks;
|
||||
_callBacks = SUDSCopyDownloaderCallBacks(callBacks);
|
||||
SUDSReleaseDownloaderCallBacks(oldCallBacks);
|
||||
}
|
||||
|
||||
- (void)startDownload
|
||||
{
|
||||
[self stopDownload];
|
||||
|
||||
// to ensure that parent folder exists
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:[_destFilePath stringByDeletingLastPathComponent]
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:NULL];
|
||||
NSURLDownload *urlDownload = [[NSURLDownload alloc] initWithRequest:_request delegate:self];
|
||||
@synchronized (self)
|
||||
{
|
||||
_download = urlDownload;
|
||||
}
|
||||
|
||||
[urlDownload setDestination:_destFilePath allowOverwrite:YES];
|
||||
}
|
||||
|
||||
- (void)stopDownload
|
||||
{
|
||||
@synchronized (self)
|
||||
{
|
||||
[_download cancel];
|
||||
[_download release];
|
||||
_download = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isInProgress
|
||||
{
|
||||
BOOL result = YES;
|
||||
@synchronized (self)
|
||||
{
|
||||
result = _download != nil;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)downloadDidBegin:(NSURLDownload *)download
|
||||
{
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader did begin process.");
|
||||
#endif
|
||||
if (_callBacks.downloadDidBegin)
|
||||
_callBacks.downloadDidBegin(self);
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
|
||||
{
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader did receive response: %@", [response description]);
|
||||
#endif
|
||||
if (_callBacks.downloadDidReceiveResponse)
|
||||
_callBacks.downloadDidReceiveResponse(self, response);
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)download didCreateDestination:(NSString *)path
|
||||
{
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader did create destination: %@", path);
|
||||
#endif
|
||||
if (_callBacks.downloadDidCreateDestination)
|
||||
_callBacks.downloadDidCreateDestination(self, path);
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length
|
||||
{
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader did receive data of length %ld bytes", (unsigned long)length);
|
||||
#endif
|
||||
if (_callBacks.downloadDidReceiveData)
|
||||
_callBacks.downloadDidReceiveData(self, length);
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
|
||||
{
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader did fail: %@", [error description]);
|
||||
#endif
|
||||
if (_callBacks.downloadDidFail)
|
||||
_callBacks.downloadDidFail(self, error);
|
||||
|
||||
[self stopDownload];
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)download
|
||||
{
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader did finish");
|
||||
#endif
|
||||
if (_callBacks.downloadDidFinish)
|
||||
_callBacks.downloadDidFinish(self);
|
||||
|
||||
[self stopDownload];
|
||||
}
|
||||
|
||||
- (BOOL)download:(NSURLDownload *)download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType
|
||||
{
|
||||
BOOL shouldDecode = NO;
|
||||
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"XPC Downloader wants decode source data of MIME type: %@", encodingType);
|
||||
#endif
|
||||
if (_callBacks.downloadShouldDecodeSourceData)
|
||||
shouldDecode = _callBacks.downloadShouldDecodeSourceData(self, encodingType);
|
||||
|
||||
return shouldDecode;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// SUDownloadServiceConstants.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 7/29/13.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef Sparkle_SUDownloadServiceConstants_h
|
||||
#define Sparkle_SUDownloadServiceConstants_h
|
||||
|
||||
const char * SUDownloadServiceURLRequestDataKey = "request_data"; // data of archived NSURLRequest
|
||||
const char * SUDownloadServiceDelegateConnectionKey = "connection"; // xpc_connection_t
|
||||
const char * SUDownloadServiceFilePathKey = "file_path"; // c-string
|
||||
|
||||
const char * SUDownloadServiceReceivedDataLengthKey = "received_data_length"; // int64_t
|
||||
const char * SUDownloadServiceReceivedResponseDataKey = "received_response_data"; // data of archived NSURLResponse
|
||||
const char * SUDownloadServiceCreatedDestinationPathKey = "created_destination_path"; // c-string
|
||||
const char * SUDownloadServiceDidBeginDownloadingKey = "did_begin_downloading"; // bool 1
|
||||
const char * SUDownloadServiceDidFinishDownloadingKey = "did_finish_downloading"; // bool 1
|
||||
const char * SUDownloadServiceReceivedFailErrorKey = "received_fail_error"; // data of archived NSError
|
||||
const char * SUDownloadServiceMIMETypeToDecodeKey = "MIME_type_to_decode"; // c-string
|
||||
const char * SUDownloadServiceShouldDecodeMIMETypeKey = "should_decode_MIME_type"; // bool
|
||||
|
||||
const char * SUDownloadServiceErrorCodeKey = "errcode"; // int64_t
|
||||
const char * SUDownloadServiceErrorMessageKey = "errmsg"; // c-string
|
||||
const char * SUDownloadServiceErrorDomainKey = "errdomain"; // c-string
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// SUXPCURLDownload.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Erik Aderstedt on 2012-08-09.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUXPCURLDownload : NSObject
|
||||
{
|
||||
@private
|
||||
id <NSURLDownloadDelegate> _delegate; // weak ref
|
||||
xpc_connection_t _connection;
|
||||
xpc_connection_t _delegateConnection;
|
||||
NSURLRequest *_request;
|
||||
NSThread *_startedThread; // weak ref
|
||||
BOOL _isDownloading;
|
||||
|
||||
BOOL _allowOverwrite;
|
||||
NSString *_destination;
|
||||
NSString *_connectionDestination;
|
||||
NSError *_downloadError;
|
||||
}
|
||||
|
||||
- (id <NSURLDownloadDelegate>)delegate;
|
||||
- (void)setDelegate:(id <NSURLDownloadDelegate>)delegate;
|
||||
|
||||
- (id)initWithRequest:(NSURLRequest *)request delegate:(id <NSURLDownloadDelegate>)delegate;
|
||||
- (void)setDestination:(NSString *)path allowOverwrite:(BOOL)allowOverwrite;
|
||||
|
||||
// Delegate methods for this method will be called from another thread.
|
||||
+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request delegate:(id <NSURLDownloadDelegate>)delegate;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,448 @@
|
||||
//
|
||||
// SUXPCURLDownload.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Erik Aderstedt on 2012-08-09.
|
||||
//
|
||||
//
|
||||
|
||||
#import "SUXPCURLDownload.h"
|
||||
#import "SUDownloadServiceConstants.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
static NSString * const kSUFetchFolderName = @"fetch.XXXXXXXX";
|
||||
|
||||
@interface SUXPCURLDownload (Private)
|
||||
|
||||
- (void)performBlock:(void (^)(void))block onThread:(NSThread *)thread synchronous:(BOOL)flag;
|
||||
- (void)fireBlock:(void (^)(void))block;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUXPCURLDownload
|
||||
|
||||
+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request delegate:(id <NSURLDownloadDelegate>)delegate
|
||||
{
|
||||
__block SUXPCURLDownload *download = nil;
|
||||
|
||||
static const char *sSynchronousDownloadQueueName = "com.devmate.SynchronousXPCDownloadQueue";
|
||||
dispatch_queue_t queue = dispatch_queue_create(sSynchronousDownloadQueueName, NULL);
|
||||
dispatch_sync(queue, ^{
|
||||
download = [[SUXPCURLDownload alloc] initWithRequest:request delegate:delegate];
|
||||
});
|
||||
|
||||
while (download && download->_isDownloading)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
|
||||
}
|
||||
|
||||
NSData *downloadData = (nil == download->_downloadError) ? [NSData dataWithContentsOfFile:download->_destination] : nil;
|
||||
[download release];
|
||||
dispatch_release(queue);
|
||||
|
||||
return downloadData;
|
||||
}
|
||||
|
||||
- (id)initWithRequest:(NSURLRequest *)request delegate:(id <NSURLDownloadDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_request = [request retain];
|
||||
_delegate = [delegate retain];
|
||||
_startedThread = [NSThread currentThread];
|
||||
|
||||
// Set up a connection.
|
||||
_connection = [self getSandboxXPCService];
|
||||
dispatch_async(dispatch_get_current_queue(), ^{
|
||||
[self startDownload:request];
|
||||
});
|
||||
|
||||
_isDownloading = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self cancel];
|
||||
|
||||
[_request release];
|
||||
[_destination release];
|
||||
[_connectionDestination release];
|
||||
[_downloadError release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSURLRequest *)request
|
||||
{
|
||||
return _request;
|
||||
}
|
||||
|
||||
- (void)startDownload:(NSURLRequest *)urlRequest
|
||||
{
|
||||
// Send a message to download a specific url.
|
||||
if ([_delegate respondsToSelector:@selector(download:decideDestinationWithSuggestedFilename:)] && _destination == nil)
|
||||
{
|
||||
void (^block)(void) = ^{
|
||||
[_delegate download:(NSURLDownload *)self decideDestinationWithSuggestedFilename:[[urlRequest URL] lastPathComponent]];
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:YES];
|
||||
}
|
||||
if (nil == _destination)
|
||||
{
|
||||
_destination = [[[urlRequest URL] lastPathComponent] copy];
|
||||
}
|
||||
|
||||
// ivar 'destination' now contains the destination URL.
|
||||
|
||||
NSURL *tempFolder = [NSURL fileURLWithPath:NSTemporaryDirectory()];
|
||||
NSString *tempFileTemplate = [[tempFolder URLByAppendingPathComponent:kSUFetchFolderName] path];
|
||||
NSString *tempFilePath = [tempFileTemplate stringByAppendingPathComponent:[_destination lastPathComponent]];
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if ([fileManager fileExistsAtPath:tempFilePath])
|
||||
[fileManager removeItemAtPath:tempFilePath error:nil];
|
||||
|
||||
_connectionDestination = [tempFilePath copy];
|
||||
|
||||
NSData *requestData = [NSKeyedArchiver archivedDataWithRootObject:urlRequest];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_data(message, SUDownloadServiceURLRequestDataKey, [requestData bytes], [requestData length]);
|
||||
xpc_dictionary_set_string(message, SUDownloadServiceFilePathKey, [tempFilePath cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
xpc_dictionary_set_connection(message, SUDownloadServiceDelegateConnectionKey, _delegateConnection);
|
||||
xpc_connection_send_message_with_reply(_connection, message, dispatch_get_main_queue(), ^(xpc_object_t object) {
|
||||
xpc_type_t type = xpc_get_type(object);
|
||||
|
||||
if (type == XPC_TYPE_ERROR && nil == _downloadError)
|
||||
{
|
||||
NSString *errMessage = @"";
|
||||
if (object == XPC_ERROR_CONNECTION_INTERRUPTED)
|
||||
{
|
||||
errMessage = @"Got XPC_ERROR_CONNECTION_INTERRUPTED error.";
|
||||
}
|
||||
else if (object == XPC_ERROR_CONNECTION_INVALID)
|
||||
{
|
||||
errMessage = @"Got XPC_ERROR_CONNECTION_INVALID error.";
|
||||
}
|
||||
|
||||
NSDictionary *errInfo = [NSDictionary dictionaryWithObject:errMessage forKey:NSLocalizedDescriptionKey];
|
||||
_downloadError = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errInfo];
|
||||
}
|
||||
else if (type == XPC_TYPE_DICTIONARY && noErr != xpc_dictionary_get_int64(object, SUDownloadServiceErrorCodeKey) && nil == _downloadError)
|
||||
{
|
||||
NSInteger errCode = (NSInteger)xpc_dictionary_get_int64(object, SUDownloadServiceErrorCodeKey);
|
||||
|
||||
const char *errDomainStr = xpc_dictionary_get_string(object, SUDownloadServiceErrorDomainKey);
|
||||
NSString *errDomain = errDomainStr ? [NSString stringWithUTF8String:errDomainStr] : NSCocoaErrorDomain;
|
||||
|
||||
const char *errMessage = xpc_dictionary_get_string(object, SUDownloadServiceErrorMessageKey) ? : "";
|
||||
NSDictionary *errInfo = [NSDictionary dictionaryWithObject:[NSString stringWithUTF8String:errMessage]
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
|
||||
_downloadError = [[NSError alloc] initWithDomain:errDomain code:errCode userInfo:errInfo];
|
||||
}
|
||||
|
||||
if (nil != _downloadError)
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(download:didFailWithError:)])
|
||||
{
|
||||
void (^block)(void) = ^{
|
||||
[_delegate download:(NSURLDownload *)self didFailWithError:_downloadError];
|
||||
_isDownloading = NO;
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
SULog(@"SUXPCURLDownload: got download error (%d - %@)", [_downloadError code], [_downloadError localizedDescription]);
|
||||
_isDownloading = NO;
|
||||
}
|
||||
}
|
||||
});
|
||||
xpc_release(message);
|
||||
}
|
||||
|
||||
- (id <NSURLDownloadDelegate>)delegate
|
||||
{
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id <NSURLDownloadDelegate>)delegate
|
||||
{
|
||||
_delegate = delegate;
|
||||
}
|
||||
|
||||
- (void)setDestination:(NSString *)path allowOverwrite:(BOOL)allowOverwrite
|
||||
{
|
||||
[_destination release];
|
||||
_destination = [path copy];
|
||||
_allowOverwrite = allowOverwrite;
|
||||
}
|
||||
|
||||
- (void)cancel
|
||||
{
|
||||
if (_connection)
|
||||
{
|
||||
xpc_connection_cancel(_connection);
|
||||
xpc_release(_connection);
|
||||
_connection = NULL;
|
||||
}
|
||||
if (_delegateConnection)
|
||||
{
|
||||
xpc_connection_cancel(_delegateConnection);
|
||||
xpc_release(_delegateConnection);
|
||||
_delegateConnection = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
- (xpc_connection_t)getSandboxXPCService
|
||||
{
|
||||
// Set up two connections, one for instructing the XPC and getting a response,
|
||||
// and another to listen for incoming connections for progress and file creation
|
||||
// notifications.
|
||||
|
||||
_connection = xpc_connection_create("com.devmate.UpdateDownloader", dispatch_get_main_queue());
|
||||
if (!_connection)
|
||||
{
|
||||
NSLog(@"Can't connect to XPC service");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
xpc_connection_set_event_handler(_connection, ^(xpc_object_t event) {
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
{
|
||||
if (event == XPC_ERROR_CONNECTION_INTERRUPTED)
|
||||
{
|
||||
NSLog(@"Got XPC_ERROR_CONNECTION_INTERRUPTED error.");
|
||||
// The service has either cancaled itself, crashed, or been
|
||||
// terminated. The XPC connection is still valid and sending a
|
||||
// message to it will re-launch the service. If the service is
|
||||
// state-full, this is the time to initialize the new service.
|
||||
|
||||
}
|
||||
else if (event == XPC_ERROR_CONNECTION_INVALID)
|
||||
{
|
||||
NSLog(@"Got XPC_ERROR_CONNECTION_INVALID error.");
|
||||
// The service is invalid. Either the service name supplied to
|
||||
// xpc_connection_create() is incorrect or we (this process) have
|
||||
// canceled the service; we can do any cleanup of appliation
|
||||
// state at this point.
|
||||
if (_delegateConnection)
|
||||
{
|
||||
xpc_connection_cancel(_delegateConnection);
|
||||
xpc_release(_delegateConnection);
|
||||
_delegateConnection = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dispatch_queue_t delegate_queue = dispatch_queue_create("com.devmate.UpdateDownloader.delegate", NULL);
|
||||
assert(delegate_queue != NULL);
|
||||
|
||||
_delegateConnection = xpc_connection_create(NULL, delegate_queue);
|
||||
xpc_connection_set_event_handler(_delegateConnection, ^(xpc_object_t event) {
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
{
|
||||
if (event == XPC_ERROR_TERMINATION_IMMINENT)
|
||||
{
|
||||
NSLog(@"received XPC_ERROR_TERMINATION_IMMINENT");
|
||||
}
|
||||
else if (event == XPC_ERROR_CONNECTION_INVALID)
|
||||
{
|
||||
NSLog(@"progress connection is closed");
|
||||
dispatch_release(delegate_queue);
|
||||
}
|
||||
}
|
||||
else if (type == XPC_TYPE_CONNECTION)
|
||||
{
|
||||
xpc_connection_t peer = (xpc_connection_t)event;
|
||||
// A new anonymous connection, from an XPC service that wants to supply us with updates.
|
||||
char *queue_name = NULL;
|
||||
dispatch_queue_t peer_event_queue = dispatch_queue_create(queue_name, NULL);
|
||||
assert(peer_event_queue != NULL);
|
||||
free(queue_name);
|
||||
|
||||
xpc_connection_set_target_queue(peer, peer_event_queue);
|
||||
xpc_connection_set_event_handler(peer, ^(xpc_object_t nevent) {
|
||||
xpc_type_t ntype = xpc_get_type(nevent);
|
||||
|
||||
if (ntype == XPC_TYPE_ERROR && nevent == XPC_ERROR_CONNECTION_INVALID)
|
||||
dispatch_release(peer_event_queue);
|
||||
if (ntype != XPC_TYPE_DICTIONARY)
|
||||
return;
|
||||
|
||||
__block xpc_object_t answer = xpc_dictionary_create_reply(nevent);
|
||||
|
||||
xpc_dictionary_apply(nevent, ^bool(const char *key, xpc_object_t value) {
|
||||
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
if (0 == strcmp(key, SUDownloadServiceDidBeginDownloadingKey))
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(downloadDidBegin:)])
|
||||
{
|
||||
void (^block)(void) = ^ {
|
||||
[_delegate downloadDidBegin:(NSURLDownload *)self];
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:NO];
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp(key, SUDownloadServiceReceivedResponseDataKey))
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(download:didReceiveResponse:)])
|
||||
{
|
||||
size_t dataLength = 0;
|
||||
const void * responseDataBytes = xpc_dictionary_get_data(nevent, SUDownloadServiceReceivedResponseDataKey, &dataLength);
|
||||
NSData *responseData = [NSData dataWithBytes:responseDataBytes length:(NSUInteger)dataLength];
|
||||
|
||||
NSURLResponse *response = [NSKeyedUnarchiver unarchiveObjectWithData:responseData];
|
||||
void (^block)(void) = ^ {
|
||||
[_delegate download:(NSURLDownload *)self didReceiveResponse:response];
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:NO];
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp(key, SUDownloadServiceReceivedDataLengthKey))
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(download:didReceiveDataOfLength:)])
|
||||
{
|
||||
int64_t dataLength = xpc_dictionary_get_int64(nevent, SUDownloadServiceReceivedDataLengthKey);
|
||||
void (^block)(void) = ^ {
|
||||
[_delegate download:(NSURLDownload *)self didReceiveDataOfLength:(NSUInteger)dataLength];
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:NO];
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp(key, SUDownloadServiceCreatedDestinationPathKey))
|
||||
{
|
||||
[_connectionDestination release];
|
||||
_connectionDestination = [[NSString alloc] initWithCString:xpc_dictionary_get_string(nevent, SUDownloadServiceCreatedDestinationPathKey)
|
||||
encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
else if (0 == strcmp(key, SUDownloadServiceReceivedFailErrorKey))
|
||||
{
|
||||
size_t dataLength = 0;
|
||||
const void * errorDataBytes = xpc_dictionary_get_data(nevent, SUDownloadServiceReceivedFailErrorKey, &dataLength);
|
||||
NSData *errorData = [NSData dataWithBytes:errorDataBytes length:dataLength];
|
||||
|
||||
NSError *error = [NSKeyedUnarchiver unarchiveObjectWithData:errorData];
|
||||
_downloadError = [error retain];
|
||||
}
|
||||
else if (0 == strcmp(key, SUDownloadServiceDidFinishDownloadingKey))
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
|
||||
NSString *destPath = _destination;
|
||||
if (nil == destPath || [destPath isEqualToString:[destPath lastPathComponent]])
|
||||
{
|
||||
destPath = _connectionDestination;
|
||||
}
|
||||
else if (!_allowOverwrite)
|
||||
{
|
||||
NSUInteger index = 1;
|
||||
NSString *parentFolder = [destPath stringByDeletingLastPathComponent];
|
||||
NSString *initialFileName = [[destPath lastPathComponent] stringByDeletingPathExtension];
|
||||
NSString *fileExtension = [destPath pathExtension];
|
||||
|
||||
while ([fileManager fileExistsAtPath:destPath])
|
||||
{
|
||||
NSString *fileName = [initialFileName stringByAppendingFormat:@"_%ld", index];
|
||||
destPath = [[parentFolder stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:fileExtension];
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
BOOL success = YES;
|
||||
|
||||
if (![destPath isEqualToString:_connectionDestination])
|
||||
{
|
||||
success = success && [fileManager createDirectoryAtPath:[destPath stringByDeletingLastPathComponent]
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error];
|
||||
if (success && [fileManager fileExistsAtPath:destPath])
|
||||
success = [fileManager removeItemAtPath:destPath error:&error];
|
||||
success = success && [fileManager moveItemAtPath:_connectionDestination toPath:destPath error:&error];
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
[self setDestination:destPath allowOverwrite:_allowOverwrite];
|
||||
|
||||
void (^block)(void) = ^ {
|
||||
if ([_delegate respondsToSelector:@selector(download:didCreateDestination:)])
|
||||
[_delegate download:(NSURLDownload *)self didCreateDestination:destPath];
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(downloadDidFinish:)])
|
||||
[_delegate downloadDidFinish:(NSURLDownload *)self];
|
||||
|
||||
_isDownloading = NO;
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
_downloadError = [error retain];
|
||||
}
|
||||
}
|
||||
else if (0 == strcmp(key, SUDownloadServiceMIMETypeToDecodeKey))
|
||||
{
|
||||
void (^block)(void) = ^{
|
||||
BOOL shouldDecode = NO;
|
||||
if ([_delegate respondsToSelector:@selector(download:shouldDecodeSourceDataOfMIMEType:)])
|
||||
{
|
||||
NSString *MIMEType = [NSString stringWithCString:xpc_dictionary_get_string(nevent, SUDownloadServiceMIMETypeToDecodeKey)
|
||||
encoding:NSUTF8StringEncoding];
|
||||
shouldDecode = [_delegate download:(NSURLDownload *)self shouldDecodeSourceDataOfMIMEType:MIMEType];
|
||||
}
|
||||
xpc_dictionary_set_bool(answer, SUDownloadServiceShouldDecodeMIMETypeKey, YES);
|
||||
};
|
||||
[self performBlock:block onThread:_startedThread synchronous:YES];
|
||||
}
|
||||
|
||||
[localPool release];
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
xpc_connection_send_message(peer, answer);
|
||||
xpc_release(answer);
|
||||
});
|
||||
xpc_connection_resume(peer);
|
||||
}
|
||||
});
|
||||
|
||||
// Need to resume the service in order for it to process messages.
|
||||
xpc_connection_resume(_delegateConnection);
|
||||
xpc_connection_resume(_connection);
|
||||
return _connection;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)performBlock:(void (^)(void))block onThread:(NSThread *)thread synchronous:(BOOL)flag
|
||||
{
|
||||
void (^blockCopy)(void) = block != NULL ? Block_copy(block) : NULL;
|
||||
[self performSelector:@selector(fireBlock:) onThread:thread withObject:blockCopy waitUntilDone:flag];
|
||||
}
|
||||
|
||||
- (void)fireBlock:(void (^)(void))block
|
||||
{
|
||||
if (NULL == block)
|
||||
return;
|
||||
|
||||
block();
|
||||
Block_release(block);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,265 @@
|
||||
//
|
||||
// main.m
|
||||
// Downloading XPC Service
|
||||
//
|
||||
// Created by Erik Aderstedt on 2012-08-09.
|
||||
// Based on the Apple sample code 'SandboxedFetch'.
|
||||
//
|
||||
|
||||
#import <xpc/xpc.h>
|
||||
#import <asl.h>
|
||||
#import <assert.h>
|
||||
#import <errno.h>
|
||||
#import <stdio.h>
|
||||
|
||||
#import "SUDownloadServiceConstants.h"
|
||||
#import "SUDSDownloader.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
static void fetch_process_request(xpc_object_t request, xpc_object_t reply);
|
||||
static void fetch_peer_event_handler(xpc_connection_t peer, xpc_object_t event);
|
||||
static void fetch_event_handler(xpc_connection_t peer);
|
||||
|
||||
#pragma mark -
|
||||
|
||||
// Process the XPC request, create a temporary file to hold downloaded,
|
||||
// data, and build/return XPC reply.
|
||||
static void fetch_process_request(xpc_object_t request, xpc_object_t reply)
|
||||
{
|
||||
__block int32_t errcode = 0;
|
||||
__block const char *errmsg = NULL;
|
||||
__block const char *errdomain = NULL;
|
||||
|
||||
xpc_connection_t connection = NULL;
|
||||
|
||||
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
|
||||
do
|
||||
{
|
||||
size_t dataLength = 0;
|
||||
const void *data = xpc_dictionary_get_data(request, SUDownloadServiceURLRequestDataKey, &dataLength);
|
||||
NSData *requestData = [NSData dataWithBytes:data length:dataLength];
|
||||
|
||||
NSURLRequest *urlRequest = [NSKeyedUnarchiver unarchiveObjectWithData:requestData];
|
||||
if (nil == urlRequest)
|
||||
{
|
||||
errcode = SUXPCServiceError;
|
||||
errdomain = [SUSparkleErrorDomain cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
errmsg = "Invalid URL request data";
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the URL and XPC connection from the XPC request
|
||||
connection = xpc_dictionary_create_connection(request, SUDownloadServiceDelegateConnectionKey);
|
||||
if (connection == NULL)
|
||||
{
|
||||
errcode = SUXPCServiceError;
|
||||
errdomain = [SUSparkleErrorDomain cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
errmsg = "Invalid XPC delegate connection";
|
||||
break;
|
||||
}
|
||||
|
||||
// Set up XPC connection endpoint for sending progress reports and receiving cancel notification.
|
||||
__block BOOL shouldStopDownload = NO;
|
||||
xpc_connection_set_event_handler(connection, ^(xpc_object_t event) {
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
|
||||
// If the remote end of this connection has gone away then stop download
|
||||
if (XPC_TYPE_ERROR == type &&
|
||||
(XPC_ERROR_CONNECTION_INTERRUPTED == event || XPC_ERROR_CONNECTION_INVALID == event))
|
||||
{
|
||||
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "Stopping download process...\n");
|
||||
shouldStopDownload = YES;
|
||||
}
|
||||
});
|
||||
xpc_connection_resume(connection);
|
||||
|
||||
NSString *destinationPath = [NSString stringWithCString:xpc_dictionary_get_string(request, SUDownloadServiceFilePathKey)
|
||||
encoding:NSUTF8StringEncoding];
|
||||
SUDSDownloader *downloader = [SUDSDownloader downloaderWithURLRequest:urlRequest
|
||||
destinationPath:destinationPath];
|
||||
|
||||
SUDSDownloaderCallBacks callBacks = {0};
|
||||
|
||||
callBacks.downloadDidReceiveData = ^(SUDSDownloader *downloader, NSUInteger dataLength) {
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUDownloadServiceReceivedDataLengthKey, (int64_t)dataLength);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
xpc_release(answer);
|
||||
};
|
||||
|
||||
callBacks.downloadDidReceiveResponse = ^(SUDSDownloader *downloader, NSURLResponse *response) {
|
||||
NSData *responseData = [NSKeyedArchiver archivedDataWithRootObject:response];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_data(message, SUDownloadServiceReceivedResponseDataKey, [responseData bytes], [responseData length]);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
xpc_release(answer);
|
||||
};
|
||||
|
||||
callBacks.downloadDidCreateDestination = ^(SUDSDownloader *downloader, NSString *destinationPath) {
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_string(message, SUDownloadServiceCreatedDestinationPathKey, [destinationPath cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
xpc_release(answer);
|
||||
};
|
||||
|
||||
callBacks.downloadDidBegin = ^(SUDSDownloader *downloader) {
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_bool(message, SUDownloadServiceDidBeginDownloadingKey, true);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
xpc_release(answer);
|
||||
};
|
||||
|
||||
callBacks.downloadDidFail = ^(SUDSDownloader *downloader, NSError *error) {
|
||||
errcode = (int32_t)[error code];
|
||||
errdomain = [[error domain] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
errmsg = [[error localizedDescription] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSData *errorData = [NSKeyedArchiver archivedDataWithRootObject:error];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_data(message, SUDownloadServiceReceivedFailErrorKey, [errorData bytes], [errorData length]);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
xpc_release(answer);
|
||||
};
|
||||
|
||||
callBacks.downloadDidFinish = ^(SUDSDownloader *downloader) {
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_bool(message, SUDownloadServiceDidFinishDownloadingKey, true);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
xpc_release(answer);
|
||||
};
|
||||
|
||||
callBacks.downloadShouldDecodeSourceData = ^BOOL(SUDSDownloader *downloader, NSString *MIMEType) {
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_string(message, SUDownloadServiceMIMETypeToDecodeKey, [MIMEType cStringUsingEncoding:NSUTF8StringEncoding]);
|
||||
xpc_object_t answer = xpc_connection_send_message_with_reply_sync(connection, message);
|
||||
xpc_release(message);
|
||||
|
||||
BOOL result = NO;
|
||||
if (xpc_get_type(answer) == XPC_TYPE_DICTIONARY)
|
||||
result = (BOOL)xpc_dictionary_get_bool(answer, SUDownloadServiceShouldDecodeMIMETypeKey);
|
||||
xpc_release(answer);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
[downloader setCallBacks:callBacks];
|
||||
|
||||
[downloader startDownload];
|
||||
while ([downloader isInProgress])
|
||||
{
|
||||
if (shouldStopDownload)
|
||||
{
|
||||
[downloader stopDownload];
|
||||
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "Download process stopped.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
|
||||
}
|
||||
}
|
||||
while (NO);
|
||||
[localPool release];
|
||||
|
||||
#if DEBUG_LOGGING_ENABLED
|
||||
NSLog(@"Download process finished. Will send last message...");
|
||||
#endif
|
||||
// Clean up and add errcode/errmsg to reply
|
||||
if (connection)
|
||||
{
|
||||
xpc_connection_cancel(connection);
|
||||
xpc_release(connection);
|
||||
}
|
||||
|
||||
xpc_dictionary_set_int64(reply, SUDownloadServiceErrorCodeKey, (int64_t)errcode);
|
||||
if (errmsg)
|
||||
{
|
||||
xpc_dictionary_set_string(reply, SUDownloadServiceErrorMessageKey, errmsg);
|
||||
}
|
||||
if (errdomain)
|
||||
{
|
||||
xpc_dictionary_set_string(reply, SUDownloadServiceErrorDomainKey, errdomain);
|
||||
}
|
||||
}
|
||||
|
||||
static void fetch_peer_event_handler(xpc_connection_t peer, xpc_object_t event)
|
||||
{
|
||||
// Get the object type.
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
if (XPC_TYPE_ERROR == type)
|
||||
{
|
||||
// Handle an error.
|
||||
if (XPC_ERROR_CONNECTION_INVALID == event)
|
||||
{
|
||||
// The client process on the other end of the connection
|
||||
// has either crashed or cancelled the connection.
|
||||
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "peer(%d) received "
|
||||
"XPC_ERROR_CONNECTION_INVALID",
|
||||
xpc_connection_get_pid(peer));
|
||||
xpc_connection_cancel(peer);
|
||||
}
|
||||
else if (XPC_ERROR_TERMINATION_IMMINENT == event)
|
||||
{
|
||||
// Handle per-connection termination cleanup. This
|
||||
// service is about to exit.
|
||||
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "peer(%d) received "
|
||||
"XPC_ERROR_TERMINATION_IMMINENT",
|
||||
xpc_connection_get_pid(peer));
|
||||
}
|
||||
}
|
||||
else if (XPC_TYPE_DICTIONARY == type)
|
||||
{
|
||||
xpc_object_t requestMessage = event;
|
||||
xpc_object_t replyMessage = xpc_dictionary_create_reply(requestMessage);
|
||||
assert(replyMessage != NULL);
|
||||
|
||||
// Process request and build a reply message.
|
||||
fetch_process_request(requestMessage, replyMessage);
|
||||
|
||||
xpc_connection_send_message(peer, replyMessage);
|
||||
xpc_release(replyMessage);
|
||||
}
|
||||
}
|
||||
|
||||
static void release_dispatch_queue(void *queue)
|
||||
{
|
||||
dispatch_release(queue);
|
||||
}
|
||||
|
||||
static void fetch_event_handler(xpc_connection_t peer)
|
||||
{
|
||||
// Generate an unique name for the queue to handle messages from
|
||||
// this peer and create a new dispatch queue for it.
|
||||
char *queue_name = NULL;
|
||||
asprintf(&queue_name, "%s-peer-%d", "com.devmate.UpdateDownloader", xpc_connection_get_pid(peer));
|
||||
dispatch_queue_t peer_event_queue = dispatch_queue_create(queue_name, DISPATCH_QUEUE_SERIAL);
|
||||
assert(peer_event_queue != NULL);
|
||||
free(queue_name);
|
||||
|
||||
// Set the target queue for connection.
|
||||
xpc_connection_set_target_queue(peer, peer_event_queue);
|
||||
xpc_connection_set_context(peer, peer_event_queue);
|
||||
xpc_connection_set_finalizer_f(peer, release_dispatch_queue);
|
||||
|
||||
// Set the handler block for connection.
|
||||
xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
|
||||
fetch_peer_event_handler(peer, event);
|
||||
});
|
||||
|
||||
// Enable the peer connection to receive messages.
|
||||
xpc_connection_resume(peer);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
xpc_main(fetch_event_handler);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/* Localized versions of Info.plist keys */
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// SUInstallServiceConstants.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 8/2/13.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef Sparkle_SUInstallServiceConstants_h
|
||||
#define Sparkle_SUInstallServiceConstants_h
|
||||
|
||||
typedef NS_ENUM(UInt64, SUInstallServiceTask)
|
||||
{
|
||||
SUInstallServiceTaskUnknown = 0,
|
||||
SUInstallServiceTaskCopyPath = 1LL,
|
||||
SUInstallServiceTaskAuthCopyPath = 2LL,
|
||||
SUInstallServiceTaskLaunchTask = 3LL
|
||||
};
|
||||
|
||||
static const char * SUInstallServiceTaskTypeKey = "task_type"; // int64_t
|
||||
|
||||
// SUInstallServiceTaskCopyPath & SUInstallServiceTaskAuthCopyPath keys
|
||||
static const char * SUInstallServiceSourcePathKey = "source_path"; // c-string
|
||||
static const char * SUInstallServiceDestinationPathKey = "destination_path"; // c-string
|
||||
static const char * SUInstallServiceAppendVersionKey = "append_version"; // bool
|
||||
|
||||
// SUInstallServiceTaskLaunchTask keys
|
||||
static const char * SUInstallServiceLaunchTaksPathKey = "launch_task_path";
|
||||
static const char * SUInstallServiceLaunchTaskArgumentsKey = "launch_task_arguments"; // xpc_array of c-strings
|
||||
static const char * SUInstallServiceLaunchTaskEnvironmentKey = "launch_task_environment"; // xpc_dictionary with keys and values of c-strings
|
||||
static const char * SUInstallServiceLaunchTaskCurrentDirKey = "launch_task_cur_dir"; // c-string
|
||||
static const char * SUInstallServiceLaunchTaskInputDataKey = "launch_task_input_data"; // xpc_data
|
||||
static const char * SUInstallServiceLaunchTaskReplyImmediatelyKey = "launch_task_reply_immediately"; // bool
|
||||
|
||||
// Reply keys
|
||||
static const char * SUInstallServiceErrorCodeKey = "error_code"; // int64_t
|
||||
static const char * SUInstallServiceErrorLocalizedDescriptionKey = "error_localized_description"; // c-string
|
||||
static const char * SUInstallServiceLaunchTaskOutputDataKey = "launch_task_output_data"; // xpc_data
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// SUXPCInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Whitney Young on 3/19/12.
|
||||
// Copyright (c) 2012 FadingRed. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface SUXPCInstaller : NSObject
|
||||
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst appendVersion:(BOOL)appendVersion error:(NSError *__autoreleasing *)outError;
|
||||
|
||||
+ (BOOL)copyPathContent:(NSString *)src toDirectory:(NSString *)dstDir error:(NSError *__autoreleasing *)outError; // dstDir will be created if absent
|
||||
|
||||
+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments;
|
||||
|
||||
+ (void)launchTaskWithPath:(NSString *)launchPath
|
||||
arguments:(NSArray *)arguments
|
||||
environment:(NSDictionary *)environment
|
||||
currentDirectoryPath:(NSString *)currentDirPath
|
||||
inputData:(NSData *)inputData
|
||||
waitUntilDone:(BOOL)waitUntilDone
|
||||
completionHandler:(void (^)(int result, NSData *outputData))completionHandler;
|
||||
|
||||
@end
|
||||
|
||||
FOUNDATION_EXPORT BOOL SUShouldUseXPCInstaller(void);
|
||||
@@ -0,0 +1,277 @@
|
||||
//
|
||||
// SUXPCInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Whitney Young on 3/19/12.
|
||||
// Copyright (c) 2012 FadingRed. All rights reserved.
|
||||
//
|
||||
|
||||
#import <xpc/xpc.h>
|
||||
#import "SUXPCInstaller.h"
|
||||
#import "SUInstallServiceConstants.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
|
||||
BOOL SUShouldUseXPCInstaller(void)
|
||||
{
|
||||
if (![SUCodeSigningVerifier hostApplicationIsSandboxed])
|
||||
return NO;
|
||||
|
||||
NSString *xpcServicePrefixPath = [[NSBundle mainBundle] bundlePath];
|
||||
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.devmate.UpdateInstaller.xpc";
|
||||
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
|
||||
}
|
||||
|
||||
@implementation SUXPCInstaller
|
||||
|
||||
+ (xpc_connection_t)getSandboxXPCService
|
||||
{
|
||||
__block xpc_connection_t serviceConnection = xpc_connection_create("com.devmate.UpdateInstaller", dispatch_get_main_queue());
|
||||
|
||||
if (!serviceConnection)
|
||||
{
|
||||
NSLog(@"Can't connect to XPC service");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
xpc_connection_set_event_handler(serviceConnection, ^(xpc_object_t event) {
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
{
|
||||
if (event == XPC_ERROR_CONNECTION_INVALID)
|
||||
{
|
||||
// The service is invalid. Either the service name supplied to
|
||||
// xpc_connection_create() is incorrect or we (this process) have
|
||||
// canceled the service; we can do any cleanup of appliation
|
||||
// state at this point.
|
||||
xpc_release(serviceConnection);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Need to resume the service in order for it to process messages.
|
||||
xpc_connection_resume(serviceConnection);
|
||||
return (serviceConnection);
|
||||
}
|
||||
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst appendVersion:(BOOL)appendVersion error:(NSError *__autoreleasing *)outError
|
||||
{
|
||||
xpc_connection_t connection = [self getSandboxXPCService];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskAuthCopyPath);
|
||||
|
||||
if (src)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceSourcePathKey, [src fileSystemRepresentation]);
|
||||
if (dst)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceDestinationPathKey, [dst fileSystemRepresentation]);
|
||||
xpc_dictionary_set_bool(message, SUInstallServiceAppendVersionKey, appendVersion ? true : false);
|
||||
|
||||
__block BOOL xpcDidReply = NO;
|
||||
__block NSError *error = nil;
|
||||
|
||||
dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
|
||||
xpc_connection_send_message_with_reply(connection, message, queue, ^(xpc_object_t response) {
|
||||
if (XPC_TYPE_ERROR == xpc_get_type(response))
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Internal XPC error."
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
else if (XPC_TYPE_DICTIONARY == xpc_get_type(response))
|
||||
{
|
||||
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
|
||||
if (errorString != NULL)
|
||||
{
|
||||
NSString *errorStr = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding];
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:errorStr ? errorStr : @""
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
}
|
||||
|
||||
xpcDidReply = YES;
|
||||
});
|
||||
|
||||
while (NO == xpcDidReply)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
|
||||
}
|
||||
|
||||
xpc_release(message);
|
||||
dispatch_release(queue);
|
||||
|
||||
if (nil != error && NULL != outError)
|
||||
{
|
||||
*outError = error;
|
||||
}
|
||||
|
||||
return (nil == error);
|
||||
}
|
||||
|
||||
+ (BOOL)copyPathContent:(NSString *)src toDirectory:(NSString *)dstDir error:(NSError * __autoreleasing*)outError
|
||||
{
|
||||
xpc_connection_t connection = [self getSandboxXPCService];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskCopyPath);
|
||||
|
||||
if (src)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceSourcePathKey, [src fileSystemRepresentation]);
|
||||
if (dstDir)
|
||||
xpc_dictionary_set_string(message, SUInstallServiceDestinationPathKey, [dstDir fileSystemRepresentation]);
|
||||
|
||||
__block BOOL xpcDidReply = NO;
|
||||
__block NSError *error = nil;
|
||||
|
||||
dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
|
||||
xpc_connection_send_message_with_reply(connection, message, queue, ^(xpc_object_t response) {
|
||||
if (XPC_TYPE_ERROR == xpc_get_type(response))
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Internal XPC error."
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
else if (XPC_TYPE_DICTIONARY == xpc_get_type(response))
|
||||
{
|
||||
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
|
||||
if (errorString != NULL)
|
||||
{
|
||||
NSString *errorStr = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding];
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:errorStr ? errorStr : @""
|
||||
forKey:NSLocalizedDescriptionKey];
|
||||
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
}
|
||||
|
||||
xpcDidReply = YES;
|
||||
});
|
||||
|
||||
while (NO == xpcDidReply)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
|
||||
}
|
||||
|
||||
xpc_release(message);
|
||||
dispatch_release(queue);
|
||||
|
||||
if (nil != error && NULL != outError)
|
||||
{
|
||||
*outError = error;
|
||||
}
|
||||
|
||||
return (nil == error);
|
||||
}
|
||||
|
||||
+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments
|
||||
{
|
||||
[self launchTaskWithPath:path
|
||||
arguments:arguments
|
||||
environment:nil
|
||||
currentDirectoryPath:nil
|
||||
inputData:nil
|
||||
waitUntilDone:NO
|
||||
completionHandler:nil];
|
||||
}
|
||||
|
||||
+ (void)launchTaskWithPath:(NSString *)launchPath
|
||||
arguments:(NSArray *)arguments
|
||||
environment:(NSDictionary *)environment
|
||||
currentDirectoryPath:(NSString *)currentDirPath
|
||||
inputData:(NSData *)inputData
|
||||
waitUntilDone:(BOOL)waitUntilDone
|
||||
completionHandler:(void (^)(int result, NSData *outputData))completionHandler
|
||||
{
|
||||
xpc_connection_t connection = [self getSandboxXPCService];
|
||||
|
||||
xpc_object_t message = xpc_dictionary_create(NULL, NULL, 0);
|
||||
xpc_dictionary_set_int64(message, SUInstallServiceTaskTypeKey, (int64_t)SUInstallServiceTaskLaunchTask);
|
||||
|
||||
if ([launchPath length])
|
||||
{
|
||||
xpc_dictionary_set_string(message, SUInstallServiceLaunchTaksPathKey, [launchPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if ([arguments count])
|
||||
{
|
||||
xpc_object_t array = xpc_array_create(NULL, 0);
|
||||
for (id argument in arguments)
|
||||
{
|
||||
NSString *strArgument = argument;
|
||||
if (![strArgument isKindOfClass:[NSString class]])
|
||||
strArgument = [argument description];
|
||||
|
||||
xpc_array_set_string(array, XPC_ARRAY_APPEND, [strArgument UTF8String]);
|
||||
}
|
||||
xpc_dictionary_set_value(message, SUInstallServiceLaunchTaskArgumentsKey, array);
|
||||
xpc_release(array);
|
||||
}
|
||||
|
||||
if ([environment count])
|
||||
{
|
||||
__block xpc_object_t dict = xpc_dictionary_create(NULL, NULL, 0);
|
||||
[environment enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL __unused *stop) {
|
||||
NSString *xpc_key = [key isKindOfClass:[NSString class]] ? key : [key description];
|
||||
NSString *xpc_value = [obj isKindOfClass:[NSString class]] ? obj : [obj description];
|
||||
|
||||
xpc_dictionary_set_string(dict, [xpc_key UTF8String], [xpc_value UTF8String]);
|
||||
}];
|
||||
|
||||
xpc_dictionary_set_value(message, SUInstallServiceLaunchTaskEnvironmentKey, dict);
|
||||
xpc_release(dict);
|
||||
}
|
||||
|
||||
if ([currentDirPath length])
|
||||
{
|
||||
xpc_dictionary_set_string(message, SUInstallServiceLaunchTaskCurrentDirKey, [currentDirPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if ([inputData length])
|
||||
{
|
||||
xpc_dictionary_set_data(message, SUInstallServiceLaunchTaskInputDataKey, [inputData bytes], [inputData length]);
|
||||
}
|
||||
|
||||
BOOL replyImmediately = (waitUntilDone || completionHandler != nil) ? NO : YES;
|
||||
xpc_dictionary_set_bool(message, SUInstallServiceLaunchTaskReplyImmediatelyKey, replyImmediately);
|
||||
|
||||
__block BOOL xpcTaskDidReply = NO;
|
||||
xpc_connection_send_message_with_reply(connection, message, dispatch_get_current_queue(), ^(xpc_object_t response) {
|
||||
int taskResult = 0;
|
||||
NSData *outputData = nil;
|
||||
|
||||
if (completionHandler != NULL)
|
||||
{
|
||||
xpc_type_t type = xpc_get_type(response);
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
{
|
||||
taskResult = SUXPCServiceError;
|
||||
}
|
||||
else if (type == XPC_TYPE_DICTIONARY)
|
||||
{
|
||||
taskResult = (int)xpc_dictionary_get_int64(response, SUInstallServiceErrorCodeKey);
|
||||
|
||||
size_t bytesLen = 0;
|
||||
const void *bytes = xpc_dictionary_get_data(response, SUInstallServiceLaunchTaskOutputDataKey, &bytesLen);
|
||||
if (NULL != bytes)
|
||||
{
|
||||
outputData = [NSData dataWithBytes:bytes length:bytesLen];
|
||||
}
|
||||
}
|
||||
|
||||
completionHandler(taskResult, outputData);
|
||||
}
|
||||
|
||||
xpcTaskDidReply = YES;
|
||||
});
|
||||
xpc_release(message);
|
||||
|
||||
if (replyImmediately || waitUntilDone)
|
||||
{
|
||||
while (NO == xpcTaskDidReply)
|
||||
{
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XPC!</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>XPCService</key>
|
||||
<dict>
|
||||
<key>ServiceType</key>
|
||||
<string>Application</string>
|
||||
<key>JoinExistingSession</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,374 @@
|
||||
//
|
||||
// main.m
|
||||
// Update
|
||||
//
|
||||
// Created by Whitney Young on 3/19/12.
|
||||
// Copyright (c) 2012 FadingRed. All rights reserved.
|
||||
//
|
||||
|
||||
#include <xpc/xpc.h>
|
||||
#include <asl.h>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUInstallServiceConstants.h"
|
||||
|
||||
static xpc_object_t SUSICopyPathContent(xpc_object_t message)
|
||||
{
|
||||
if (NULL == message)
|
||||
return NULL;
|
||||
|
||||
const char *src = xpc_dictionary_get_string(message, SUInstallServiceSourcePathKey);
|
||||
const char *dst = xpc_dictionary_get_string(message, SUInstallServiceDestinationPathKey);
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *sourcePath = src ? [manager stringWithFileSystemRepresentation:src length:strlen(src)] : nil;
|
||||
NSString *targetPath = dst ? [manager stringWithFileSystemRepresentation:dst length:strlen(dst)] : nil;
|
||||
|
||||
NSError *error = nil;
|
||||
do
|
||||
{
|
||||
if (nil == sourcePath)
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Source path is absent." forKey:NSLocalizedDescriptionKey];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
break;
|
||||
}
|
||||
|
||||
if (nil == targetPath)
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Destination path is absent." forKey:NSLocalizedDescriptionKey];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
break;
|
||||
}
|
||||
|
||||
NSArray *contents = nil;
|
||||
|
||||
BOOL isSrcDirectory = NO;
|
||||
BOOL isSrcExist = [manager fileExistsAtPath:sourcePath isDirectory:&isSrcDirectory];
|
||||
isSrcDirectory = isSrcDirectory && ![[NSWorkspace sharedWorkspace] isFilePackageAtPath:sourcePath];
|
||||
if (isSrcExist && isSrcDirectory)
|
||||
{
|
||||
contents = [manager contentsOfDirectoryAtPath:sourcePath error:&error];
|
||||
}
|
||||
else if (isSrcExist)
|
||||
{
|
||||
contents = [NSArray arrayWithObject:@""];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:@"Source does not exist on disk." forKey:NSLocalizedDescriptionKey];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
|
||||
}
|
||||
|
||||
if (nil != error)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
BOOL isDstDirectory = NO;
|
||||
BOOL isDstExist = [manager fileExistsAtPath:targetPath isDirectory:&isDstDirectory];
|
||||
if (isSrcDirectory && (!isDstExist || !isDstDirectory))
|
||||
{
|
||||
if (isDstExist)
|
||||
[manager removeItemAtPath:targetPath error:&error];
|
||||
[manager createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:&error];
|
||||
}
|
||||
else if (!isSrcDirectory)
|
||||
{
|
||||
if (isDstExist && !isDstDirectory)
|
||||
[manager removeItemAtPath:targetPath error:&error];
|
||||
[manager createDirectoryAtPath:targetPath withIntermediateDirectories:YES attributes:nil error:&error];
|
||||
}
|
||||
|
||||
if (nil != error)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
for (NSString *item in contents)
|
||||
{
|
||||
NSString *fromPath = [item length] ? [sourcePath stringByAppendingPathComponent:item] : sourcePath;
|
||||
NSString *toPath = [item length] ? [targetPath stringByAppendingPathComponent:item] : [targetPath stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
if (![manager isReadableFileAtPath:fromPath])
|
||||
{
|
||||
SULog(@"XPC Install Service: will skip \"%@\"", fromPath);
|
||||
continue;
|
||||
}
|
||||
|
||||
SULog(@"XPC Install Service: will copy \"%@\" to \"%@\"", fromPath, toPath);
|
||||
|
||||
if ([manager fileExistsAtPath:toPath])
|
||||
[manager removeItemAtPath:toPath error:&error];
|
||||
|
||||
if (![manager copyItemAtPath:fromPath toPath:toPath error:&error])
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (NO);
|
||||
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(message);
|
||||
if (nil != error)
|
||||
{
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)[error code]);
|
||||
const char *errorMsg = [[error localizedDescription] length] ? [[error localizedDescription] UTF8String] : "";
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, errorMsg);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static xpc_object_t SUISCopyPathWithAuthentication(xpc_object_t message)
|
||||
{
|
||||
if (NULL == message)
|
||||
return NULL;
|
||||
|
||||
const char *src = xpc_dictionary_get_string(message, SUInstallServiceSourcePathKey);
|
||||
const char *dst = xpc_dictionary_get_string(message, SUInstallServiceDestinationPathKey);
|
||||
bool appendVersion = xpc_dictionary_get_bool(message, SUInstallServiceAppendVersionKey);
|
||||
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
NSString *relaunchPathToCopy = src ? [manager stringWithFileSystemRepresentation:src length:strlen(src)] : nil;
|
||||
NSString *targetPath = dst ? [manager stringWithFileSystemRepresentation:dst length:strlen(dst)] : nil;
|
||||
NSError *error = nil;
|
||||
BOOL result = [SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath appendVersion:appendVersion error:&error];
|
||||
|
||||
// send response to indicate ok
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(message);
|
||||
if (!result && error != nil)
|
||||
{
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)[error code]);
|
||||
const char *errorMsg = [[error localizedDescription] length] ? [[error localizedDescription] UTF8String] : "";
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, errorMsg);
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static xpc_object_t SUISLaunchTask(xpc_object_t message)
|
||||
{
|
||||
if (NULL == message)
|
||||
return NULL;
|
||||
|
||||
const char *path = xpc_dictionary_get_string(message, SUInstallServiceLaunchTaksPathKey);
|
||||
NSString *launchPath = path ? [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path length:strlen(path)] : nil;
|
||||
|
||||
xpc_object_t array = xpc_dictionary_get_value(message, SUInstallServiceLaunchTaskArgumentsKey);
|
||||
NSArray *arguments = nil;
|
||||
if (NULL != array)
|
||||
{
|
||||
size_t count = xpc_array_get_count(array);
|
||||
NSMutableArray *mutableArgs = [NSMutableArray arrayWithCapacity:count];
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
NSString *argument = [NSString stringWithUTF8String:xpc_array_get_string(array, i)];
|
||||
[mutableArgs addObject: argument ? argument : @""];
|
||||
}
|
||||
|
||||
arguments = mutableArgs;
|
||||
}
|
||||
|
||||
xpc_object_t dict = xpc_dictionary_get_value(message, SUInstallServiceLaunchTaskEnvironmentKey);
|
||||
NSDictionary *environment = nil;
|
||||
if (NULL != dict)
|
||||
{
|
||||
size_t count = xpc_dictionary_get_count(dict);
|
||||
__block NSMutableDictionary *mutableEnv = [NSMutableDictionary dictionaryWithCapacity:count];
|
||||
|
||||
xpc_dictionary_apply(dict, ^bool(const char *key, xpc_object_t value) {
|
||||
NSString *envKey = [NSString stringWithUTF8String:key];
|
||||
NSString *envValue = [NSString stringWithUTF8String:value];
|
||||
[mutableEnv setObject:envValue forKey:envKey];
|
||||
return true;
|
||||
});
|
||||
|
||||
environment = mutableEnv;
|
||||
}
|
||||
|
||||
path = xpc_dictionary_get_string(message, SUInstallServiceLaunchTaskCurrentDirKey);
|
||||
NSString *currentDirPath = path ? [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path length:strlen(path)] : nil;
|
||||
|
||||
size_t bytesLen = 0;
|
||||
const void *bytes = xpc_dictionary_get_data(message, SUInstallServiceLaunchTaskInputDataKey, &bytesLen);
|
||||
NSData *inputData = bytes ? [NSData dataWithBytes:bytes length:bytesLen] : nil;
|
||||
|
||||
bool shouldReplyImmediatly = xpc_dictionary_get_bool(message, SUInstallServiceLaunchTaskReplyImmediatelyKey);
|
||||
|
||||
// prepare NSTask
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
NSPipe *inputPipe = [NSPipe pipe];
|
||||
NSPipe *outputPipe = [NSPipe pipe];
|
||||
|
||||
[task setStandardInput:inputPipe];
|
||||
[task setStandardOutput:outputPipe];
|
||||
[task setStandardError:outputPipe];
|
||||
|
||||
if (launchPath != nil)
|
||||
[task setLaunchPath:launchPath];
|
||||
if ([arguments count])
|
||||
[task setArguments:arguments];
|
||||
if ([environment count])
|
||||
[task setEnvironment:environment];
|
||||
if (currentDirPath != nil)
|
||||
[task setCurrentDirectoryPath:currentDirPath];
|
||||
|
||||
__block NSData *outputData = nil;
|
||||
__block int taskResult = 0;
|
||||
__block BOOL isTaskRunning = YES;
|
||||
|
||||
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
||||
NSArray *notificationObjects = nil;
|
||||
|
||||
if (!shouldReplyImmediatly)
|
||||
{
|
||||
id object1 = [notificationCenter addObserverForName:NSFileHandleReadToEndOfFileCompletionNotification
|
||||
object:[outputPipe fileHandleForReading]
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification *note) {
|
||||
outputData = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem];
|
||||
isTaskRunning = NO;
|
||||
}];
|
||||
|
||||
id object2 = [notificationCenter addObserverForName:NSTaskDidTerminateNotification
|
||||
object:task
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification __unused *note) {
|
||||
taskResult = [task terminationStatus];
|
||||
}];
|
||||
|
||||
notificationObjects = [NSArray arrayWithObjects:object1, object2, nil];
|
||||
}
|
||||
|
||||
[[outputPipe fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
|
||||
|
||||
@try
|
||||
{
|
||||
[task launch];
|
||||
|
||||
if ([inputData length])
|
||||
{
|
||||
[[inputPipe fileHandleForWriting] writeData:inputData];
|
||||
[[inputPipe fileHandleForWriting] closeFile];
|
||||
}
|
||||
|
||||
if (!shouldReplyImmediatly)
|
||||
{
|
||||
// loop until we are done receiving the data
|
||||
while (YES == isTaskRunning)
|
||||
{
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.5, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@catch (...)
|
||||
{
|
||||
taskResult = SUXPCServiceError;
|
||||
}
|
||||
|
||||
// send response to indicate ok
|
||||
xpc_object_t reply = xpc_dictionary_create_reply(message);
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)taskResult);
|
||||
if (outputData != nil)
|
||||
{
|
||||
xpc_dictionary_set_data(reply, SUInstallServiceLaunchTaskOutputDataKey, [outputData bytes], [outputData length]);
|
||||
}
|
||||
|
||||
for (id object in notificationObjects)
|
||||
{
|
||||
[notificationCenter removeObserver:object];
|
||||
}
|
||||
outputData = nil;
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static void peer_event_handler(xpc_connection_t peer, xpc_object_t event)
|
||||
{
|
||||
xpc_type_t type = xpc_get_type(event);
|
||||
if (type == XPC_TYPE_ERROR)
|
||||
{
|
||||
if (event == XPC_ERROR_CONNECTION_INVALID)
|
||||
{
|
||||
// The client process on the other end of the connection has either
|
||||
// crashed or cancelled the connection. After receiving this error,
|
||||
// the connection is in an invalid state, and you do not need to
|
||||
// call xpc_connection_cancel(). Just tear down any associated state
|
||||
// here.
|
||||
}
|
||||
else if (event == XPC_ERROR_TERMINATION_IMMINENT)
|
||||
{
|
||||
// Handle per-connection termination cleanup.
|
||||
}
|
||||
}
|
||||
else if (type == XPC_TYPE_DICTIONARY)
|
||||
{
|
||||
// Handle the message.
|
||||
int64_t task = xpc_dictionary_get_int64(event, SUInstallServiceTaskTypeKey);
|
||||
NSLog(@"XPC Installer: will do the task %lld", (int64_t)task);
|
||||
|
||||
xpc_object_t reply = NULL;
|
||||
|
||||
@autoreleasepool
|
||||
{
|
||||
switch (task)
|
||||
{
|
||||
case SUInstallServiceTaskCopyPath:
|
||||
{
|
||||
reply = SUSICopyPathContent(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case SUInstallServiceTaskAuthCopyPath:
|
||||
{
|
||||
reply = SUISCopyPathWithAuthentication(event);
|
||||
break;
|
||||
}
|
||||
|
||||
case SUInstallServiceTaskLaunchTask:
|
||||
{
|
||||
reply = SUISLaunchTask(event);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
SULog(@"XPC Install Service: Unknown XPC service task %lld", task);
|
||||
|
||||
reply = xpc_dictionary_create_reply(event);
|
||||
xpc_dictionary_set_int64(reply, SUInstallServiceErrorCodeKey, (int64_t)SUXPCServiceError);
|
||||
xpc_dictionary_set_string(reply, SUInstallServiceErrorLocalizedDescriptionKey, "Unknown install cervice task.");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == reply)
|
||||
{
|
||||
reply = xpc_dictionary_create_reply(event);
|
||||
}
|
||||
|
||||
xpc_connection_send_message(peer, reply);
|
||||
xpc_release(reply);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_handler(xpc_connection_t peer)
|
||||
{
|
||||
// By defaults, new connections will target the default dispatch
|
||||
// concurrent queue.
|
||||
xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
|
||||
peer_event_handler(peer, event);
|
||||
});
|
||||
|
||||
// This will tell the connection to begin listening for events. If you
|
||||
// have some other initialization that must be done asynchronously, then
|
||||
// you can defer this call until after that initialization is done.
|
||||
xpc_connection_resume(peer);
|
||||
}
|
||||
|
||||
int main(int __unused argc, const char __unused *argv[])
|
||||
{
|
||||
xpc_main(event_handler);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// install_service.pch
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Dmytro Tretiakov on 4/25/14.
|
||||
//
|
||||
//
|
||||
|
||||
#import "Sparkle.pch"
|
||||
#import "SULog.h"
|
||||
@@ -9,32 +9,18 @@
|
||||
#ifndef SUAPPCAST_H
|
||||
#define SUAPPCAST_H
|
||||
|
||||
#if __has_feature(modules)
|
||||
@import Foundation;
|
||||
#else
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
#import "SUExport.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUAppcastItem;
|
||||
SU_EXPORT @interface SUAppcast : NSObject<NSURLDownloadDelegate>
|
||||
|
||||
@property (copy, nullable) NSString *userAgentString;
|
||||
@property (copy) NSString *userAgentString;
|
||||
@property (copy) NSDictionary *httpHeaders;
|
||||
|
||||
#if __has_feature(objc_generics)
|
||||
@property (copy, nullable) NSDictionary<NSString *, NSString *> *httpHeaders;
|
||||
#else
|
||||
@property (copy, nullable) NSDictionary *httpHeaders;
|
||||
#endif
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *))err;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url inBackground:(BOOL)bg completionBlock:(void (^)(NSError *_Nullable))err;
|
||||
- (SUAppcast *)copyWithoutDeltaUpdates;
|
||||
|
||||
@property (readonly, copy, nullable) NSArray *items;
|
||||
@property (readonly, copy) NSArray *items;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -6,14 +6,14 @@
|
||||
// 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"
|
||||
#import "SULocalizations.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface NSXMLElement (SUAppcastExtensions)
|
||||
@property (readonly, copy) NSDictionary *attributesAsDictionary;
|
||||
@@ -30,10 +30,7 @@
|
||||
if (!attrName) {
|
||||
continue;
|
||||
}
|
||||
NSString *attributeStringValue = [attribute stringValue];
|
||||
if (attributeStringValue != nil) {
|
||||
[dictionary setObject:attributeStringValue forKey:attrName];
|
||||
}
|
||||
dictionary[attrName] = [attribute stringValue];
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
@@ -57,22 +54,18 @@
|
||||
@synthesize download;
|
||||
@synthesize items;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url inBackground:(BOOL)background completionBlock:(void (^)(NSError *))block
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *))block
|
||||
{
|
||||
self.completionBlock = block;
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
|
||||
if (background) {
|
||||
request.networkServiceType = NSURLNetworkServiceTypeBackground;
|
||||
}
|
||||
|
||||
if (self.userAgentString) {
|
||||
[request setValue:self.userAgentString forHTTPHeaderField:@"User-Agent"];
|
||||
}
|
||||
|
||||
if (self.httpHeaders) {
|
||||
for (NSString *key in self.httpHeaders) {
|
||||
NSString *value = [self.httpHeaders objectForKey:key];
|
||||
id value = [self.httpHeaders objectForKey:key];
|
||||
[request setValue:value forHTTPHeaderField:key];
|
||||
}
|
||||
}
|
||||
@@ -100,166 +93,147 @@
|
||||
- (void)downloadDidFinish:(NSURLDownload *)__unused aDownload
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSArray *appcastItems = [self parseAppcastItemsFromXMLFile:[NSURL fileURLWithPath:self.downloadFilename] error:&error];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil];
|
||||
self.downloadFilename = nil;
|
||||
|
||||
if (appcastItems) {
|
||||
self.items = appcastItems;
|
||||
self.completionBlock(nil);
|
||||
self.completionBlock = nil;
|
||||
} else {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary
|
||||
dictionaryWithObject: SULocalizedString(@"An error occurred while parsing the update feed.", nil)
|
||||
forKey: NSLocalizedDescriptionKey];
|
||||
if (error) {
|
||||
[userInfo setObject:error forKey:NSUnderlyingErrorKey];
|
||||
}
|
||||
[self reportError:[NSError errorWithDomain:SUSparkleErrorDomain
|
||||
code:SUAppcastParseError
|
||||
userInfo:userInfo]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSDictionary *)attributesOfNode:(NSXMLElement *)node
|
||||
{
|
||||
NSEnumerator *attributeEnum = [[node attributes] objectEnumerator];
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
|
||||
for (NSXMLNode *attribute in attributeEnum) {
|
||||
NSString *attrName = [self sparkleNamespacedNameOfNode:attribute];
|
||||
if (!attrName) {
|
||||
continue;
|
||||
}
|
||||
NSString *stringValue = [attribute stringValue];
|
||||
if (stringValue) {
|
||||
[dictionary setObject:stringValue forKey:attrName];
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
-(NSString *)sparkleNamespacedNameOfNode:(NSXMLNode *)node {
|
||||
// XML namespace prefix is semantically meaningless, so compare namespace URI
|
||||
// NS URI isn't used to fetch anything, and must match exactly, so we look for http:// not https://
|
||||
if ([[node URI] isEqualToString:@"http://www.andymatuschak.org/xml-namespaces/sparkle"]) {
|
||||
NSString *localName = [node localName];
|
||||
assert(localName);
|
||||
return [@"sparkle:" stringByAppendingString:localName];
|
||||
} else {
|
||||
return [node name]; // Backwards compatibility
|
||||
}
|
||||
}
|
||||
|
||||
-(NSArray *)parseAppcastItemsFromXMLFile:(NSURL *)appcastFile error:(NSError *__autoreleasing*)errorp {
|
||||
if (errorp) {
|
||||
*errorp = nil;
|
||||
}
|
||||
|
||||
if (!appcastFile) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSUInteger options = NSXMLNodeLoadExternalEntitiesNever; // Prevent inclusion from file://
|
||||
NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:appcastFile options:options error:errorp];
|
||||
if (nil == document) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSArray *xmlItems = [document nodesForXPath:@"/rss/channel/item" error:errorp];
|
||||
if (nil == xmlItems) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSXMLDocument *document = nil;
|
||||
BOOL failed = NO;
|
||||
NSArray *xmlItems = nil;
|
||||
NSMutableArray *appcastItems = [NSMutableArray array];
|
||||
NSEnumerator *nodeEnum = [xmlItems objectEnumerator];
|
||||
NSXMLNode *node;
|
||||
|
||||
while((node = [nodeEnum nextObject])) {
|
||||
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];
|
||||
|
||||
// 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 = [self sparkleNamespacedNameOfNode:node];
|
||||
if (name) {
|
||||
NSMutableArray *nodes = [nodesDict objectForKey:name];
|
||||
if (nodes == nil) {
|
||||
nodes = [NSMutableArray array];
|
||||
[nodesDict setObject:nodes forKey:name];
|
||||
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];
|
||||
}
|
||||
[nodes addObject:node];
|
||||
node = [node nextSibling];
|
||||
}
|
||||
node = [node nextSibling];
|
||||
}
|
||||
}
|
||||
|
||||
for (NSString *name in nodesDict) {
|
||||
node = [self bestNodeInNodes:[nodesDict objectForKey:name]];
|
||||
if ([name isEqualToString:SURSSElementEnclosure]) {
|
||||
// enclosure is flattened as a separate dictionary for some reason
|
||||
NSDictionary *encDict = [self attributesOfNode:(NSXMLElement *)node];
|
||||
[dict setObject:encDict forKey:name];
|
||||
}
|
||||
else if ([name isEqualToString:SURSSElementPubDate]) {
|
||||
// We don't want to parse and create a NSDate instance -
|
||||
// that's a risk we can avoid. We don't use the date anywhere other
|
||||
// than it being accessible from SUAppcastItem
|
||||
NSString *dateString = node.stringValue;
|
||||
if (dateString) {
|
||||
[dict setObject:dateString forKey:name];
|
||||
}
|
||||
}
|
||||
else if ([name isEqualToString:SUAppcastElementDeltas]) {
|
||||
NSMutableArray *deltas = [NSMutableArray array];
|
||||
NSEnumerator *childEnum = [[node children] objectEnumerator];
|
||||
for (NSXMLNode *child in childEnum) {
|
||||
if ([[child name] isEqualToString:SURSSElementEnclosure]) {
|
||||
[deltas addObject:[self attributesOfNode:(NSXMLElement *)child]];
|
||||
}
|
||||
}
|
||||
[dict setObject:deltas forKey:name];
|
||||
}
|
||||
else if ([name isEqualToString:SUAppcastElementTags]) {
|
||||
NSMutableArray *tags = [NSMutableArray array];
|
||||
NSEnumerator *childEnum = [[node children] objectEnumerator];
|
||||
for (NSXMLNode *child in childEnum) {
|
||||
NSString *childName = child.name;
|
||||
if (childName) {
|
||||
[tags addObject:childName];
|
||||
}
|
||||
}
|
||||
[dict setObject:tags forKey:name];
|
||||
}
|
||||
else if (name != nil) {
|
||||
// add all other values as strings
|
||||
NSString *theValue = [[node stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
if (theValue != nil) {
|
||||
[dict setObject:theValue forKey:name];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (NSString *name in nodesDict)
|
||||
{
|
||||
node = [self bestNodeInNodes:nodesDict[name]];
|
||||
if ([name isEqualToString:SURSSElementEnclosure])
|
||||
{
|
||||
// enclosure is flattened as a separate dictionary for some reason
|
||||
NSDictionary *encDict = [(NSXMLElement *)node attributesAsDictionary];
|
||||
dict[name] = encDict;
|
||||
|
||||
NSString *errString;
|
||||
SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict failureReason:&errString];
|
||||
if (anItem) {
|
||||
[appcastItems addObject:anItem];
|
||||
}
|
||||
else {
|
||||
SULog(SULogLevelError, @"Sparkle Updater: Failed to parse appcast item: %@.\nAppcast dictionary was: %@", errString, dict);
|
||||
if (errorp) *errorp = [NSError errorWithDomain:SUSparkleErrorDomain
|
||||
code:SUAppcastParseError
|
||||
userInfo:@{NSLocalizedDescriptionKey: errString}];
|
||||
return nil;
|
||||
}
|
||||
else if ([name isEqualToString:SURSSElementPubDate])
|
||||
{
|
||||
// pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString
|
||||
NSString *string = node.stringValue;
|
||||
if (string) {
|
||||
NSDate *date = [NSDate dateWithNaturalLanguageString:string];
|
||||
if (date)
|
||||
dict[name] = date;
|
||||
}
|
||||
}
|
||||
else if ([name isEqualToString:SUAppcastElementDeltas])
|
||||
{
|
||||
NSMutableArray *deltas = [NSMutableArray array];
|
||||
NSEnumerator *childEnum = [[node children] objectEnumerator];
|
||||
for (NSXMLNode *child in childEnum) {
|
||||
if ([[child name] isEqualToString:SURSSElementEnclosure])
|
||||
[deltas addObject:[(NSXMLElement *)child attributesAsDictionary]];
|
||||
}
|
||||
dict[name] = deltas;
|
||||
}
|
||||
else if ([name isEqualToString:SUAppcastElementTags]) {
|
||||
NSMutableArray *tags = [NSMutableArray array];
|
||||
NSEnumerator *childEnum = [[node children] objectEnumerator];
|
||||
for (NSXMLNode *child in childEnum) {
|
||||
NSString *childName = child.name;
|
||||
if (childName)
|
||||
[tags addObject:childName];
|
||||
}
|
||||
dict[name] = tags;
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
self.items = appcastItems;
|
||||
|
||||
return appcastItems;
|
||||
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 {
|
||||
self.completionBlock(nil);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused aDownload didFailWithError:(NSError *)error
|
||||
@@ -279,18 +253,14 @@
|
||||
|
||||
- (void)reportError:(NSError *)error
|
||||
{
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
|
||||
NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey];
|
||||
|
||||
self.completionBlock([NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred in retrieving update information. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: [error localizedDescription],
|
||||
NSUnderlyingErrorKey: error,
|
||||
}];
|
||||
|
||||
NSURL *failingUrl = [error.userInfo objectForKey:NSURLErrorFailingURLErrorKey];
|
||||
if (failingUrl) {
|
||||
[userInfo setObject:failingUrl forKey:NSURLErrorFailingURLErrorKey];
|
||||
}
|
||||
|
||||
self.completionBlock([NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:userInfo]);
|
||||
NSURLErrorFailingURLErrorKey: failingUrl ? failingUrl : [NSNull null],
|
||||
}]);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
@@ -298,7 +268,7 @@
|
||||
{
|
||||
// We use this method to pick out the localized version of a node when one's available.
|
||||
if ([nodes count] == 1)
|
||||
return [nodes objectAtIndex:0];
|
||||
return nodes[0];
|
||||
else if ([nodes count] == 0)
|
||||
return nil;
|
||||
|
||||
@@ -309,24 +279,12 @@
|
||||
lang = [[node attributeForName:@"xml:lang"] stringValue];
|
||||
[languages addObject:(lang ? lang : @"")];
|
||||
}
|
||||
lang = [[NSBundle preferredLocalizationsFromArray:languages] objectAtIndex:0];
|
||||
lang = [NSBundle preferredLocalizationsFromArray:languages][0];
|
||||
i = [languages indexOfObject:([languages containsObject:lang] ? lang : @"")];
|
||||
if (i == NSNotFound) {
|
||||
i = 0;
|
||||
}
|
||||
return [nodes objectAtIndex:i];
|
||||
}
|
||||
|
||||
- (SUAppcast *)copyWithoutDeltaUpdates {
|
||||
SUAppcast *other = [SUAppcast new];
|
||||
NSMutableArray *nonDeltaItems = [NSMutableArray new];
|
||||
|
||||
for(SUAppcastItem *item in self.items) {
|
||||
if (![item isDeltaUpdate]) [nonDeltaItems addObject:item];
|
||||
}
|
||||
|
||||
other.items = nonDeltaItems;
|
||||
return other;
|
||||
return nodes[i];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -9,23 +9,18 @@
|
||||
#ifndef SUAPPCASTITEM_H
|
||||
#define SUAPPCASTITEM_H
|
||||
|
||||
#if __has_feature(modules)
|
||||
@import Foundation;
|
||||
#else
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
#import "SUExport.h"
|
||||
|
||||
SU_EXPORT @interface SUAppcastItem : NSObject
|
||||
@property (copy, readonly) NSString *title;
|
||||
@property (copy, readonly) NSString *dateString;
|
||||
@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 (nonatomic, readonly) uint64_t contentLength;
|
||||
@property (copy, readonly) NSString *versionString;
|
||||
@property (copy, readonly) NSString *displayVersionString;
|
||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
||||
|
||||
@@ -6,16 +6,17 @@
|
||||
// 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"
|
||||
#import "SUConstants.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUAppcastItem ()
|
||||
@property (copy, readwrite) NSString *title;
|
||||
@property (copy, readwrite) NSString *dateString;
|
||||
@property (copy, readwrite) NSDate *date;
|
||||
@property (copy, readwrite) NSString *itemDescription;
|
||||
@property (strong, readwrite) NSURL *releaseNotesURL;
|
||||
@property (copy, readwrite) NSString *DSASignature;
|
||||
@@ -30,12 +31,11 @@
|
||||
@end
|
||||
|
||||
@implementation SUAppcastItem
|
||||
@synthesize dateString;
|
||||
@synthesize date;
|
||||
@synthesize deltaUpdates;
|
||||
@synthesize displayVersionString;
|
||||
@synthesize DSASignature;
|
||||
@synthesize fileURL;
|
||||
@synthesize contentLength = _contentLength;
|
||||
@synthesize infoURL;
|
||||
@synthesize itemDescription;
|
||||
@synthesize maximumSystemVersion;
|
||||
@@ -47,13 +47,12 @@
|
||||
|
||||
- (BOOL)isDeltaUpdate
|
||||
{
|
||||
NSDictionary *rssElementEnclosure = [self.propertiesDictionary objectForKey:SURSSElementEnclosure];
|
||||
return [rssElementEnclosure objectForKey:SUAppcastAttributeDeltaFrom] != nil;
|
||||
return self.propertiesDictionary[SURSSElementEnclosure][SUAppcastAttributeDeltaFrom] != nil;
|
||||
}
|
||||
|
||||
- (BOOL)isCriticalUpdate
|
||||
{
|
||||
return [[self.propertiesDictionary objectForKey:SUAppcastElementTags] containsObject:SUAppcastElementCriticalUpdate];
|
||||
return [self.propertiesDictionary[SUAppcastElementTags] containsObject:SUAppcastElementCriticalUpdate];
|
||||
}
|
||||
|
||||
- (BOOL)isInformationOnlyUpdate
|
||||
@@ -70,7 +69,7 @@
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSDictionary *enclosure = [dict objectForKey:SURSSElementEnclosure];
|
||||
id enclosure = dict[SURSSElementEnclosure];
|
||||
|
||||
// Try to find a version string.
|
||||
// Finding the new version number from the RSS feed is a little bit hacky. There are two ways:
|
||||
@@ -80,17 +79,17 @@
|
||||
// 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 objectForKey:SUAppcastAttributeVersion];
|
||||
NSString *newVersion = enclosure[SUAppcastAttributeVersion];
|
||||
if (newVersion == nil) {
|
||||
newVersion = [dict objectForKey:SUAppcastAttributeVersion]; // Get version from the item, in case it's a download-less item (i.e. paid upgrade).
|
||||
newVersion = dict[SUAppcastAttributeVersion]; // 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(SULogLevelError, @"warning: <%@> for URL '%@' is missing %@ attribute. Version comparison may be unreliable. Please always specify %@", SURSSElementEnclosure, [enclosure objectForKey:SURSSAttributeURL], SUAppcastAttributeVersion, SUAppcastAttributeVersion);
|
||||
SULog(@"warning: <%@> for URL '%@' is missing %@ attribute. Version comparison may be unreliable. Please always specify %@", SURSSElementEnclosure, enclosure[SURSSAttributeURL], SUAppcastAttributeVersion, SUAppcastAttributeVersion);
|
||||
|
||||
// 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 objectForKey:SURSSAttributeURL] componentsSeparatedByString:@"_"];
|
||||
NSArray *fileComponents = [enclosure[SURSSAttributeURL] componentsSeparatedByString:@"_"];
|
||||
if ([fileComponents count] > 1) {
|
||||
newVersion = [[fileComponents lastObject] stringByDeletingPathExtension];
|
||||
}
|
||||
@@ -104,14 +103,14 @@
|
||||
}
|
||||
|
||||
propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict];
|
||||
self.title = [dict objectForKey:SURSSElementTitle];
|
||||
self.dateString = [dict objectForKey:SURSSElementPubDate];
|
||||
self.itemDescription = [dict objectForKey:SURSSElementDescription];
|
||||
self.title = dict[SURSSElementTitle];
|
||||
self.date = dict[SURSSElementPubDate];
|
||||
self.itemDescription = dict[SURSSElementDescription];
|
||||
|
||||
NSString *theInfoURL = [dict objectForKey:SURSSElementLink];
|
||||
NSString *theInfoURL = dict[SURSSElementLink];
|
||||
if (theInfoURL) {
|
||||
if (![theInfoURL isKindOfClass:[NSString class]]) {
|
||||
SULog(SULogLevelError, @"%@ -%@ Info URL is not of valid type.", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
|
||||
SULog(@"%@ -%@ Info URL is not of valid type.", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
|
||||
} else {
|
||||
self.infoURL = [NSURL URLWithString:theInfoURL];
|
||||
}
|
||||
@@ -126,39 +125,29 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *enclosureURLString = [enclosure objectForKey:SURSSAttributeURL];
|
||||
NSString *enclosureURLString = enclosure[SURSSAttributeURL];
|
||||
if (!enclosureURLString && !theInfoURL) {
|
||||
if (error) {
|
||||
*error = @"Feed item's enclosure lacks URL";
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (enclosureURLString) {
|
||||
NSString *enclosureLengthString = [enclosure objectForKey:SURSSAttributeLength];
|
||||
long long contentLength = 0;
|
||||
if (enclosureLengthString != nil) {
|
||||
contentLength = [enclosureLengthString longLongValue];
|
||||
}
|
||||
_contentLength = (contentLength > 0) ? (uint64_t)contentLength : 0;
|
||||
}
|
||||
|
||||
if (enclosureURLString) {
|
||||
// Sparkle used to always URL-encode, so for backwards compatibility spaces in URLs must be forgiven.
|
||||
NSString *fileURLString = [enclosureURLString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
|
||||
NSString *fileURLString = [[enclosureURLString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
self.fileURL = [NSURL URLWithString:fileURLString];
|
||||
}
|
||||
if (enclosure) {
|
||||
self.DSASignature = [enclosure objectForKey:SUAppcastAttributeDSASignature];
|
||||
self.DSASignature = enclosure[SUAppcastAttributeDSASignature];
|
||||
}
|
||||
|
||||
self.versionString = newVersion;
|
||||
self.minimumSystemVersion = [dict objectForKey:SUAppcastElementMinimumSystemVersion];
|
||||
self.maximumSystemVersion = [dict objectForKey:SUAppcastElementMaximumSystemVersion];
|
||||
self.minimumSystemVersion = dict[SUAppcastElementMinimumSystemVersion];
|
||||
self.maximumSystemVersion = dict[SUAppcastElementMaximumSystemVersion];
|
||||
|
||||
NSString *shortVersionString = [enclosure objectForKey:SUAppcastAttributeShortVersionString];
|
||||
NSString *shortVersionString = enclosure[SUAppcastAttributeShortVersionString];
|
||||
if (nil == shortVersionString) {
|
||||
shortVersionString = [dict objectForKey:SUAppcastAttributeShortVersionString]; // fall back on the <item>
|
||||
shortVersionString = dict[SUAppcastAttributeShortVersionString]; // fall back on the <item>
|
||||
}
|
||||
|
||||
if (shortVersionString) {
|
||||
@@ -168,33 +157,28 @@
|
||||
}
|
||||
|
||||
// Find the appropriate release notes URL.
|
||||
NSString *releaseNotesString = [dict objectForKey:SUAppcastElementReleaseNotesLink];
|
||||
NSString *releaseNotesString = dict[SUAppcastElementReleaseNotesLink];
|
||||
if (releaseNotesString) {
|
||||
NSURL *url = [NSURL URLWithString:releaseNotesString];
|
||||
if ([url isFileURL]) {
|
||||
SULog(SULogLevelError, @"Release notes with file:// URLs are not supported");
|
||||
} else {
|
||||
self.releaseNotesURL = url;
|
||||
}
|
||||
self.releaseNotesURL = [NSURL URLWithString:releaseNotesString];
|
||||
} 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;
|
||||
}
|
||||
|
||||
NSArray *deltaDictionaries = [dict objectForKey:SUAppcastElementDeltas];
|
||||
NSArray *deltaDictionaries = dict[SUAppcastElementDeltas];
|
||||
if (deltaDictionaries) {
|
||||
NSMutableDictionary *deltas = [NSMutableDictionary dictionary];
|
||||
for (NSDictionary *deltaDictionary in deltaDictionaries) {
|
||||
NSString *deltaFrom = [deltaDictionary objectForKey:SUAppcastAttributeDeltaFrom];
|
||||
NSString *deltaFrom = deltaDictionary[SUAppcastAttributeDeltaFrom];
|
||||
if (!deltaFrom) continue;
|
||||
|
||||
NSMutableDictionary *fakeAppCastDict = [dict mutableCopy];
|
||||
[fakeAppCastDict removeObjectForKey:SUAppcastElementDeltas];
|
||||
[fakeAppCastDict setObject:deltaDictionary forKey:SURSSElementEnclosure];
|
||||
fakeAppCastDict[SURSSElementEnclosure] = deltaDictionary;
|
||||
SUAppcastItem *deltaItem = [[SUAppcastItem alloc] initWithDictionary:fakeAppCastDict];
|
||||
|
||||
[deltas setObject:deltaItem forKey:deltaFrom];
|
||||
deltas[deltaFrom] = deltaItem;
|
||||
}
|
||||
self.deltaUpdates = deltas;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// SUApplicationInfo.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 2/28/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SUApplicationInfo : NSObject
|
||||
|
||||
+ (BOOL)isBackgroundApplication:(NSApplication *)application;
|
||||
|
||||
+ (NSImage *)bestIconForHost:(SUHost *)host;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// SUApplicationInfo.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 2/28/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUApplicationInfo.h"
|
||||
#import "SUBundleIcon.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
@implementation SUApplicationInfo
|
||||
|
||||
+ (BOOL)isBackgroundApplication:(NSApplication *)application
|
||||
{
|
||||
return (application.activationPolicy == NSApplicationActivationPolicyAccessory);
|
||||
}
|
||||
|
||||
+ (NSImage *)bestIconForHost:(SUHost *)host
|
||||
{
|
||||
NSURL *iconURL = [SUBundleIcon iconURLForHost:host];
|
||||
|
||||
NSImage *icon = (iconURL == nil) ? nil : [[NSImage alloc] initWithContentsOfURL:iconURL];
|
||||
// Use a default icon if none is defined.
|
||||
if (!icon) {
|
||||
// this asumption may not be correct (eg. even though we're not the main bundle, it could be still be a regular app)
|
||||
// but still better than nothing if no icon was included
|
||||
BOOL isMainBundle = [host.bundle isEqualTo:[NSBundle mainBundle]];
|
||||
|
||||
NSString *fileType = isMainBundle ? (__bridge NSString *)kUTTypeApplication : (__bridge NSString *)kUTTypeBundle;
|
||||
icon = [[NSWorkspace sharedWorkspace] iconForFileType:fileType];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef SUAUTOMATICUPDATEALERT_H
|
||||
#define SUAUTOMATICUPDATEALERT_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUWindowController.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, SUAutomaticInstallationChoice) {
|
||||
SUInstallNowChoice,
|
||||
@@ -18,7 +18,7 @@ typedef NS_ENUM(NSInteger, SUAutomaticInstallationChoice) {
|
||||
};
|
||||
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUAutomaticUpdateAlert : NSWindowController
|
||||
@interface SUAutomaticUpdateAlert : SUWindowController
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle completionBlock:(void (^)(SUAutomaticInstallationChoice))c;
|
||||
- (IBAction)installNow:sender;
|
||||
|
||||
@@ -7,32 +7,19 @@
|
||||
//
|
||||
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
#import "SULocalizations.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUApplicationInfo.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
#import "SUTouchBarForwardDeclarations.h"
|
||||
#import "SUTouchBarButtonGroup.h"
|
||||
|
||||
static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUAutomaticUpdateAlert";
|
||||
|
||||
@interface SUAutomaticUpdateAlert () <NSTouchBarDelegate>
|
||||
@interface SUAutomaticUpdateAlert ()
|
||||
@property (strong) void(^completionBlock)(SUAutomaticInstallationChoice);
|
||||
@property (strong) SUAppcastItem *updateItem;
|
||||
@property (strong) SUHost *host;
|
||||
|
||||
@property (weak) IBOutlet NSButton *skipButton;
|
||||
@property (weak) IBOutlet NSButton *laterButton;
|
||||
@property (weak) IBOutlet NSButton *installButton;
|
||||
@end
|
||||
|
||||
@implementation SUAutomaticUpdateAlert
|
||||
@synthesize host;
|
||||
@synthesize updateItem;
|
||||
@synthesize completionBlock;
|
||||
@synthesize skipButton;
|
||||
@synthesize laterButton;
|
||||
@synthesize installButton;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block
|
||||
{
|
||||
@@ -42,13 +29,12 @@ static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_B
|
||||
self.completionBlock = block;
|
||||
self.host = aHost;
|
||||
[self setShouldCascadeWindows:NO];
|
||||
|
||||
[[self window] center];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *__nonnull)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; }
|
||||
- (NSString *__nonnull)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; }
|
||||
|
||||
- (IBAction)installNow:(id)__unused sender
|
||||
{
|
||||
@@ -71,17 +57,9 @@ static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_B
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
- (void)windowDidLoad
|
||||
{
|
||||
if ([self.updateItem isCriticalUpdate]) {
|
||||
self.skipButton.enabled = NO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (NSImage *__nonnull)applicationIcon
|
||||
{
|
||||
return [SUApplicationInfo bestIconForHost:self.host];
|
||||
return [self.host icon];
|
||||
}
|
||||
|
||||
- (NSString *__nonnull)titleText
|
||||
@@ -108,23 +86,4 @@ static NSString *const SUAutomaticUpdateAlertTouchBarIndentifier = @"" SPARKLE_B
|
||||
}
|
||||
}
|
||||
|
||||
- (NSTouchBar *)makeTouchBar
|
||||
{
|
||||
NSTouchBar *touchBar = [[NSClassFromString(@"NSTouchBar") alloc] init];
|
||||
touchBar.defaultItemIdentifiers = @[SUAutomaticUpdateAlertTouchBarIndentifier,];
|
||||
touchBar.principalItemIdentifier = SUAutomaticUpdateAlertTouchBarIndentifier;
|
||||
touchBar.delegate = self;
|
||||
return touchBar;
|
||||
}
|
||||
|
||||
- (NSTouchBarItem *)touchBar:(NSTouchBar * __unused)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
|
||||
{
|
||||
if ([identifier isEqualToString:SUAutomaticUpdateAlertTouchBarIndentifier]) {
|
||||
NSCustomTouchBarItem* item = [(NSCustomTouchBarItem *)[NSClassFromString(@"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier];
|
||||
item.viewController = [[SUTouchBarButtonGroup alloc] initByReferencingButtons:@[self.installButton, self.laterButton, self.skipButton]];
|
||||
return item;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -9,9 +9,11 @@
|
||||
#ifndef SUAUTOMATICUPDATEDRIVER_H
|
||||
#define SUAUTOMATICUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -7,15 +7,10 @@
|
||||
//
|
||||
|
||||
#import "SUAutomaticUpdateDriver.h"
|
||||
#import "SUUpdaterPrivate.h"
|
||||
#import "SUUpdaterDelegate.h"
|
||||
#import "SULocalizations.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUApplicationInfo.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;
|
||||
@@ -31,7 +26,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
@property (assign) BOOL postponingInstallation;
|
||||
@property (assign) BOOL showErrors;
|
||||
@property (assign) BOOL willUpdateOnTermination;
|
||||
@property (assign) BOOL isTerminating;
|
||||
@property (strong) SUAutomaticUpdateAlert *alert;
|
||||
@property (strong) NSTimer *showUpdateAlertTimer;
|
||||
|
||||
@@ -42,19 +36,17 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
@synthesize postponingInstallation;
|
||||
@synthesize showErrors;
|
||||
@synthesize willUpdateOnTermination;
|
||||
@synthesize isTerminating;
|
||||
@synthesize alert;
|
||||
@synthesize showUpdateAlertTimer;
|
||||
|
||||
- (BOOL)shouldShowUI
|
||||
{
|
||||
return self.showErrors;
|
||||
}
|
||||
|
||||
- (void)showUpdateAlert
|
||||
{
|
||||
self.interruptible = NO;
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
|
||||
if (self.alert) {
|
||||
[self.alert close];
|
||||
}
|
||||
|
||||
self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) {
|
||||
[self automaticUpdateAlertFinishedWithChoice:choice];
|
||||
}];
|
||||
@@ -62,7 +54,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
// 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 ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) {
|
||||
if ([self.host isBackgroundApplication]) {
|
||||
[[self.alert window] setHidesOnDeactivate:NO];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
@@ -73,10 +65,34 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(id)__unused ua
|
||||
- (void)downloadReleaseNotesAndWaitUntilDone
|
||||
{
|
||||
NSURL *releaseNotesURL = self.updateItem.releaseNotesURL;
|
||||
if (nil == releaseNotesURL || [releaseNotesURL isFileURL])
|
||||
return;
|
||||
|
||||
static NSString * const kSUAutomaticUpdateParamName = @"autoupdate";
|
||||
|
||||
NSString *URLString = releaseNotesURL.absoluteString;
|
||||
URLString = [URLString stringByAppendingFormat:@"%@%@=1", (releaseNotesURL.query != nil) ? @"&" : @"?", kSUAutomaticUpdateParamName];
|
||||
releaseNotesURL = [NSURL URLWithString:URLString];
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:releaseNotesURL];
|
||||
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
|
||||
[self updateURLRequestHTTPHeaders:request];
|
||||
[NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
// For correct DevMate statistics need to send request for Release Notes.
|
||||
[self downloadReleaseNotesAndWaitUntilDone];
|
||||
[super didFindValidUpdate];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(systemWillPowerOff:) name:NSWorkspaceWillPowerOffNotification object:nil];
|
||||
|
||||
// Sudden termination is available on 10.6+
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
@@ -84,8 +100,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
|
||||
self.willUpdateOnTermination = YES;
|
||||
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)])
|
||||
{
|
||||
BOOL relaunch = YES;
|
||||
@@ -95,7 +110,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
[invocation setArgument:&relaunch atIndex:2];
|
||||
[invocation setArgument:&showUI atIndex:3];
|
||||
[invocation setTarget:self];
|
||||
|
||||
|
||||
[updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation];
|
||||
}
|
||||
|
||||
@@ -113,32 +128,17 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)resumeUpdateInteractively {
|
||||
if ([self isInterruptible]) {
|
||||
[self showUpdateAlert];
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(BOOL)downloadsUpdatesInBackground {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)stopUpdatingOnTermination
|
||||
{
|
||||
if (self.willUpdateOnTermination)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
|
||||
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self name:NSWorkspaceWillPowerOffNotification object:nil];
|
||||
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
[processInfo enableSuddenTermination];
|
||||
|
||||
self.willUpdateOnTermination = NO;
|
||||
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)])
|
||||
[updaterDelegate updater:self.updater didCancelInstallUpdateOnQuit:self.updateItem];
|
||||
}
|
||||
@@ -156,14 +156,11 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
- (void)abortUpdate:(SUUpdateAbortReason)reason
|
||||
{
|
||||
[self.alert close];
|
||||
|
||||
self.isTerminating = NO;
|
||||
[self stopUpdatingOnTermination];
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
[super abortUpdate];
|
||||
[super abortUpdate:reason];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)__unused aNotification
|
||||
@@ -174,7 +171,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
|
||||
- (void)automaticUpdateAlertFinishedWithChoice:(SUAutomaticInstallationChoice)choice
|
||||
{
|
||||
self.alert = nil;
|
||||
switch (choice)
|
||||
{
|
||||
case SUInstallNowChoice:
|
||||
@@ -184,18 +180,18 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
|
||||
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];
|
||||
[self abortUpdate:SUUpdateAbortCanceledByUser];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
if (relaunch) {
|
||||
@@ -206,31 +202,11 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
[super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
|
||||
}
|
||||
|
||||
- (void)systemWillPowerOff:(NSNotification *)__unused note
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSystemPowerOffError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"The update will not be installed because the user requested for the system to power off", nil)
|
||||
}]];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)__unused note
|
||||
{
|
||||
// We don't want to terminate the app if the user or someone else initiated a termination
|
||||
// Use a property instead of passing an argument to installWithToolAndRelaunch:
|
||||
// because we give the delegate an invocation to our install methods and
|
||||
// this code was added later :|
|
||||
self.isTerminating = YES;
|
||||
|
||||
[self installWithToolAndRelaunch:NO];
|
||||
}
|
||||
|
||||
- (void)terminateApp
|
||||
{
|
||||
if (!self.isTerminating) {
|
||||
[super terminateApp];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if (self.showErrors) {
|
||||
@@ -238,13 +214,12 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
} else {
|
||||
// Call delegate separately here because otherwise it won't know we stopped.
|
||||
// Normally this gets called by the superclass
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) {
|
||||
[updaterDelegate updater:self.updater didAbortWithError:error];
|
||||
}
|
||||
|
||||
[self abortUpdate];
|
||||
[self abortUpdate:SUUpdateAbortGotError];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
#ifndef SUBASICUPDATEDRIVER_H
|
||||
#define SUBASICUPDATEDRIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUpdateDriver.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUAppcast.h"
|
||||
|
||||
@class SUAppcast, SUAppcastItem, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate>
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate, SUUnarchiverDelegate>
|
||||
|
||||
@property (strong, readonly) SUAppcastItem *updateItem;
|
||||
@property (strong, readonly) NSURLDownload *download;
|
||||
@@ -21,32 +24,31 @@
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host;
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui;
|
||||
+ (BOOL)hostSupportsItem:(SUAppcastItem *)ui;
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui;
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui;
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui;
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac;
|
||||
- (void)didFindValidUpdate;
|
||||
- (void)didNotFindUpdate;
|
||||
|
||||
- (void)updateURLRequestHTTPHeaders:(NSMutableURLRequest *)request;
|
||||
- (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;
|
||||
|
||||
// Needed to preserve compatibility to subclasses, even though our unarchiver code uses blocks now
|
||||
- (void)unarchiver:(id)ua extractedProgress:(double)progress;
|
||||
- (void)unarchiverDidFinish:(id)ua;
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch;
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
|
||||
- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error;
|
||||
|
||||
- (void)cleanUpDownload;
|
||||
|
||||
- (void)abortUpdate;
|
||||
- (void)abortUpdate:(SUUpdateAbortReason)reason;
|
||||
- (void)abortUpdateWithError:(NSError *)error;
|
||||
- (void)terminateApp;
|
||||
|
||||
|
||||
@@ -8,22 +8,21 @@
|
||||
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUOperatingSystem.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 "SUUpdaterPrivate.h"
|
||||
#import "SUUpdaterDelegate.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SUUpdateValidator.h"
|
||||
#import "SULocalizations.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUUpdater_Private.h"
|
||||
#import "SUXPCInstaller.h"
|
||||
|
||||
CF_EXPORT CFDictionaryRef DMCopyHTTPRequestHeaders(CFBundleRef appBundle, CFDataRef httpBodyData);
|
||||
|
||||
@interface SUBasicUpdateDriver ()
|
||||
|
||||
@@ -35,8 +34,6 @@
|
||||
@property (copy) NSString *tempDir;
|
||||
@property (copy) NSString *relaunchPath;
|
||||
|
||||
@property (nonatomic) SUUpdateValidator *updateValidator;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUBasicUpdateDriver
|
||||
@@ -49,8 +46,6 @@
|
||||
@synthesize tempDir;
|
||||
@synthesize relaunchPath;
|
||||
|
||||
@synthesize updateValidator = _updateValidator;
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
|
||||
{
|
||||
[super checkForUpdatesAtURL:URL host:aHost];
|
||||
@@ -60,12 +55,15 @@
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
|
||||
request.allHTTPHeaderFields = [self.updater httpHeaders];
|
||||
[self updateURLRequestHTTPHeaders:request];
|
||||
|
||||
SUAppcast *appcast = [[SUAppcast alloc] init];
|
||||
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
[appcast setUserAgentString:[updater userAgentString]];
|
||||
[appcast setHttpHeaders:[updater httpHeaders]];
|
||||
[appcast fetchAppcastFromURL:URL inBackground:self.downloadsAppcastInBackground completionBlock:^(NSError *error) {
|
||||
[appcast setUserAgentString:[self.updater userAgentString]];
|
||||
[appcast setHttpHeaders:request.allHTTPHeaderFields];
|
||||
[appcast fetchAppcastFromURL:URL completionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
[self abortUpdateWithError:error];
|
||||
} else {
|
||||
@@ -77,68 +75,44 @@
|
||||
- (id<SUVersionComparison>)versionComparator
|
||||
{
|
||||
id<SUVersionComparison> comparator = nil;
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
|
||||
|
||||
// Give the delegate a chance to provide a custom version comparator
|
||||
if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) {
|
||||
comparator = [[updater delegate] versionComparatorForUpdater:self.updater];
|
||||
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 alloc] init];
|
||||
comparator = [SUStandardVersionComparator defaultComparator];
|
||||
}
|
||||
|
||||
return comparator;
|
||||
}
|
||||
|
||||
+ (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem * __autoreleasing *)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id<SUVersionComparison>)comparator
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui
|
||||
{
|
||||
SUAppcastItem *item = nil;
|
||||
for(SUAppcastItem *candidate in appcastItems) {
|
||||
if ([[self class] hostSupportsItem:candidate]) {
|
||||
if (!item || [comparator compareVersion:item.versionString toVersion:candidate.versionString] == NSOrderedAscending) {
|
||||
item = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item && deltaItem) {
|
||||
SUAppcastItem *deltaUpdateItem = [[item deltaUpdates] objectForKey:hostVersion];
|
||||
if (deltaUpdateItem && [[self class] hostSupportsItem:deltaUpdateItem]) {
|
||||
*deltaItem = deltaUpdateItem;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
}
|
||||
|
||||
+ (BOOL)hostSupportsItem:(SUAppcastItem *)ui
|
||||
- (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;
|
||||
|
||||
id<SUVersionComparison> versionComparator = [[SUStandardVersionComparator alloc] init];
|
||||
|
||||
// Check minimum and maximum System Version
|
||||
if ([ui minimumSystemVersion] != nil && ![[ui minimumSystemVersion] isEqualToString:@""]) {
|
||||
minimumVersionOK = [versionComparator compareVersion:[ui minimumSystemVersion] toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending;
|
||||
minimumVersionOK = [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedDescending;
|
||||
}
|
||||
if ([ui maximumSystemVersion] != nil && ![[ui maximumSystemVersion] isEqualToString:@""]) {
|
||||
maximumVersionOK = [versionComparator compareVersion:[ui maximumSystemVersion] toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending;
|
||||
maximumVersionOK = [[SUStandardVersionComparator defaultComparator] compareVersion:[ui maximumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedAscending;
|
||||
}
|
||||
|
||||
return minimumVersionOK && maximumVersionOK;
|
||||
}
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui
|
||||
{
|
||||
return [[self versionComparator] compareVersion:[self.host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
|
||||
{
|
||||
NSString *skippedVersion = [self.host objectForUserDefaultsKey:SUSkippedVersionKey];
|
||||
@@ -148,40 +122,35 @@
|
||||
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
|
||||
{
|
||||
return ui && [[self class] hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui];
|
||||
return ui && [self hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui];
|
||||
}
|
||||
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac
|
||||
{
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) {
|
||||
[[updater delegate] updater:self.updater didFinishLoadingAppcast:ac];
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) {
|
||||
[[self.updater delegate] updater:self.updater didFinishLoadingAppcast:ac];
|
||||
}
|
||||
|
||||
NSDictionary *userInfo = @{ SUUpdaterAppcastNotificationKey: 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 ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it?
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it?
|
||||
{
|
||||
item = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:self.updater];
|
||||
}
|
||||
|
||||
if (item != nil) // 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.
|
||||
{
|
||||
if ([item isDeltaUpdate]) {
|
||||
self.nonDeltaUpdateItem = [[updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:self.updater];
|
||||
}
|
||||
}
|
||||
else // If not, we'll take care of it ourselves.
|
||||
{
|
||||
// Find the best supported update
|
||||
SUAppcastItem *deltaUpdateItem = nil;
|
||||
item = [[self class] bestItemFromAppcastItems:ac.items getDeltaItem:&deltaUpdateItem withHostVersion:self.host.version comparator:[self versionComparator]];
|
||||
|
||||
if (item && deltaUpdateItem) {
|
||||
// Find the first update we can actually use.
|
||||
NSEnumerator *updateEnumerator = [[ac items] objectEnumerator];
|
||||
do {
|
||||
item = [updateEnumerator nextObject];
|
||||
} while (item && ![self hostSupportsItem:item]);
|
||||
|
||||
SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]];
|
||||
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
|
||||
self.nonDeltaUpdateItem = item;
|
||||
item = deltaUpdateItem;
|
||||
}
|
||||
@@ -199,11 +168,9 @@
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
||||
[[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
|
||||
[[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
||||
@@ -214,10 +181,8 @@
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
|
||||
if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
|
||||
[[updater delegate] updaterDidNotFindUpdate:self.updater];
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
|
||||
[[self.updater delegate] updaterDidNotFindUpdate:self.updater];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
|
||||
@@ -229,46 +194,29 @@
|
||||
}]];
|
||||
}
|
||||
|
||||
- (NSString *)appCachePath
|
||||
- (void)updateURLRequestHTTPHeaders:(NSMutableURLRequest *)request
|
||||
{
|
||||
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cachePath = nil;
|
||||
if ([cachePaths count]) {
|
||||
cachePath = [cachePaths objectAtIndex:0];
|
||||
}
|
||||
if (!cachePath) {
|
||||
SULog(SULogLevelError, @"Failed to find user's cache directory! Using system default");
|
||||
cachePath = NSTemporaryDirectory();
|
||||
NSURL *hostBundleURL = self.host.bundlePath.length ? [NSURL fileURLWithPath:self.host.bundlePath] : nil;
|
||||
CFBundleRef hostBundle = hostBundleURL ? CFBundleCreate(kCFAllocatorDefault, (__bridge CFURLRef)hostBundleURL) : NULL;
|
||||
NSDictionary *devmateHeaders = (__bridge_transfer NSDictionary *)DMCopyHTTPRequestHeaders(hostBundle, NULL);
|
||||
if (devmateHeaders.count)
|
||||
{
|
||||
[request setAllHTTPHeaderFields:devmateHeaders];
|
||||
}
|
||||
|
||||
NSString *name = [self.host.bundle bundleIdentifier];
|
||||
if (!name) {
|
||||
name = [self.host name];
|
||||
if (NULL != hostBundle)
|
||||
{
|
||||
CFRelease(hostBundle);
|
||||
}
|
||||
|
||||
cachePath = [cachePath stringByAppendingPathComponent:name];
|
||||
cachePath = [cachePath stringByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER];
|
||||
return cachePath;
|
||||
}
|
||||
|
||||
- (void)downloadUpdate
|
||||
{
|
||||
// Clear cache directory so that downloads can't possibly accumulate inside
|
||||
NSString *appCachePath = [self appCachePath];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:appCachePath]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:appCachePath error:NULL];
|
||||
}
|
||||
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]];
|
||||
if (self.downloadsUpdatesInBackground) {
|
||||
request.networkServiceType = NSURLNetworkServiceTypeBackground;
|
||||
}
|
||||
|
||||
[request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"];
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) {
|
||||
[[updater delegate] updater:self.updater
|
||||
[request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"];
|
||||
[self updateURLRequestHTTPHeaders:request];
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) {
|
||||
[[self.updater delegate] updater:self.updater
|
||||
willDownloadUpdate:self.updateItem
|
||||
withRequest:request];
|
||||
}
|
||||
@@ -278,14 +226,13 @@
|
||||
- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name
|
||||
{
|
||||
NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]];
|
||||
|
||||
NSString *appCachePath = [self appCachePath];
|
||||
|
||||
self.tempDir = [appCachePath stringByAppendingPathComponent:downloadFileName];
|
||||
|
||||
|
||||
self.tempDir = [self.host.appCachePath stringByAppendingPathComponent:downloadFileName];
|
||||
int cnt = 1;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:self.tempDir] && cnt <= 999)
|
||||
{
|
||||
self.tempDir = [appCachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]];
|
||||
self.tempDir = [self.host.appCachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]];
|
||||
}
|
||||
|
||||
// Create the temporary directory if necessary.
|
||||
@@ -301,6 +248,90 @@
|
||||
[self.download setDestination:self.downloadPath allowOverwrite:YES];
|
||||
}
|
||||
|
||||
/**
|
||||
* If the update is a package, then it must be signed using DSA. No other verification is done.
|
||||
*
|
||||
* If the update is a bundle, then it must meet any one of:
|
||||
*
|
||||
* * old and new DSA public keys are the same and valid (it allows change of Code Signing identity), or
|
||||
*
|
||||
* * old and new Code Signing identity are the same and valid
|
||||
*
|
||||
*/
|
||||
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
|
||||
{
|
||||
BOOL isUpdateValid = NO;
|
||||
|
||||
do
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *installSourcePath = [SUInstaller installSourcePathInUpdateFolder:extractedPath forHost:self.host isPackage:&isPackage isGuided:NULL];
|
||||
if (installSourcePath == nil)
|
||||
{
|
||||
SULog(@"No suitable install is found in the update. The update will be rejected.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Modern packages are not distributed as bundles and are code signed differently than regular applications
|
||||
if (isPackage)
|
||||
{
|
||||
isUpdateValid = [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey];
|
||||
if (!isUpdateValid)
|
||||
{
|
||||
SULog(@"DSA signature validation of the package failed. The update will be rejected.");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
NSBundle *newBundle = [NSBundle bundleWithPath:installSourcePath];
|
||||
if (newBundle == nil)
|
||||
{
|
||||
SULog(@"No suitable bundle is found in the update. The update will be rejected.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check Code Signing equality
|
||||
NSError *error = nil;
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier applicationAtPathIsCodeSigned:installSourcePath];
|
||||
updateIsCodeSigned = updateIsCodeSigned && [SUCodeSigningVerifier codeSignatureIsValidAtPath:installSourcePath error:&error];
|
||||
if (!updateIsCodeSigned)
|
||||
{
|
||||
SULog(@"Update has no valid Code Signing (%ld - %@)", error.code, error.localizedDescription);
|
||||
}
|
||||
|
||||
BOOL shouldCheckCodeSignEquality = updateIsCodeSigned ? [SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.host.bundlePath] : NO;
|
||||
if (shouldCheckCodeSignEquality && [SUCodeSigningVerifier codeSignatureAtPath:self.host.bundlePath matchesSignatureAtPath:installSourcePath error:&error])
|
||||
{
|
||||
isUpdateValid = YES;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SULog(@"Code signatures differs in application and update (%ld - %@)", error.code, error.localizedDescription);
|
||||
}
|
||||
|
||||
// Check DSA signature
|
||||
SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle];
|
||||
NSString *newPublicDSAKey = newHost.publicDSAKey;
|
||||
|
||||
BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey];
|
||||
if (!dsaKeysMatch)
|
||||
{
|
||||
SULog(@"DSA keys are different for update and application.");
|
||||
}
|
||||
|
||||
isUpdateValid = dsaKeysMatch && [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:newPublicDSAKey];
|
||||
if (!isUpdateValid)
|
||||
{
|
||||
SULog(@"DSA signature validation failed. The update has a public DSA key and is signed with a DSA key, but the %@ doesn't match the signature. The update will be rejected.", dsaKeysMatch ? @"public key" : @"new public key shipped with the update");
|
||||
}
|
||||
}
|
||||
while (NO);
|
||||
|
||||
return isUpdateValid;
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)__unused d
|
||||
{
|
||||
assert(self.updateItem);
|
||||
@@ -310,28 +341,22 @@
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error
|
||||
{
|
||||
NSURL *failingUrl = [error.userInfo objectForKey:NSURLErrorFailingURLErrorKey];
|
||||
NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey];
|
||||
if (!failingUrl) {
|
||||
failingUrl = [self.updateItem fileURL];
|
||||
}
|
||||
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) {
|
||||
[[updater delegate] updater:self.updater
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) {
|
||||
[[self.updater delegate] updater:self.updater
|
||||
failedToDownloadUpdate:self.updateItem
|
||||
error:error];
|
||||
}
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil),
|
||||
NSUnderlyingErrorKey: error,
|
||||
}];
|
||||
if (failingUrl) {
|
||||
[userInfo setObject:failingUrl forKey:NSURLErrorFailingURLErrorKey];
|
||||
}
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]];
|
||||
NSURLErrorFailingURLErrorKey: failingUrl ? failingUrl : [NSNull null],
|
||||
}]];
|
||||
}
|
||||
|
||||
- (BOOL)download:(NSURLDownload *)__unused download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType
|
||||
@@ -343,38 +368,14 @@
|
||||
|
||||
- (void)extractUpdate
|
||||
{
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:updater.decryptionPassword];
|
||||
|
||||
BOOL success;
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:[[self.host bundle] bundlePath]];
|
||||
if (!unarchiver) {
|
||||
SULog(SULogLevelError, @"Error: No valid unarchiver for %@!", self.downloadPath);
|
||||
|
||||
success = NO;
|
||||
} else {
|
||||
// Currently unsafe archives are the only case where we can prevalidate before extraction, but that could change in the future
|
||||
BOOL needsPrevalidation = [[unarchiver class] unsafeIfArchiveIsNotValidated];
|
||||
|
||||
self.updateValidator = [[SUUpdateValidator alloc] initWithDownloadPath:self.downloadPath dsaSignature:self.updateItem.DSASignature host:self.host performingPrevalidation:needsPrevalidation];
|
||||
|
||||
success = self.updateValidator.canValidate;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
NSError *reason = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey: @"Failed to extract update."}];
|
||||
[self unarchiverDidFailWithError:reason];
|
||||
} else {
|
||||
[unarchiver unarchiveWithCompletionBlock:^(NSError *err){
|
||||
if (err) {
|
||||
[self unarchiverDidFailWithError:err];
|
||||
return;
|
||||
}
|
||||
|
||||
[self unarchiverDidFinish:nil];
|
||||
} progressBlock:^(double progress) {
|
||||
[self unarchiver:nil extractedProgress:progress];
|
||||
}];
|
||||
SULog(@"Error: No valid unarchiver for %@!", self.downloadPath);
|
||||
[self unarchiverDidFail:nil];
|
||||
return;
|
||||
}
|
||||
unarchiver.delegate = self;
|
||||
[unarchiver start];
|
||||
}
|
||||
|
||||
- (void)failedToApplyDeltaUpdate
|
||||
@@ -386,30 +387,21 @@
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
// By default does nothing, can be overridden
|
||||
- (void)unarchiver:(id)__unused ua extractedProgress:(double)__unused progress
|
||||
{
|
||||
}
|
||||
|
||||
// Note this method can be overridden (and is)
|
||||
- (void)unarchiverDidFinish:(id)__unused ua
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFailWithError:(NSError *)err
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
// No longer needed
|
||||
self.updateValidator = nil;
|
||||
|
||||
if ([self.updateItem isDeltaUpdate]) {
|
||||
[self failedToApplyDeltaUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
[self abortUpdateWithError:err];
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) }]];
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch
|
||||
@@ -418,62 +410,29 @@
|
||||
[self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch];
|
||||
}
|
||||
|
||||
// Creates intermediate directories up until targetPath if they don't already exist,
|
||||
// and removes the directory at targetPath if one already exists there
|
||||
- (BOOL)preparePathForRelaunchTool:(NSString *)targetPath error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
if ([fileManager fileExistsAtPath:targetPath]) {
|
||||
NSError *removeError = nil;
|
||||
if (![fileManager removeItemAtPath:targetPath error:&removeError]) {
|
||||
if (error != NULL) {
|
||||
*error = removeError;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
NSError *createDirectoryError = nil;
|
||||
if (![fileManager createDirectoryAtPath:[targetPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:@{} error:&createDirectoryError]) {
|
||||
if (error != NULL) {
|
||||
*error = createDirectoryError;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)mayUpdateAndRestart
|
||||
{
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
return (!updater.delegate || ![updater.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [updater.delegate updaterShouldRelaunchApplication:self.updater]);
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
assert(self.updateItem);
|
||||
assert(self.updateValidator);
|
||||
|
||||
BOOL validationCheckSuccess = [self.updateValidator validateWithUpdateDirectory:self.tempDir];
|
||||
if (!validationCheckSuccess) {
|
||||
|
||||
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),
|
||||
};
|
||||
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 mayUpdateAndRestart])
|
||||
if (![self.updater mayUpdateAndRestart])
|
||||
{
|
||||
[self abortUpdate];
|
||||
[self abortUpdate:SUUpdateAbortForbiddenByDelegate];
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the host app an opportunity to postpone the install and relaunch.
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
static BOOL postponedOnce = NO;
|
||||
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if (!postponedOnce && [updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)])
|
||||
{
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]];
|
||||
@@ -491,48 +450,37 @@
|
||||
[updaterDelegate updater:self.updater willInstallUpdate:self.updateItem];
|
||||
}
|
||||
|
||||
NSBundle *sparkleBundle = updater.sparkleBundle;
|
||||
NSBundle *sparkleBundle = self.updater.sparkleBundle;
|
||||
|
||||
// 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 *const relaunchToolName = @"" SPARKLE_RELAUNCH_TOOL_NAME;
|
||||
NSString *const relaunchToolSourcePath = [sparkleBundle pathForResource:relaunchToolName ofType:@"app"];
|
||||
NSString *relaunchCopyTargetPath = nil;
|
||||
NSError *error = nil;
|
||||
BOOL copiedRelaunchPath = NO;
|
||||
NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:relaunchToolName ofType:@"app"];
|
||||
if (relaunchPathToCopy != nil) {
|
||||
NSString *targetPath = [self.host.appCachePath 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 (relaunchToolSourcePath) {
|
||||
relaunchCopyTargetPath = [[self appCachePath] stringByAppendingPathComponent:[relaunchToolSourcePath lastPathComponent]];
|
||||
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
|
||||
NSURL *relaunchToolSourceURL = [NSURL fileURLWithPath:relaunchToolSourcePath];
|
||||
NSURL *relaunchCopyTargetURL = [NSURL fileURLWithPath:relaunchCopyTargetPath];
|
||||
|
||||
// We only need to run our copy of the app by spawning a task
|
||||
// Since we are copying the app to a directory that is write-accessible, we don't need to muck with owner/group IDs
|
||||
if ([self preparePathForRelaunchTool:relaunchCopyTargetPath error:&error] && [fileManager copyItemAtURL:relaunchToolSourceURL toURL:relaunchCopyTargetURL error:&error]) {
|
||||
copiedRelaunchPath = YES;
|
||||
|
||||
// We probably don't need to release the quarantine, but we'll do it just in case it's necessary.
|
||||
// Perhaps in a sandboxed environment this matters more. Note that this may not be a fatal error.
|
||||
NSError *quarantineError = nil;
|
||||
if (![fileManager releaseItemFromQuarantineAtRootURL:relaunchCopyTargetURL error:&quarantineError]) {
|
||||
SULog(SULogLevelError, @"Failed to release quarantine on %@ with error %@", relaunchCopyTargetPath, quarantineError);
|
||||
}
|
||||
BOOL copySuccess = NO;
|
||||
if (SUShouldUseXPCInstaller())
|
||||
{
|
||||
copySuccess = [SUXPCInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath appendVersion:SPARKLE_APPEND_VERSION_NUMBER error:&error];
|
||||
}
|
||||
else
|
||||
{
|
||||
copySuccess = [SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath appendVersion:SPARKLE_APPEND_VERSION_NUMBER error:&error];
|
||||
}
|
||||
if (copySuccess) {
|
||||
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] : @"")]
|
||||
}]];
|
||||
}
|
||||
}
|
||||
|
||||
if (!copiedRelaunchPath) {
|
||||
[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 copy relauncher (%@) to temporary path (%@)! %@",
|
||||
relaunchToolSourcePath, relaunchCopyTargetPath, (error ? [error localizedDescription] : @"")],
|
||||
}]];
|
||||
return;
|
||||
}
|
||||
|
||||
self.relaunchPath = relaunchCopyTargetPath; // Set for backwards compatibility, in case any delegates modify it
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)])
|
||||
[updaterDelegate updaterWillRelaunchApplication:self.updater];
|
||||
@@ -542,29 +490,33 @@
|
||||
// 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 %@ and %@)", relaunchToolSourcePath, self.relaunchPath],
|
||||
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:)]) {
|
||||
NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:self.updater];
|
||||
if (delegateRelaunchPath != nil) {
|
||||
pathToRelaunch = delegateRelaunchPath;
|
||||
}
|
||||
pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater];
|
||||
}
|
||||
NSArray *arguments = @[self.host.bundlePath.length ? self.host.bundlePath: @"",
|
||||
pathToRelaunch.length ? pathToRelaunch : @"",
|
||||
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
|
||||
self.tempDir.length ? self.tempDir : @"",
|
||||
relaunch ? @"1" : @"0",
|
||||
showUI ? @"1" : @"0"];
|
||||
if (SUShouldUseXPCInstaller())
|
||||
{
|
||||
[SUXPCInstaller launchTaskWithPath:relaunchToolPath arguments:arguments environment:nil currentDirectoryPath:nil inputData:nil waitUntilDone:NO completionHandler:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:arguments];
|
||||
}
|
||||
|
||||
[NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath],
|
||||
pathToRelaunch,
|
||||
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
|
||||
self.tempDir,
|
||||
relaunch ? @"1" : @"0",
|
||||
showUI ? @"1" : @"0"]];
|
||||
[self terminateApp];
|
||||
}
|
||||
|
||||
// Note: this is overridden by the automatic update driver to not terminate in some cases
|
||||
- (void)terminateApp
|
||||
{
|
||||
[NSApp terminate:self];
|
||||
@@ -596,36 +548,30 @@
|
||||
}]];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
- (void)abortUpdate:(SUUpdateAbortReason)reason
|
||||
{
|
||||
[self cleanUpDownload];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
self.updateItem = nil;
|
||||
[super abortUpdate];
|
||||
[super abortUpdate:reason];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if ([error code] != SUNoUpdateError) { // Let's not bother logging this.
|
||||
NSError *errorToDisplay = error;
|
||||
int finiteRecursion=5;
|
||||
do {
|
||||
SULog(SULogLevelError, @"Error: %@ %@ (URL %@)", errorToDisplay.localizedDescription, errorToDisplay.localizedFailureReason, [errorToDisplay.userInfo objectForKey:NSURLErrorFailingURLErrorKey]);
|
||||
errorToDisplay = [errorToDisplay.userInfo objectForKey:NSUnderlyingErrorKey];
|
||||
} while(--finiteRecursion && errorToDisplay);
|
||||
SULog(@"Error: %@ %@ (URL %@)", error.localizedDescription, error.localizedFailureReason, error.userInfo[NSURLErrorFailingURLErrorKey]);
|
||||
}
|
||||
if (self.download) {
|
||||
[self.download cancel];
|
||||
}
|
||||
|
||||
// Notify host app that update has aborted
|
||||
id<SUUpdaterPrivate> updater = self.updater;
|
||||
id<SUUpdaterDelegate> updaterDelegate = [updater delegate];
|
||||
id<SUUpdaterDelegate> updaterDelegate = [self.updater delegate];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) {
|
||||
[updaterDelegate updater:self.updater didAbortWithError:error];
|
||||
}
|
||||
|
||||
[self abortUpdate];
|
||||
[self abortUpdate:SUUpdateAbortGotError];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -9,9 +9,7 @@
|
||||
#ifndef SUBINARYDELTAAPPLY_H
|
||||
#define SUBINARYDELTAAPPLY_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class NSString;
|
||||
BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose, void (^progressCallback)(double), NSError * __autoreleasing *error);
|
||||
BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose, NSError * __autoreleasing *error);
|
||||
|
||||
#endif
|
||||
@@ -15,19 +15,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
static BOOL 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] };
|
||||
const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]};
|
||||
BOOL success = (bspatch(4, argv) == 0);
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
return success;
|
||||
}
|
||||
|
||||
BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose, void (^progressCallback)(double progress), NSError *__autoreleasing *error)
|
||||
BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose, NSError * __autoreleasing *error)
|
||||
{
|
||||
xar_t x = xar_open([patchFile fileSystemRepresentation], READ);
|
||||
if (!x) {
|
||||
@@ -36,71 +34,69 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
int minorDiffVersion = 0;
|
||||
SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION;
|
||||
|
||||
NSString *expectedBeforeHashv1 = nil;
|
||||
NSString *expectedAfterHashv1 = nil;
|
||||
|
||||
|
||||
NSString *expectedNewBeforeHash = nil;
|
||||
NSString *expectedNewAfterHash = nil;
|
||||
|
||||
progressCallback(0/6.0);
|
||||
|
||||
|
||||
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_KEY)) {
|
||||
const char *value = 0;
|
||||
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MAJOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
majorDiffVersion = (SUBinaryDeltaMajorVersion)[@(value) intValue];
|
||||
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
minorDiffVersion = [@(value) intValue];
|
||||
|
||||
minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue];
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_KEY, &value);
|
||||
if (value)
|
||||
expectedNewBeforeHash = @(value);
|
||||
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_KEY, &value);
|
||||
if (value)
|
||||
expectedNewAfterHash = @(value);
|
||||
|
||||
|
||||
// only available in version 1.0
|
||||
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_OLD_KEY, &value);
|
||||
if (value)
|
||||
expectedBeforeHashv1 = @(value);
|
||||
|
||||
|
||||
// only available in version 1.0
|
||||
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_OLD_KEY, &value);
|
||||
if (value)
|
||||
expectedAfterHashv1 = @(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (majorDiffVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Unable to identify diff-version %u in delta. Giving up.", majorDiffVersion] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
if (majorDiffVersion > LATEST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A later version is needed to apply this patch (on major version %u, but patch requests version %u).", LATEST_DELTA_DIFF_MAJOR_VERSION, majorDiffVersion] }];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
BOOL usesNewTreeHash = MAJOR_VERSION_IS_AT_LEAST(majorDiffVersion, SUBeigeMajorVersion);
|
||||
|
||||
|
||||
NSString *expectedBeforeHash = usesNewTreeHash ? expectedNewBeforeHash : expectedBeforeHashv1;
|
||||
NSString *expectedAfterHash = usesNewTreeHash ? expectedNewAfterHash : expectedAfterHashv1;
|
||||
|
||||
@@ -115,9 +111,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
fprintf(stderr, "Applying version %u.%u patch...\n", majorDiffVersion, minorDiffVersion);
|
||||
fprintf(stderr, "Verifying source...");
|
||||
}
|
||||
|
||||
progressCallback(1/6.0);
|
||||
|
||||
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorDiffVersion);
|
||||
if (!beforeHash) {
|
||||
if (verbose) {
|
||||
@@ -142,9 +136,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nCopying files...");
|
||||
}
|
||||
|
||||
progressCallback(2/6.0);
|
||||
|
||||
|
||||
if (!removeTree(destination)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -154,9 +146,6 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(3/6.0);
|
||||
|
||||
if (!copyTree(source, destination)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -166,9 +155,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(4/6.0);
|
||||
|
||||
|
||||
BOOL hasExtractKeyAvailable = MAJOR_VERSION_IS_AT_LEAST(majorDiffVersion, SUBeigeMajorVersion);
|
||||
|
||||
if (verbose) {
|
||||
@@ -185,9 +172,10 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
// Don't use -[NSFileManager fileExistsAtPath:] because it will follow symbolic links
|
||||
BOOL fileExisted = verbose && [fileManager attributesOfItemAtPath:destinationFilePath error:nil];
|
||||
BOOL removedFile = NO;
|
||||
|
||||
|
||||
const char *value;
|
||||
if (!xar_prop_get(file, DELETE_KEY, &value) || (!hasExtractKeyAvailable && !xar_prop_get(file, DELETE_THEN_EXTRACT_OLD_KEY, &value))) {
|
||||
if (!xar_prop_get(file, DELETE_KEY, &value) ||
|
||||
(!hasExtractKeyAvailable && !xar_prop_get(file, DELETE_THEN_EXTRACT_OLD_KEY, &value))) {
|
||||
if (!removeTree(destinationFilePath)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -203,7 +191,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
removedFile = YES;
|
||||
}
|
||||
|
||||
@@ -217,12 +205,13 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n🔨 %s %s", VERBOSE_PATCHED, [path fileSystemRepresentation]);
|
||||
}
|
||||
} else if ((hasExtractKeyAvailable && !xar_prop_get(file, EXTRACT_KEY, &value)) || (!hasExtractKeyAvailable && xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value))) { // extract and permission modifications don't coexist
|
||||
|
||||
} else if ((hasExtractKeyAvailable && !xar_prop_get(file, EXTRACT_KEY, &value)) ||
|
||||
(!hasExtractKeyAvailable && xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value))) { // extract and permission modifications don't coexist
|
||||
|
||||
if (xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]) != 0) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -232,7 +221,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
if (verbose) {
|
||||
if (fileExisted) {
|
||||
fprintf(stderr, "\n✏️ %s %s", VERBOSE_UPDATED, [path fileSystemRepresentation]);
|
||||
@@ -243,7 +232,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
} else if (verbose && removedFile) {
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_DELETED, [path fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
|
||||
if (!xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value)) {
|
||||
mode_t mode = (mode_t)[[NSString stringWithUTF8String:value] intValue];
|
||||
if (!modifyPermissions(destinationFilePath, mode)) {
|
||||
@@ -255,7 +244,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n👮 %s %s (0%o)", VERBOSE_MODIFIED, [path fileSystemRepresentation], mode);
|
||||
}
|
||||
@@ -263,8 +252,6 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
xar_close(x);
|
||||
|
||||
progressCallback(5/6.0);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nVerifying destination...");
|
||||
}
|
||||
@@ -290,8 +277,6 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
return NO;
|
||||
}
|
||||
|
||||
progressCallback(6/6.0);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
}
|
||||
|
||||
@@ -57,7 +57,16 @@ typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion)
|
||||
SUBeigeMajorVersion = 2
|
||||
};
|
||||
|
||||
// Only keep track of the latest minor version for each major version
|
||||
typedef NS_ENUM(uint16_t, SUBinaryDeltaMinorVersion)
|
||||
{
|
||||
SUAzureMinorVersion = 1,
|
||||
SUBeigeMinorVersion = 1,
|
||||
};
|
||||
|
||||
#define FIRST_DELTA_DIFF_MAJOR_VERSION SUAzureMajorVersion
|
||||
#define FIRST_DELTA_DIFF_MINOR_VERSION ((SUBinaryDeltaMinorVersion)0)
|
||||
|
||||
#define LATEST_DELTA_DIFF_MAJOR_VERSION SUBeigeMajorVersion
|
||||
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
@@ -71,5 +80,5 @@ extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path);
|
||||
NSString *temporaryFilename(NSString *base);
|
||||
NSString *temporaryDirectory(NSString *base);
|
||||
NSString *stringWithFileSystemRepresentation(const char*);
|
||||
int latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion);
|
||||
SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion);
|
||||
#endif
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#import "SUFileManager.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
@@ -18,8 +17,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
int compareFiles(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcoll((*a)->fts_name, (*b)->fts_name);
|
||||
@@ -34,20 +31,19 @@ NSString *pathRelativeToDirectory(NSString *directory, NSString *path)
|
||||
return path;
|
||||
}
|
||||
|
||||
NSString *stringWithFileSystemRepresentation(const char *input)
|
||||
{
|
||||
NSString *stringWithFileSystemRepresentation(const char *input) {
|
||||
return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:input length:strlen(input)];
|
||||
}
|
||||
|
||||
int latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion)
|
||||
SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion)
|
||||
{
|
||||
switch (majorVersion) {
|
||||
case SUAzureMajorVersion:
|
||||
return 1;
|
||||
return SUAzureMinorVersion;
|
||||
case SUBeigeMajorVersion:
|
||||
return 2;
|
||||
return SUBeigeMinorVersion;
|
||||
}
|
||||
return 0;
|
||||
return (SUBinaryDeltaMinorVersion)0;
|
||||
}
|
||||
|
||||
NSString *temporaryFilename(NSString *base)
|
||||
@@ -76,18 +72,18 @@ NSString *temporaryDirectory(NSString *base)
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
[data appendBytes:template.fileSystemRepresentation length:strlen(template.fileSystemRepresentation) + 1];
|
||||
|
||||
|
||||
char *buffer = data.mutableBytes;
|
||||
char *templateResult = mkdtemp(buffer);
|
||||
if (templateResult == NULL) {
|
||||
perror("mkdtemp");
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
return stringWithFileSystemRepresentation(templateResult);
|
||||
}
|
||||
|
||||
static void _hashOfBuffer(unsigned char *hash, const char *buffer, ssize_t bufferLength)
|
||||
static void _hashOfBuffer(unsigned char *hash, const char* buffer, ssize_t bufferLength)
|
||||
{
|
||||
assert(bufferLength >= 0 && bufferLength <= UINT32_MAX);
|
||||
CC_SHA1_CTX hashContext;
|
||||
@@ -96,7 +92,7 @@ static void _hashOfBuffer(unsigned char *hash, const char *buffer, ssize_t buffe
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
}
|
||||
|
||||
static BOOL _hashOfFileContents(unsigned char *hash, FTSENT *ent)
|
||||
static BOOL _hashOfFileContents(unsigned char* hash, FTSENT *ent)
|
||||
{
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
char linkDestination[MAXPATHLEN + 1];
|
||||
@@ -119,12 +115,12 @@ static BOOL _hashOfFileContents(unsigned char *hash, FTSENT *ent)
|
||||
_hashOfBuffer(hash, NULL, 0);
|
||||
} else {
|
||||
void *buffer = mmap(0, (size_t)fileSize, PROT_READ, MAP_FILE | MAP_PRIVATE, fileDescriptor, 0);
|
||||
if (buffer == (void *)-1) {
|
||||
if (buffer == (void*)-1) {
|
||||
close(fileDescriptor);
|
||||
perror("mmap");
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
_hashOfBuffer(hash, buffer, fileSize);
|
||||
munmap(buffer, (size_t)fileSize);
|
||||
}
|
||||
@@ -148,12 +144,12 @@ NSData *hashOfFileContents(FTSENT *ent)
|
||||
|
||||
NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
{
|
||||
char pathBuffer[PATH_MAX] = { 0 };
|
||||
char pathBuffer[PATH_MAX] = {0};
|
||||
if (![path getFileSystemRepresentation:pathBuffer maxLength:sizeof(pathBuffer)]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
char *const sourcePaths[] = { pathBuffer, 0 };
|
||||
char * const sourcePaths[] = {pathBuffer, 0};
|
||||
FTS *fts = fts_open(sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
@@ -163,19 +159,16 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
|
||||
// Ensure the path uses filesystem-specific Unicode normalization #1017
|
||||
NSString *normalizedPath = stringWithFileSystemRepresentation(pathBuffer);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
if (ent->fts_info == FTS_D && !MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(normalizedPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(path, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (relativePath.length == 0)
|
||||
continue;
|
||||
|
||||
@@ -187,12 +180,12 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
|
||||
const char *relativePathBytes = [relativePath fileSystemRepresentation];
|
||||
CC_SHA1_Update(&hashContext, relativePathBytes, (CC_LONG)strlen(relativePathBytes));
|
||||
|
||||
|
||||
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
uint16_t mode = ent->fts_statp->st_mode;
|
||||
uint16_t type = ent->fts_info;
|
||||
uint16_t permissions = mode & PERMISSION_FLAGS;
|
||||
|
||||
|
||||
CC_SHA1_Update(&hashContext, &type, sizeof(type));
|
||||
CC_SHA1_Update(&hashContext, &permissions, sizeof(permissions));
|
||||
}
|
||||
@@ -227,7 +220,7 @@ BOOL removeTree(NSString *path)
|
||||
|
||||
BOOL copyTree(NSString *source, NSString *dest)
|
||||
{
|
||||
return [[SUFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:source] toURL:[NSURL fileURLWithPath:dest] error:NULL];
|
||||
return [[NSFileManager defaultManager] copyItemAtPath:source toPath:dest error:nil];
|
||||
}
|
||||
|
||||
BOOL modifyPermissions(NSString *path, mode_t desiredPermissions)
|
||||
@@ -237,12 +230,12 @@ BOOL modifyPermissions(NSString *path, mode_t desiredPermissions)
|
||||
if (!attributes) {
|
||||
return NO;
|
||||
}
|
||||
NSNumber *permissions = [attributes objectForKey:NSFilePosixPermissions];
|
||||
NSNumber *permissions = attributes[NSFilePosixPermissions];
|
||||
if (!permissions) {
|
||||
return NO;
|
||||
}
|
||||
mode_t newMode = ([permissions unsignedShortValue] & ~PERMISSION_FLAGS) | desiredPermissions;
|
||||
int (*changeModeFunc)(const char *, mode_t) = [[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod;
|
||||
int (*changeModeFunc)(const char *, mode_t) = [attributes[NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod;
|
||||
if (changeModeFunc([path fileSystemRepresentation], newMode) != 0) {
|
||||
return NO;
|
||||
}
|
||||
|
||||