Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 81 lines (66 sloc) 1.947 kb
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
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
5aa1e18 Improved headers from Charles D. H. Williams.
andym authored
9 #import "Sparkle.h"
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
10 #import "SUAppcast.h"
11
12 @implementation SUAppcast
13
14 - (void)fetchAppcastFromURL:(NSURL *)url
15 {
16 [NSThread detachNewThreadSelector:@selector(_fetchAppcastFromURL:) toTarget:self withObject:url]; // let's not block the main thread
17 }
18
19 - (void)setDelegate:del
20 {
21 delegate = del;
22 }
23
24 - (void)dealloc
25 {
26 [items release];
27 [super dealloc];
28 }
29
30 - (SUAppcastItem *)newestItem
31 {
32 return [items objectAtIndex:0]; // the RSS class takes care of sorting by published date, descending.
33 }
34
35 - (NSArray *)items
36 {
37 return items;
38 }
39
40 - (void)_fetchAppcastFromURL:(NSURL *)url
41 {
42 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
43
c2f173e Fixing #75: memory leaks when Sparkle can't connect to the internet.
andym authored
44 RSS *feed = [RSS alloc];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
45 @try
46 {
63011aa Beware of falling bricks! Huge refactoring commit #1: cleansing Sparkle ...
andym authored
47 NSString *userAgent = nil;
48 if ([delegate respondsToSelector:@selector(userAgentForAppcast:)])
49 userAgent = [delegate userAgentForAppcast:self];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
50
c2f173e Fixing #75: memory leaks when Sparkle can't connect to the internet.
andym authored
51 feed = [feed initWithURL:url normalize:YES userAgent:userAgent];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
52 if (!feed)
53 [NSException raise:@"SUFeedException" format:@"Couldn't fetch feed from server."];
54
55 // Set up all the appcast items
56 NSMutableArray *tempItems = [NSMutableArray array];
57 id enumerator = [[feed newsItems] objectEnumerator], current;
58 while ((current = [enumerator nextObject]))
59 {
60 [tempItems addObject:[[[SUAppcastItem alloc] initWithDictionary:current] autorelease]];
61 }
62 items = [[NSArray arrayWithArray:tempItems] retain];
63
64 if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
65 [delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO];
66
67 }
68 @catch (NSException *e)
69 {
70 if ([delegate respondsToSelector:@selector(appcastDidFailToLoad:)])
71 [delegate performSelectorOnMainThread:@selector(appcastDidFailToLoad:) withObject:self waitUntilDone:NO];
72 }
73 @finally
74 {
c2f173e Fixing #75: memory leaks when Sparkle can't connect to the internet.
andym authored
75 [feed release];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
76 [pool release];
77 }
78 }
79
80 @end
Something went wrong with that request. Please try again.