Skip to content

Commit

Permalink
#18 Fixed update run-mode error handling
Browse files Browse the repository at this point in the history
The update run-mode now uses the --debug option to print out any errors.
Created CDUpdate class for handling the Sparkle updates, subclass of CDCommon.
Re-organized project files for more logical approach when working on a given area.
  • Loading branch information
Mark Whitaker committed Nov 1, 2011
1 parent 5985a5c commit d250170
Show file tree
Hide file tree
Showing 39 changed files with 353 additions and 370 deletions.
598 changes: 273 additions & 325 deletions CocoaDialog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Expand Up @@ -129,7 +129,7 @@
- (void)updaterWillRelaunchApplication:(SUUpdater *)updater;

// Called if updater was aborted.
- (void)updaterAborted;
- (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error;

// 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.
Expand Down
Binary file modified Frameworks/Sparkle.framework/Versions/A/Sparkle
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/AppController.h
Expand Up @@ -19,9 +19,9 @@
*/

#import <Foundation/Foundation.h>
#import <Sparkle/Sparkle.h>
#import "CDOptions.h"
#import "CDControl.h"
#import "CDUpdate.h"
#import "CDBubbleControl.h"
#import "CDCheckboxControl.h"
#import "CDFileSelectControl.h"
Expand Down
43 changes: 1 addition & 42 deletions Source/AppController.m
Expand Up @@ -26,27 +26,6 @@ - (NSString *) appVersion {
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
}

- (BOOL) updaterShouldPromptInstall:(SUUpdater *)updater {
return NO;
}

- (BOOL) updaterShouldRelaunchApplication:(SUUpdater *)updater {
return NO;
}

- (void) updaterAborted {
exit(1);
}

- (void) updaterDidNotFindUpdate:(SUUpdater *)update {
exit(2);
}

- (void) dealloc {
[super dealloc];
}


#pragma mark - Initialization
- (void) awakeFromNib
{
Expand Down Expand Up @@ -106,27 +85,7 @@ - (void) awakeFromNib
[NSApp terminate:self];
}
else if ([runMode caseInsensitiveCompare:@"update"] == NSOrderedSame) {
SUUpdater * updater = [SUUpdater sharedUpdater];
[updater setDelegate:self];
NSURL *appcastURL = [NSURL URLWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"SUFeedURL"]];
if (appcastURL != nil) {
[updater setFeedURL:appcastURL];
}
else {
[updater setFeedURL:[NSURL URLWithString:@"https://raw.github.com/mstratman/cocoadialog/master/sparkle-release/appcast.xml"]];
}
[updater setSendsSystemProfile:YES];
[updater resetUpdateCycle];
[updater setAutomaticallyChecksForUpdates:YES];
if ([options hasOpt:@"quiet"]) {
[updater setAutomaticallyDownloadsUpdates:YES];
[updater checkForUpdatesInBackground];
}
else {
[updater setAutomaticallyDownloadsUpdates:NO];
[updater checkForUpdates:nil];
}
[NSApp run];
[[[[CDUpdate alloc] initWithOptions:options] autorelease] update];
}
// runMode needs to run through control logic
else {
Expand Down
2 changes: 1 addition & 1 deletion Source/CDCommon.m
Expand Up @@ -12,7 +12,7 @@ @implementation CDCommon
@synthesize options;

- (void) debug:(NSString *)message {
NSString *output = [NSString stringWithFormat:@"ERROR: %@\n", message];
NSString *output = [NSString stringWithFormat:@"cocoaDialog Error: %@\n", message];
// Output to stdErr
NSFileHandle *fh = [NSFileHandle fileHandleWithStandardError];
if (fh) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions Source/CDUpdate.h
@@ -0,0 +1,16 @@
//
// CDUpdate.h
// cocoaDialog
//
// Created by Mark Whitaker on 10/31/11.
// Copyright (c) 2011 Mark Whitaker. All rights reserved.
//

#import <Sparkle/Sparkle.h>
#import "CDCommon.h"

@interface CDUpdate : CDCommon

- (void) update;

@end
60 changes: 60 additions & 0 deletions Source/CDUpdate.m
@@ -0,0 +1,60 @@
//
// CDUpdate.m
// cocoaDialog
//
// Created by Mark Whitaker on 10/31/11.
// Copyright (c) 2011 Mark Whitaker. All rights reserved.
//

#import "CDUpdate.h"

@implementation CDUpdate

- (BOOL) updaterShouldPromptInstall:(SUUpdater *)updater {
return NO;
}

- (BOOL) updaterShouldRelaunchApplication:(SUUpdater *)updater {
return NO;
}

- (void) updater:(SUUpdater *)updater didAbortWithError:(NSError *)error {
if ([options hasOpt:@"debug"]) {
NSString *output = @"An unknown error occurred while trying to update.";
if (error != nil) {
output = [error localizedDescription];
}
[self debug:output];
}
exit(1);
}

- (void) updaterDidNotFindUpdate:(SUUpdater *)update {
exit(2);
}

- (void) update {
SUUpdater * updater = [SUUpdater sharedUpdater];
[updater setDelegate:self];
NSURL *appcastURL = [NSURL URLWithString:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"SUFeedURL"]];
if (appcastURL != nil) {
[updater setFeedURL:appcastURL];
}
else {
[updater setFeedURL:[NSURL URLWithString:@"https://raw.github.com/mstratman/cocoadialog/master/sparkle-release/appcast.xml"]];
}
[updater setSendsSystemProfile:YES];
[updater resetUpdateCycle];
[updater setAutomaticallyChecksForUpdates:YES];
if ([options hasOpt:@"quiet"]) {
[updater setAutomaticallyDownloadsUpdates:YES];
[updater checkForUpdatesInBackground];
}
else {
[updater setAutomaticallyDownloadsUpdates:NO];
[updater checkForUpdates:nil];
}
[NSApp run];
}

@end

0 comments on commit d250170

Please sign in to comment.