Permalink
Browse files

Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…

…Sparkle. More super-unstable refactorings to come...
  • Loading branch information...
1 parent f4c6738 commit 98832c49145411c5e13e118fe686ff6c52bcbbe6 @andymatuschak andymatuschak committed Jul 16, 2008
View
@@ -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 <Cocoa/Cocoa.h>
-
-@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
View
@@ -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
View
@@ -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;
View
@@ -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 @@ - (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb delega
- (void)dealloc
{
- [hostBundle release];
+ [host release];
[updateItem release];
[super dealloc];
}
@@ -53,17 +53,17 @@ - (IBAction)doNotInstall:sender
- (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
@@ -13,7 +13,7 @@ @implementation SUAutomaticUpdateDriver
- (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 @@ - (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(S
break;
case SUDoNotInstallChoice:
- [[SUUserDefaults standardUserDefaults] setObject:[updateItem versionString] forKey:SUSkippedVersionKey];
+ [host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
[self abortUpdate];
break;
}
@@ -59,9 +59,9 @@ - (void)applicationWillTerminate:(NSNotification *)note
[self installUpdate];
}
-- (void)installerFinishedForHostBundle:(NSBundle *)hb
+- (void)installerFinishedForHost:(SUHost *)aHost
{
- if (hb != hostBundle) { return; }
+ if (aHost != host) { return; }
if (!postponingInstallation)
[self relaunchHostApp];
}
View
@@ -12,9 +12,8 @@
#import <Cocoa/Cocoa.h>
#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;
Oops, something went wrong.

0 comments on commit 98832c4

Please sign in to comment.