Skip to content

Commit

Permalink
Beware of falling bricks! Huge refactoring commit #1: cleansing Spark…
Browse files Browse the repository at this point in the history
…le of the plague that was SUUtilities.
  • Loading branch information
andym committed Dec 22, 2007
1 parent 535416a commit 63011aa
Show file tree
Hide file tree
Showing 28 changed files with 551 additions and 563 deletions.
1 change: 0 additions & 1 deletion NSApplication+AppCopies.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "NSApplication+AppCopies.h"
#import "SUUtilities.h"

@implementation NSApplication (SUAppCopies)

Expand Down
45 changes: 45 additions & 0 deletions NSBundle+SUAdditions.h
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions NSBundle+SUAdditions.m
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion NSFileManager+Verification.m
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
7 changes: 3 additions & 4 deletions SUAppcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,4 +24,6 @@

@interface NSObject (SUAppcastDelegate)
- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
- (void)appcastDidFailToLoad:(SUAppcast *)appcast;
- (NSString *)userAgentForAppcast:(SUAppcast *)appcast;
@end
15 changes: 3 additions & 12 deletions SUAppcast.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +24,6 @@ - (void)setDelegate:del

- (void)dealloc
{
[utilities release];
[items release];
[super dealloc];
}
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions SUAutomaticUpdateAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 11 additions & 12 deletions SUAutomaticUpdateAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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
39 changes: 0 additions & 39 deletions SUBundleDefaults.h

This file was deleted.

Loading

0 comments on commit 63011aa

Please sign in to comment.