From 98832c49145411c5e13e118fe686ff6c52bcbbe6 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Tue, 15 Jul 2008 23:26:06 -0700 Subject: [PATCH 01/14] Beginnings of insane SUHost-based refactoring to get rid of NSBundle+Sparkle. More super-unstable refactorings to come... --- NSBundle+SUAdditions.h | 59 -------- NSBundle+SUAdditions.m | 89 ----------- SUAutomaticUpdateAlert.h | 6 +- SUAutomaticUpdateAlert.m | 14 +- SUAutomaticUpdateDriver.m | 8 +- SUBasicUpdateDriver.h | 9 +- SUBasicUpdateDriver.m | 71 +++++---- SUHost.h | 32 ++++ SUHost.m | 169 +++++++++++++++++++++ SUInstaller.h | 9 +- SUInstaller.m | 28 ++-- SUPackageInstaller.h | 2 +- SUPackageInstaller.m | 4 +- SUPlainInstaller.h | 2 +- SUPlainInstaller.m | 12 +- SUStatusController.h | 5 +- SUStatusController.m | 12 +- SUSystemProfiler.h | 2 +- SUSystemProfiler.m | 6 +- SUUIBasedUpdateDriver.m | 24 +-- SUUpdateAlert.h | 6 +- SUUpdateAlert.m | 22 +-- SUUpdateDriver.h | 5 +- SUUpdateDriver.m | 4 +- SUUpdatePermissionPrompt.h | 5 +- SUUpdatePermissionPrompt.m | 22 +-- SUUpdater.h | 27 ++-- SUUpdater.m | 242 +++++++++++++++++++----------- SUUserDefaults.h | 41 ----- SUUserDefaults.m | 97 ------------ SUUserInitiatedUpdateDriver.m | 6 +- SUWindowController.h | 3 +- SUWindowController.m | 2 +- Sparkle.h | 3 +- Sparkle.xcodeproj/project.pbxproj | 26 ++-- 35 files changed, 527 insertions(+), 547 deletions(-) delete mode 100644 NSBundle+SUAdditions.h delete mode 100644 NSBundle+SUAdditions.m create mode 100644 SUHost.h create mode 100644 SUHost.m delete mode 100644 SUUserDefaults.h delete mode 100644 SUUserDefaults.m diff --git a/NSBundle+SUAdditions.h b/NSBundle+SUAdditions.h deleted file mode 100644 index ed2475c4..00000000 --- a/NSBundle+SUAdditions.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// NSBundle+SUAdditions.h -// Sparkle -// -// Created by Andy Matuschak on 12/21/07. -// Copyright 2007 Andy Matuschak. All rights reserved. -// - -#ifndef NSBUNDLE_PLUS_ADDITIONS_H -#define NSBUNDLE_PLUS_ADDITIONS_H - -#import - -@interface NSBundle (SUAdditions) -/*! - @method - @abstract Returns a name for the bundle suitable for display to the user. - @discussion This is performed by asking NSFileManager for the display name of the bundle. -*/ -- (NSString *)name; - -/*! - @method - @abstract Returns the current internal version of the bundle. - @discussion This uses the CFBundleVersion info value. This string is not appropriate for display to users: use -displayVersion instead. -*/ -- (NSString *)version; - -/*! - @method - @abstract Returns the bundle's version, suitable for display to the user. - @discussion If the CFBundleShortVersionString is available and different from the CFBundleVersion, this looks like CFBundleShortVersionString (CFBundleVersion). If the version strings are the same or CFBundleShortVersionString is not defined, this is equivalent to -version. -*/ -- (NSString *)displayVersion; - -/*! - @method - @abstract Returns a suitable icon for this bundle. - @discussion Uses the CFBundleIconFile icon if defined; otherwise, uses the default application icon. -*/ -- (NSImage *)icon; - -/*! - @method - @abstract Returns whether the application is running from a disk image. -*/ -- (BOOL)isRunningFromDiskImage; - -/*! - @method - @abstract Returns a profile of the users system useful for statistical purposes. - @discussion Returns an array of dictionaries; each dictionary represents a piece of data and has keys "key", "visibleKey", "value", and "visibleValue". -*/ -- (NSArray *)systemProfile; - -- (NSString *)publicDSAKey; -@end - -#endif diff --git a/NSBundle+SUAdditions.m b/NSBundle+SUAdditions.m deleted file mode 100644 index de3c0ce1..00000000 --- a/NSBundle+SUAdditions.m +++ /dev/null @@ -1,89 +0,0 @@ -// -// NSBundle+SUAdditions.m -// Sparkle -// -// Created by Andy Matuschak on 12/21/07. -// Copyright 2007 Andy Matuschak. All rights reserved. -// - -#import "Sparkle.h" -#import "NSBundle+SUAdditions.h" - -#ifndef NSAppKitVersionNumber10_4 -#define NSAppKitVersionNumber10_4 824 -#endif - -@implementation NSBundle (SUAdditions) - -- (NSString *)name -{ - NSString *name = [self objectForInfoDictionaryKey:@"CFBundleDisplayName"]; - if (name) return name; - - name = [self objectForInfoDictionaryKey:@"CFBundleName"]; - if (name) return name; - - return [[[NSFileManager defaultManager] displayNameAtPath:[self bundlePath]] stringByDeletingPathExtension]; -} - -- (NSString *)version -{ - return [self objectForInfoDictionaryKey:@"CFBundleVersion"]; -} - -- (NSString *)displayVersion -{ - NSString *shortVersionString = [self objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; - if (shortVersionString) - return shortVersionString; - else - return [self version]; // Fall back on the normal version string. -} - -- (NSImage *)icon -{ - // Cache the application icon. - NSString *iconPath = [self pathForResource:[self objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:@"icns"]; - // According to the OS X docs, "CFBundleIconFile - This key identifies the file containing - // the icon for the bundle. The filename you specify does not need to include the .icns - // extension, although it may." - // - // However, if it *does* include the '.icns' the above method fails (tested on OS X 10.3.9) so we'll also try: - if (!iconPath) - iconPath = [self pathForResource:[self objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType: nil]; - NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:iconPath] autorelease]; - // Use a default icon if none is defined. - if (!icon) { icon = [NSImage imageNamed:@"NSDefaultApplicationIcon"]; } - return icon; -} - -- (BOOL)isRunningFromDiskImage -{ - // This check causes crashes on 10.3; for now, we'll just skip it. - if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_4) - return NO; - - NSDictionary *pathProperties = [[NSWorkspace sharedWorkspace] propertiesForPath:[self bundlePath]]; - BOOL isDiskImage = [pathProperties objectForKey:NSWorkspace_RBimagefilepath] != nil; - BOOL isFileVault = [[pathProperties objectForKey:NSWorkspace_RBmntonname] hasPrefix:@"/Users/"]; - return isDiskImage && !isFileVault; -} - -- (NSString *)publicDSAKey -{ - // Maybe the key is just a string in the Info.plist. - NSString *key = [self objectForInfoDictionaryKey:SUPublicDSAKeyKey]; - if (key) { return key; } - - // More likely, we've got a reference to a Resources file by filename: - NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; - if (!keyFilename) { return nil; } - return [NSString stringWithContentsOfFile:[self pathForResource:keyFilename ofType:nil]]; -} - -- (NSArray *)systemProfile -{ - return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHostBundle:self]; -} - -@end diff --git a/SUAutomaticUpdateAlert.h b/SUAutomaticUpdateAlert.h index 76fb35f4..dc2183e5 100644 --- a/SUAutomaticUpdateAlert.h +++ b/SUAutomaticUpdateAlert.h @@ -18,14 +18,14 @@ typedef enum SUDoNotInstallChoice } SUAutomaticInstallationChoice; -@class SUAppcastItem; +@class SUAppcastItem, SUHost; @interface SUAutomaticUpdateAlert : SUWindowController { SUAppcastItem *updateItem; id delegate; - NSBundle *hostBundle; + SUHost *host; } -- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hostBundle delegate:delegate; +- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:delegate; - (IBAction)installNow:sender; - (IBAction)installLater:sender; - (IBAction)doNotInstall:sender; diff --git a/SUAutomaticUpdateAlert.m b/SUAutomaticUpdateAlert.m index 824460df..99a0aa6b 100644 --- a/SUAutomaticUpdateAlert.m +++ b/SUAutomaticUpdateAlert.m @@ -11,14 +11,14 @@ @implementation SUAutomaticUpdateAlert -- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb delegate:del; +- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hb delegate:del; { - self = [super initWithHostBundle:hb windowNibName:@"SUAutomaticUpdateAlert"]; + self = [super initWithHost:hb windowNibName:@"SUAutomaticUpdateAlert"]; if (self) { updateItem = [item retain]; delegate = del; - hostBundle = [hb retain]; + host = [hb retain]; [self setShouldCascadeWindows:NO]; [[self window] center]; } @@ -27,7 +27,7 @@ - (void)dealloc { - [hostBundle release]; + [host release]; [updateItem release]; [super dealloc]; } @@ -53,17 +53,17 @@ - (NSImage *)applicationIcon { - return [hostBundle icon]; + return [host icon]; } - (NSString *)titleText { - return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [hostBundle name]]; + return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [host name]]; } - (NSString *)descriptionText { - return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [hostBundle name], [hostBundle displayVersion]]; + return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [host name], [host displayVersion]]; } @end diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 56dae07e..a9c842e3 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -13,7 +13,7 @@ - (void)unarchiverDidFinish:(SUUnarchiver *)ua { - alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem hostBundle:hostBundle delegate:self]; + alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem host:host delegate:self]; if ([NSApp isActive]) [[alert window] makeKeyAndOrderFront:self]; else @@ -40,7 +40,7 @@ break; case SUDoNotInstallChoice: - [[SUUserDefaults standardUserDefaults] setObject:[updateItem versionString] forKey:SUSkippedVersionKey]; + [host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; [self abortUpdate]; break; } @@ -59,9 +59,9 @@ [self installUpdate]; } -- (void)installerFinishedForHostBundle:(NSBundle *)hb +- (void)installerFinishedForHost:(SUHost *)aHost { - if (hb != hostBundle) { return; } + if (aHost != host) { return; } if (!postponingInstallation) [self relaunchHostApp]; } diff --git a/SUBasicUpdateDriver.h b/SUBasicUpdateDriver.h index ddafed6c..a047be2c 100644 --- a/SUBasicUpdateDriver.h +++ b/SUBasicUpdateDriver.h @@ -12,9 +12,8 @@ #import #import "SUUpdateDriver.h" -@class SUAppcastItem, SUUnarchiver, SUAppcast, SUUnarchiver; +@class SUAppcastItem, SUUnarchiver, SUAppcast, SUUnarchiver, SUHost; @interface SUBasicUpdateDriver : SUUpdateDriver { - NSBundle *hostBundle; SUAppcastItem *updateItem; NSURLDownload *download; @@ -23,7 +22,7 @@ NSString *relaunchPath; } -- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb; +- (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)hb; - (void)appcastDidFinishLoading:(SUAppcast *)ac; - (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error; @@ -45,8 +44,8 @@ - (void)unarchiverDidFail:(SUUnarchiver *)ua; - (void)installUpdate; -- (void)installerFinishedForHostBundle:(NSBundle *)hb; -- (void)installerForHostBundle:(NSBundle *)hb failedWithError:(NSError *)error; +- (void)installerFinishedForHost:(SUHost *)hb; +- (void)installerForHost:(SUHost *)hb failedWithError:(NSError *)error; - (void)relaunchHostApp; - (void)cleanUp; diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index eb2990b5..cc5a191f 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -6,18 +6,17 @@ // Copyright 2008 Andy Matuschak. All rights reserved. // -#import "SUBasicUpdateDriver.h" #import "Sparkle.h" +#import "SUBasicUpdateDriver.h" @implementation SUBasicUpdateDriver -- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb +- (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)aHost { - hostBundle = [hb retain]; - - if ([hostBundle isRunningFromDiskImage]) + [super checkForUpdatesAtURL:appcastURL host:aHost]; + if ([aHost isRunningFromDiskImage]) { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [hostBundle name]] forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]]; return; } @@ -26,9 +25,9 @@ [appcast release]; [appcast setDelegate:self]; - [appcast setUserAgentString:[NSString stringWithFormat: @"%@/%@ Sparkle/1.5b4", [hostBundle name], [hostBundle displayVersion]]]; + [appcast setUserAgentString:[NSString stringWithFormat: @"%@/%@ Sparkle/1.5b4", [aHost name], [aHost displayVersion]]]; [appcast fetchAppcastFromURL:appcastURL]; - [[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey]; + [host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey]; } - (id )_versionComparator @@ -36,8 +35,8 @@ id comparator = nil; // Give the delegate a chance to provide a custom version comparator - if ([delegate respondsToSelector:@selector(versionComparatorForHostBundle:)]) - comparator = [delegate versionComparatorForHostBundle:hostBundle]; + if ([delegate respondsToSelector:@selector(versionComparatorForHost:)]) + comparator = [delegate versionComparatorForHost:host]; // If we don't get a comparator from the delegate, use the default comparator if (!comparator) @@ -48,7 +47,7 @@ - (BOOL)isItemNewer:(SUAppcastItem *)ui { - return [[self _versionComparator] compareVersion:[hostBundle version] toVersion:[ui versionString]] == NSOrderedAscending; + return [[self _versionComparator] compareVersion:[host version] toVersion:[ui versionString]] == NSOrderedAscending; } - (BOOL)hostSupportsItem:(SUAppcastItem *)ui @@ -59,7 +58,7 @@ - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui { - NSString *skippedVersion = [[SUUserDefaults standardUserDefaults] objectForKey:SUSkippedVersionKey]; + NSString *skippedVersion = [host objectForUserDefaultsKey:SUSkippedVersionKey]; if (skippedVersion == nil) { return NO; } return [[self _versionComparator] compareVersion:[ui versionString] toVersion:skippedVersion] != NSOrderedDescending; } @@ -71,13 +70,13 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac { - if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHostBundle:)]) - [delegate appcastDidFinishLoading:ac forHostBundle:hostBundle]; + if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHost:)]) + [delegate appcastDidFinishLoading:ac forHost:host]; // Now we have to find the best valid update in the appcast. - if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHostBundle:)]) // Does the delegate want to handle it? + if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHost:)]) // Does the delegate want to handle it? { - updateItem = [delegate bestValidUpdateInAppcast:ac forHostBundle:hostBundle]; + updateItem = [delegate bestValidUpdateInAppcast:ac forHost:host]; } else // If not, we'll take care of it ourselves. { @@ -106,16 +105,16 @@ - (void)didFindValidUpdate { - if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHostBundle:)]) - [delegate didFindValidUpdate:updateItem toHostBundle:hostBundle]; + if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHost:)]) + [delegate didFindValidUpdate:updateItem toHost:host]; [self downloadUpdate]; } - (void)didNotFindUpdate { - if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)]) - [delegate didNotFindUpdateToHostBundle:hostBundle]; - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [hostBundle name]] forKey:NSLocalizedDescriptionKey]]]; + if ([delegate respondsToSelector:@selector(didNotFindUpdateToHost:)]) + [delegate didNotFindUpdateToHost:host]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]]; } - (void)downloadUpdate @@ -131,7 +130,7 @@ // We create a temporary directory in /tmp and stick the file there. // Not using a GUID here because hdiutil for some reason chokes on GUIDs. Too long? I really have no idea. - NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [hostBundle name], [hostBundle version]]; + NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [host version]]; NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix]; int cnt=1; while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999999) @@ -164,9 +163,9 @@ - (void)extractUpdate { // DSA verification, if activated by the developer - if ([[hostBundle objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue]) + if ([[host objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue]) { - if (![[NSFileManager defaultManager] validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[hostBundle publicDSAKey]]) + if (![[NSFileManager defaultManager] validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[host publicDSAKey]]) { [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObject:@"The update is improperly signed." forKey:NSLocalizedDescriptionKey]]]; return; @@ -201,8 +200,8 @@ - (void)installUpdate { - if ([delegate respondsToSelector:@selector(updateWillInstall:toHostBundle:)]) - [delegate updateWillInstall:updateItem toHostBundle:hostBundle]; + if ([delegate respondsToSelector:@selector(updateWillInstall:toHost:)]) + [delegate updateWillInstall:updateItem toHost:host]; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""]; NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; @@ -211,12 +210,12 @@ if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil]) relaunchPath = [targetPath retain]; - [SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHostBundle:hostBundle delegate:self synchronously:[self shouldInstallSynchronously]]; + [SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHost:host delegate:self synchronously:[self shouldInstallSynchronously]]; } -- (void)installerFinishedForHostBundle:(NSBundle *)hb +- (void)installerFinishedForHost:(SUHost *)aHost { - if (hb != hostBundle) { return; } + if (aHost != host) { return; } [self relaunchHostApp]; } @@ -224,13 +223,13 @@ { // Give the host app an opportunity to postpone the relaunch. static BOOL postponedOnce = NO; - if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHostBundle:untilInvoking:)]) + if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHost:untilInvoking:)]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]]; [invocation setSelector:@selector(relaunchHostApp)]; [invocation setTarget:self]; postponedOnce = YES; - if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHostBundle:hostBundle untilInvoking:invocation]) + if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHost:host untilInvoking:invocation]) return; } @@ -243,12 +242,12 @@ if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath]) { // Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin. - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [[NSBundle mainBundle] name]], NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath], NSLocalizedFailureReasonErrorKey, nil]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [host name]], NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath], NSLocalizedFailureReasonErrorKey, nil]]]; // We intentionally don't abandon the update here so that the host won't initiate another. return; } - [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:[hostBundle bundlePath], [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]]; + [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:[host bundlePath], [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]]; [NSApp terminate:self]; } @@ -258,9 +257,9 @@ [[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil]; } -- (void)installerForHostBundle:(NSBundle *)hb failedWithError:(NSError *)error +- (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error { - if (hb != hostBundle) { return; } + if (aHost != host) { return; } [[NSFileManager defaultManager] removeFileAtPath:relaunchPath handler:NULL]; // Clean up the copied relauncher. [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]]; } @@ -284,7 +283,7 @@ - (void)dealloc { - [hostBundle release]; + [host release]; [download release]; [downloadPath release]; [relaunchPath release]; diff --git a/SUHost.h b/SUHost.h new file mode 100644 index 00000000..d2e769fc --- /dev/null +++ b/SUHost.h @@ -0,0 +1,32 @@ +// +// SUHost.h +// Sparkle +// +// Copyright 2008 Andy Matuschak. All rights reserved. +// + +#import "Sparkle.h" + +@interface SUHost : NSObject +{ + NSBundle *bundle; +} + +- (id)initWithBundle:(NSBundle *)aBundle; +- (NSBundle *)bundle; +- (NSString *)bundlePath; +- (NSString *)name; +- (NSString *)version; +- (NSString *)displayVersion; +- (NSImage *)icon; +- (BOOL)isRunningFromDiskImage; +- (NSString *)publicDSAKey; +- (NSArray *)systemProfile; + +- (id)objectForInfoDictionaryKey:(NSString *)key; +- (BOOL)boolForInfoDictionaryKey:(NSString *)key; +- (id)objectForUserDefaultsKey:(NSString *)defaultName; +- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName; +- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName; +- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName; +@end diff --git a/SUHost.m b/SUHost.m new file mode 100644 index 00000000..c35c86a2 --- /dev/null +++ b/SUHost.m @@ -0,0 +1,169 @@ +// +// SUHost.m +// Sparkle +// +// Copyright 2008 Andy Matuschak. All rights reserved. +// + +#import "Sparkle.h" + +@implementation SUHost + +- (id)initWithBundle:(NSBundle *)aBundle +{ + if (aBundle == nil) aBundle = [NSBundle mainBundle]; + if ((self = [super init])) + { + bundle = [aBundle retain]; + } + return self; +} + +- (void)dealloc +{ + [bundle release]; + [super dealloc]; +} + +- (NSBundle *)bundle +{ + return bundle; +} + +- (NSString *)bundlePath +{ + return [bundle bundlePath]; +} + +- (NSString *)name +{ + NSString *name = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"]; + if (name) return name; + + name = [self objectForInfoDictionaryKey:@"CFBundleName"]; + if (name) return name; + + return [[[NSFileManager defaultManager] displayNameAtPath:[bundle bundlePath]] stringByDeletingPathExtension]; +} + +- (NSString *)version +{ + return [bundle objectForInfoDictionaryKey:@"CFBundleVersion"]; +} + +- (NSString *)displayVersion +{ + NSString *shortVersionString = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + if (shortVersionString) + return shortVersionString; + else + return [self version]; // Fall back on the normal version string. +} + +- (NSImage *)icon +{ + // Cache the application icon. + NSString *iconPath = [bundle pathForResource:[bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:@"icns"]; + // According to the OS X docs, "CFBundleIconFile - This key identifies the file containing + // the icon for the bundle. The filename you specify does not need to include the .icns + // extension, although it may." + // + // However, if it *does* include the '.icns' the above method fails (tested on OS X 10.3.9) so we'll also try: + if (!iconPath) + iconPath = [bundle pathForResource:[bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType: nil]; + NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:iconPath] autorelease]; + // Use a default icon if none is defined. + if (!icon) { icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericApplicationIcon)]; } + return icon; +} + +- (BOOL)isRunningFromDiskImage +{ + // This check causes crashes on 10.3; for now, we'll just skip it. + if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_4) + return NO; + + NSDictionary *pathProperties = [[NSWorkspace sharedWorkspace] propertiesForPath:[bundle bundlePath]]; + BOOL isDiskImage = [pathProperties objectForKey:NSWorkspace_RBimagefilepath] != nil; + BOOL isFileVault = [[pathProperties objectForKey:NSWorkspace_RBmntonname] hasPrefix:@"/Users/"]; + return isDiskImage && !isFileVault; +} + +- (NSString *)publicDSAKey +{ + // Maybe the key is just a string in the Info.plist. + NSString *key = [bundle objectForInfoDictionaryKey:SUPublicDSAKeyKey]; + if (key) { return key; } + + // More likely, we've got a reference to a Resources file by filename: + NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; + if (!keyFilename) { return nil; } + return [NSString stringWithContentsOfFile:[bundle pathForResource:keyFilename ofType:nil]]; +} + +- (NSArray *)systemProfile +{ + return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:self]; +} + +- (id)objectForInfoDictionaryKey:(NSString *)key +{ + return [bundle objectForInfoDictionaryKey:key]; +} + +- (BOOL)boolForInfoDictionaryKey:(NSString *)key +{ + return [[self objectForInfoDictionaryKey:key] boolValue]; +} + +- (id)objectForUserDefaultsKey:(NSString *)defaultName +{ + CFPropertyListRef obj = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)[bundle bundleIdentifier]); + // Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistratioDomain, so anything + // passed into -[NSUserDefaults registerDefaults:] is ignored. The following line falls + // back to using NSUserDefaults, but only if the host bundle is the main bundle, and no value + // is found elsewhere. + if (obj == NULL && bundle != [NSBundle mainBundle]) + obj = [[NSUserDefaults standardUserDefaults] objectForKey:defaultName]; +#if MAC_OS_X_VERSION_MIN_REQUIRED > 1050 + return [NSMakeCollectable(obj) autorelease]; +#else + return [(id)obj autorelease]; +#endif +} + +- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName; +{ + CFPreferencesSetValue((CFStringRef)defaultName, value, (CFStringRef)[bundle bundleIdentifier], kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + CFPreferencesSynchronize((CFStringRef)[bundle bundleIdentifier], kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + // If anything's bound to this through an NSUserDefaultsController, it won't know that anything's changed. + // We can't get an NSUserDefaults object for anything other than the standard one for the app, so this won't work for bundles. + // But it's the best we can do: this will make NSUserDefaultsControllers know about the changes that have been made. + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName +{ + BOOL value; + CFPropertyListRef plr = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)[bundle bundleIdentifier]); + if (plr == NULL) + value = NO; + else { + value = (BOOL)CFBooleanGetValue((CFBooleanRef)plr); + CFRelease(plr); + } + + return value; +} + +- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName +{ + CFPreferencesSetValue((CFStringRef)defaultName, (CFBooleanRef)[NSNumber numberWithBool:value], (CFStringRef)[bundle bundleIdentifier], kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + CFPreferencesSynchronize((CFStringRef)[bundle bundleIdentifier], kCFPreferencesCurrentUser, kCFPreferencesAnyHost); + // If anything's bound to this through an NSUserDefaultsController, it won't know that anything's changed. + // We can't get an NSUserDefaults object for anything other than the standard one for the app, so this won't work for bundles. + // But it's the best we can do: this will make NSUserDefaultsControllers know about the changes that have been made. + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +@end diff --git a/SUInstaller.h b/SUInstaller.h index 08bfc974..cbfb9f77 100644 --- a/SUInstaller.h +++ b/SUInstaller.h @@ -11,14 +11,15 @@ #import +@class SUHost; @interface SUInstaller : NSObject { } -+ (void)installFromUpdateFolder:(NSString *)updateFolder overHostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously; -+ (void)_finishInstallationWithResult:(BOOL)result hostBundle:(NSBundle *)hostBundle error:(NSError *)error delegate:delegate; ++ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously; ++ (void)_finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate; @end @interface NSObject (SUInstallerDelegateInformalProtocol) -- (void)installerFinishedForHostBundle:(NSBundle *)hostBundle; -- (void)installerForHostBundle:(NSBundle *)hostBundle failedWithError:(NSError *)error; +- (void)installerFinishedForHost:(SUHost *)host; +- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error; @end #endif diff --git a/SUInstaller.m b/SUInstaller.m index 54a465da..d35488c8 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -11,15 +11,15 @@ #import "SUPackageInstaller.h" NSString *SUInstallerPathKey = @"SUInstallerPath"; -NSString *SUInstallerHostBundleKey = @"SUInstallerHostBundle"; +NSString *SUInstallerHostKey = @"SUInstallerHost"; NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; @implementation SUInstaller -+ (void)installFromUpdateFolder:(NSString *)updateFolder overHostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously ++ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously { // Search subdirectories for the application - NSString *currentFile, *newAppDownloadPath = nil, *bundleFileName = [[hostBundle bundlePath] lastPathComponent], *alternateBundleFileName = [[hostBundle name] stringByAppendingPathExtension:[[hostBundle bundlePath] pathExtension]]; + NSString *currentFile, *newAppDownloadPath = nil, *bundleFileName = [[host bundlePath] lastPathComponent], *alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]]; BOOL isPackage = NO; NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:updateFolder]; while ((currentFile = [dirEnum nextObject])) @@ -42,7 +42,7 @@ NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; // Some DMGs have symlinks into /Applications! That's no good! And there's no point in looking in bundles. if ([[NSFileManager defaultManager] isAliasFolderAtPath:currentPath] || - [[currentFile pathExtension] isEqualToString:[[hostBundle bundlePath] pathExtension]] || + [[currentFile pathExtension] isEqualToString:[[host bundlePath] pathExtension]] || [[currentFile pathExtension] isEqualToString:@"pkg"] || [[currentFile pathExtension] isEqualToString:@"mpkg"]) { @@ -52,34 +52,34 @@ NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; if (newAppDownloadPath == nil) { - [self _finishInstallationWithResult:NO hostBundle:hostBundle error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate]; + [self _finishInstallationWithResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate]; } else { - [(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationWithPath:newAppDownloadPath hostBundle:hostBundle delegate:delegate synchronously:synchronously]; + [(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationWithPath:newAppDownloadPath host:host delegate:delegate synchronously:synchronously]; } } -+ (void)_mdimportBundle:(NSBundle *)bundle ++ (void)_mdimportHost:(SUHost *)host { NSTask *mdimport = [[[NSTask alloc] init] autorelease]; [mdimport setLaunchPath:@"/usr/bin/mdimport"]; - [mdimport setArguments:[NSArray arrayWithObject:[bundle bundlePath]]]; + [mdimport setArguments:[NSArray arrayWithObject:[host bundlePath]]]; [mdimport launch]; } -+ (void)_finishInstallationWithResult:(BOOL)result hostBundle:(NSBundle *)hostBundle error:(NSError *)error delegate:delegate ++ (void)_finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate { if (result == YES) { - [self _mdimportBundle:hostBundle]; - if ([delegate respondsToSelector:@selector(installerFinishedForHostBundle:)]) - [delegate installerFinishedForHostBundle:hostBundle]; + [self _mdimportHost:host]; + if ([delegate respondsToSelector:@selector(installerFinishedForHost:)]) + [delegate installerFinishedForHost:host]; } else { - if ([delegate respondsToSelector:@selector(installerForHostBundle:failedWithError:)]) - [delegate installerForHostBundle:hostBundle failedWithError:error]; + if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)]) + [delegate installerForHost:host failedWithError:error]; } } diff --git a/SUPackageInstaller.h b/SUPackageInstaller.h index 94bb3ad0..65b1a892 100644 --- a/SUPackageInstaller.h +++ b/SUPackageInstaller.h @@ -13,7 +13,7 @@ #import "SUPlainInstaller.h" @interface SUPackageInstaller : SUPlainInstaller { } -+ (void)installPath:(NSString *)path overHostBundle:(NSBundle *)bundle delegate:delegate; ++ (void)installPath:(NSString *)path overHost:(SUHost *)bundle delegate:delegate; @end #endif diff --git a/SUPackageInstaller.m b/SUPackageInstaller.m index f91a24cd..057e150e 100644 --- a/SUPackageInstaller.m +++ b/SUPackageInstaller.m @@ -11,7 +11,7 @@ @implementation SUPackageInstaller -+ (void)installPath:(NSString *)path overHostBundle:(NSBundle *)bundle delegate:delegate ++ (void)installPath:(NSString *)path overHost:(SUHost *)bundle delegate:delegate { NSError *error = nil; BOOL result = YES; @@ -26,7 +26,7 @@ NSTask *installer = [NSTask launchedTaskWithLaunchPath:installerPath arguments:[NSArray arrayWithObjects:path, nil]]; [installer waitUntilExit]; // Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine. - [self _finishInstallationWithResult:result hostBundle:bundle error:error delegate:delegate]; + [self _finishInstallationWithResult:result host:bundle error:error delegate:delegate]; } @end diff --git a/SUPlainInstaller.h b/SUPlainInstaller.h index 075ffe66..142d2e07 100644 --- a/SUPlainInstaller.h +++ b/SUPlainInstaller.h @@ -12,7 +12,7 @@ #import "Sparkle.h" @interface SUPlainInstaller : SUInstaller { } -+ (void)performInstallationWithPath:(NSString *)path hostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously; ++ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously; @end #endif diff --git a/SUPlainInstaller.m b/SUPlainInstaller.m index f876c19e..940d55d2 100644 --- a/SUPlainInstaller.m +++ b/SUPlainInstaller.m @@ -9,30 +9,30 @@ #import "SUPlainInstaller.h" extern NSString *SUInstallerPathKey; -extern NSString *SUInstallerHostBundleKey; +extern NSString *SUInstallerHostKey; extern NSString *SUInstallerDelegateKey; @implementation SUPlainInstaller -+ (void)installPath:(NSString *)path overHostBundle:(NSBundle *)bundle delegate:delegate ++ (void)installPath:(NSString *)path overHost:(SUHost *)bundle delegate:delegate { NSError *error; BOOL result = [[NSFileManager defaultManager] copyPathWithAuthentication:path overPath:[bundle bundlePath] error:&error]; - [self _finishInstallationWithResult:result hostBundle:bundle error:error delegate:delegate]; + [self _finishInstallationWithResult:result host:bundle error:error delegate:delegate]; } + (void)_performInstallationWithInfo:(NSDictionary *)info { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [self installPath:[info objectForKey:SUInstallerPathKey] overHostBundle:[info objectForKey:SUInstallerHostBundleKey] delegate:[info objectForKey:SUInstallerDelegateKey]]; + [self installPath:[info objectForKey:SUInstallerPathKey] overHost:[info objectForKey:SUInstallerHostKey] delegate:[info objectForKey:SUInstallerDelegateKey]]; [pool drain]; } -+ (void)performInstallationWithPath:(NSString *)path hostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously; ++ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously; { - NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, hostBundle, SUInstallerHostBundleKey, delegate, SUInstallerDelegateKey, nil]; + NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, nil]; if (synchronously) [self _performInstallationWithInfo:info]; else diff --git a/SUStatusController.h b/SUStatusController.h index e56dc8e7..c73ea5b8 100644 --- a/SUStatusController.h +++ b/SUStatusController.h @@ -11,15 +11,16 @@ #import "SUWindowController.h" +@class SUHost; @interface SUStatusController : SUWindowController { double progressValue, maxProgressValue; NSString *title, *statusText, *buttonTitle; IBOutlet NSButton *actionButton; IBOutlet NSProgressIndicator* progressBar; - NSBundle *hostBundle; + SUHost *host; } -- (id)initWithHostBundle:(NSBundle *)hostBundle; +- (id)initWithHost:(SUHost *)host; // Pass 0 for the max progress value to get an indeterminate progress bar. // Pass nil for the status text to not show it. diff --git a/SUStatusController.m b/SUStatusController.m index f344569b..e6796e07 100644 --- a/SUStatusController.m +++ b/SUStatusController.m @@ -11,12 +11,12 @@ @implementation SUStatusController -- (id)initWithHostBundle:(NSBundle *)hb +- (id)initWithHost:(SUHost *)hb { - self = [super initWithHostBundle:hb windowNibName:@"SUStatus"]; + self = [super initWithHost:hb windowNibName:@"SUStatus"]; if (self) { - hostBundle = [hb retain]; + host = [hb retain]; [self setShouldCascadeWindows:NO]; } return self; @@ -24,7 +24,7 @@ - (void)dealloc { - [hostBundle release]; + [host release]; [title release]; [statusText release]; [buttonTitle release]; @@ -40,12 +40,12 @@ - (NSString *)windowTitle { - return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [hostBundle name]]; + return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [host name]]; } - (NSImage *)applicationIcon { - return [hostBundle icon]; + return [host icon]; } - (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText diff --git a/SUSystemProfiler.h b/SUSystemProfiler.h index 8ce9f545..187de646 100644 --- a/SUSystemProfiler.h +++ b/SUSystemProfiler.h @@ -11,7 +11,7 @@ @interface SUSystemProfiler : NSObject {} + (SUSystemProfiler *)sharedSystemProfiler; -- (NSMutableArray *)systemProfileArrayForHostBundle:(NSBundle *)hostBundle; +- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host; @end #endif diff --git a/SUSystemProfiler.m b/SUSystemProfiler.m index af109350..0d36cbd7 100644 --- a/SUSystemProfiler.m +++ b/SUSystemProfiler.m @@ -27,7 +27,7 @@ return [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease]; } -- (NSMutableArray *)systemProfileArrayForHostBundle:(NSBundle *)hostBundle +- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host { NSDictionary *modelTranslation = [self modelTranslationTable]; @@ -115,10 +115,10 @@ [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"lang",@"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0],nil] forKeys:profileDictKeys]]; // Application sending the request - NSString *appName = [hostBundle name]; + NSString *appName = [host name]; if (appName) [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appName",@"Application Name", appName, appName,nil] forKeys:profileDictKeys]]; - NSString *appVersion = [hostBundle version]; + NSString *appVersion = [host version]; if (appVersion) [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appVersion",@"Application Version", appVersion, appVersion,nil] forKeys:profileDictKeys]]; diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index b7196dc0..c712d223 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -13,11 +13,11 @@ - (void)didFindValidUpdate { - updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem hostBundle:hostBundle]; + updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem host:host]; [updateAlert setDelegate:self]; // If the app is a menubar app or the like, we need to focus it first: - if ([[hostBundle objectForInfoDictionaryKey:@"LSUIElement"] doubleValue]) { [NSApp activateIgnoringOtherApps:YES]; } + if ([[host objectForInfoDictionaryKey:@"LSUIElement"] doubleValue]) { [NSApp activateIgnoringOtherApps:YES]; } // Only show the update alert if the app is active; otherwise, we'll wait until it is. if ([NSApp isActive]) @@ -28,10 +28,10 @@ - (void)didNotFindUpdate { - if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)]) - [delegate didNotFindUpdateToHostBundle:hostBundle]; - NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up to date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [hostBundle name], [hostBundle displayVersion]]; - [alert setIcon:[hostBundle icon]]; + if ([delegate respondsToSelector:@selector(didNotFindUpdateToHost:)]) + [delegate didNotFindUpdateToHost:host]; + NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up to date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [host name], [host displayVersion]]; + [alert setIcon:[host icon]]; [alert runModal]; [self abortUpdate]; } @@ -45,13 +45,13 @@ - (void)updateAlert:(SUUpdateAlert *)alert finishedWithChoice:(SUUpdateAlertChoice)choice { [updateAlert release]; updateAlert = nil; - if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:toHostBundle:)]) - [delegate userChoseAction:choice forUpdate:updateItem toHostBundle:hostBundle]; - [[SUUserDefaults standardUserDefaults] setObject:nil forKey:SUSkippedVersionKey]; + if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:toHost:)]) + [delegate userChoseAction:choice forUpdate:updateItem toHost:host]; + [host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { case SUInstallUpdateChoice: - statusController = [[SUStatusController alloc] initWithHostBundle:hostBundle]; + statusController = [[SUStatusController alloc] initWithHost:host]; [statusController beginActionWithTitle:SULocalizedString(@"Downloading update\u2026", @"Take care not to overflow the status window.") maxProgressValue:0 statusText:nil]; [statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO]; [statusController showWindow:self]; @@ -59,7 +59,7 @@ break; case SUSkipThisVersionChoice: - [[SUUserDefaults standardUserDefaults] setObject:[updateItem versionString] forKey:SUSkippedVersionKey]; + [host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; case SURemindMeLaterChoice: [self abortUpdate]; break; @@ -138,7 +138,7 @@ - (void)abortUpdateWithError:(NSError *)error { NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"Update Error!", nil) defaultButton:SULocalizedString(@"Cancel Update", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:[error localizedDescription]]; - [alert setIcon:[hostBundle icon]]; + [alert setIcon:[host icon]]; [alert runModal]; [super abortUpdateWithError:error]; } diff --git a/SUUpdateAlert.h b/SUUpdateAlert.h index a0288aba..1602b4a6 100644 --- a/SUUpdateAlert.h +++ b/SUUpdateAlert.h @@ -18,10 +18,10 @@ typedef enum SUSkipThisVersionChoice } SUUpdateAlertChoice; -@class WebView, SUAppcastItem; +@class WebView, SUAppcastItem, SUHost; @interface SUUpdateAlert : SUWindowController { SUAppcastItem *updateItem; - NSBundle *hostBundle; + SUHost *host; id delegate; IBOutlet WebView *releaseNotesView; @@ -30,7 +30,7 @@ typedef enum BOOL webViewFinishedLoading; } -- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hostBundle; +- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host; - (void)setDelegate:delegate; - (IBAction)installUpdate:sender; diff --git a/SUUpdateAlert.m b/SUUpdateAlert.m index 5421bde4..b3cc05f3 100644 --- a/SUUpdateAlert.m +++ b/SUUpdateAlert.m @@ -13,12 +13,12 @@ @implementation SUUpdateAlert -- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb +- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hb { - self = [super initWithHostBundle:hb windowNibName:@"SUUpdateAlert"]; + self = [super initWithHost:hb windowNibName:@"SUUpdateAlert"]; if (self) { - hostBundle = [hb retain]; + host = [hb retain]; updateItem = [item retain]; [self setShouldCascadeWindows:NO]; } @@ -28,7 +28,7 @@ - (void)dealloc { [updateItem release]; - [hostBundle release]; + [host release]; [super dealloc]; } @@ -85,7 +85,7 @@ - (BOOL)showsReleaseNotes { - NSNumber *shouldShowReleaseNotes = [hostBundle objectForInfoDictionaryKey:SUShowReleaseNotesKey]; + NSNumber *shouldShowReleaseNotes = [host objectForInfoDictionaryKey:SUShowReleaseNotesKey]; if (shouldShowReleaseNotes == nil) return YES; // defaults to YES else @@ -94,11 +94,11 @@ - (BOOL)allowsAutomaticUpdates { - if (![[hostBundle objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue]) + if (![[host objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue]) return NO; // Automatic updating requires DSA-signed updates - if (![hostBundle objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]) + if (![host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey]) return YES; // defaults to YES - return [[hostBundle objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] boolValue]; + return [[host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] boolValue]; } - (void)awakeFromNib @@ -140,17 +140,17 @@ - (NSImage *)applicationIcon { - return [hostBundle icon]; + return [host icon]; } - (NSString *)titleText { - return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is available!", nil), [hostBundle name]]; + return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is available!", nil), [host name]]; } - (NSString *)descriptionText { - return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available\u2014you have %@. Would you like to download it now?", nil), [hostBundle name], [updateItem displayVersionString], [hostBundle displayVersion]]; + return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available\u2014you have %@. Would you like to download it now?", nil), [host name], [updateItem displayVersionString], [host displayVersion]]; } - (void)webView:(WebView *)sender didFinishLoadForFrame:frame diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index face46e4..7c9485d2 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -13,12 +13,15 @@ extern NSString *SUUpdateDriverFinishedNotification; +@class SUHost; @interface SUUpdateDriver : NSObject { + SUHost *host; + BOOL finished; id delegate; } -- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb; +- (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)hb; - (void)abortUpdate; - (BOOL)finished; diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index 81e5ce9e..d6c6d9e1 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -11,9 +11,9 @@ NSString *SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @implementation SUUpdateDriver -- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb +- (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)h { - [NSException raise:@"SUAbstractDriverError" format:@"Don't use SUUpdateDriver directly; use a subclass."]; + host = [h retain]; } - (void)abortUpdate diff --git a/SUUpdatePermissionPrompt.h b/SUUpdatePermissionPrompt.h index 24959da7..ad8e47d6 100644 --- a/SUUpdatePermissionPrompt.h +++ b/SUUpdatePermissionPrompt.h @@ -16,15 +16,16 @@ typedef enum { SUDoNotAutomaticallyCheck } SUPermissionPromptResult; +@class SUHost; @interface SUUpdatePermissionPrompt : SUWindowController { - NSBundle *hostBundle; + SUHost *host; id delegate; IBOutlet NSTextField *descriptionTextField; IBOutlet NSView *moreInfoView; IBOutlet NSButton *moreInfoButton; BOOL isShowingMoreInfo, shouldSendProfile; } -+ (void)promptWithHostBundle:(NSBundle *)hb delegate:(id)d; ++ (void)promptWithHost:(SUHost *)hb delegate:(id)d; - (IBAction)toggleMoreInfo:(id)sender; - (IBAction)finishPrompt:(id)sender; @end diff --git a/SUUpdatePermissionPrompt.m b/SUUpdatePermissionPrompt.m index b954d435..290ca197 100644 --- a/SUUpdatePermissionPrompt.m +++ b/SUUpdatePermissionPrompt.m @@ -13,15 +13,15 @@ - (BOOL)shouldAskAboutProfile { - return [[hostBundle objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; + return [[host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; } -- (id)initWithHostBundle:(NSBundle *)hb delegate:(id)d +- (id)initWithHost:(SUHost *)hb delegate:(id)d { - self = [super initWithHostBundle:hb windowNibName:@"SUUpdatePermissionPrompt"]; + self = [super initWithHost:hb windowNibName:@"SUUpdatePermissionPrompt"]; if (self) { - hostBundle = [hb retain]; + host = [hb retain]; delegate = [d retain]; isShowingMoreInfo = NO; shouldSendProfile = [self shouldAskAboutProfile]; @@ -30,9 +30,9 @@ return self; } -+ (void)promptWithHostBundle:(NSBundle *)hb delegate:(id)d ++ (void)promptWithHost:(SUHost *)hb delegate:(id)d { - id prompt = [[[self class] alloc] initWithHostBundle:hb delegate:d]; + id prompt = [[[self class] alloc] initWithHost:hb delegate:d]; [NSApp runModalForWindow:[prompt window]]; } @@ -48,23 +48,23 @@ - (void)dealloc { - [hostBundle release]; + [host release]; [super dealloc]; } - (NSImage *)icon { - return [hostBundle icon]; + return [host icon]; } - (NSString *)promptDescription { - return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [hostBundle name]]; + return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [host name]]; } - (NSArray *)systemProfileInformationArray { - return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHostBundle:hostBundle]; + return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:host]; } - (IBAction)toggleMoreInfo:(id)sender @@ -116,7 +116,7 @@ { if (![delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)]) [NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", delegate]; - [[SUUserDefaults standardUserDefaults] setBool:shouldSendProfile forKey:SUSendProfileInfoKey]; + [host setBool:shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey]; [delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)]; [[self window] close]; [NSApp stopModal]; diff --git a/SUUpdater.h b/SUUpdater.h index 1d633531..1381a497 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -17,11 +17,12 @@ NSTimer *checkTimer; SUUpdateDriver *driver; - NSBundle *hostBundle; + SUHost *host; IBOutlet id delegate; } + (SUUpdater *)sharedUpdater; ++ (SUUpdater *)updaterForBundle:(NSBundle *)bundle; - (void)setDelegate:(id)delegate; @@ -37,10 +38,6 @@ // This forces an update to begin with a particular driver (see SU*UpdateDriver.h) - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)driver; -// For non-.app updates: -// Call this when your bundle is loaded to tell Sparkle what to update. -- (void)setHostBundle:(NSBundle *)hostBundle; - // Call this to appropriately reschedule or cancel the update checking timer if preferences for time interval or automatic checks change. // If you're using a .app, this'll be picked up automatically via NSUserDefaultsController, but for non-.apps, there's no way to observe changes. - (void)updatePreferencesChanged; @@ -51,39 +48,39 @@ @interface NSObject (SUUpdaterDelegateInformalProtocol) // This method allows you to add extra parameters to the appcast URL, potentially based on whether or not // Sparkle will also be sending along the system profile. This method should return an array of dictionaries with the following keys: -- (NSArray *)feedParametersForHostBundle:(NSBundle *)bundle sendingSystemProfile:(BOOL)sendingProfile; +- (NSArray *)feedParametersForHost:(SUHost *)bundle sendingSystemProfile:(BOOL)sendingProfile; // Use this to override the default behavior for Sparkle prompting the user about automatic update checks. -- (BOOL)shouldPromptForPermissionToCheckForUpdatesToHostBundle:(NSBundle *)bundle; +- (BOOL)shouldPromptForPermissionToCheckForUpdatesToHost:(SUHost *)bundle; // Implement this if you want to do some special handling with the appcast once it finishes loading. -- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHostBundle:(NSBundle *)bundle; +- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHost:(SUHost *)bundle; // If you're using special logic or extensions in your appcast, implement this to use your own logic for finding // a valid update, if any, in the given appcast. -- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHostBundle:(NSBundle *)bundle; +- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHost:(SUHost *)bundle; // Sent when a valid update is found by the update driver. -- (void)didFindValidUpdate:(SUAppcastItem *)update toHostBundle:(NSBundle *)bundle; +- (void)didFindValidUpdate:(SUAppcastItem *)update toHost:(SUHost *)bundle; // Sent when a valid update is not found. -- (void)didNotFindUpdateToHostBundle:(NSBundle *)hb; +- (void)didNotFindUpdateToHost:(SUHost *)hb; // Sent when the user makes a choice in the update alert dialog (install now / remind me later / skip this version). -- (void)userChoseAction:(SUUpdateAlertChoice)action forUpdate:(SUAppcastItem *)update toHostBundle:(NSBundle *)bundle; +- (void)userChoseAction:(SUUpdateAlertChoice)action forUpdate:(SUAppcastItem *)update toHost:(SUHost *)bundle; // Sent immediately before installing the specified update. -- (void)updateWillInstall:(SUAppcastItem *)update toHostBundle:(NSBundle *)bundle; +- (void)updateWillInstall:(SUAppcastItem *)update toHost:(SUHost *)bundle; // Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue. -- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update toHostBundle:(NSBundle *)hostBundle untilInvoking:(NSInvocation *)invocation; +- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update toHost:(SUHost *)hostBundle untilInvoking:(NSInvocation *)invocation; // Called immediately before relaunching. - (void)updaterWillRelaunchApplication; // This method allows you to provide a custom version comparator. // If you don't implement this method or return nil, the standard version comparator will be used. -- (id )versionComparatorForHostBundle:(NSBundle *)hb; +- (id )versionComparatorForHost:(SUHost *)hb; @end diff --git a/SUUpdater.m b/SUUpdater.m index 4db0b093..b9659b7a 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -15,6 +15,10 @@ - (BOOL)shouldScheduleUpdateCheck; - (void)scheduleNextUpdateCheck; - (NSTimeInterval)checkInterval; +- (void)registerAsObserver; +- (void)unregisterAsObserver; +- (void)updateDriverDidFinish:(NSNotification *)note; +- initForBundle:(NSBundle *)bundle; - (NSURL *)feedURL; @end @@ -22,71 +26,107 @@ #pragma mark Initialization -static SUUpdater *sharedUpdater = nil; +static NSMutableDictionary *sharedUpdaters = nil; +static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; -// SUUpdater's a singleton now! And I'm enforcing it! -// This will probably break the world if you try to write a Sparkle-enabled plugin for a Sparkle-enabled app. + (SUUpdater *)sharedUpdater { - if (sharedUpdater == nil) - sharedUpdater = [[[self class] alloc] init]; - return sharedUpdater; + return [self updaterForBundle:[NSBundle mainBundle]]; } -- (id)init +// SUUpdater has a singleton for each bundle. We use the fact that NSBundle instances are also singletons, so we can use them as keys. If you don't trust that you can also use the identifier as key ++ (SUUpdater *)updaterForBundle:(NSBundle *)bundle +{ + if (bundle == nil) bundle = [NSBundle mainBundle]; + id updater = [sharedUpdaters objectForKey:[NSValue valueWithNonretainedObject:bundle]]; + if (updater == nil) + updater = [[[self class] alloc] initWithBundle:bundle]; + return updater; +} + +// This is the designated initializer for SUUpdater, important for subclasses +- initForBundle:(NSBundle *)bundle { self = [super init]; - if (sharedUpdater) + if (bundle == nil) bundle = [NSBundle mainBundle]; + id updater = [sharedUpdaters objectForKey:[NSValue valueWithNonretainedObject:bundle]]; + if (updater) { [self release]; - self = sharedUpdater; + self = [updater retain]; } - else if (self != nil) + else if (self) { - sharedUpdater = self; - [self setHostBundle:[NSBundle mainBundle]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) name:NSApplicationDidFinishLaunchingNotification object:NSApp]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(driverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil]; - [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:0 context:NULL]; - [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:0 context:NULL]; + if (sharedUpdaters == nil) + sharedUpdaters = [[NSMutableDictionary alloc] init]; + [sharedUpdaters setObject:self forKey:[NSValue valueWithNonretainedObject:bundle]]; + host = [[SUHost alloc] initWithBundle:bundle]; + [self registerAsObserver]; } return self; } +// This will be used when the updater is instantiated in a nib such as MainMenu +- (id)init +{ + return [self initForBundle:[NSBundle mainBundle]]; +} + - (void)applicationDidFinishLaunching:(NSNotification *)note { - // If the user has been asked about automatic checks and said no, get out of here. - if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKey] && - [[SUUserDefaults standardUserDefaults] boolForKey:SUEnableAutomaticChecksKey] == NO) { return; } - - // Does the delegate want to take care of the logic for when we should ask permission to update? - if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle:)]) - { - if ([delegate shouldPromptForPermissionToCheckForUpdatesToHostBundle:hostBundle]) - [SUUpdatePermissionPrompt promptWithHostBundle:hostBundle delegate:self]; - } - // Has he been asked already? And don't ask if the host has a default value set in its Info.plist. - else if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKey] == nil && - [hostBundle objectForInfoDictionaryKey:SUEnableAutomaticChecksKey] == nil) - { - if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKeyOld]) - [[SUUserDefaults standardUserDefaults] setBool:[[SUUserDefaults standardUserDefaults] boolForKey:SUEnableAutomaticChecksKeyOld] forKey:SUEnableAutomaticChecksKey]; - // Now, we don't want to ask the user for permission to do a weird thing on the first launch. - // We wait until the second launch. - else if ([[SUUserDefaults standardUserDefaults] boolForKey:SUHasLaunchedBeforeKey] == NO) - [[SUUserDefaults standardUserDefaults] setBool:YES forKey:SUHasLaunchedBeforeKey]; - else - [SUUpdatePermissionPrompt promptWithHostBundle:hostBundle delegate:self]; + BOOL shouldPrompt = NO; + + // If the user has been asked about automatic checks, don't bother prompting + if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKey]) + { + shouldPrompt = NO; + } + // Does the delegate want to take care of the logic for when we should ask permission to update? + else if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle:)]) + { + shouldPrompt = [delegate shouldPromptForPermissionToCheckForUpdatesToHost:host]; + } + // Has he been asked already? And don't ask if the host has a default value set in its Info.plist. + else if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKey] == nil && + [host objectForInfoDictionaryKey:SUEnableAutomaticChecksKey] == nil) + { + if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]) + [host setBool:[host boolForUserDefaultsKey:SUEnableAutomaticChecksKeyOld] forUserDefaultsKey:SUEnableAutomaticChecksKey]; + // Now, we don't want to ask the user for permission to do a weird thing on the first launch. + // We wait until the second launch. + else if ([host boolForUserDefaultsKey:SUHasLaunchedBeforeKey] == NO) + [host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey]; + else + shouldPrompt = YES; + } + + if (shouldPrompt) + { + [SUUpdatePermissionPrompt promptWithHost:host delegate:self]; + // We start the update checks and register as observer for changes after the prompt finishes } - - // We check if the user's said they want updates, or they haven't said anything, and the default is set to checking. - [self scheduleNextUpdateCheck]; + else + { + // We check if the user's said they want updates, or they haven't said anything, and the default is set to checking. + [self scheduleNextUpdateCheck]; + } } - (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result { - [[SUUserDefaults standardUserDefaults] setBool:(result == SUAutomaticallyCheck) forKey:SUEnableAutomaticChecksKey]; - [self scheduleNextUpdateCheck]; + BOOL automaticallyCheck = (result == SUAutomaticallyCheck); + [host setBool:automaticallyCheck forUserDefaultsKey:SUEnableAutomaticChecksKey]; + // Schedule checks, but make sure we ignore the delayed call from KVO + [self updatePreferencesChanged]; +} + +- (void)updateDriverDidFinish:(NSNotification *)note +{ + if ([note object] == driver && [driver finished]) + { + [driver release]; driver = nil; + [self scheduleNextUpdateCheck]; + } } - (void)scheduleNextUpdateCheck @@ -99,7 +139,7 @@ static SUUpdater *sharedUpdater = nil; if (![self shouldScheduleUpdateCheck]) return; // How long has it been since last we checked for an update? - NSDate *lastCheckDate = [[SUUserDefaults standardUserDefaults] objectForKey:SULastCheckTimeKey]; + NSDate *lastCheckDate = [host objectForUserDefaultsKey:SULastCheckTimeKey]; if (!lastCheckDate) { lastCheckDate = [NSDate distantPast]; } NSTimeInterval intervalSinceCheck = [[NSDate date] timeIntervalSinceDate:lastCheckDate]; @@ -127,37 +167,70 @@ static SUUpdater *sharedUpdater = nil; if ([self updateInProgress]) { return; } if (checkTimer) { [checkTimer invalidate]; checkTimer = nil; } + // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). + NSString *appcastString = [host objectForUserDefaultsKey:SUFeedURLKey]; + if (!appcastString) + appcastString = [host objectForInfoDictionaryKey:SUFeedURLKey]; + if (!appcastString) + [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; + driver = [d retain]; if ([driver delegate] == nil) { [driver setDelegate:delegate]; } - [driver checkForUpdatesAtURL:[self feedURL] hostBundle:hostBundle]; + [driver checkForUpdatesAtURL:[self feedURL] host:host]; +} + +- (void)registerAsObserver +{ + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) name:NSApplicationDidFinishLaunchingNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDriverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil]; + // No sense observing the shared NSUserDefaultsController when we're not updating the main bundle. + if ([host bundle] != [NSBundle mainBundle]) return; + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:0 context:SUUpdaterDefaultsObservationContext]; + [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:0 context:SUUpdaterDefaultsObservationContext]; +} + +- (void)unregisterAsObserver +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; + // Removing self as a KVO observer if no observer was registered leads to an NSException. But we don't care. + @try + { + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey]]; + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey]]; + } + @catch (NSException *e) { } } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (object == [NSUserDefaultsController sharedUserDefaultsController] && ([keyPath hasSuffix:SUScheduledCheckIntervalKey] || [keyPath hasSuffix:SUEnableAutomaticChecksKey])) - { - [self updatePreferencesChanged]; - } - else - { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } + if (context == SUUpdaterDefaultsObservationContext) + { + // Allow a small delay, because perhaps the user or developer wants to change both preferences. This allows the developer to interpret a zero check interval as a sign to disable automatic checking. + // Or we may get this from the developer and from our own KVO observation, this will effectively coalesce them. + [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(updatePreferencesChanged) object:nil]; + [self performSelector:@selector(updatePreferencesChanged) withObject:nil afterDelay:15]; + [self updatePreferencesChanged]; + } + else + { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } } - (void)updatePreferencesChanged { - [self scheduleNextUpdateCheck]; + [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(updatePreferencesChanged) object:nil]; + [self scheduleNextUpdateCheck]; } - (BOOL)shouldScheduleUpdateCheck { // Breaking this down for readability: // If the user says he wants automatic update checks, let's do it. - if ([[SUUserDefaults standardUserDefaults] boolForKey:SUEnableAutomaticChecksKey] == YES) + if ([host boolForUserDefaultsKey:SUEnableAutomaticChecksKey] == YES) return YES; // If the user hasn't said anything, but the developer says we should do it, let's do it. - if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKey] == nil && - [[hostBundle objectForInfoDictionaryKey:SUEnableAutomaticChecksKey] boolValue] == YES) + if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKey] == nil && [host boolForInfoDictionaryKey:SUEnableAutomaticChecksKey] == YES) return YES; return NO; // Otherwise, don't bother. } @@ -165,16 +238,15 @@ static SUUpdater *sharedUpdater = nil; - (BOOL)automaticallyUpdates { // If the SUAllowsAutomaticUpdatesKey exists and is set to NO, return NO. - if ([hostBundle objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] && - [[hostBundle objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] boolValue] == NO) + if ([host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] && [host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey] == NO) return NO; // If we're not using DSA signatures, we aren't going to trust any updates automatically. - if ([[hostBundle objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue] != YES) + if ([host boolForInfoDictionaryKey:SUExpectsDSASignatureKey] != YES) return NO; // If there's no setting, or it's set to no, we're not automatically updating. - if ([[SUUserDefaults standardUserDefaults] boolForKey:SUAutomaticallyUpdateKey] != YES) + if ([host boolForUserDefaultsKey:SUAutomaticallyUpdateKey] != YES) return NO; return YES; // Otherwise, we're good to go. @@ -183,9 +255,9 @@ static SUUpdater *sharedUpdater = nil; - (NSURL *)_baseFeedURL { // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). - NSString *appcastString = [[SUUserDefaults standardUserDefaults] objectForKey:SUFeedURLKey]; + NSString *appcastString = [host objectForUserDefaultsKey:SUFeedURLKey]; if (!appcastString) - appcastString = [hostBundle objectForInfoDictionaryKey:SUFeedURLKey]; + appcastString = [host objectForInfoDictionaryKey:SUFeedURLKey]; if (!appcastString) // Can't find an appcast string! [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; NSCharacterSet* quoteSet = [NSCharacterSet characterSetWithCharactersInString: @"\"\'"]; // Some feed publishers add quotes; strip 'em. @@ -197,12 +269,12 @@ static SUUpdater *sharedUpdater = nil; NSURL *baseFeedURL = [self _baseFeedURL]; // Determine all the parameters we're attaching to the base feed URL. - BOOL sendingSystemProfile = ([[SUUserDefaults standardUserDefaults] boolForKey:SUSendProfileInfoKey] == YES); + BOOL sendingSystemProfile = ([host boolForUserDefaultsKey:SUSendProfileInfoKey] == YES); NSArray *parameters = [NSArray array]; if ([delegate respondsToSelector:@selector(feedParametersForHostBundle:sendingSystemProfile:)]) - parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForHostBundle:hostBundle sendingSystemProfile:sendingSystemProfile]]; + parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForHost:host sendingSystemProfile:sendingSystemProfile]]; if (sendingSystemProfile) - parameters = [parameters arrayByAddingObjectsFromArray:[hostBundle systemProfile]]; + parameters = [parameters arrayByAddingObjectsFromArray:[host systemProfile]]; if (parameters == nil || [parameters count] == 0) { return baseFeedURL; } // Build up the parameterized URL. @@ -222,10 +294,10 @@ static SUUpdater *sharedUpdater = nil; { NSTimeInterval checkInterval = 0; // Find the stored check interval. User defaults override Info.plist. - if ([[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey]) - checkInterval = [[[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey] doubleValue]; - else if ([hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey]) - checkInterval = [[hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey] doubleValue]; + if ([host objectForUserDefaultsKey:SUScheduledCheckIntervalKey]) + checkInterval = [[host objectForUserDefaultsKey:SUScheduledCheckIntervalKey] doubleValue]; + else if ([host objectForInfoDictionaryKey:SUScheduledCheckIntervalKey]) + checkInterval = [[host objectForInfoDictionaryKey:SUScheduledCheckIntervalKey] doubleValue]; if (checkInterval < SU_MIN_CHECK_INTERVAL) // This can also mean one that isn't set. checkInterval = SU_DEFAULT_CHECK_INTERVAL; @@ -234,9 +306,9 @@ static SUUpdater *sharedUpdater = nil; - (void)dealloc { - [hostBundle release]; + [self unregisterAsObserver]; + [host release]; if (checkTimer) { [checkTimer invalidate]; } - [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @@ -252,25 +324,25 @@ static SUUpdater *sharedUpdater = nil; delegate = aDelegate; } -- (void)setHostBundle:(NSBundle *)hb -{ - if (hostBundle == hb) return; - [hostBundle release]; - hostBundle = [hb retain]; - [[SUUserDefaults standardUserDefaults] setIdentifier:[hostBundle bundleIdentifier]]; -} - - (BOOL)updateInProgress { return driver && ([driver finished] == NO); } -- (void)driverDidFinish:(NSNotification *)notification +// Redirect driver delegate methods to our delegate +/* +- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHost:(SUHost *)bundle { - if ([notification object] != driver) return; - [driver release]; - driver = nil; - [self scheduleNextUpdateCheck]; + if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHost:)]) + [delegate appcastDidFinishLoading:ac forHost:bundle]; } +- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHost:(SUHost *)bundle +{ + if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHost:)]) // Does the delegate want to handle it? + return [delegate bestValidUpdateInAppcast:ac forHost:bundle]; + else + return nil; +}*/ + @end diff --git a/SUUserDefaults.h b/SUUserDefaults.h deleted file mode 100644 index ba2eedb2..00000000 --- a/SUUserDefaults.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// SUUserDefaults.h -// Sparkle -// -// Created by Andy Matuschak on 12/21/07. -// Copyright 2007 Andy Matuschak. All rights reserved. -// - -#ifndef SUUSERDEFAULTS_H -#define SUUSERDEFAULTS_H - -/*! - @class - @abstract A substitute for NSUserDefaults that will work with arbitrary bundle identifiers. - @discussion Make sure you call -setIdentifier: before using SUUserDefaults. The other methods in this class work just like those in NSUserDefaults. -*/ - -@interface SUUserDefaults : NSObject { - NSString *identifier; -} - -/*! - @method - @abstract Returns a singleton instance of the user defaults class. -*/ -+ (SUUserDefaults *)standardUserDefaults; - -/*! - @method - @abstract Sets which bundle identifier to use when setting and retrieving defaults. - @discussion It is imperative that you set the identifier through this method before trying to set or retrieve defaults. -*/ -- (void)setIdentifier:(NSString *)identifier; - -- (id)objectForKey:(NSString *)defaultName; -- (void)setObject:(id)value forKey:(NSString *)defaultName; -- (BOOL)boolForKey:(NSString *)defaultName; -- (void)setBool:(BOOL)value forKey:(NSString *)defaultName; -@end - -#endif diff --git a/SUUserDefaults.m b/SUUserDefaults.m deleted file mode 100644 index 26f995ad..00000000 --- a/SUUserDefaults.m +++ /dev/null @@ -1,97 +0,0 @@ -// -// SUUserDefaults.m -// Sparkle -// -// Created by Andy Matuschak on 12/21/07. -// Copyright 2007 Andy Matuschak. All rights reserved. -// - -#import "Sparkle.h" -#import "SUUserDefaults.h" - -@implementation SUUserDefaults - -+ (SUUserDefaults *)standardUserDefaults -{ - static SUUserDefaults *standardUserDefaults = nil; - if (standardUserDefaults == nil) - standardUserDefaults = [[SUUserDefaults alloc] init]; - return standardUserDefaults; -} - -- (void)dealloc -{ - [identifier release]; - [super dealloc]; -} - -- (void)setIdentifier:(NSString *)anIdentifier -{ - if (identifier != anIdentifier) - { - [identifier release]; - identifier = [anIdentifier copy]; - } -} - -- (void)verifyIdentifier -{ - if (identifier == nil) - [NSException raise:@"SUUserDefaultsMissingIdentifier" format:@"You must set the SUUserDefaults identifier before using it."]; -} - -- (id)objectForKey:(NSString *)defaultName -{ - [self verifyIdentifier]; - CFPropertyListRef obj = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)identifier); - // Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistrationDomain, so anything - // passed into -[NSUserDefaults registerDefaults:] is ignored. The following line falls - // back to using NSUserDefaults, but only if the host bundle is the main bundle, and no value - // is found elsewhere. - if (obj == NULL && [identifier isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) - obj = [[NSUserDefaults standardUserDefaults] objectForKey:defaultName]; - id result = nil; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 - result = [NSMakeCollectable(obj) autorelease]; -#endif - return result ?: (id)obj; -} - -- (void)setObject:(id)value forKey:(NSString *)defaultName; -{ - [self verifyIdentifier]; - CFPreferencesSetValue((CFStringRef)defaultName, value, (CFStringRef)identifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - CFPreferencesSynchronize((CFStringRef)identifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - // If anything's bound to this through an NSUserDefaultsController, it won't know that anything's changed. - // We can't get an NSUserDefaults object for anything other than the standard one for the app, so this won't work for bundles. - // But it's the best we can do: this will make NSUserDefaultsControllers know about the changes that have been made. - [[NSUserDefaults standardUserDefaults] synchronize]; -} - -- (BOOL)boolForKey:(NSString *)defaultName -{ - BOOL value; - [self verifyIdentifier]; - CFPropertyListRef plr = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)identifier); - if (plr == NULL) - value = NO; - else { - value = (BOOL)CFBooleanGetValue((CFBooleanRef)plr); - CFRelease(plr); - } - - return value; -} - -- (void)setBool:(BOOL)value forKey:(NSString *)defaultName -{ - [self verifyIdentifier]; - CFPreferencesSetValue((CFStringRef)defaultName, (CFBooleanRef)[NSNumber numberWithBool:value], (CFStringRef)identifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - CFPreferencesSynchronize((CFStringRef)identifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); - // If anything's bound to this through an NSUserDefaultsController, it won't know that anything's changed. - // We can't get an NSUserDefaults object for anything other than the standard one for the app, so this won't work for bundles. - // But it's the best we can do: this will make NSUserDefaultsControllers know about the changes that have been made. - [[NSUserDefaults standardUserDefaults] synchronize]; -} - -@end diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index 94fa66a8..88c3bfce 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -11,10 +11,10 @@ @implementation SUUserInitiatedUpdateDriver -- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb +- (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)hb { - [super checkForUpdatesAtURL:appcastURL hostBundle:hb]; - checkingController = [[SUStatusController alloc] initWithHostBundle:hb]; + [super checkForUpdatesAtURL:appcastURL host:hb]; + checkingController = [[SUStatusController alloc] initWithHost:hb]; [[checkingController window] center]; // Force the checking controller to load its window. [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates\u2026", nil) maxProgressValue:0 statusText:nil]; [checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; diff --git a/SUWindowController.h b/SUWindowController.h index 8b50a64c..2962429d 100644 --- a/SUWindowController.h +++ b/SUWindowController.h @@ -11,9 +11,10 @@ #import +@class SUHost; @interface SUWindowController : NSWindowController { } // We use this instead of plain old NSWindowController initWithWindowNibName so that we'll be able to find the right path when running in a bundle loaded from another app. -- (id)initWithHostBundle:(NSBundle *)hb windowNibName:(NSString *)nibName; +- (id)initWithHost:(SUHost *)hb windowNibName:(NSString *)nibName; @end #endif diff --git a/SUWindowController.m b/SUWindowController.m index f73ef80d..7e48b52e 100644 --- a/SUWindowController.m +++ b/SUWindowController.m @@ -10,7 +10,7 @@ @implementation SUWindowController -- (id)initWithHostBundle:(NSBundle *)hb windowNibName:(NSString *)nibName +- (id)initWithHost:(SUHost *)hb windowNibName:(NSString *)nibName { NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:nibName ofType:@"nib"]; if (path == nil) // Slight hack to resolve issues with running Sparkle in debug configurations. diff --git a/Sparkle.h b/Sparkle.h index db304b09..4d0b1091 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -25,7 +25,6 @@ // This list should include the shared headers. It doesn't matter if some of them aren't shared (unless // there are name-space collisions) so we can list all of them to start with: -#import "NSBundle+SUAdditions.h" #import "NSFileManager+Aliases.h" #import "NSFileManager+Authentication.h" #import "NSFileManager+Verification.h" @@ -40,6 +39,7 @@ #import "SUAutomaticUpdateDriver.h" #import "SUBasicUpdateDriver.h" #import "SUConstants.h" +#import "SUHost.h" #import "SUInstaller.h" #import "SUProbingUpdateDriver.h" #import "SUScheduledUpdateDriver.h" @@ -53,7 +53,6 @@ #import "SUUpdater.h" #import "SUUpdatePermissionPrompt.h" #import "SUUserInitiatedUpdateDriver.h" -#import "SUUserDefaults.h" #import "SUVersionComparisonProtocol.h" #import "SUWindowController.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 0e874f89..246f8ce4 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -55,13 +55,9 @@ 618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5210DAE8E8A0026945C /* SUPackageInstaller.m */; }; 6196CFF909C72148000DC222 /* SUStatusController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6196CFE309C71ADE000DC222 /* SUStatusController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6196CFE409C71ADE000DC222 /* SUStatusController.m */; }; - 61A225930D1C3ADD00430CCD /* NSBundle+SUAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A225910D1C3ADD00430CCD /* NSBundle+SUAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61A225940D1C3ADD00430CCD /* NSBundle+SUAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225920D1C3ADD00430CCD /* NSBundle+SUAdditions.m */; }; 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A2259C0D1C495D00430CCD /* SUVersionComparisonProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; }; - 61A2262B0D1C58FD00430CCD /* SUUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A226290D1C58FD00430CCD /* SUUserDefaults.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61A2262C0D1C58FD00430CCD /* SUUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A2262A0D1C58FD00430CCD /* SUUserDefaults.m */; }; 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */; }; 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A354530DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -95,6 +91,8 @@ 61C1F2790DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */; }; 61C46F340D9C54F300B06326 /* SUUpdatePermissionPrompt.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61C46F330D9C54F300B06326 /* SUUpdatePermissionPrompt.nib */; }; 61D85D6D0E10B2ED00F9B4A9 /* SUPipedUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6129C0B90E0B79810062CE76 /* SUPipedUnarchiver.m */; }; + 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; }; + 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */ = {isa = PBXBuildFile; fileRef = 61EF67580E25C5B400F754E0 /* SUHost.h */; }; 61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */; }; 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; DAAEFC9B0DA5722F0051E0D0 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; @@ -206,13 +204,9 @@ 619B17210E1E9D0800E72754 /* de */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = de; path = de.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; 619B17220E1E9D0800E72754 /* de */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = de; path = de.lproj/SUUpdateAlert.nib; sourceTree = ""; }; 619B17230E1E9D0800E72754 /* de */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = de; path = de.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; - 61A225910D1C3ADD00430CCD /* NSBundle+SUAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSBundle+SUAdditions.h"; sourceTree = ""; }; - 61A225920D1C3ADD00430CCD /* NSBundle+SUAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSBundle+SUAdditions.m"; sourceTree = ""; }; 61A2259C0D1C495D00430CCD /* SUVersionComparisonProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionComparisonProtocol.h; sourceTree = ""; }; 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardVersionComparator.h; sourceTree = ""; }; 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUStandardVersionComparator.m; sourceTree = ""; }; - 61A226290D1C58FD00430CCD /* SUUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUserDefaults.h; sourceTree = ""; }; - 61A2262A0D1C58FD00430CCD /* SUUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUserDefaults.m; sourceTree = ""; }; 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUSystemProfiler.h; sourceTree = ""; }; 61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUSystemProfiler.m; sourceTree = ""; }; 61A354530DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUserInitiatedUpdateDriver.h; sourceTree = ""; }; @@ -249,6 +243,8 @@ 61C1F2760DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+ExtendedAttributes.h"; sourceTree = ""; }; 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+ExtendedAttributes.m"; sourceTree = ""; }; 61C46F350D9C54F300B06326 /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; + 61EF67550E25B58D00F754E0 /* SUHost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUHost.m; sourceTree = ""; }; + 61EF67580E25C5B400F754E0 /* SUHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUHost.h; sourceTree = ""; }; 61F3651A0E18987B007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; 61F3652A0E189883007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUUpdateAlert.nib; sourceTree = ""; }; 61F3652B0E189883007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; @@ -473,8 +469,8 @@ 61B5F8F309C4CE5900B25A18 /* Other Sources */ = { isa = PBXGroup; children = ( - 61A225910D1C3ADD00430CCD /* NSBundle+SUAdditions.h */, - 61A225920D1C3ADD00430CCD /* NSBundle+SUAdditions.m */, + 61EF67580E25C5B400F754E0 /* SUHost.h */, + 61EF67550E25B58D00F754E0 /* SUHost.m */, 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */, 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */, 610134750DD252E60049ACDF /* NSWorkspace+SystemVersion.h */, @@ -482,8 +478,6 @@ 61299B3509CB04E000B7442F /* Sparkle.h */, 61299A5B09CA6D4500B7442F /* SUConstants.h */, 61299A5F09CA6EB100B7442F /* SUConstants.m */, - 61A226290D1C58FD00430CCD /* SUUserDefaults.h */, - 61A2262A0D1C58FD00430CCD /* SUUserDefaults.m */, ); includeInIndex = 1; name = "Other Sources"; @@ -563,10 +557,8 @@ 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */, 611779590D1111C900749C97 /* NSWorkspace_RBAdditions.h in Headers */, - 61A225930D1C3ADD00430CCD /* NSBundle+SUAdditions.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */, - 61A2262B0D1C58FD00430CCD /* SUUserDefaults.h in Headers */, 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */, 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */, 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */, @@ -588,6 +580,7 @@ 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */, 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */, + 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -824,9 +817,7 @@ 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */, 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */, 6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */, - 61A225940D1C3ADD00430CCD /* NSBundle+SUAdditions.m in Sources */, 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, - 61A2262C0D1C58FD00430CCD /* SUUserDefaults.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */, 6171D9080D57B81800BFE886 /* NSFileManager+Aliases.m in Sources */, @@ -846,6 +837,7 @@ 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */, 6102FE5C0E08C7EC00F85D09 /* SUUnarchiver_Private.m in Sources */, 61D85D6D0E10B2ED00F9B4A9 /* SUPipedUnarchiver.m in Sources */, + 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1041,7 +1033,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH)"; + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; GCC_DYNAMIC_NO_PIC = NO; From 3146ffb8e1b91b9f7b53c8a0e515c5f889b4215b Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 16 Jul 2008 22:15:29 -0700 Subject: [PATCH 02/14] Fixes 248929, 244738 Removed NSWorkspace+RBAdditions: we're now checking if the volume is read-only instead of specifically whether it's a disk image. This also means the warning string changed. Sorry, localizers! --- NSWorkspace_RBAdditions.h | 41 ------- NSWorkspace_RBAdditions.m | 177 ------------------------------ SUBasicUpdateDriver.m | 4 +- SUHost.h | 2 +- SUHost.m | 14 +-- SUUserInitiatedUpdateDriver.m | 2 +- Sparkle.h | 1 - Sparkle.xcodeproj/project.pbxproj | 8 -- en.lproj/Sparkle.strings | Bin 8022 -> 8198 bytes 9 files changed, 9 insertions(+), 240 deletions(-) delete mode 100644 NSWorkspace_RBAdditions.h delete mode 100644 NSWorkspace_RBAdditions.m diff --git a/NSWorkspace_RBAdditions.h b/NSWorkspace_RBAdditions.h deleted file mode 100644 index bd50fb13..00000000 --- a/NSWorkspace_RBAdditions.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// NSWorkspace_RBAdditions.h -// PathProps -// -// Created by Rainer Brockerhoff on 10/04/2007. -// Copyright 2007 Rainer Brockerhoff. All rights reserved. -// - -#ifndef NSWORKSPACE_RBADDITIONS_H -#define NSWORKSPACE_RBADDITIONS_H - - -extern NSString* NSWorkspace_RBfstypename; -extern NSString* NSWorkspace_RBmntonname; -extern NSString* NSWorkspace_RBmntfromname; -extern NSString* NSWorkspace_RBdeviceinfo; -extern NSString* NSWorkspace_RBimagefilepath; -extern NSString* NSWorkspace_RBconnectiontype; -extern NSString* NSWorkspace_RBpartitionscheme; -extern NSString* NSWorkspace_RBserverURL; - -@interface NSWorkspace (NSWorkspace_RBAdditions) - -// This method will return nil if the input path is invalid. Otherwise, the returned NSDictionary may contain -// the following keys: -//- NSWorkspace_RBfstypename: will always be present.Shows the filesystem type (usually "hfs"), from statfs. -//- NSWorkspace_RBmntonname: will always be present. Shows the volume mount point. -//- NSWorkspace_RBmntfromname: will always be present. Shows the BSD device path for local volumes; info for -// remote volumes depends on the filesystem type. -//- NSWorkspace_RBconnectiontype: should always be present for local volumes. Shows the connection type ("SATA", "USB", etc.). -//- NSWorkspace_RBpartitionscheme: should always be present for local volumes. Shows the partition scheme. -//- NSWorkspace_RBdeviceinfo: should always be present for local volumes. Shows some information about the -// physical device; varies widely. -//- NSWorkspace_RBimagefilepath: should be present for disk images only. Shows the path of the disk image file. -//- NSWorkspace_RBserverURL: should be present for remote volumes only. Shows the server URL. - -- (NSDictionary*)propertiesForPath:(NSString*)path; - -@end - -#endif diff --git a/NSWorkspace_RBAdditions.m b/NSWorkspace_RBAdditions.m deleted file mode 100644 index 1ffac239..00000000 --- a/NSWorkspace_RBAdditions.m +++ /dev/null @@ -1,177 +0,0 @@ -// -// NSWorkspace_RBAdditions.m -// PathProps -// -// Created by Rainer Brockerhoff on 10/04/2007. -// Copyright 2007 Rainer Brockerhoff. All rights reserved. -// - -#import "Sparkle.h" -#import "NSWorkspace_RBAdditions.h" - -#include -#include -#include - -NSString* NSWorkspace_RBfstypename = @"NSWorkspace_RBfstypename"; -NSString* NSWorkspace_RBmntonname = @"NSWorkspace_RBmntonname"; -NSString* NSWorkspace_RBmntfromname = @"NSWorkspace_RBmntfromname"; -NSString* NSWorkspace_RBdeviceinfo = @"NSWorkspace_RBdeviceinfo"; -NSString* NSWorkspace_RBimagefilepath = @"NSWorkspace_RBimagefilepath"; -NSString* NSWorkspace_RBconnectiontype = @"NSWorkspace_RBconnectiontype"; -NSString* NSWorkspace_RBpartitionscheme = @"NSWorkspace_RBpartitionscheme"; -NSString* NSWorkspace_RBserverURL = @"NSWorkspace_RBserverURL"; - -// This static funtion concatenates two strings, but first checks several possibilities... -// like one or the other nil, or one containing the other already. - -static NSString* AddPart(NSString* first,NSString* second) { - if (!second) { - return first; - } - second = [second stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - if (first) { - if ([first rangeOfString:second options:NSCaseInsensitiveSearch].location==NSNotFound) { - if ([second rangeOfString:first options:NSCaseInsensitiveSearch].location==NSNotFound) { - return [NSString stringWithFormat:@"%@; %@",first,second]; - } - return second; - } - return first; - } - return second; -} - -// This static functions recurses "upwards" over the IO registry. Returns strings that are concatenated -// and ultimately end up under the NSWorkspace_RBdeviceinfo key. -// This isn't too robust in that it assumes that objects returned by the objectForKey methods are -// either strings or dictionaries. A "standard" implementations would use either only CoreFoundation and -// IOKit calls for this, or do more robust type checking on the returned objects. -// -// Also notice that this works as determined experimentally in 10.4.9, there's no official docs I could find. -// YMMV, and it may stop working in any new version of Mac OS X. - -static NSString* CheckParents(io_object_t thing,NSString* part,NSMutableDictionary* dict) { - NSString* result = part; - io_iterator_t parentsIterator = 0; - kern_return_t kernResult = IORegistryEntryGetParentIterator(thing,kIOServicePlane,&parentsIterator); - if ((kernResult==KERN_SUCCESS)&&parentsIterator) { - io_object_t nextParent = 0; - while ((nextParent = IOIteratorNext(parentsIterator))) { - NSDictionary* props = nil; - NSString* image = nil; - NSString* partition = nil; - NSString* connection = nil; - kernResult = IORegistryEntryCreateCFProperties(nextParent,(CFMutableDictionaryRef*)&props,kCFAllocatorDefault,0); - if (IOObjectConformsTo(nextParent,"IOApplePartitionScheme")) { - partition = [props objectForKey:@"Content Mask"]; - } else if (IOObjectConformsTo(nextParent,"IOMedia")) { - partition = [props objectForKey:@"Content"]; - } else if (IOObjectConformsTo(nextParent,"IODiskImageBlockStorageDeviceOutKernel")) { - NSData* data = nil; - if ((data = [[props objectForKey:@"Protocol Characteristics"] objectForKey:@"Virtual Interface Location Path"])) { - image = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease]; - } - } else if (IOObjectConformsTo(nextParent,"IOHDIXHDDriveInKernel")) { - image = [props objectForKey:@"KDIURLPath"]; - } - NSDictionary* subdict; - if ((subdict = [props objectForKey:@"Protocol Characteristics"])) { - connection = [subdict objectForKey:@"Physical Interconnect"]; - } else { - connection = [props objectForKey:@"Physical Interconnect"]; - } - if (connection) { - [dict setObject:AddPart([dict objectForKey:NSWorkspace_RBconnectiontype],connection) forKey:NSWorkspace_RBconnectiontype]; - } - if (partition) { - [dict setObject:partition forKey:NSWorkspace_RBpartitionscheme]; - } - if (image) { - [dict setObject:image forKey:NSWorkspace_RBimagefilepath]; - } - NSString* value; - if ((subdict = [props objectForKey:@"Device Characteristics"])) { - if ((value = [subdict objectForKey:@"Product Name"])) { - result = AddPart(result,value); - } - if ((value = [subdict objectForKey:@"Product Revision Level"])) { - result = AddPart(result,value); - } - if ((value = [subdict objectForKey:@"Vendor Name"])) { - result = AddPart(result,value); - } - } - if ((value = [props objectForKey:@"USB Serial Number"])) { - result = AddPart(result,value); - } - if ((value = [props objectForKey:@"USB Vendor Name"])) { - result = AddPart(result,value); - } - io_name_t ts; // char[128] - NSString* cls = ( IOObjectGetClass (nextParent, ts) == KERN_SUCCESS ) ? [NSString stringWithUTF8String:ts ] : nil; - if (![cls isEqualToString:@"IOPCIDevice"]) { - -// Uncomment the following line to have the device tree dumped to the console. -// NSLog(@"=================================> %@:%@\n",cls,props); - - result = CheckParents(nextParent,result,dict); - } - if (props) { CFRelease(props); } - IOObjectRelease(nextParent); - } - } - if (parentsIterator) { - IOObjectRelease(parentsIterator); - } - return result; -} - -@implementation NSWorkspace (NSWorkspace_RBAdditions) - -// Returns a NSDictionary with properties for the path. See details in the .h file. -// This assumes that the length of path is less than PATH_MAX (currently 1024 characters). - -- (NSDictionary*)propertiesForPath:(NSString*)path { - const char* ccpath = [path fileSystemRepresentation]; - NSMutableDictionary* result = nil; - struct statfs fs = {}; - if (!statfs(ccpath,&fs)) { - NSString* from = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:fs.f_mntfromname length:strlen(fs.f_mntfromname)]; - result = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithUTF8String:fs.f_fstypename], NSWorkspace_RBfstypename, [[NSFileManager defaultManager] stringWithFileSystemRepresentation:fs.f_mntonname length:strlen(fs.f_mntonname)], NSWorkspace_RBmntonname, nil]; - const char* devstring = "/dev/"; - size_t devstringlen = 5; - if (strncmp(fs.f_mntfromname,devstring,devstringlen)==0) { - // For a local volume,get the IO registry tree and search it for further info. - mach_port_t masterPort = 0; - io_iterator_t mediaIterator = 0; - kern_return_t kernResult = IOMasterPort(bootstrap_port,&masterPort); - if (kernResult==KERN_SUCCESS) { - CFMutableDictionaryRef classesToMatch = IOBSDNameMatching(masterPort,0,&fs.f_mntfromname[devstringlen]); - if (classesToMatch) { - kernResult = IOServiceGetMatchingServices(masterPort,classesToMatch,&mediaIterator); - if ((kernResult==KERN_SUCCESS)&&mediaIterator) { - io_object_t firstMedia = 0; - while ((firstMedia = IOIteratorNext(mediaIterator))) { - NSString* stuff = CheckParents(firstMedia,nil,result); - if (stuff) { - [result setObject:stuff forKey:NSWorkspace_RBdeviceinfo]; - } - IOObjectRelease(firstMedia); - } - } - } - } - if (mediaIterator) { - IOObjectRelease(mediaIterator); - } - if (masterPort) { - mach_port_deallocate(mach_task_self(),masterPort); - } - } - [result setObject:from forKey:NSWorkspace_RBmntfromname]; - } - return result; -} - -@end diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 21a20a5d..0199eb10 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -14,9 +14,9 @@ - (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)aHost { [super checkForUpdatesAtURL:appcastURL host:aHost]; - if ([aHost isRunningFromDiskImage]) + if ([aHost isRunningOnReadOnlyVolume]) { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]]; return; } diff --git a/SUHost.h b/SUHost.h index d2e769fc..832327b8 100644 --- a/SUHost.h +++ b/SUHost.h @@ -19,7 +19,7 @@ - (NSString *)version; - (NSString *)displayVersion; - (NSImage *)icon; -- (BOOL)isRunningFromDiskImage; +- (BOOL)isRunningOnReadOnlyVolume; - (NSString *)publicDSAKey; - (NSArray *)systemProfile; diff --git a/SUHost.m b/SUHost.m index c35c86a2..e5a17096 100644 --- a/SUHost.m +++ b/SUHost.m @@ -6,6 +6,7 @@ // #import "Sparkle.h" +#import // For statfs for isRunningOnReadOnlyVolume @implementation SUHost @@ -77,16 +78,11 @@ return icon; } -- (BOOL)isRunningFromDiskImage +- (BOOL)isRunningOnReadOnlyVolume { - // This check causes crashes on 10.3; for now, we'll just skip it. - if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_4) - return NO; - - NSDictionary *pathProperties = [[NSWorkspace sharedWorkspace] propertiesForPath:[bundle bundlePath]]; - BOOL isDiskImage = [pathProperties objectForKey:NSWorkspace_RBimagefilepath] != nil; - BOOL isFileVault = [[pathProperties objectForKey:NSWorkspace_RBmntonname] hasPrefix:@"/Users/"]; - return isDiskImage && !isFileVault; + struct statfs statfs_info; + statfs([[bundle bundlePath] fileSystemRepresentation], &statfs_info); + return (statfs_info.f_flags & MNT_RDONLY); } - (NSString *)publicDSAKey diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index c64d5e60..8ba7a573 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -18,7 +18,7 @@ [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates\u2026", nil) maxProgressValue:0 statusText:nil]; [checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; [checkingController showWindow:self]; - [super checkForUpdatesAtURL:appcastURL hostBundle:hb]; + [super checkForUpdatesAtURL:appcastURL host:hb]; } - (void)closeCheckingWindow diff --git a/Sparkle.h b/Sparkle.h index 4d0b1091..c76dfe82 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -28,7 +28,6 @@ #import "NSFileManager+Aliases.h" #import "NSFileManager+Authentication.h" #import "NSFileManager+Verification.h" -#import "NSWorkspace_RBAdditions.h" #import "NSWorkspace+SystemVersion.h" #import "NTSynchronousTask.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index d9b1399b..587a9a04 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -22,8 +22,6 @@ 610D5A1A0A1661B8004AAD9C /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; }; 610D5A750A1670A4004AAD9C /* SUStatus.nib in Resources */ = {isa = PBXBuildFile; fileRef = 610D5A740A1670A4004AAD9C /* SUStatus.nib */; }; 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */; }; - 611779590D1111C900749C97 /* NSWorkspace_RBAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */; }; 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61180BCB0D64138900B4E0D1 /* SUWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61180BC90D64138900B4E0D1 /* SUWindowController.m */; }; @@ -167,8 +165,6 @@ 610D5A740A1670A4004AAD9C /* SUStatus.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = SUStatus.nib; sourceTree = ""; }; 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTSynchronousTask.m; sourceTree = ""; }; 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTSynchronousTask.h; sourceTree = ""; }; - 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSWorkspace_RBAdditions.m; sourceTree = ""; }; - 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSWorkspace_RBAdditions.h; sourceTree = ""; }; 6117796E0D1112E000749C97 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; 61180BC80D64138900B4E0D1 /* SUWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUWindowController.h; sourceTree = ""; }; 61180BC90D64138900B4E0D1 /* SUWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUWindowController.m; sourceTree = ""; }; @@ -474,8 +470,6 @@ children = ( 61EF67580E25C5B400F754E0 /* SUHost.h */, 61EF67550E25B58D00F754E0 /* SUHost.m */, - 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */, - 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */, 610134750DD252E60049ACDF /* NSWorkspace+SystemVersion.h */, 610134760DD252E60049ACDF /* NSWorkspace+SystemVersion.m */, 61299B3509CB04E000B7442F /* Sparkle.h */, @@ -559,7 +553,6 @@ 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */, - 611779590D1111C900749C97 /* NSWorkspace_RBAdditions.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */, 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */, @@ -820,7 +813,6 @@ 61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */, 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */, 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */, - 6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */, 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */, diff --git a/en.lproj/Sparkle.strings b/en.lproj/Sparkle.strings index 7165acdf292cc2f13add74e84c492b3065165d14..f8f89008a5481d935128b325dda16a0b6a40408b 100644 GIT binary patch delta 189 zcmca+*XFQc6_aKWLn=ceLkfc~Lq0eFg91Ytke$O&%8(0`Qvk9u8L}BtC+}sJ yR#gDX6amE&foehQ0)`TxY%-9a1LUUw Date: Wed, 16 Jul 2008 23:51:39 -0700 Subject: [PATCH 03/14] Fixes 244857 Made a first crack at redifining the SUUpdater delegate protocol. Still not sure about a couple things, so please don't change your delegate methods to conform until this gets merged into trunk. Also made the SUUpdateDrivers not have the updater's delegate as their delegate (that was really icky). Now they're just coupled with the SUUpdater, which is icky as well, but less icky, at least. --- SUBasicUpdateDriver.m | 38 ++++++++++++++++++++++---------------- SUUIBasedUpdateDriver.m | 7 +++---- SUUpdateDriver.h | 3 --- SUUpdateDriver.m | 2 -- SUUpdater.h | 27 +++++++++++++-------------- SUUpdater.m | 26 ++++++-------------------- 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 0199eb10..c5332f39 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -34,9 +34,10 @@ { id comparator = nil; + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; // Give the delegate a chance to provide a custom version comparator - if ([delegate respondsToSelector:@selector(versionComparatorForHost:)]) - comparator = [delegate versionComparatorForHost:host]; + if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) + comparator = [[updater delegate] versionComparatorForUpdater:updater]; // If we don't get a comparator from the delegate, use the default comparator if (!comparator) @@ -70,13 +71,14 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac { - if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHost:)]) - [delegate appcastDidFinishLoading:ac forHost:host]; + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) + [[updater delegate] updater:updater didFinishLoadingAppcast:ac]; // Now we have to find the best valid update in the appcast. - if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHost:)]) // Does the delegate want to handle it? + if ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? { - updateItem = [delegate bestValidUpdateInAppcast:ac forHost:host]; + updateItem = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:updater]; } else // If not, we'll take care of it ourselves. { @@ -105,15 +107,17 @@ - (void)didFindValidUpdate { - if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHost:)]) - [delegate didFindValidUpdate:updateItem toHost:host]; + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) + [[updater delegate] updater:updater didFindValidUpdate:updateItem]; [self downloadUpdate]; } - (void)didNotFindUpdate { - if ([delegate respondsToSelector:@selector(didNotFindUpdateToHost:)]) - [delegate didNotFindUpdateToHost:host]; + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) + [[updater delegate] updaterDidNotFindUpdate:updater]; [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]]; } @@ -206,8 +210,9 @@ - (void)installUpdate { - if ([delegate respondsToSelector:@selector(updateWillInstall:toHost:)]) - [delegate updateWillInstall:updateItem toHost:host]; + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)]) + [[updater delegate] updater:updater willInstallUpdate:updateItem]; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""]; NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; @@ -229,21 +234,22 @@ { // Give the host app an opportunity to postpone the relaunch. static BOOL postponedOnce = NO; - if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHost:untilInvoking:)]) + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if (!postponedOnce && [[updater delegate] respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]]; [invocation setSelector:@selector(relaunchHostApp)]; [invocation setTarget:self]; postponedOnce = YES; - if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHost:host untilInvoking:invocation]) + if ([[updater delegate] updater:updater shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation]) return; } [self cleanUp]; // Clean up the download and extracted files. [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; - if ([delegate respondsToSelector:@selector(updaterWillRelaunchApplication)]) - [delegate updaterWillRelaunchApplication]; + if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication)]) + [[updater delegate] updaterWillRelaunchApplication:updater]; if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath]) { diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index c712d223..23b69e0c 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -28,8 +28,9 @@ - (void)didNotFindUpdate { - if ([delegate respondsToSelector:@selector(didNotFindUpdateToHost:)]) - [delegate didNotFindUpdateToHost:host]; + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) + [[updater delegate] updaterDidNotFindUpdate:updater]; NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up to date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [host name], [host displayVersion]]; [alert setIcon:[host icon]]; [alert runModal]; @@ -45,8 +46,6 @@ - (void)updateAlert:(SUUpdateAlert *)alert finishedWithChoice:(SUUpdateAlertChoice)choice { [updateAlert release]; updateAlert = nil; - if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:toHost:)]) - [delegate userChoseAction:choice forUpdate:updateItem toHost:host]; [host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 7c9485d2..16057b57 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -19,14 +19,11 @@ extern NSString *SUUpdateDriverFinishedNotification; SUHost *host; BOOL finished; - id delegate; } - (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)hb; - (void)abortUpdate; - (BOOL)finished; -- delegate; -- (void)setDelegate:delegate; @end #endif diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index d6c6d9e1..5f568514 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -23,6 +23,4 @@ NSString *SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; } - (BOOL)finished { return finished; } -- delegate { return delegate; } -- (void)setDelegate:del { delegate = del; } @end diff --git a/SUUpdater.h b/SUUpdater.h index 1381a497..cf9cb4dc 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -23,8 +23,10 @@ + (SUUpdater *)sharedUpdater; + (SUUpdater *)updaterForBundle:(NSBundle *)bundle; +- (NSBundle *)hostBundle; - (void)setDelegate:(id)delegate; +- delegate; // This IBAction is meant for a main menu item. Hook up any menu item to this action, // and Sparkle will check for updates and report back its findings verbosely. @@ -47,40 +49,37 @@ @interface NSObject (SUUpdaterDelegateInformalProtocol) // This method allows you to add extra parameters to the appcast URL, potentially based on whether or not -// Sparkle will also be sending along the system profile. This method should return an array of dictionaries with the following keys: -- (NSArray *)feedParametersForHost:(SUHost *)bundle sendingSystemProfile:(BOOL)sendingProfile; +// Sparkle will also be sending along the system profile. This method should return an array of dictionaries with keys: "key" and "value". +- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile; // Use this to override the default behavior for Sparkle prompting the user about automatic update checks. -- (BOOL)shouldPromptForPermissionToCheckForUpdatesToHost:(SUHost *)bundle; +- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SUUpdater *)bundle; // Implement this if you want to do some special handling with the appcast once it finishes loading. -- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHost:(SUHost *)bundle; +- (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast; // If you're using special logic or extensions in your appcast, implement this to use your own logic for finding // a valid update, if any, in the given appcast. -- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHost:(SUHost *)bundle; +- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)bundle; // Sent when a valid update is found by the update driver. -- (void)didFindValidUpdate:(SUAppcastItem *)update toHost:(SUHost *)bundle; +- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update; // Sent when a valid update is not found. -- (void)didNotFindUpdateToHost:(SUHost *)hb; - -// Sent when the user makes a choice in the update alert dialog (install now / remind me later / skip this version). -- (void)userChoseAction:(SUUpdateAlertChoice)action forUpdate:(SUAppcastItem *)update toHost:(SUHost *)bundle; +- (void)updaterDidNotFindUpdate:(SUUpdater *)update; // Sent immediately before installing the specified update. -- (void)updateWillInstall:(SUAppcastItem *)update toHost:(SUHost *)bundle; +- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update; // Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue. -- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update toHost:(SUHost *)hostBundle untilInvoking:(NSInvocation *)invocation; +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation; // Called immediately before relaunching. -- (void)updaterWillRelaunchApplication; +- (void)updaterWillRelaunchApplication:(SUUpdater *)updater; // This method allows you to provide a custom version comparator. // If you don't implement this method or return nil, the standard version comparator will be used. -- (id )versionComparatorForHost:(SUHost *)hb; +- (id )versionComparatorForUpdater:(SUUpdater *)updater; @end diff --git a/SUUpdater.m b/SUUpdater.m index b9659b7a..1984b5a6 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -82,9 +82,9 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv shouldPrompt = NO; } // Does the delegate want to take care of the logic for when we should ask permission to update? - else if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle:)]) + else if ([delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)]) { - shouldPrompt = [delegate shouldPromptForPermissionToCheckForUpdatesToHost:host]; + shouldPrompt = [delegate updaterShouldPromptForPermissionToCheckForUpdates:self]; } // Has he been asked already? And don't ask if the host has a default value set in its Info.plist. else if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKey] == nil && @@ -175,7 +175,6 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; driver = [d retain]; - if ([driver delegate] == nil) { [driver setDelegate:delegate]; } [driver checkForUpdatesAtURL:[self feedURL] host:host]; } @@ -271,8 +270,8 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv // Determine all the parameters we're attaching to the base feed URL. BOOL sendingSystemProfile = ([host boolForUserDefaultsKey:SUSendProfileInfoKey] == YES); NSArray *parameters = [NSArray array]; - if ([delegate respondsToSelector:@selector(feedParametersForHostBundle:sendingSystemProfile:)]) - parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForHost:host sendingSystemProfile:sendingSystemProfile]]; + if ([delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) + parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]]; if (sendingSystemProfile) parameters = [parameters arrayByAddingObjectsFromArray:[host systemProfile]]; if (parameters == nil || [parameters count] == 0) { return baseFeedURL; } @@ -329,20 +328,7 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv return driver && ([driver finished] == NO); } -// Redirect driver delegate methods to our delegate -/* -- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHost:(SUHost *)bundle -{ - if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHost:)]) - [delegate appcastDidFinishLoading:ac forHost:bundle]; -} - -- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHost:(SUHost *)bundle -{ - if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHost:)]) // Does the delegate want to handle it? - return [delegate bestValidUpdateInAppcast:ac forHost:bundle]; - else - return nil; -}*/ +- delegate { return delegate; } +- (NSBundle *)hostBundle { return [host bundle]; } @end From a31dc3a102e517d158374ee6b5a0204af02c92e6 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 17 Jul 2008 21:19:07 -0700 Subject: [PATCH 04/14] Fixes BOOL user defaults lookup for registered defaults on Tiger. --- SUHost.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SUHost.m b/SUHost.m index e5a17096..f6969685 100644 --- a/SUHost.m +++ b/SUHost.m @@ -140,15 +140,18 @@ - (BOOL)boolForUserDefaultsKey:(NSString *)defaultName { + if (bundle == [NSBundle mainBundle]) + return [[NSUserDefaults standardUserDefaults] boolForKey:defaultName]; + BOOL value; CFPropertyListRef plr = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)[bundle bundleIdentifier]); if (plr == NULL) value = NO; - else { + else + { value = (BOOL)CFBooleanGetValue((CFBooleanRef)plr); CFRelease(plr); } - return value; } From 675c66ff9dc36ef3deda54fbce1623bed076d27f Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 21 Jul 2008 23:40:52 -0700 Subject: [PATCH 05/14] Fixes 250170 Sparkle now remembers to call the delegate's didFindValidUpdate method when using a UI-based update controller. Thanks, Stefan Schimanski! --- SUUIBasedUpdateDriver.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index 23b69e0c..5fdbc5e5 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -19,6 +19,10 @@ // If the app is a menubar app or the like, we need to focus it first: if ([[host objectForInfoDictionaryKey:@"LSUIElement"] doubleValue]) { [NSApp activateIgnoringOtherApps:YES]; } + SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]]; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) + [[updater delegate] updater:updater didFindValidUpdate:updateItem]; + // Only show the update alert if the app is active; otherwise, we'll wait until it is. if ([NSApp isActive]) [[updateAlert window] makeKeyAndOrderFront:self]; From cec916695662f2bd238774529cf73bb2b74fdc9b Mon Sep 17 00:00:00 2001 From: Matt Stevens Date: Tue, 22 Jul 2008 20:24:12 -0600 Subject: [PATCH 06/14] Improved notification handling for otherwise UI-less background applications. --- SUBasicUpdateDriver.h | 2 ++ SUBasicUpdateDriver.m | 3 ++- SUUIBasedUpdateDriver.h | 2 ++ SUUIBasedUpdateDriver.m | 27 +++++++++++++++++++++------ SUUpdatePermissionPrompt.m | 7 ++++++- SUUserInitiatedUpdateDriver.m | 9 ++++++++- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/SUBasicUpdateDriver.h b/SUBasicUpdateDriver.h index ddafed6c..74dd3aff 100644 --- a/SUBasicUpdateDriver.h +++ b/SUBasicUpdateDriver.h @@ -21,6 +21,8 @@ NSString *downloadPath; NSString *relaunchPath; + + BOOL isBackgroundApplication; } - (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb; diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 21299159..f2ed18e5 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -14,6 +14,7 @@ - (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb { hostBundle = [hb retain]; + isBackgroundApplication = ([[hostBundle objectForInfoDictionaryKey:@"LSUIElement"] doubleValue]); if ([hostBundle isRunningFromDiskImage]) { @@ -165,7 +166,7 @@ { // We don't want the download system to extract our gzips. // Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug. - return ([encodingType rangeOfString:@"gzip"].origin == NSNotFound); + return ([encodingType rangeOfString:@"gzip"].location == NSNotFound); } - (void)extractUpdate diff --git a/SUUIBasedUpdateDriver.h b/SUUIBasedUpdateDriver.h index d3459801..09a96472 100644 --- a/SUUIBasedUpdateDriver.h +++ b/SUUIBasedUpdateDriver.h @@ -18,6 +18,8 @@ SUUpdateAlert *updateAlert; } +- (void)showModalAlert:(NSAlert *)alert; + @end #endif diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index b7196dc0..19bdd9fe 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -16,8 +16,15 @@ updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem hostBundle:hostBundle]; [updateAlert setDelegate:self]; - // If the app is a menubar app or the like, we need to focus it first: - if ([[hostBundle objectForInfoDictionaryKey:@"LSUIElement"] doubleValue]) { [NSApp activateIgnoringOtherApps:YES]; } + // 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 (isBackgroundApplication) + { + [[updateAlert window] setHidesOnDeactivate:NO]; + [[updateAlert window] setLevel:NSNormalWindowLevel]; + [NSApp activateIgnoringOtherApps:YES]; + } // Only show the update alert if the app is active; otherwise, we'll wait until it is. if ([NSApp isActive]) @@ -31,8 +38,7 @@ if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)]) [delegate didNotFindUpdateToHostBundle:hostBundle]; NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up to date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [hostBundle name], [hostBundle displayVersion]]; - [alert setIcon:[hostBundle icon]]; - [alert runModal]; + [self showModalAlert:alert]; [self abortUpdate]; } @@ -138,8 +144,7 @@ - (void)abortUpdateWithError:(NSError *)error { NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"Update Error!", nil) defaultButton:SULocalizedString(@"Cancel Update", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:[error localizedDescription]]; - [alert setIcon:[hostBundle icon]]; - [alert runModal]; + [self showModalAlert:alert]; [super abortUpdateWithError:error]; } @@ -153,4 +158,14 @@ [super abortUpdate]; } +- (void)showModalAlert:(NSAlert *)alert +{ + // When showing a modal alert we need to ensure that background applications + // are focused to inform the user since there is no dock icon to notify them. + if (isBackgroundApplication) { [NSApp activateIgnoringOtherApps:YES]; } + + [alert setIcon:[hostBundle icon]]; + [alert runModal]; +} + @end diff --git a/SUUpdatePermissionPrompt.m b/SUUpdatePermissionPrompt.m index b954d435..1a474c7c 100644 --- a/SUUpdatePermissionPrompt.m +++ b/SUUpdatePermissionPrompt.m @@ -32,7 +32,12 @@ + (void)promptWithHostBundle:(NSBundle *)hb delegate:(id)d { - id prompt = [[[self class] alloc] initWithHostBundle:hb delegate:d]; + // If this is a background application we need to focus it in order to bring the prompt + // to the user's attention. Otherwise the prompt would be hidden behind other applications and + // the user would not know why the application was paused. + if ([[hb objectForInfoDictionaryKey:@"LSUIElement"] doubleValue]) { [NSApp activateIgnoringOtherApps:YES]; } + + id prompt = [[[self class] alloc] initWithHostBundle:hb delegate:d]; [NSApp runModalForWindow:[prompt window]]; } diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index 5a019f0d..f0b60051 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -12,13 +12,20 @@ @implementation SUUserInitiatedUpdateDriver - (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb -{ +{ checkingController = [[SUStatusController alloc] initWithHostBundle:hb]; [[checkingController window] center]; // Force the checking controller to load its window. [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates\u2026", nil) maxProgressValue:0 statusText:nil]; [checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; [checkingController showWindow:self]; [super checkForUpdatesAtURL:appcastURL hostBundle:hb]; + + // For background applications, obtain focus. + // Useful if the update check is requested from another app like System Preferences. + if (isBackgroundApplication) + { + [NSApp activateIgnoringOtherApps:YES]; + } } - (void)closeCheckingWindow From ac4e4e405bd35c603e8208953f1497aead751585 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 23 Jul 2008 20:27:01 -0700 Subject: [PATCH 07/14] Fixes 245991 COMPATIBILITY ISSUE: Changed updatePreferencesChanged to resetUpdateCycle to give better semantics for bundle-ish apps which need to start the update cycle manually since applicationDidFinishLaunching: won't do the right thing. --- SUUpdater.h | 5 ++--- SUUpdater.m | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/SUUpdater.h b/SUUpdater.h index cf9cb4dc..ad7df7ac 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -40,9 +40,8 @@ // This forces an update to begin with a particular driver (see SU*UpdateDriver.h) - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)driver; -// Call this to appropriately reschedule or cancel the update checking timer if preferences for time interval or automatic checks change. -// If you're using a .app, this'll be picked up automatically via NSUserDefaultsController, but for non-.apps, there's no way to observe changes. -- (void)updatePreferencesChanged; +// Call this to appropriately schedule or cancel the update checking timer according to the preferences for time interval and automatic checks. +- (void)resetUpdateCycle; - (BOOL)updateInProgress; @end diff --git a/SUUpdater.m b/SUUpdater.m index 1984b5a6..f79b8432 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -117,7 +117,7 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv BOOL automaticallyCheck = (result == SUAutomaticallyCheck); [host setBool:automaticallyCheck forUserDefaultsKey:SUEnableAutomaticChecksKey]; // Schedule checks, but make sure we ignore the delayed call from KVO - [self updatePreferencesChanged]; + [self resetUpdateCycle]; } - (void)updateDriverDidFinish:(NSNotification *)note @@ -206,9 +206,9 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv { // Allow a small delay, because perhaps the user or developer wants to change both preferences. This allows the developer to interpret a zero check interval as a sign to disable automatic checking. // Or we may get this from the developer and from our own KVO observation, this will effectively coalesce them. - [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(updatePreferencesChanged) object:nil]; - [self performSelector:@selector(updatePreferencesChanged) withObject:nil afterDelay:15]; - [self updatePreferencesChanged]; + [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil]; + [self performSelector:@selector(resetUpdateCycle) withObject:nil afterDelay:15]; + [self resetUpdateCycle]; } else { @@ -216,9 +216,9 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv } } -- (void)updatePreferencesChanged +- (void)resetUpdateCycle { - [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(updatePreferencesChanged) object:nil]; + [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil]; [self scheduleNextUpdateCheck]; } From e14727dcc3b125001f538d0903402ca3cb96151b Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 23 Jul 2008 20:41:49 -0700 Subject: [PATCH 08/14] More reliable bzr revision labeling script (shouldn't break the compilation). --- Sparkle.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index c2c6a340..c3c5e005 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -780,7 +780,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = "/usr/bin/env ruby"; - shellScript = "# Xcode auto-versioning script for Subversion\n# by Axel Andersson, modified by Daniel Jalkut to add\n# \"--revision HEAD\" to the svn info line, which allows\n# the latest revision to always be used.\n\nif ENV[\"BUILT_PRODUCTS_DIR\"].nil?\n\tSTDERR.print \"#{$0}: Must be run from Xcode!\"\n\texit(1)\nend\n\n# Get the current Bzr revision number and use it to set the CFBundleVersion value\nENV[\"PATH\"] = \"/bin:/sw/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/opt/local/bin\"\nrev = `/usr/bin/env bzr revno`\nexit(0)\ninfo = \"#{ENV[\"BUILT_PRODUCTS_DIR\"]}/#{ENV[\"WRAPPER_NAME\"]}/Resources/Info.plist\"\nversion = rev[/[\\d.]+/]\n\nif version.nil?\n\tSTDERR.print \"#{$0}: Can't find a Bazaar revision!\"\n\texit(0)\nend\n\ninfo_contents = File.read(info)\nif info_contents.nil?\n\tSTDERR.print \"#{$0}: Can't read in the Info.plist file!\"\n\texit(1)\nend\n\ninfo_contents.sub!(/([\\t ]+CFBundleVersion<\\/key>\\n[\\t ]+).*?(<\\/string>)/, '\\1' + version + '\\2')\nSTDERR.print info_contents\nf = File.open(info, \"w\")\nf.write(info_contents)\nf.close"; + shellScript = "# Xcode auto-versioning script for Subversion\n# by Axel Andersson, modified by Daniel Jalkut to add\n# \"--revision HEAD\" to the svn info line, which allows\n# the latest revision to always be used.\n\nif ENV[\"BUILT_PRODUCTS_DIR\"].nil?\n\tSTDERR.print \"#{$0}: Must be run from Xcode!\"\n\texit(1)\nend\n\n# Get the current Bzr revision number and use it to set the CFBundleVersion value\nENV[\"PATH\"] = \"/bin:/sw/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/opt/local/bin\"\nexit(0) if `type bzr` == \"\"\nrev = `/usr/bin/env bzr revno`\ninfo = \"#{ENV[\"BUILT_PRODUCTS_DIR\"]}/#{ENV[\"WRAPPER_NAME\"]}/Resources/Info.plist\"\nversion = rev[/[\\d.]+/]\n\nif version.nil?\n\tSTDERR.print \"#{$0}: Can't find a Bazaar revision!\"\n\texit(0)\nend\n\ninfo_contents = File.read(info)\nif info_contents.nil?\n\tSTDERR.print \"#{$0}: Can't read in the Info.plist file!\"\n\texit(1)\nend\n\ninfo_contents.sub!(/([\\t ]+CFBundleVersion<\\/key>\\n[\\t ]+).*?(<\\/string>)/, '\\1' + version + '\\2')\nSTDERR.print info_contents\nf = File.open(info, \"w\")\nf.write(info_contents)\nf.close"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ From 7454b8f2f603b143d4200d9f087c5edb40527bee Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 23 Jul 2008 21:42:32 -0700 Subject: [PATCH 09/14] Small changes for clarity. --- SUUserInitiatedUpdateDriver.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index 59a31260..b9831838 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -18,11 +18,11 @@ [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates\u2026", nil) maxProgressValue:0 statusText:nil]; [checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; [checkingController showWindow:self]; - [super checkForUpdatesAtURL:appcastURL host:host]; + [super checkForUpdatesAtURL:appcastURL host:aHost]; // For background applications, obtain focus. // Useful if the update check is requested from another app like System Preferences. - if ([host isBackgroundApplication]) + if ([aHost isBackgroundApplication]) { [NSApp activateIgnoringOtherApps:YES]; } From de9be8b4810d0aa829dd2373145282a520604d67 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 23 Jul 2008 22:49:47 -0700 Subject: [PATCH 10/14] Fixes 244428 Removed all Cocoa categories from Sparkle by integrating things into other classes or making categories on existing Sparkle classes. Whoo! --- NSFileManager+Aliases.h | 18 --- NSFileManager+Aliases.m | 33 ------ NSFileManager+Authentication.h | 16 --- NSFileManager+ExtendedAttributes.h | 53 --------- NSFileManager+ExtendedAttributes.m | 98 ---------------- NSWorkspace+SystemVersion.h | 18 --- NSWorkspace+SystemVersion.m | 36 ------ SUBasicUpdateDriver.m | 6 +- ...eManager+Verification.h => SUDSAVerifier.h | 10 +- ...eManager+Verification.m => SUDSAVerifier.m | 9 +- SUHost.h | 2 + SUHost.m | 24 ++++ SUInstaller.m | 22 +++- SUPlainInstaller.h | 1 + SUPlainInstaller.m | 3 +- SUPlainInstallerInternals.h | 18 +++ ...ntication.m => SUPlainInstallerInternals.m | 110 ++++++++++++++++-- SUSystemProfiler.m | 2 +- Sparkle.h | 6 - Sparkle.xcodeproj/project.pbxproj | 82 ++++++------- 20 files changed, 219 insertions(+), 348 deletions(-) delete mode 100644 NSFileManager+Aliases.h delete mode 100644 NSFileManager+Aliases.m delete mode 100644 NSFileManager+Authentication.h delete mode 100644 NSFileManager+ExtendedAttributes.h delete mode 100644 NSFileManager+ExtendedAttributes.m delete mode 100644 NSWorkspace+SystemVersion.h delete mode 100644 NSWorkspace+SystemVersion.m rename NSFileManager+Verification.h => SUDSAVerifier.h (50%) rename NSFileManager+Verification.m => SUDSAVerifier.m (95%) create mode 100644 SUPlainInstallerInternals.h rename NSFileManager+Authentication.m => SUPlainInstallerInternals.m (69%) diff --git a/NSFileManager+Aliases.h b/NSFileManager+Aliases.h deleted file mode 100644 index 673b12b3..00000000 --- a/NSFileManager+Aliases.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// NSFileManager+Aliases.h -// Sparkle -// -// Created by Andy Matuschak on 2/4/08. -// Copyright 2008 Andy Matuschak. All rights reserved. -// - -#ifndef NSFILEMANAGER_PLUS_ALIASES_H -#define NSFILEMANAGER_PLUS_ALIASES_H - -#import - -@interface NSFileManager (SUAliases) -- (BOOL)isAliasFolderAtPath:(NSString *)path; -@end - -#endif diff --git a/NSFileManager+Aliases.m b/NSFileManager+Aliases.m deleted file mode 100644 index 9b2ab411..00000000 --- a/NSFileManager+Aliases.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// NSFileManager+Aliases.m -// Sparkle -// -// Created by Andy Matuschak on 2/4/08. -// Copyright 2008 Andy Matuschak. All rights reserved. -// - -#import "NSFileManager+Aliases.h" - - -@implementation NSFileManager (SUAliases) - -- (BOOL)isAliasFolderAtPath:(NSString *)path -{ - FSRef fileRef; - OSStatus err = noErr; - Boolean aliasFileFlag, folderFlag; - NSURL *fileURL = [NSURL fileURLWithPath:path]; - - if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef)) - err = coreFoundationUnknownErr; - - if (noErr == err) - err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag); - - if (noErr == err) - return (BOOL)(aliasFileFlag && folderFlag); - else - return NO; -} - -@end diff --git a/NSFileManager+Authentication.h b/NSFileManager+Authentication.h deleted file mode 100644 index 80b91a9b..00000000 --- a/NSFileManager+Authentication.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// NSFileManager+Authentication.m -// Sparkle -// -// Created by Andy Matuschak on 3/9/06. -// Copyright 2006 Andy Matuschak. All rights reserved. -// - -#ifndef NSFILEMANAGER_PLUS_AUTHENTICATION_H -#define NSFILEMANAGER_PLUS_AUTHENTICATION_H - -@interface NSFileManager (SUAuthenticationAdditions) -- (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst error:(NSError **)error; -@end - -#endif diff --git a/NSFileManager+ExtendedAttributes.h b/NSFileManager+ExtendedAttributes.h deleted file mode 100644 index 6744ce0b..00000000 --- a/NSFileManager+ExtendedAttributes.h +++ /dev/null @@ -1,53 +0,0 @@ -// -// NSFileManager+ExtendedAttributes.h -// Sparkle -// -// Created by Mark Mentovai on 2008-01-22. -// Copyright 2008 Mark Mentovai. All rights reserved. -// - -#ifndef NSFILEMANAGER_PLUS_EXTENDEDATTRIBUTES -#define NSFILEMANAGER_PLUS_EXTENDEDATTRIBUTES - -#import - -@interface NSFileManager (MMExtendedAttributes) - -// Wraps the removexattr system call, allowing an AppKit-style NSString* to -// be used for the pathname argument. Note that the order of the arguments -// has changed from what removexattr accepts, so that code reads more -// naturally. -// -// removexattr is only available on Mac OS X 10.4 ("Tiger") and later. If -// built with an SDK that includes removexattr, this method will link against -// removexattr directly. When using earlier SDKs, this method will dynamically -// look up the removexattr symbol at runtime. If the symbol is not present, -// as will be the case when running on 10.3, this method returns -1 and sets -// errno to ENOSYS. -- (int)removeXAttr:(const char*)name - fromFile:(NSString*)file - options:(int)options; - -// Removes the directory tree rooted at |root| from the file quarantine. -// The quarantine was introduced on Mac OS X 10.5 and is described at: -// -// http://developer.apple.com/releasenotes/Carbon/RN-LaunchServices/index.html -//#apple_ref/doc/uid/TP40001369-DontLinkElementID_2 -// -// If |root| is not a directory, then it alone is removed from the quarantine. -// Symbolic links, including |root| if it is a symbolic link, will not be -// traversed. -// -// Ordinarily, the quarantine is managed by calling LSSetItemAttribute -// to set the kLSItemQuarantineProperties attribute to a dictionary specifying -// the quarantine properties to be applied. However, it does not appear to be -// possible to remove an item from the quarantine directly through any public -// Launch Services calls. Instead, this method takes advantage of the fact -// that the quarantine is implemented in part by setting an extended attribute, -// "com.apple.quarantine", on affected files. Removing this attribute is -// sufficient to remove files from the quarantine. -- (void)releaseFromQuarantine:(NSString*)root; - -@end - -#endif diff --git a/NSFileManager+ExtendedAttributes.m b/NSFileManager+ExtendedAttributes.m deleted file mode 100644 index 4a2c3d86..00000000 --- a/NSFileManager+ExtendedAttributes.m +++ /dev/null @@ -1,98 +0,0 @@ -// -// NSFileManager+ExtendedAttributes.m -// Sparkle -// -// Created by Mark Mentovai on 2008-01-22. -// Copyright 2008 Mark Mentovai. All rights reserved. -// - -#import "NSFileManager+ExtendedAttributes.h" - -#include -#include - -// Extended attribute support was introduced in Mac OS X 10.4 ("Tiger"). -// If building with an earlier SDK, provide definitions needed to handle -// extended attributes at runtime. -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 // SDK >= 10.4 -#include -#else // SDK >= 10.4 -#define XATTR_NOFOLLOW 1 -#endif // SDK >= 10.4 - -@implementation NSFileManager (MMExtendedAttributes) - -- (int)removeXAttr:(const char*)name - fromFile:(NSString*)file - options:(int)options -{ - typedef int (*removexattr_type)(const char*, const char*, int); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 // SDK >= 10.4 - // Reference removexattr directly, it's in the SDK. - static removexattr_type removexattr_func = removexattr; -#else // SDK >= 10.4 - // removexattr isn't in this SDK, look it up at runtime. - static removexattr_type removexattr_func = NULL; - static BOOL didSymbolLookup = NO; - if (!didSymbolLookup) { - didSymbolLookup = YES; - removexattr_func = dlsym(RTLD_NEXT, "removexattr"); - } -#endif // SDK >= 10.4 - -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4 // DT < 10.4 - // Make sure that the symbol is present. This checks the deployment - // target instead of the SDK so that it's able to catch dlsym failures - // as well as the null symbol that would result from building with the - // 10.4 SDK and a lower deployment target, and running on 10.3. - if (!removexattr_func) { - errno = ENOSYS; - return -1; - } -#endif // DT < 10.4 - - const char* path = NULL; - @try { - path = [file fileSystemRepresentation]; - } - @catch (id exception) { - // -[NSString fileSystemRepresentation] throws an exception if it's - // unable to convert the string to something suitable. Map that to - // EDOM, "argument out of domain", which sort of conveys that there - // was a conversion failure. - errno = EDOM; - return -1; - } - - return removexattr_func(path, name, options); -} - -- (void)releaseFromQuarantine:(NSString*)root -{ - const char* quarantineAttribute = "com.apple.quarantine"; - const int removeXAttrOptions = XATTR_NOFOLLOW; - - [self removeXAttr:quarantineAttribute - fromFile:root - options:removeXAttrOptions]; - - // Only recurse if it's actually a directory. Don't recurse into a - // root-level symbolic link. - NSDictionary* rootAttributes = - [self fileAttributesAtPath:root traverseLink:NO]; - NSString* rootType = [rootAttributes objectForKey:NSFileType]; - - if (rootType == NSFileTypeDirectory) { - // The NSDirectoryEnumerator will avoid recursing into any contained - // symbolic links, so no further type checks are needed. - NSDirectoryEnumerator* directoryEnumerator = [self enumeratorAtPath:root]; - NSString* file = nil; - while ((file = [directoryEnumerator nextObject])) { - [self removeXAttr:quarantineAttribute - fromFile:[root stringByAppendingPathComponent:file] - options:removeXAttrOptions]; - } - } -} - -@end diff --git a/NSWorkspace+SystemVersion.h b/NSWorkspace+SystemVersion.h deleted file mode 100644 index 52e81afc..00000000 --- a/NSWorkspace+SystemVersion.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// NSWorkspace+SystemVersion.h -// Sparkle -// -// Created by Andy Matuschak on 5/7/08. -// Copyright 2008 Andy Matuschak. All rights reserved. -// - -#ifndef NSWORKSPACE_PLUS_SYSTEMVERSION_H -#define NSWORKSPACE_PLUS_SYSTEMVERSION_H - -#import - -@interface NSWorkspace (SUSystemVersion) -+ (NSString *)systemVersionString; -@end - -#endif diff --git a/NSWorkspace+SystemVersion.m b/NSWorkspace+SystemVersion.m deleted file mode 100644 index 408cb872..00000000 --- a/NSWorkspace+SystemVersion.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// NSWorkspace+SystemVersion.m -// Sparkle -// -// Created by Andy Matuschak on 5/7/08. -// Copyright 2008 Andy Matuschak. All rights reserved. -// - -#import "NSWorkspace+SystemVersion.h" - - -@implementation NSWorkspace (SUSystemVersion) -+ (NSString *)systemVersionString -{ - // This returns a version string of the form X.Y.Z - // There may be a better way to deal with the problem that gestaltSystemVersionMajor - // et al. are not defined in 10.3, but this is probably good enough. - NSString* verStr = nil; -#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 - SInt32 major, minor, bugfix; - OSErr err1 = Gestalt(gestaltSystemVersionMajor, &major); - OSErr err2 = Gestalt(gestaltSystemVersionMinor, &minor); - OSErr err3 = Gestalt(gestaltSystemVersionBugFix, &bugfix); - if (!err1 && !err2 && !err3) - { - verStr = [NSString stringWithFormat:@"%d.%d.%d", major, minor, bugfix]; - } - else -#endif - { - NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist"; - verStr = [[[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"] retain]; - } - return verStr; -} -@end diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 8d437a36..a9a850da 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -9,6 +9,8 @@ #import "Sparkle.h" #import "SUBasicUpdateDriver.h" +#import "SUDSAVerifier.h" + @implementation SUBasicUpdateDriver - (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)aHost @@ -54,7 +56,7 @@ - (BOOL)hostSupportsItem:(SUAppcastItem *)ui { if ([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) { return YES; } - return [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion] toVersion:[NSWorkspace systemVersionString]] != NSOrderedDescending; + return [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedDescending; } - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui @@ -176,7 +178,7 @@ // DSA verification, if activated by the developer if ([[host objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue]) { - if (![[NSFileManager defaultManager] validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[host publicDSAKey]]) + if (![SUDSAVerifier validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[host publicDSAKey]]) { [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObject:@"The update is improperly signed." forKey:NSLocalizedDescriptionKey]]]; return; diff --git a/NSFileManager+Verification.h b/SUDSAVerifier.h similarity index 50% rename from NSFileManager+Verification.h rename to SUDSAVerifier.h index 9a97eacd..8043f945 100644 --- a/NSFileManager+Verification.h +++ b/SUDSAVerifier.h @@ -1,17 +1,17 @@ // -// NSFileManager+Verification.h +// SUDSAVerifier.h // Sparkle // // Created by Andy Matuschak on 3/16/06. // Copyright 2006 Andy Matuschak. All rights reserved. // -#ifndef NSFILEMANAGER_PLUS_VERIFICATION_H -#define NSFILEMANAGER_PLUS_VERIFICATION_H +#ifndef SUDSAVERIFIER_H +#define SUDSAVERIFIER_H // For the paranoid folks! -@interface NSFileManager (SUVerification) -- (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString; +@interface SUDSAVerifier {} ++ (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString; @end #endif diff --git a/NSFileManager+Verification.m b/SUDSAVerifier.m similarity index 95% rename from NSFileManager+Verification.m rename to SUDSAVerifier.m index 51d0a62d..e9ee03e5 100644 --- a/NSFileManager+Verification.m +++ b/SUDSAVerifier.m @@ -1,5 +1,5 @@ // -// NSFileManager+Verification.m +// SUDSAVerifier.m // Sparkle // // Created by Andy Matuschak on 3/16/06. @@ -8,8 +8,7 @@ // DSA stuff adapted from code provided by Allan Odgaard. Thanks, Allan! -#import "Sparkle.h" -#import "NSFileManager+Verification.h" +#import "SUDSAVerifier.h" #import #import @@ -102,9 +101,9 @@ EVP_PKEY* load_dsa_key(char *key) return pkey; } -@implementation NSFileManager (SUVerification) +@implementation SUDSAVerifier -- (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString ++ (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString { BOOL result = NO; if (!encodedSignature) { return NO; } diff --git a/SUHost.h b/SUHost.h index 24c41525..3c2b9ab1 100644 --- a/SUHost.h +++ b/SUHost.h @@ -12,6 +12,8 @@ NSBundle *bundle; } ++ (NSString *)systemVersionString; + - (id)initWithBundle:(NSBundle *)aBundle; - (NSBundle *)bundle; - (NSString *)bundlePath; diff --git a/SUHost.m b/SUHost.m index 78359c92..f764f9e5 100644 --- a/SUHost.m +++ b/SUHost.m @@ -170,4 +170,28 @@ [[NSUserDefaults standardUserDefaults] synchronize]; } ++ (NSString *)systemVersionString +{ + // This returns a version string of the form X.Y.Z + // There may be a better way to deal with the problem that gestaltSystemVersionMajor + // et al. are not defined in 10.3, but this is probably good enough. + NSString* verStr = nil; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 + SInt32 major, minor, bugfix; + OSErr err1 = Gestalt(gestaltSystemVersionMajor, &major); + OSErr err2 = Gestalt(gestaltSystemVersionMinor, &minor); + OSErr err3 = Gestalt(gestaltSystemVersionBugFix, &bugfix); + if (!err1 && !err2 && !err3) + { + verStr = [NSString stringWithFormat:@"%d.%d.%d", major, minor, bugfix]; + } + else +#endif + { + NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist"; + verStr = [[[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"] retain]; + } + return verStr; +} + @end diff --git a/SUInstaller.m b/SUInstaller.m index d35488c8..c73c3bc2 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -16,6 +16,26 @@ NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; @implementation SUInstaller ++ (BOOL)_isAliasFolderAtPath:(NSString *)path +{ + FSRef fileRef; + OSStatus err = noErr; + Boolean aliasFileFlag, folderFlag; + NSURL *fileURL = [NSURL fileURLWithPath:path]; + + if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef)) + err = coreFoundationUnknownErr; + + if (noErr == err) + err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag); + + if (noErr == err) + return (BOOL)(aliasFileFlag && folderFlag); + else + return NO; +} + + + (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously { // Search subdirectories for the application @@ -41,7 +61,7 @@ NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; } // Some DMGs have symlinks into /Applications! That's no good! And there's no point in looking in bundles. - if ([[NSFileManager defaultManager] isAliasFolderAtPath:currentPath] || + if ([self _isAliasFolderAtPath:currentPath] || [[currentFile pathExtension] isEqualToString:[[host bundlePath] pathExtension]] || [[currentFile pathExtension] isEqualToString:@"pkg"] || [[currentFile pathExtension] isEqualToString:@"mpkg"]) diff --git a/SUPlainInstaller.h b/SUPlainInstaller.h index 142d2e07..8cd31ce2 100644 --- a/SUPlainInstaller.h +++ b/SUPlainInstaller.h @@ -10,6 +10,7 @@ #define SUPLAININSTALLER_H #import "Sparkle.h" +#import "SUInstaller.h" @interface SUPlainInstaller : SUInstaller { } + (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously; diff --git a/SUPlainInstaller.m b/SUPlainInstaller.m index 940d55d2..3e1876b0 100644 --- a/SUPlainInstaller.m +++ b/SUPlainInstaller.m @@ -7,6 +7,7 @@ // #import "SUPlainInstaller.h" +#import "SUPlainInstallerInternals.h" extern NSString *SUInstallerPathKey; extern NSString *SUInstallerHostKey; @@ -17,7 +18,7 @@ extern NSString *SUInstallerDelegateKey; + (void)installPath:(NSString *)path overHost:(SUHost *)bundle delegate:delegate { NSError *error; - BOOL result = [[NSFileManager defaultManager] copyPathWithAuthentication:path overPath:[bundle bundlePath] error:&error]; + BOOL result = [self copyPathWithAuthentication:path overPath:[bundle bundlePath] error:&error]; [self _finishInstallationWithResult:result host:bundle error:error delegate:delegate]; } diff --git a/SUPlainInstallerInternals.h b/SUPlainInstallerInternals.h new file mode 100644 index 00000000..1214394b --- /dev/null +++ b/SUPlainInstallerInternals.h @@ -0,0 +1,18 @@ +// +// SUPlainInstallerInternals.m +// Sparkle +// +// Created by Andy Matuschak on 3/9/06. +// Copyright 2006 Andy Matuschak. All rights reserved. +// + +#ifndef SUPLAININSTALLERINTERNALS_H +#define SUPLAININSTALLERINTERNALS_H + +#import "SUPlainInstaller.h" + +@interface SUPlainInstaller (Internals) ++ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst error:(NSError **)error; +@end + +#endif diff --git a/NSFileManager+Authentication.m b/SUPlainInstallerInternals.m similarity index 69% rename from NSFileManager+Authentication.m rename to SUPlainInstallerInternals.m index a0c922e5..bcb2db75 100644 --- a/NSFileManager+Authentication.m +++ b/SUPlainInstallerInternals.m @@ -1,15 +1,13 @@ // -// NSFileManager+Authentication.m +// SUPlainInstallerInternals.m // Sparkle // // Created by Andy Matuschak on 3/9/06. // Copyright 2006 Andy Matuschak. All rights reserved. // -// This code based on generous contribution from Allan Odgaard. Thanks, Allan! - #import "Sparkle.h" -#import "NSFileManager+Authentication.h" +#import "SUPlainInstallerInternals.h" #import #import @@ -17,7 +15,30 @@ #import #import -#import "NSFileManager+ExtendedAttributes.h" +@interface SUPlainInstaller (MMExtendedAttributes) +// Removes the directory tree rooted at |root| from the file quarantine. +// The quarantine was introduced on Mac OS X 10.5 and is described at: +// +// http://developer.apple.com/releasenotes/Carbon/RN-LaunchServices/index.html +//#apple_ref/doc/uid/TP40001369-DontLinkElementID_2 +// +// If |root| is not a directory, then it alone is removed from the quarantine. +// Symbolic links, including |root| if it is a symbolic link, will not be +// traversed. +// +// Ordinarily, the quarantine is managed by calling LSSetItemAttribute +// to set the kLSItemQuarantineProperties attribute to a dictionary specifying +// the quarantine properties to be applied. However, it does not appear to be +// possible to remove an item from the quarantine directly through any public +// Launch Services calls. Instead, this method takes advantage of the fact +// that the quarantine is implemented in part by setting an extended attribute, +// "com.apple.quarantine", on affected files. Removing this attribute is +// sufficient to remove files from the quarantine. ++ (void)releaseFromQuarantine:(NSString*)root; +@end + +// Authorization code based on generous contribution from Allan Odgaard. Thanks, Allan! + static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments) { sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL); @@ -37,9 +58,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return returnValue; } -@implementation NSFileManager (SUAuthenticationAdditions) +@implementation SUPlainInstaller (Internals) -- (BOOL)currentUserOwnsPath:(NSString *)oPath ++ (BOOL)currentUserOwnsPath:(NSString *)oPath { const char *path = [oPath fileSystemRepresentation]; uid_t uid = getuid(); @@ -74,7 +95,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return res; } -- (NSString *)_temporaryCopyNameForPath:(NSString *)path ++ (NSString *)_temporaryCopyNameForPath:(NSString *)path { // Let's try to read the version number so the filename will be more meaningful. NSString *postFix; @@ -98,7 +119,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return tempDir; } -- (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst error:(NSError **)error ++ (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst error:(NSError **)error { NSString *tmp = [self _temporaryCopyNameForPath:dst]; const char* srcPath = [src fileSystemRepresentation]; @@ -199,7 +220,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return res; } -- (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst error:(NSError **)error ++ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst error:(NSError **)error { if (![[NSFileManager defaultManager] fileExistsAtPath:dst]) { @@ -247,3 +268,72 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza } @end + +#include +#include +#include + +@implementation SUPlainInstaller (MMExtendedAttributes) + ++ (int)removeXAttr:(const char*)name + fromFile:(NSString*)file + options:(int)options +{ + typedef int (*removexattr_type)(const char*, const char*, int); + // Reference removexattr directly, it's in the SDK. + static removexattr_type removexattr_func = removexattr; + + // Make sure that the symbol is present. This checks the deployment + // target instead of the SDK so that it's able to catch dlsym failures + // as well as the null symbol that would result from building with the + // 10.4 SDK and a lower deployment target, and running on 10.3. + if (!removexattr_func) { + errno = ENOSYS; + return -1; + } + + const char* path = NULL; + @try { + path = [file fileSystemRepresentation]; + } + @catch (id exception) { + // -[NSString fileSystemRepresentation] throws an exception if it's + // unable to convert the string to something suitable. Map that to + // EDOM, "argument out of domain", which sort of conveys that there + // was a conversion failure. + errno = EDOM; + return -1; + } + + return removexattr_func(path, name, options); +} + ++ (void)releaseFromQuarantine:(NSString*)root +{ + const char* quarantineAttribute = "com.apple.quarantine"; + const int removeXAttrOptions = XATTR_NOFOLLOW; + + [self removeXAttr:quarantineAttribute + fromFile:root + options:removeXAttrOptions]; + + // Only recurse if it's actually a directory. Don't recurse into a + // root-level symbolic link. + NSDictionary* rootAttributes = + [[NSFileManager defaultManager] fileAttributesAtPath:root traverseLink:NO]; + NSString* rootType = [rootAttributes objectForKey:NSFileType]; + + if (rootType == NSFileTypeDirectory) { + // The NSDirectoryEnumerator will avoid recursing into any contained + // symbolic links, so no further type checks are needed. + NSDirectoryEnumerator* directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:root]; + NSString* file = nil; + while ((file = [directoryEnumerator nextObject])) { + [self removeXAttr:quarantineAttribute + fromFile:[root stringByAppendingPathComponent:file] + options:removeXAttrOptions]; + } + } +} + +@end diff --git a/SUSystemProfiler.m b/SUSystemProfiler.m index 0d36cbd7..1f72aab5 100644 --- a/SUSystemProfiler.m +++ b/SUSystemProfiler.m @@ -39,7 +39,7 @@ unsigned long length = sizeof(value) ; // OS version - NSString *currentSystemVersion = [NSWorkspace systemVersionString]; + NSString *currentSystemVersion = [SUHost systemVersionString]; if (currentSystemVersion != nil) [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"osVersion",@"OS Version",currentSystemVersion,currentSystemVersion,nil] forKeys:profileDictKeys]]; diff --git a/Sparkle.h b/Sparkle.h index dfee4405..921575e1 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -25,13 +25,7 @@ // This list should include the shared headers. It doesn't matter if some of them aren't shared (unless // there are name-space collisions) so we can list all of them to start with: -#import "NSFileManager+Aliases.h" -#import "NSFileManager+Authentication.h" -#import "NSFileManager+Verification.h" -#import "NSWorkspace+SystemVersion.h" - #import "NTSynchronousTask.h" - #import "SUAppcast.h" #import "SUAppcastItem.h" #import "SUAutomaticUpdateAlert.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index c3c5e005..8ce94a94 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -9,8 +9,6 @@ /* Begin PBXBuildFile section */ 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134710DD250470049ACDF /* SUUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; 610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 610134720DD250470049ACDF /* SUUpdateDriver.m */; }; - 610134770DD252E60049ACDF /* NSWorkspace+SystemVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134750DD252E60049ACDF /* NSWorkspace+SystemVersion.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 610134780DD252E60049ACDF /* NSWorkspace+SystemVersion.m in Sources */ = {isa = PBXBuildFile; fileRef = 610134760DD252E60049ACDF /* NSWorkspace+SystemVersion.m */; }; 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6101347C0DD2541A0049ACDF /* SUProbingUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6101347A0DD2541A0049ACDF /* SUProbingUpdateDriver.m */; }; 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -28,9 +26,9 @@ 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */; }; 61227A160DB548B800AB99EA /* SUVersionComparisonTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */; }; - 61299A2F09CA2DAB00B7442F /* NSFileManager+Verification.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* NSFileManager+Verification.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61299A3009CA2DAB00B7442F /* NSFileManager+Verification.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A2E09CA2DAB00B7442F /* NSFileManager+Verification.m */; }; - 61299A4A09CA2DD000B7442F /* NSFileManager+Authentication.h in Headers */ = {isa = PBXBuildFile; fileRef = 6129984309C9E2DA00B7442F /* NSFileManager+Authentication.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61299A3009CA2DAB00B7442F /* SUDSAVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A2E09CA2DAB00B7442F /* SUDSAVerifier.m */; }; + 61299A4A09CA2DD000B7442F /* SUPlainInstallerInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 6129984309C9E2DA00B7442F /* SUPlainInstallerInternals.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A8B09CA790200B7442F /* SUUnarchiver.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -42,8 +40,6 @@ 615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */ = {isa = PBXBuildFile; fileRef = 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */; }; 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61699BCC0DDB92BD005878A4 /* SUVersionComparisonTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 61227A140DB548B800AB99EA /* SUVersionComparisonTest.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 6171D9070D57B81800BFE886 /* NSFileManager+Aliases.h in Headers */ = {isa = PBXBuildFile; fileRef = 6171D9050D57B81800BFE886 /* NSFileManager+Aliases.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 6171D9080D57B81800BFE886 /* NSFileManager+Aliases.m in Sources */ = {isa = PBXBuildFile; fileRef = 6171D9060D57B81800BFE886 /* NSFileManager+Aliases.m */; }; 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA4FF0DAE88B40026945C /* SUInstaller.h */; settings = {ATTRIBUTES = (Public, ); }; }; 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5000DAE88B40026945C /* SUInstaller.m */; }; 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5030DAE8AB80026945C /* SUPlainInstaller.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -64,7 +60,7 @@ 61AAE82A0A321A8000D8810D /* SUUpdateAlert.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8260A321A7F00D8810D /* SUUpdateAlert.nib */; }; 61B5F8ED09C4CE3C00B25A18 /* SUUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */; }; - 61B5F8EF09C4CE3C00B25A18 /* NSFileManager+Authentication.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E509C4CE3C00B25A18 /* NSFileManager+Authentication.m */; }; + 61B5F8EF09C4CE3C00B25A18 /* SUPlainInstallerInternals.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E509C4CE3C00B25A18 /* SUPlainInstallerInternals.m */; }; 61B5F8F709C4CEB300B25A18 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 61B5F90F09C4CF3A00B25A18 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; }; 61B5F92E09C4CFD800B25A18 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61B5F92A09C4CFD800B25A18 /* InfoPlist.strings */; }; @@ -84,8 +80,6 @@ 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B93C0A0DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93C080DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m */; }; 61BBDF820A49220C00378739 /* Sparkle.icns in Resources */ = {isa = PBXBuildFile; fileRef = 61BBDF810A49220C00378739 /* Sparkle.icns */; }; - 61C1F2780DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 61C1F2760DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61C1F2790DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */; }; 61C2680A0E2DB5D000175E6C /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = 61C268090E2DB5D000175E6C /* License.txt */; }; 61C46F340D9C54F300B06326 /* SUUpdatePermissionPrompt.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61C46F330D9C54F300B06326 /* SUUpdatePermissionPrompt.nib */; }; 61D85D6D0E10B2ED00F9B4A9 /* SUPipedUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6129C0B90E0B79810062CE76 /* SUPipedUnarchiver.m */; }; @@ -152,8 +146,6 @@ 0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 610134710DD250470049ACDF /* SUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateDriver.h; sourceTree = ""; }; 610134720DD250470049ACDF /* SUUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDriver.m; sourceTree = ""; }; - 610134750DD252E60049ACDF /* NSWorkspace+SystemVersion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSWorkspace+SystemVersion.h"; sourceTree = ""; }; - 610134760DD252E60049ACDF /* NSWorkspace+SystemVersion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSWorkspace+SystemVersion.m"; sourceTree = ""; }; 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbingUpdateDriver.h; sourceTree = ""; }; 6101347A0DD2541A0049ACDF /* SUProbingUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUProbingUpdateDriver.m; sourceTree = ""; }; 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPipedUnarchiver.h; sourceTree = ""; }; @@ -174,9 +166,9 @@ 612279DA0DB5470200AB99EA /* Sparkle Unit Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Sparkle Unit Tests-Info.plist"; path = "Tests/Sparkle Unit Tests-Info.plist"; sourceTree = ""; }; 61227A140DB548B800AB99EA /* SUVersionComparisonTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUVersionComparisonTest.h; path = Tests/SUVersionComparisonTest.h; sourceTree = ""; }; 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUVersionComparisonTest.m; path = Tests/SUVersionComparisonTest.m; sourceTree = ""; }; - 6129984309C9E2DA00B7442F /* NSFileManager+Authentication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Authentication.h"; sourceTree = ""; }; - 61299A2D09CA2DAB00B7442F /* NSFileManager+Verification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Verification.h"; sourceTree = ""; }; - 61299A2E09CA2DAB00B7442F /* NSFileManager+Verification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+Verification.m"; sourceTree = ""; }; + 6129984309C9E2DA00B7442F /* SUPlainInstallerInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPlainInstallerInternals.h; sourceTree = ""; }; + 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUDSAVerifier.h; sourceTree = ""; }; + 61299A2E09CA2DAB00B7442F /* SUDSAVerifier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDSAVerifier.m; sourceTree = ""; }; 61299A5B09CA6D4500B7442F /* SUConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUConstants.h; sourceTree = ""; }; 61299A5F09CA6EB100B7442F /* SUConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUConstants.m; sourceTree = ""; }; 61299A8B09CA790200B7442F /* SUUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiver.h; sourceTree = ""; }; @@ -187,8 +179,6 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdatePermissionPrompt.m; sourceTree = ""; }; 613242130CD06CEF00106AA4 /* relaunch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = relaunch.m; sourceTree = ""; }; 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SUModelTranslation.plist; sourceTree = ""; }; - 6171D9050D57B81800BFE886 /* NSFileManager+Aliases.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Aliases.h"; sourceTree = ""; }; - 6171D9060D57B81800BFE886 /* NSFileManager+Aliases.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+Aliases.m"; sourceTree = ""; }; 618915700E35937600B5E981 /* sv */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = sv; path = sv.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; 618915710E35937600B5E981 /* sv */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = sv; path = sv.lproj/SUUpdateAlert.nib; sourceTree = ""; }; 618915720E35937600B5E981 /* sv */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = sv; path = sv.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; @@ -220,7 +210,7 @@ 61AAE8710A321F7700D8810D /* nl */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Sparkle.strings; sourceTree = ""; }; 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SUUpdater.h; sourceTree = ""; }; 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SUUpdater.m; sourceTree = ""; }; - 61B5F8E509C4CE3C00B25A18 /* NSFileManager+Authentication.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+Authentication.m"; sourceTree = ""; }; + 61B5F8E509C4CE3C00B25A18 /* SUPlainInstallerInternals.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SUPlainInstallerInternals.m; sourceTree = ""; }; 61B5F8F609C4CEB300B25A18 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = ""; }; 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sparkle Test App.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 61B5F90409C4CEE200B25A18 /* Test Application-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Test Application-Info.plist"; path = "Test Application/Test Application-Info.plist"; sourceTree = ""; }; @@ -241,8 +231,6 @@ 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUScheduledUpdateDriver.h; sourceTree = ""; }; 61B93C080DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUScheduledUpdateDriver.m; sourceTree = ""; }; 61BBDF810A49220C00378739 /* Sparkle.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Sparkle.icns; sourceTree = ""; }; - 61C1F2760DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+ExtendedAttributes.h"; sourceTree = ""; }; - 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+ExtendedAttributes.m"; sourceTree = ""; }; 61C268090E2DB5D000175E6C /* License.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = License.txt; sourceTree = ""; }; 61C46F350D9C54F300B06326 /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; 61EF67550E25B58D00F754E0 /* SUHost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUHost.m; sourceTree = ""; }; @@ -336,7 +324,7 @@ 0867D691FE84028FC02AAC07 /* Sparkle */ = { isa = PBXGroup; children = ( - 61F83F6E0DBFE07A006FDD30 /* Update Drivers */, + 61F83F6E0DBFE07A006FDD30 /* Update Control */, 61299B3909CB055000B7442F /* Appcast Support */, 618FA6DB0DB485440026945C /* Installation */, 6101354A0DD25B7F0049ACDF /* Unarchiving */, @@ -400,14 +388,6 @@ isa = PBXGroup; children = ( 613242130CD06CEF00106AA4 /* relaunch.m */, - 6129984309C9E2DA00B7442F /* NSFileManager+Authentication.h */, - 61B5F8E509C4CE3C00B25A18 /* NSFileManager+Authentication.m */, - 61299A2D09CA2DAB00B7442F /* NSFileManager+Verification.h */, - 61299A2E09CA2DAB00B7442F /* NSFileManager+Verification.m */, - 6171D9050D57B81800BFE886 /* NSFileManager+Aliases.h */, - 6171D9060D57B81800BFE886 /* NSFileManager+Aliases.m */, - 61C1F2760DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h */, - 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */, ); name = Support; sourceTree = ""; @@ -462,6 +442,8 @@ 618FA5000DAE88B40026945C /* SUInstaller.m */, 618FA5030DAE8AB80026945C /* SUPlainInstaller.h */, 618FA5040DAE8AB80026945C /* SUPlainInstaller.m */, + 6129984309C9E2DA00B7442F /* SUPlainInstallerInternals.h */, + 61B5F8E509C4CE3C00B25A18 /* SUPlainInstallerInternals.m */, 618FA5200DAE8E8A0026945C /* SUPackageInstaller.h */, 618FA5210DAE8E8A0026945C /* SUPackageInstaller.m */, 6101355D0DD25BB70049ACDF /* Support */, @@ -474,8 +456,6 @@ children = ( 61EF67580E25C5B400F754E0 /* SUHost.h */, 61EF67550E25B58D00F754E0 /* SUHost.m */, - 610134750DD252E60049ACDF /* NSWorkspace+SystemVersion.h */, - 610134760DD252E60049ACDF /* NSWorkspace+SystemVersion.m */, 61299B3509CB04E000B7442F /* Sparkle.h */, 61299A5B09CA6D4500B7442F /* SUConstants.h */, 61299A5F09CA6EB100B7442F /* SUConstants.m */, @@ -496,11 +476,18 @@ name = "Test Application Sources"; sourceTree = ""; }; - 61F83F6E0DBFE07A006FDD30 /* Update Drivers */ = { + 61CFB2C10E384958007A1735 /* Support */ = { + isa = PBXGroup; + children = ( + 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */, + 61299A2E09CA2DAB00B7442F /* SUDSAVerifier.m */, + ); + name = Support; + sourceTree = ""; + }; + 61CFB2C20E38496B007A1735 /* Drivers */ = { isa = PBXGroup; children = ( - 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */, - 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */, 610134710DD250470049ACDF /* SUUpdateDriver.h */, 610134720DD250470049ACDF /* SUUpdateDriver.m */, 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */, @@ -516,7 +503,18 @@ 61A354530DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h */, 61A354540DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.m */, ); - name = "Update Drivers"; + name = Drivers; + sourceTree = ""; + }; + 61F83F6E0DBFE07A006FDD30 /* Update Control */ = { + isa = PBXGroup; + children = ( + 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */, + 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */, + 61CFB2C20E38496B007A1735 /* Drivers */, + 61CFB2C10E384958007A1735 /* Support */, + ); + name = "Update Control"; sourceTree = ""; }; FA1941C40D94A6EA00DD942E /* Configurations */ = { @@ -551,8 +549,8 @@ 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, 61B5FCDF09C52A9F00B25A18 /* SUUpdateAlert.h in Headers */, 6196CFF909C72148000DC222 /* SUStatusController.h in Headers */, - 61299A2F09CA2DAB00B7442F /* NSFileManager+Verification.h in Headers */, - 61299A4A09CA2DD000B7442F /* NSFileManager+Authentication.h in Headers */, + 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */, + 61299A4A09CA2DD000B7442F /* SUPlainInstallerInternals.h in Headers */, 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */, 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, @@ -562,9 +560,7 @@ 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */, 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */, 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */, - 6171D9070D57B81800BFE886 /* NSFileManager+Aliases.h in Headers */, 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */, - 61C1F2780DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h in Headers */, 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */, 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */, 618FA5220DAE8E8A0026945C /* SUPackageInstaller.h in Headers */, @@ -573,7 +569,6 @@ 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */, 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */, 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */, - 610134770DD252E60049ACDF /* NSWorkspace+SystemVersion.h in Headers */, 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */, 61699BCC0DDB92BD005878A4 /* SUVersionComparisonTest.h in Headers */, 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */, @@ -807,12 +802,12 @@ buildActionMask = 2147483647; files = ( 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */, - 61B5F8EF09C4CE3C00B25A18 /* NSFileManager+Authentication.m in Sources */, + 61B5F8EF09C4CE3C00B25A18 /* SUPlainInstallerInternals.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 61B5FCDE09C52A9F00B25A18 /* SUUpdateAlert.m in Sources */, 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */, - 61299A3009CA2DAB00B7442F /* NSFileManager+Verification.m in Sources */, + 61299A3009CA2DAB00B7442F /* SUDSAVerifier.m in Sources */, 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */, 61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */, 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */, @@ -820,9 +815,7 @@ 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */, - 6171D9080D57B81800BFE886 /* NSFileManager+Aliases.m in Sources */, 61180BCB0D64138900B4E0D1 /* SUWindowController.m in Sources */, - 61C1F2790DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m in Sources */, 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */, 618FA5060DAE8AB80026945C /* SUPlainInstaller.m in Sources */, 618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */, @@ -831,7 +824,6 @@ 61B93B280DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m in Sources */, 61B93C0A0DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m in Sources */, 610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */, - 610134780DD252E60049ACDF /* NSWorkspace+SystemVersion.m in Sources */, 6101347C0DD2541A0049ACDF /* SUProbingUpdateDriver.m in Sources */, 61A354560DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.m in Sources */, 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */, From f815eec2c0411c3bad526a1e70c9b7756ab21500 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 23 Jul 2008 23:40:01 -0700 Subject: [PATCH 11/14] Fixes 243884 Made Sparkle.h no longer a massive multi-headed abomination: now only SUAppcastItem, SUAppcast and SUUpdater (and SUVersionComparisonProtocol because it's part of the delegate protocol) are public. COMPATIBILITY ISSUE: This means there's no longer a public SUProbingUpdateDriver or a checkForUpdatesWithDriver: method. Now use checkForUpdateInformation. I may change that API before release, though. I'm thinking it might be better to give the delegate the opportunity to reject a potential update instead: then you'd just call checkForUpdatesInBackground and override that delegate method to always return NO. We'll see. --- SUAppcastItem.h | 1 - SUAutomaticUpdateAlert.m | 3 +- SUAutomaticUpdateDriver.m | 4 ++- SUBasicUpdateDriver.m | 5 ++- SUHost.m | 4 ++- SUSystemProfiler.h | 1 + SUSystemProfiler.m | 2 +- SUUIBasedUpdateDriver.m | 5 ++- SUUpdateAlert.m | 2 +- SUUpdatePermissionPrompt.h | 2 +- SUUpdatePermissionPrompt.m | 3 +- SUUpdater.h | 10 +++--- SUUpdater.m | 15 +++++++- SUUserInitiatedUpdateDriver.m | 4 ++- Sparkle.h | 40 +++------------------- Sparkle.pch | 15 ++++++++ Sparkle.xcodeproj/project.pbxproj | 57 +++++++++++++++++-------------- Tests/SUVersionComparisonTest.m | 2 +- 18 files changed, 95 insertions(+), 80 deletions(-) create mode 100644 Sparkle.pch diff --git a/SUAppcastItem.h b/SUAppcastItem.h index d0c0523e..d233cd08 100644 --- a/SUAppcastItem.h +++ b/SUAppcastItem.h @@ -9,7 +9,6 @@ #ifndef SUAPPCASTITEM_H #define SUAPPCASTITEM_H - @interface SUAppcastItem : NSObject { NSString *title; NSDate *date; diff --git a/SUAutomaticUpdateAlert.m b/SUAutomaticUpdateAlert.m index 70a3b15f..3c800232 100644 --- a/SUAutomaticUpdateAlert.m +++ b/SUAutomaticUpdateAlert.m @@ -6,9 +6,10 @@ // Copyright 2006 Andy Matuschak. All rights reserved. // -#import "Sparkle.h" #import "SUAutomaticUpdateAlert.h" +#import "SUHost.h" + @implementation SUAutomaticUpdateAlert - (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:del; diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index a9c842e3..9f5f985c 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -7,7 +7,9 @@ // #import "SUAutomaticUpdateDriver.h" -#import "Sparkle.h" + +#import "SUAutomaticUpdateAlert.h" +#import "SUHost.h" @implementation SUAutomaticUpdateDriver diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index a9a850da..83e7433c 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -6,10 +6,13 @@ // Copyright 2008 Andy Matuschak. All rights reserved. // -#import "Sparkle.h" #import "SUBasicUpdateDriver.h" +#import "SUHost.h" #import "SUDSAVerifier.h" +#import "SUInstaller.h" +#import "SUStandardVersionComparator.h" +#import "SUUnarchiver.h" @implementation SUBasicUpdateDriver diff --git a/SUHost.m b/SUHost.m index f764f9e5..8c3c6311 100644 --- a/SUHost.m +++ b/SUHost.m @@ -5,7 +5,9 @@ // Copyright 2008 Andy Matuschak. All rights reserved. // -#import "Sparkle.h" +#import "SUHost.h" + +#import "SUSystemProfiler.h" #import // For statfs for isRunningOnReadOnlyVolume @implementation SUHost diff --git a/SUSystemProfiler.h b/SUSystemProfiler.h index 187de646..6238e39c 100644 --- a/SUSystemProfiler.h +++ b/SUSystemProfiler.h @@ -9,6 +9,7 @@ #ifndef SUSYSTEMPROFILER_H #define SUSYSTEMPROFILER_H +@class SUHost; @interface SUSystemProfiler : NSObject {} + (SUSystemProfiler *)sharedSystemProfiler; - (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host; diff --git a/SUSystemProfiler.m b/SUSystemProfiler.m index 1f72aab5..05099f7a 100644 --- a/SUSystemProfiler.m +++ b/SUSystemProfiler.m @@ -7,9 +7,9 @@ // Adapted from Sparkle+, by Tom Harrington. // -#import "Sparkle.h" #import "SUSystemProfiler.h" +#import "SUHost.h" #import @implementation SUSystemProfiler diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index cdde3f72..7fec812d 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -7,7 +7,10 @@ // #import "SUUIBasedUpdateDriver.h" -#import "Sparkle.h" + +#import "SUUpdateAlert.h" +#import "SUHost.h" +#import "SUStatusController.h" @implementation SUUIBasedUpdateDriver diff --git a/SUUpdateAlert.m b/SUUpdateAlert.m index ef9f360e..3ad9ba62 100644 --- a/SUUpdateAlert.m +++ b/SUUpdateAlert.m @@ -6,9 +6,9 @@ // Copyright 2006 Andy Matuschak. All rights reserved. // -#import "Sparkle.h" #import "SUUpdateAlert.h" +#import "SUHost.h" #import @implementation SUUpdateAlert diff --git a/SUUpdatePermissionPrompt.h b/SUUpdatePermissionPrompt.h index 3da5ffa5..09bb3b4b 100644 --- a/SUUpdatePermissionPrompt.h +++ b/SUUpdatePermissionPrompt.h @@ -9,7 +9,7 @@ #ifndef SUUPDATEPERMISSIONPROMPT_H #define SUUPDATEPERMISSIONPROMPT_H -#import "Sparkle.h" +#import "SUWindowController.h" typedef enum { SUAutomaticallyCheck, diff --git a/SUUpdatePermissionPrompt.m b/SUUpdatePermissionPrompt.m index 7902e516..0eba27f5 100644 --- a/SUUpdatePermissionPrompt.m +++ b/SUUpdatePermissionPrompt.m @@ -8,6 +8,7 @@ #import "SUUpdatePermissionPrompt.h" +#import "SUHost.h" @implementation SUUpdatePermissionPrompt @@ -69,7 +70,7 @@ - (NSArray *)systemProfileInformationArray { - return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:host]; + return [host systemProfile]; } - (IBAction)toggleMoreInfo:(id)sender diff --git a/SUUpdater.h b/SUUpdater.h index ad7df7ac..c0552387 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -9,10 +9,9 @@ #ifndef SUUPDATER_H #define SUUPDATER_H -#import "SUUpdateAlert.h" -#import "SUVersionComparisonProtocol.h" +#import -@class SUUpdateDriver, SUAppcastItem, SUAppcast; +@class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast; @interface SUUpdater : NSObject { NSTimer *checkTimer; SUUpdateDriver *driver; @@ -37,8 +36,9 @@ // update is found, it will be downloaded and prepped for installation. - (void)checkForUpdatesInBackground; -// This forces an update to begin with a particular driver (see SU*UpdateDriver.h) -- (void)checkForUpdatesWithDriver:(SUUpdateDriver *)driver; +// This begins a "probing" check for updates which will not actually offer to update to that version. The delegate methods, though, +// (up to updater:didFindValidUpdate: and updaterDidNotFindUpdate:), are called, so you can use that information in your UI. +- (void)checkForUpdateInformation; // Call this to appropriately schedule or cancel the update checking timer according to the preferences for time interval and automatic checks. - (void)resetUpdateCycle; diff --git a/SUUpdater.m b/SUUpdater.m index f79b8432..d53c3175 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -6,10 +6,18 @@ // Copyright 2006 Andy Matuschak. All rights reserved. // -#import "Sparkle.h" #import "SUUpdater.h" +#import "SUHost.h" +#import "SUUpdatePermissionPrompt.h" + +#import "SUAutomaticUpdateDriver.h" +#import "SUProbingUpdateDriver.h" +#import "SUUserInitiatedUpdateDriver.h" +#import "SUScheduledUpdateDriver.h" + @interface SUUpdater (Private) +- (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; - (NSArray *)feedParameters; - (BOOL)automaticallyUpdates; - (BOOL)shouldScheduleUpdateCheck; @@ -162,6 +170,11 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv [self checkForUpdatesWithDriver:[[[SUUserInitiatedUpdateDriver alloc] init] autorelease]]; } +- (void)checkForUpdateInformation +{ + [self checkForUpdatesWithDriver:[[[SUProbingUpdateDriver alloc] init] autorelease]]; +} + - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)d { if ([self updateInProgress]) { return; } diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index b9831838..5e742db8 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -7,7 +7,9 @@ // #import "SUUserInitiatedUpdateDriver.h" -#import "Sparkle.h" + +#import "SUStatusController.h" +#import "SUHost.h" @implementation SUUserInitiatedUpdateDriver diff --git a/Sparkle.h b/Sparkle.h index 921575e1..bea7eb30 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -6,47 +6,15 @@ // Copyright 2006 Andy Matuschak. All rights reserved. // -// -// Prefix header for all source files of the 'Sparkle' target in the 'Sparkle' project. -// - #ifndef SPARKLE_H #define SPARKLE_H -#define SULocalizedString(key,comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", [NSBundle bundleWithIdentifier:@"org.andymatuschak.Sparkle"], comment) -#define SUAbstractFail() NSAssert2(nil, @"Can't call %@ on an instance of %@; this is an abstract method!", __PRETTY_FUNCTION__, [self class]); - -#ifdef __OBJC__ -#import -#import "SUConstants.h" -#endif - - // This list should include the shared headers. It doesn't matter if some of them aren't shared (unless // there are name-space collisions) so we can list all of them to start with: -#import "NTSynchronousTask.h" -#import "SUAppcast.h" -#import "SUAppcastItem.h" -#import "SUAutomaticUpdateAlert.h" -#import "SUAutomaticUpdateDriver.h" -#import "SUBasicUpdateDriver.h" -#import "SUConstants.h" -#import "SUHost.h" -#import "SUInstaller.h" -#import "SUProbingUpdateDriver.h" -#import "SUScheduledUpdateDriver.h" -#import "SUStandardVersionComparator.h" -#import "SUStatusController.h" -#import "SUSystemProfiler.h" -#import "SUUIBasedUpdateDriver.h" -#import "SUUnarchiver.h" -#import "SUUpdateAlert.h" -#import "SUUpdateDriver.h" -#import "SUUpdater.h" -#import "SUUpdatePermissionPrompt.h" -#import "SUUserInitiatedUpdateDriver.h" -#import "SUVersionComparisonProtocol.h" -#import "SUWindowController.h" +#import +#import +#import +#import #endif diff --git a/Sparkle.pch b/Sparkle.pch new file mode 100644 index 00000000..aefba5ec --- /dev/null +++ b/Sparkle.pch @@ -0,0 +1,15 @@ +// +// Sparkle.pch +// Sparkle +// +// Created by Andy Matuschak on 7/23/08. +// Copyright 2008 Andy Matuschak. All rights reserved. +// + +#define SULocalizedString(key,comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", [NSBundle bundleWithIdentifier:@"org.andymatuschak.Sparkle"], comment) +#define SUAbstractFail() NSAssert2(nil, @"Can't call %@ on an instance of %@; this is an abstract method!", __PRETTY_FUNCTION__, [self class]); + +#ifdef __OBJC__ +#import +#import "SUConstants.h" +#endif diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 8ce94a94..b7fff51d 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -7,53 +7,53 @@ objects = { /* Begin PBXBuildFile section */ - 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134710DD250470049ACDF /* SUUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134710DD250470049ACDF /* SUUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 610134720DD250470049ACDF /* SUUpdateDriver.m */; }; - 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 6101347C0DD2541A0049ACDF /* SUProbingUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6101347A0DD2541A0049ACDF /* SUProbingUpdateDriver.m */; }; - 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; + 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */; }; - 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */; settings = {ATTRIBUTES = (); }; }; 6102FE5C0E08C7EC00F85D09 /* SUUnarchiver_Private.m in Sources */ = {isa = PBXBuildFile; fileRef = 6102FE5A0E08C7EC00F85D09 /* SUUnarchiver_Private.m */; }; 61072EB30DF2640C008FE88B /* ConfigFrameworkReleaseGCSupport.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 61072EB20DF2640C008FE88B /* ConfigFrameworkReleaseGCSupport.xcconfig */; }; 610D5A1A0A1661B8004AAD9C /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; }; 610D5A750A1670A4004AAD9C /* SUStatus.nib in Resources */ = {isa = PBXBuildFile; fileRef = 610D5A740A1670A4004AAD9C /* SUStatus.nib */; }; 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */; }; 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; - 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (); }; }; 61180BCB0D64138900B4E0D1 /* SUWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61180BC90D64138900B4E0D1 /* SUWindowController.m */; }; - 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */; settings = {ATTRIBUTES = (); }; }; 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */; }; 61227A160DB548B800AB99EA /* SUVersionComparisonTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */; }; - 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */; settings = {ATTRIBUTES = (); }; }; 61299A3009CA2DAB00B7442F /* SUDSAVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A2E09CA2DAB00B7442F /* SUDSAVerifier.m */; }; - 61299A4A09CA2DD000B7442F /* SUPlainInstallerInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 6129984309C9E2DA00B7442F /* SUPlainInstallerInternals.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61299A4A09CA2DD000B7442F /* SUPlainInstallerInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 6129984309C9E2DA00B7442F /* SUPlainInstallerInternals.h */; settings = {ATTRIBUTES = (); }; }; + 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (); }; }; 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; - 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A8B09CA790200B7442F /* SUUnarchiver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A8B09CA790200B7442F /* SUUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A8C09CA790200B7442F /* SUUnarchiver.m */; }; 61299B3609CB04E000B7442F /* Sparkle.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299B3509CB04E000B7442F /* Sparkle.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; settings = {ATTRIBUTES = (); }; }; 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */; }; 61407C390A4099050009F71F /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; }; 615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */ = {isa = PBXBuildFile; fileRef = 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */; }; - 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61699BCC0DDB92BD005878A4 /* SUVersionComparisonTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 61227A140DB548B800AB99EA /* SUVersionComparisonTest.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA4FF0DAE88B40026945C /* SUInstaller.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */; settings = {ATTRIBUTES = (); }; }; + 61699BCC0DDB92BD005878A4 /* SUVersionComparisonTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 61227A140DB548B800AB99EA /* SUVersionComparisonTest.h */; settings = {ATTRIBUTES = (); }; }; + 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA4FF0DAE88B40026945C /* SUInstaller.h */; settings = {ATTRIBUTES = (); }; }; 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5000DAE88B40026945C /* SUInstaller.m */; }; - 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5030DAE8AB80026945C /* SUPlainInstaller.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5030DAE8AB80026945C /* SUPlainInstaller.h */; settings = {ATTRIBUTES = (); }; }; 618FA5060DAE8AB80026945C /* SUPlainInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5040DAE8AB80026945C /* SUPlainInstaller.m */; }; - 618FA5220DAE8E8A0026945C /* SUPackageInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5200DAE8E8A0026945C /* SUPackageInstaller.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 618FA5220DAE8E8A0026945C /* SUPackageInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5200DAE8E8A0026945C /* SUPackageInstaller.h */; settings = {ATTRIBUTES = (); }; }; 618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5210DAE8E8A0026945C /* SUPackageInstaller.m */; }; - 6196CFF909C72148000DC222 /* SUStatusController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6196CFE309C71ADE000DC222 /* SUStatusController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6196CFF909C72148000DC222 /* SUStatusController.h in Headers */ = {isa = PBXBuildFile; fileRef = 6196CFE309C71ADE000DC222 /* SUStatusController.h */; settings = {ATTRIBUTES = (); }; }; 6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6196CFE409C71ADE000DC222 /* SUStatusController.m */; }; 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A2259C0D1C495D00430CCD /* SUVersionComparisonProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */; settings = {ATTRIBUTES = (); }; }; 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; }; - 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */; settings = {ATTRIBUTES = (); }; }; 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */; }; - 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A354530DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A354530DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61A354560DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A354540DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.m */; }; 61AAE8280A321A7F00D8810D /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 61AAE8290A321A8000D8810D /* SUAutomaticUpdateAlert.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8240A321A7F00D8810D /* SUAutomaticUpdateAlert.nib */; }; @@ -72,21 +72,22 @@ 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */; }; 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B5FCDE09C52A9F00B25A18 /* SUUpdateAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FCA109C5228F00B25A18 /* SUUpdateAlert.m */; }; - 61B5FCDF09C52A9F00B25A18 /* SUUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5FCA009C5228F00B25A18 /* SUUpdateAlert.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93A390DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61B5FCDF09C52A9F00B25A18 /* SUUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5FCA009C5228F00B25A18 /* SUUpdateAlert.h */; settings = {ATTRIBUTES = (); }; }; + 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93A390DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61B93A3D0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93A3A0DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.m */; }; - 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93B250DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93B250DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61B93B280DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93B260DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m */; }; - 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61B93C0A0DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93C080DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m */; }; 61BBDF820A49220C00378739 /* Sparkle.icns in Resources */ = {isa = PBXBuildFile; fileRef = 61BBDF810A49220C00378739 /* Sparkle.icns */; }; 61C2680A0E2DB5D000175E6C /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = 61C268090E2DB5D000175E6C /* License.txt */; }; 61C46F340D9C54F300B06326 /* SUUpdatePermissionPrompt.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61C46F330D9C54F300B06326 /* SUUpdatePermissionPrompt.nib */; }; + 61CFB3290E385186007A1735 /* Sparkle.pch in Headers */ = {isa = PBXBuildFile; fileRef = 61CFB3280E385186007A1735 /* Sparkle.pch */; }; 61D85D6D0E10B2ED00F9B4A9 /* SUPipedUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6129C0B90E0B79810062CE76 /* SUPipedUnarchiver.m */; }; 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; }; 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */ = {isa = PBXBuildFile; fileRef = 61EF67580E25C5B400F754E0 /* SUHost.h */; }; 61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */; }; - 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (Required, ); }; }; DAAEFC9B0DA5722F0051E0D0 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; DAAEFD4E0DA572330051E0D0 /* relaunch.m in Sources */ = {isa = PBXBuildFile; fileRef = 613242130CD06CEF00106AA4 /* relaunch.m */; }; @@ -233,6 +234,7 @@ 61BBDF810A49220C00378739 /* Sparkle.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Sparkle.icns; sourceTree = ""; }; 61C268090E2DB5D000175E6C /* License.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = License.txt; sourceTree = ""; }; 61C46F350D9C54F300B06326 /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; + 61CFB3280E385186007A1735 /* Sparkle.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sparkle.pch; sourceTree = ""; }; 61EF67550E25B58D00F754E0 /* SUHost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUHost.m; sourceTree = ""; }; 61EF67580E25C5B400F754E0 /* SUHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUHost.h; sourceTree = ""; }; 61F3651A0E18987B007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; @@ -457,6 +459,7 @@ 61EF67580E25C5B400F754E0 /* SUHost.h */, 61EF67550E25B58D00F754E0 /* SUHost.m */, 61299B3509CB04E000B7442F /* Sparkle.h */, + 61CFB3280E385186007A1735 /* Sparkle.pch */, 61299A5B09CA6D4500B7442F /* SUConstants.h */, 61299A5F09CA6EB100B7442F /* SUConstants.m */, ); @@ -576,6 +579,7 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */, 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, + 61CFB3290E385186007A1735 /* Sparkle.pch in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -953,6 +957,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941D50D94A70100DD942E /* ConfigFrameworkRelease.xcconfig */; buildSettings = { + GCC_PREFIX_HEADER = Sparkle.pch; }; name = Release; }; diff --git a/Tests/SUVersionComparisonTest.m b/Tests/SUVersionComparisonTest.m index a21cb124..c6e0f93a 100644 --- a/Tests/SUVersionComparisonTest.m +++ b/Tests/SUVersionComparisonTest.m @@ -7,7 +7,7 @@ // #import "SUVersionComparisonTest.h" -#import "Sparkle.h" +#import "SUStandardVersionComparator.h" @implementation SUVersionComparisonTest From e769ba58ccc2d7d4ce9388f69c74b1c7977f971d Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 24 Jul 2008 19:35:29 -0700 Subject: [PATCH 12/14] Reordered Sparkle.h to emphasize SUUpdater.h Removed reference to the RSS class from SUAppcast.h --- SUAppcast.h | 2 +- Sparkle.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SUAppcast.h b/SUAppcast.h index 57874c0d..171148a4 100644 --- a/SUAppcast.h +++ b/SUAppcast.h @@ -9,7 +9,7 @@ #ifndef SUAPPCAST_H #define SUAPPCAST_H -@class RSS, SUAppcastItem; +@class SUAppcastItem; @interface SUAppcast : NSObject { NSArray *items; NSString *userAgentString; diff --git a/Sparkle.h b/Sparkle.h index bea7eb30..08dd5777 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -12,9 +12,10 @@ // This list should include the shared headers. It doesn't matter if some of them aren't shared (unless // there are name-space collisions) so we can list all of them to start with: +#import + #import #import -#import #import #endif From 1aea1b699af405ea86f9c75c2e1004e2eb214b2f Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 24 Jul 2008 20:11:09 -0700 Subject: [PATCH 13/14] The Sparkle preference keys are now declared private / deprecated / allowed to change without me receiving hate email. However! SUUpdater is now KVC-compliant for: automaticallyCheckForUpdates updateCheckInterval feedURL --- SUUpdater.h | 9 +++++++++ SUUpdater.m | 54 ++++++++++++++++++++++++++++------------------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/SUUpdater.h b/SUUpdater.h index c0552387..27aa38af 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -27,6 +27,15 @@ - (void)setDelegate:(id)delegate; - delegate; +- (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecks; +- (BOOL)automaticallyChecksForUpdates; + +- (void)setUpdateCheckInterval:(NSTimeInterval)interval; +- (NSTimeInterval)updateCheckInterval; + +- (void)setFeedURL:(NSURL *)feedURL; +- (NSURL *)feedURL; + // This IBAction is meant for a main menu item. Hook up any menu item to this action, // and Sparkle will check for updates and report back its findings verbosely. - (IBAction)checkForUpdates:sender; diff --git a/SUUpdater.m b/SUUpdater.m index d53c3175..726b4c73 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -18,16 +18,13 @@ @interface SUUpdater (Private) - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; -- (NSArray *)feedParameters; - (BOOL)automaticallyUpdates; -- (BOOL)shouldScheduleUpdateCheck; - (void)scheduleNextUpdateCheck; -- (NSTimeInterval)checkInterval; - (void)registerAsObserver; - (void)unregisterAsObserver; - (void)updateDriverDidFinish:(NSNotification *)note; - initForBundle:(NSBundle *)bundle; -- (NSURL *)feedURL; +- (NSURL *)parameterizedFeedURL; @end @implementation SUUpdater @@ -99,7 +96,7 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv [host objectForInfoDictionaryKey:SUEnableAutomaticChecksKey] == nil) { if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]) - [host setBool:[host boolForUserDefaultsKey:SUEnableAutomaticChecksKeyOld] forUserDefaultsKey:SUEnableAutomaticChecksKey]; + [self setAutomaticallyChecksForUpdates:[host boolForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]]; // Now, we don't want to ask the user for permission to do a weird thing on the first launch. // We wait until the second launch. else if ([host boolForUserDefaultsKey:SUHasLaunchedBeforeKey] == NO) @@ -122,8 +119,7 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv - (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result { - BOOL automaticallyCheck = (result == SUAutomaticallyCheck); - [host setBool:automaticallyCheck forUserDefaultsKey:SUEnableAutomaticChecksKey]; + [self setAutomaticallyChecksForUpdates:(result == SUAutomaticallyCheck)]; // Schedule checks, but make sure we ignore the delayed call from KVO [self resetUpdateCycle]; } @@ -144,7 +140,7 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv [checkTimer invalidate]; checkTimer = nil; } - if (![self shouldScheduleUpdateCheck]) return; + if (![self automaticallyChecksForUpdates]) return; // How long has it been since last we checked for an update? NSDate *lastCheckDate = [host objectForUserDefaultsKey:SULastCheckTimeKey]; @@ -153,8 +149,8 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv // Now we want to figure out how long until we check again. NSTimeInterval delayUntilCheck; - if (intervalSinceCheck < [self checkInterval]) - delayUntilCheck = ([self checkInterval] - intervalSinceCheck); // It hasn't been long enough. + if (intervalSinceCheck < [self updateCheckInterval]) + delayUntilCheck = ([self updateCheckInterval] - intervalSinceCheck); // It hasn't been long enough. else delayUntilCheck = 0; // We're overdue! Run one now. checkTimer = [NSTimer scheduledTimerWithTimeInterval:delayUntilCheck target:self selector:@selector(checkForUpdatesInBackground) userInfo:nil repeats:NO]; @@ -179,16 +175,9 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv { if ([self updateInProgress]) { return; } if (checkTimer) { [checkTimer invalidate]; checkTimer = nil; } - - // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). - NSString *appcastString = [host objectForUserDefaultsKey:SUFeedURLKey]; - if (!appcastString) - appcastString = [host objectForInfoDictionaryKey:SUFeedURLKey]; - if (!appcastString) - [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; - + driver = [d retain]; - [driver checkForUpdatesAtURL:[self feedURL] host:host]; + [driver checkForUpdatesAtURL:[self parameterizedFeedURL] host:host]; } - (void)registerAsObserver @@ -235,7 +224,12 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv [self scheduleNextUpdateCheck]; } -- (BOOL)shouldScheduleUpdateCheck +- (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyCheckForUpdates +{ + [host setBool:automaticallyCheckForUpdates forUserDefaultsKey:SUEnableAutomaticChecksKey]; +} + +- (BOOL)automaticallyChecksForUpdates { // Breaking this down for readability: // If the user says he wants automatic update checks, let's do it. @@ -264,7 +258,12 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv return YES; // Otherwise, we're good to go. } -- (NSURL *)_baseFeedURL +- (void)setFeedURL:(NSURL *)feedURL +{ + [host setObject:[feedURL absoluteString] forUserDefaultsKey:SUFeedURLKey]; +} + +- (NSURL *)feedURL { // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). NSString *appcastString = [host objectForUserDefaultsKey:SUFeedURLKey]; @@ -273,12 +272,12 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv if (!appcastString) // Can't find an appcast string! [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; NSCharacterSet* quoteSet = [NSCharacterSet characterSetWithCharactersInString: @"\"\'"]; // Some feed publishers add quotes; strip 'em. - return [NSURL URLWithString:[appcastString stringByTrimmingCharactersInSet:quoteSet]] ; + return [NSURL URLWithString:[appcastString stringByTrimmingCharactersInSet:quoteSet]]; } -- (NSURL *)feedURL +- (NSURL *)parameterizedFeedURL { - NSURL *baseFeedURL = [self _baseFeedURL]; + NSURL *baseFeedURL = [self feedURL]; // Determine all the parameters we're attaching to the base feed URL. BOOL sendingSystemProfile = ([host boolForUserDefaultsKey:SUSendProfileInfoKey] == YES); @@ -302,7 +301,12 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv return [NSURL URLWithString:[appcastStringWithProfile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; } -- (NSTimeInterval)checkInterval +- (void)setUpdateCheckInterval:(NSTimeInterval)updateCheckInterval +{ + [host setObject:[NSNumber numberWithDouble:updateCheckInterval] forUserDefaultsKey:SUScheduledCheckIntervalKey]; +} + +- (NSTimeInterval)updateCheckInterval { NSTimeInterval checkInterval = 0; // Find the stored check interval. User defaults override Info.plist. From f42fb51952d4bbafd295ea40a2289e2ae897ff47 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 24 Jul 2008 20:15:04 -0700 Subject: [PATCH 14/14] Made automaticallyChecksForUpdates and updateCheckInterval KVO-compliant. --- SUUpdater.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SUUpdater.m b/SUUpdater.m index 726b4c73..555100c1 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -210,6 +210,10 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv // Or we may get this from the developer and from our own KVO observation, this will effectively coalesce them. [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil]; [self performSelector:@selector(resetUpdateCycle) withObject:nil afterDelay:15]; + if ([keyPath rangeOfString:SUEnableAutomaticChecksKey].location != NSNotFound) + [self didChangeValueForKey:@"automaticallyChecksForUpdates"]; + else if ([keyPath rangeOfString:SUScheduledCheckIntervalKey].location != NSNotFound) + [self didChangeValueForKey:@"updateCheckInterval"]; [self resetUpdateCycle]; } else