Permalink
Browse files

Beware of falling bricks! Huge refactoring commit #1: cleansing Spark…

…le of the plague that was SUUtilities.
  • Loading branch information...
1 parent 535416a commit 63011aaefd6e9f2306599a4dff1aa437474d9d84 andym committed Dec 22, 2007
@@ -7,7 +7,6 @@
//
#import "NSApplication+AppCopies.h"
-#import "SUUtilities.h"
@implementation NSApplication (SUAppCopies)
View
@@ -0,0 +1,45 @@
+//
+// NSBundle+SUAdditions.h
+// Sparkle
+//
+// Created by Andy Matuschak on 12/21/07.
+// Copyright 2007 Andy Matuschak. All rights reserved.
+//
+
+#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;
+@end
View
@@ -0,0 +1,58 @@
+//
+// NSBundle+SUAdditions.m
+// Sparkle
+//
+// Created by Andy Matuschak on 12/21/07.
+// Copyright 2007 Andy Matuschak. All rights reserved.
+//
+
+#import "NSBundle+SUAdditions.h"
+#import "NSWorkspace_RBAdditions.h"
+
+@implementation NSBundle (SUAdditions)
+
+- (NSString *)name
+{
+ NSString *name = [self objectForInfoDictionaryKey:@"CFBundleDisplayName"];
+ if (name)
+ return name;
+ else
+ return [[[NSFileManager defaultManager] displayNameAtPath:[self bundlePath]] stringByDeletingPathExtension];
+}
+
+- (NSString *)version
+{
+ return [self objectForInfoDictionaryKey:@"CFBundleVersion"];
+}
+
+- (NSString *)displayVersion
+{
+ NSString *shortVersionString = [self objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
+ if (shortVersionString)
+ {
+ if ([shortVersionString isEqualToString:[self version]])
+ return shortVersionString;
+ else
+ return [shortVersionString stringByAppendingFormat:@" (%@)", [self version]];
+ }
+ 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"];
+ NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:iconPath] autorelease];
+ if (icon)
+ return icon;
+ else // Use a default icon if none is defined.
+ return [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericApplicationIcon)];
+}
+
+- (BOOL)isRunningFromDiskImage
+{
+ return [[[NSWorkspace sharedWorkspace] propertiesForPath:[self bundlePath]] objectForKey:NSWorkspace_RBimagefilepath] != nil;
+}
+
+@end
@@ -9,7 +9,6 @@
// DSA stuff adapted from code provided by Allan Odgaard. Thanks, Allan!
#import "NSFileManager+Verification.h"
-#import "SUUtilities.h"
#import "md5.h"
#import <stdio.h>
View
@@ -8,15 +8,12 @@
#import <Cocoa/Cocoa.h>
-@class RSS, SUAppcastItem, SUUtilities;
+@class RSS, SUAppcastItem;
@interface SUAppcast : NSObject {
NSArray *items;
id delegate;
- SUUtilities *utilities;
}
-- (id)initWithUtilities:(SUUtilities *)aUtility;
-
- (void)fetchAppcastFromURL:(NSURL *)url;
- (void)setDelegate:delegate;
@@ -27,4 +24,6 @@
@interface NSObject (SUAppcastDelegate)
- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
+- (void)appcastDidFailToLoad:(SUAppcast *)appcast;
+- (NSString *)userAgentForAppcast:(SUAppcast *)appcast;
@end
View
@@ -8,20 +8,10 @@
#import "SUAppcast.h"
#import "SUAppcastItem.h"
-#import "SUUtilities.h"
#import "RSS.h"
@implementation SUAppcast
-- (id)initWithUtilities:(SUUtilities *)aUtility
-{
- self = [super init];
- if (self != nil) {
- utilities = [aUtility retain];
- }
- return self;
-}
-
- (void)fetchAppcastFromURL:(NSURL *)url
{
[NSThread detachNewThreadSelector:@selector(_fetchAppcastFromURL:) toTarget:self withObject:url]; // let's not block the main thread
@@ -34,7 +24,6 @@ - (void)setDelegate:del
- (void)dealloc
{
- [utilities release];
[items release];
[super dealloc];
}
@@ -56,7 +45,9 @@ - (void)_fetchAppcastFromURL:(NSURL *)url
RSS *feed = [RSS alloc];
@try
{
- NSString *userAgent = [NSString stringWithFormat: @"%@/%@ (Mac OS X) Sparkle/1.5b1", [utilities hostAppName], [utilities hostAppVersion]];
+ NSString *userAgent = nil;
+ if ([delegate respondsToSelector:@selector(userAgentForAppcast:)])
+ userAgent = [delegate userAgentForAppcast:self];
feed = [feed initWithURL:url normalize:YES userAgent:userAgent];
if (!feed)
View
@@ -8,13 +8,13 @@
#import <Cocoa/Cocoa.h>
-@class SUAppcastItem, SUUtilities;
+@class SUAppcastItem;
@interface SUAutomaticUpdateAlert : NSWindowController {
SUAppcastItem *updateItem;
- SUUtilities *utilities;
+ NSBundle *hostBundle;
}
-- initWithAppcastItem:(SUAppcastItem *)item andUtilities:(SUUtilities *)aUtility;;
+- initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hostBundle;
- (IBAction)relaunchNow:sender;
- (IBAction)relaunchLater:sender;
View
@@ -7,34 +7,33 @@
//
#import "SUAutomaticUpdateAlert.h"
-#import "SUUtilities.h"
+#import "NSBundle+SUAdditions.h"
#import "SUAppcastItem.h"
@implementation SUAutomaticUpdateAlert
-- initWithAppcastItem:(SUAppcastItem *)item andUtilities:(SUUtilities *)aUtility;
+- initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb;
{
+ updateItem = [item retain];
+ hostBundle = [hb retain];
+
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUAutomaticUpdateAlert" ofType:@"nib"];
- if (!path) // slight hack to resolve issues with running with in configurations
+ if (path == nil) // Slight hack to resolve issues with running Sparkle in debug configurations.
{
- NSBundle *current = [NSBundle bundleForClass:[self class]];
- NSString *frameworkPath = [[[NSBundle mainBundle] sharedFrameworksPath] stringByAppendingFormat:@"/Sparkle.framework", [current bundleIdentifier]];
+ NSString *frameworkPath = [[hostBundle sharedFrameworksPath] stringByAppendingString:@"/Sparkle.framework"];
NSBundle *framework = [NSBundle bundleWithPath:frameworkPath];
path = [framework pathForResource:@"SUAutomaticUpdateAlert" ofType:@"nib"];
}
[super initWithWindowNibPath:path owner:self];
-
- updateItem = [item retain];
- utilities = [aUtility retain];
[self setShouldCascadeWindows:NO];
return self;
}
- (void) dealloc
{
- [utilities release];
+ [hostBundle release];
[updateItem release];
[super dealloc];
}
@@ -54,17 +53,17 @@ - (IBAction)relaunchLater:sender
- (NSImage *)applicationIcon
{
- return [utilities hostAppIcon];
+ return [hostBundle icon];
}
- (NSString *)titleText
{
- return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ has been installed!", nil), [utilities hostAppDisplayName]];
+ return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ has been installed!", nil), [hostBundle name]];
}
- (NSString *)descriptionText
{
- return [NSString stringWithFormat:SULocalizedString(@"%@ %@ has been installed and will be ready to use next time %@ starts! Would you like to relaunch now?", nil), [utilities hostAppDisplayName], [updateItem versionString], [utilities hostAppDisplayName]];
+ return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been installed and will be ready to use next time %1$@ starts! Would you like to relaunch now?", nil), [hostBundle name], [hostBundle displayVersion]];
}
@end
View
@@ -1,39 +0,0 @@
-//
-// SUBundleDefaults.h
-// Sparkle
-//
-// Created by Christopher Atlan on 07.11.07.
-// Copyright 2007 Christopher Atlan. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-@class SUUtilities;
-@interface SUBundleDefaults : NSObject {
- SUUtilities *utilities;
- NSString *applicationID;
-}
-
-- (id)initWithUtilitie:(SUUtilities *)theUtilities;
-
-- (id)objectForKey:(NSString *)defaultName;
-- (void)setObject:(id)value forKey:(NSString *)defaultName;
-- (void)removeObjectForKey:(NSString *)defaultName;
-
-- (NSString *)stringForKey:(NSString *)defaultName;
-- (NSArray *)arrayForKey:(NSString *)defaultName;
-- (NSDictionary *)dictionaryForKey:(NSString *)defaultName;
-- (NSData *)dataForKey:(NSString *)defaultName;
-- (NSArray *)stringArrayForKey:(NSString *)defaultName;
-/*
-- (int)integerForKey:(NSString *)defaultName;
-- (float)floatForKey:(NSString *)defaultName;
-*/
-- (BOOL)boolForKey:(NSString *)defaultName;
-/*
-- (void)setInteger:(int)value forKey:(NSString *)defaultName;
-- (void)setFloat:(float)value forKey:(NSString *)defaultName;
-*/
-- (void)setBool:(BOOL)value forKey:(NSString *)defaultName;
-
-@end
Oops, something went wrong.

0 comments on commit 63011aa

Please sign in to comment.