|
Revision 269, 1.8 kB
(checked in by durin42, 2 years ago)
|
Initial non-working updater app - it gets as far as downloading an update, but
it doesn't know how to unarchive yet. I've grabbed a bunch of sources from
Sparkle (duh from the filenames) but this is all we'll use from there, as from
here on out our mission is quite different from theirs. I've not yet tested
the appcast support very thoroughly, but it seems to be working in my initial
tests. I need to change it from NSUserDefaults to CFPreferencesCopyAppValue,
and fix the appcast URL in the Info.plist (note to other devs: the current URL
resolves to a nonroutable IP - you've been warned!).
I'll do unarchiving in a bit - but first I need to think about some things. I
think the solution Graham offered of using a shell script and exec() will be best.
|
| Line | |
|---|
| 1 |
// |
|---|
| 2 |
// SUAppcast.m |
|---|
| 3 |
// Sparkle |
|---|
| 4 |
// |
|---|
| 5 |
// Created by Andy Matuschak on 3/12/06. |
|---|
| 6 |
// Copyright 2006 Andy Matuschak. All rights reserved. |
|---|
| 7 |
// |
|---|
| 8 |
|
|---|
| 9 |
#import "SUAppcast.h" |
|---|
| 10 |
#import "SUAppcastItem.h" |
|---|
| 11 |
#import "SUUtilities.h" |
|---|
| 12 |
#import "RSS.h" |
|---|
| 13 |
|
|---|
| 14 |
@implementation SUAppcast |
|---|
| 15 |
|
|---|
| 16 |
- (void)fetchAppcastFromURL:(NSURL *)url |
|---|
| 17 |
{ |
|---|
| 18 |
[NSThread detachNewThreadSelector:@selector(_fetchAppcastFromURL:) toTarget:self withObject:url]; // let's not block the main thread |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
- (void)setDelegate:del |
|---|
| 22 |
{ |
|---|
| 23 |
delegate = del; |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
- (void)dealloc |
|---|
| 27 |
{ |
|---|
| 28 |
[items release]; |
|---|
| 29 |
[super dealloc]; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
- (SUAppcastItem *)newestItem |
|---|
| 33 |
{ |
|---|
| 34 |
return [items objectAtIndex:0]; // the RSS class takes care of sorting by published date, descending. |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
- (NSArray *)items |
|---|
| 38 |
{ |
|---|
| 39 |
return items; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
- (void)_fetchAppcastFromURL:(NSURL *)url |
|---|
| 43 |
{ |
|---|
| 44 |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 45 |
|
|---|
| 46 |
RSS *feed; |
|---|
| 47 |
@try |
|---|
| 48 |
{ |
|---|
| 49 |
NSString *userAgent = [NSString stringWithFormat: @"%@/%@ (Mac OS X) Sparkle/1.0", SUHostAppName(), SUHostAppVersion()]; |
|---|
| 50 |
|
|---|
| 51 |
feed = [[RSS alloc] initWithURL:url normalize:YES userAgent:userAgent]; |
|---|
| 52 |
// Set up all the appcast items |
|---|
| 53 |
NSMutableArray *tempItems = [NSMutableArray array]; |
|---|
| 54 |
id enumerator = [[feed newsItems] objectEnumerator], current; |
|---|
| 55 |
while ((current = [enumerator nextObject])) |
|---|
| 56 |
{ |
|---|
| 57 |
[tempItems addObject:[[[SUAppcastItem alloc] initWithDictionary:current] autorelease]]; |
|---|
| 58 |
} |
|---|
| 59 |
items = [[NSArray arrayWithArray:tempItems] retain]; |
|---|
| 60 |
[feed release]; |
|---|
| 61 |
|
|---|
| 62 |
if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)]) |
|---|
| 63 |
[delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO]; |
|---|
| 64 |
|
|---|
| 65 |
} |
|---|
| 66 |
@catch (NSException *e) |
|---|
| 67 |
{ |
|---|
| 68 |
if ([delegate respondsToSelector:@selector(appcastDidFailToLoad:)]) |
|---|
| 69 |
[delegate performSelectorOnMainThread:@selector(appcastDidFailToLoad:) withObject:self waitUntilDone:NO]; |
|---|
| 70 |
} |
|---|
| 71 |
@finally |
|---|
| 72 |
{ |
|---|
| 73 |
[pool release]; |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
@end |
|---|