~andymatuschak/sparkle/main

« back to all changes in this revision

Viewing changes to SUStatusChecker.m

  • Committer: andym
  • Date: 2007-07-10 04:55:25 UTC
  • Revision ID: andym@localhost-20070710045525-3awjris3of5zx0s0
Holy restructuring, batman! Watch out for falling folders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  SUStatusChecker.m
 
3
//  Sparkle
 
4
//
 
5
//  Created by Evan Schoenberg on 7/6/06.
 
6
//
 
7
 
 
8
#import "SUStatusChecker.h"
 
9
#import "SUAppcast.h"
 
10
#import "SUAppcastItem.h"
 
11
 
 
12
@interface SUStatusChecker (Private)
 
13
- (id)initForDelegate:(id<SUStatusCheckerDelegate>)inDelegate;
 
14
- (void)checkForUpdatesAndNotify:(BOOL)verbosity;
 
15
- (BOOL)newVersionAvailable;
 
16
@end;
 
17
 
 
18
@implementation SUStatusChecker
 
19
 
 
20
+ (SUStatusChecker *)statusCheckerForDelegate:(id<SUStatusCheckerDelegate>)inDelegate;
 
21
{
 
22
        SUStatusChecker *statusChecker = [[self alloc] initForDelegate:inDelegate];
 
23
 
 
24
        return [statusChecker autorelease];
 
25
}
 
26
 
 
27
- (id)initForDelegate:(id<SUStatusCheckerDelegate>)inDelegate
 
28
{
 
29
        [super init];
 
30
 
 
31
        scDelegate = [inDelegate retain];
 
32
 
 
33
        [self checkForUpdatesAndNotify:NO];
 
34
 
 
35
        return self;
 
36
}
 
37
 
 
38
- (void)dealloc
 
39
{
 
40
        [scDelegate release]; scDelegate = nil;
 
41
        
 
42
        [super dealloc];
 
43
}
 
44
 
 
45
- (void)applicationDidFinishLaunching:(NSNotification *)note
 
46
{
 
47
        //Take no action when the application finishes launching
 
48
}
 
49
 
 
50
- (void)appcastDidFinishLoading:(SUAppcast *)ac
 
51
{
 
52
        @try
 
53
        {
 
54
                if (!ac) { [NSException raise:@"SUAppcastException" format:@"Couldn't get a valid appcast from the server."]; }
 
55
                
 
56
                updateItem = [[ac newestItem] retain];
 
57
                [ac autorelease];
 
58
                
 
59
                if (![updateItem fileVersion])
 
60
                {
 
61
                        [NSException raise:@"SUAppcastException" format:@"Can't extract a version string from the appcast feed. The filenames should look like YourApp_1.5.tgz, where 1.5 is the version number."];
 
62
                }
 
63
 
 
64
                [scDelegate statusChecker:self
 
65
                                         foundVersion:[updateItem fileVersion]
 
66
                                         isNewVersion:[self newVersionAvailable]];
 
67
        }
 
68
        @catch (NSException *e)
 
69
        {
 
70
                NSLog([e reason]);
 
71
 
 
72
                [scDelegate statusChecker:self foundVersion:nil isNewVersion:NO];       
 
73
        }
 
74
 
 
75
        updateInProgress = NO;
 
76
}
 
77
 
 
78
@end