Skip to content
Browse files

Fixed 243883:

Removed the last @try/@catch from my code. Thanks to Christiaan Hofman for the patch.
  • Loading branch information...
1 parent 4ffb7ea commit 74337fb65aac99df8a793c7ea9a8711f54bc43cd @andymatuschak andymatuschak committed
Showing with 66 additions and 46 deletions.
  1. +1 −0 SUAppcast.h
  2. +31 −18 SUAppcast.m
  3. +34 −28 SUAppcastItem.m
View
1 SUAppcast.h
@@ -14,6 +14,7 @@
NSArray *items;
NSString *userAgentString;
id delegate;
+ RSS *feed;
}
- (void)fetchAppcastFromURL:(NSURL *)url;
View
49 SUAppcast.m
@@ -17,6 +17,7 @@ @implementation SUAppcast
- (void)dealloc
{
+ [feed release];
[items release];
[super dealloc];
}
@@ -28,36 +29,48 @@ - (NSArray *)items
- (void)fetchAppcastFromURL:(NSURL *)url
{
- RSS *feed = [[RSS alloc] initWithURL:url userAgent:userAgentString delegate:self];
- CFRetain(feed); // Manage the RSS feed's memory manually.
+ feed = [[RSS alloc] initWithURL:url userAgent:userAgentString delegate:self];
}
-- (void)feedDidFinishLoading:(RSS *)feed
+- (void)feedDidFinishLoading:(RSS *)aFeed
{
// Set up all the appcast items:
NSArray *tempItems = [NSMutableArray array];
id enumerator = [[feed newsItems] objectEnumerator], current;
- @try
+ BOOL success = YES;
+ while ((current = [enumerator nextObject]))
+ {
+ SUAppcastItem *item = [[[SUAppcastItem alloc] initWithDictionary:current] autorelease];
+ if (item)
+ {
+ [(NSMutableArray *)tempItems addObject:item];
+ }
+ else
+ {
+ success = NO;
+ break;
+ }
+ }
+ if (success)
{
- while ((current = [enumerator nextObject]))
- {
- [(NSMutableArray *)tempItems addObject:[[[SUAppcastItem alloc] initWithDictionary:current] autorelease]];
- }
- items = [[NSArray arrayWithArray:tempItems] retain]; // Make the items list immutable.
-
- if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
- [delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO];
+ items = [tempItems copy]; // Make the items list immutable.
+
+ if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
+ [delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO];
+ }
+ else
+ {
+ [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, nil]]];
}
- @catch (NSException *parseException)
- {
- [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, [parseException reason], SUTechnicalErrorInformationKey, nil]]];
- }
- CFRelease(feed);
+ [feed release];
+ feed = nil;
}
-- (void)feed:(RSS *)feed didFailWithError:(NSError *)error
+- (void)feed:(RSS *)aFeed didFailWithError:(NSError *)error
{
[self reportError:error];
+ [feed release];
+ feed = nil;
}
- (void)reportError:(NSError *)error
View
62 SUAppcastItem.m
@@ -106,16 +106,7 @@ - (void)setMinimumSystemVersion:(NSString *)systemVersionString
self = [super init];
if (self)
{
- propertiesDictionary = [dict retain];
- [self setTitle:[dict objectForKey:@"title"]];
- [self setDate:[dict objectForKey:@"pubDate"]];
- [self setDescription:[dict objectForKey:@"description"]];
-
id enclosure = [dict objectForKey:@"enclosure"];
- if (enclosure == nil || [enclosure objectForKey:@"url"] == nil)
- [NSException raise:@"SUAppcastException" format:@"Couldn't find an download URL for feed entry %@!", [self title]];
- [self setFileURL:[NSURL URLWithString:[[enclosure objectForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
- [self setDSASignature:[enclosure objectForKey:@"sparkle:dsaSignature"]];
// Try to find a version string.
// Finding the new version number from the RSS feed is a little bit hacky. There are two ways:
@@ -126,32 +117,47 @@ - (void)setMinimumSystemVersion:(NSString *)systemVersionString
// The big caveat with this is that you can't have underscores in your version strings, as that'll confuse Sparkle.
// Feel free to change the separator string to a hyphen or something more suited to your needs if you like.
NSString *newVersion = [enclosure objectForKey:@"sparkle:version"];
- if (!newVersion) // no sparkle:version attribute
+ if (newVersion == nil) // no sparkle:version attribute
{
// Separate the url by underscores and take the last component, as that'll be closest to the end,
// then we remove the extension. Hopefully, this will be the version.
NSArray *fileComponents = [[enclosure objectForKey:@"url"] componentsSeparatedByString:@"_"];
if ([fileComponents count] > 1)
newVersion = [[fileComponents lastObject] stringByDeletingPathExtension];
- else
- [NSException raise:@"SUAppcastException" format:@"Couldn't find a version string for %@! You need a sparkle:version attribute.", [enclosure objectForKey:@"url"]];
}
- [self setVersionString:newVersion];
- [self setMinimumSystemVersion:[dict objectForKey:@"sparkle:minimumSystemVersion"]];
-
- NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"];
- if (shortVersionString)
- [self setDisplayVersionString:shortVersionString];
- else
- [self setDisplayVersionString:[self versionString]];
-
- // Find the appropriate release notes URL.
- if ([dict objectForKey:@"sparkle:releaseNotesLink"])
- [self setReleaseNotesURL:[NSURL URLWithString:[dict objectForKey:@"sparkle:releaseNotesLink"]]];
- else if ([[self description] hasPrefix:@"http://"]) // if the description starts with http://, use that.
- [self setReleaseNotesURL:[NSURL URLWithString:[self description]]];
- else
- [self setReleaseNotesURL:nil];
+
+ if (enclosure == nil || [enclosure objectForKey:@"url"] == nil || newVersion == nil)
+ {
+ [self release];
+ self = nil;
+ }
+ else
+ {
+ propertiesDictionary = [dict retain];
+ [self setTitle:[dict objectForKey:@"title"]];
+ [self setDate:[dict objectForKey:@"pubDate"]];
+ [self setDescription:[dict objectForKey:@"description"]];
+
+ [self setFileURL:[NSURL URLWithString:[[enclosure objectForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
+ [self setDSASignature:[enclosure objectForKey:@"sparkle:dsaSignature"]];
+
+ [self setVersionString:newVersion];
+ [self setMinimumSystemVersion:[dict objectForKey:@"sparkle:minimumSystemVersion"]];
+
+ NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"];
+ if (shortVersionString)
+ [self setDisplayVersionString:shortVersionString];
+ else
+ [self setDisplayVersionString:[self versionString]];
+
+ // Find the appropriate release notes URL.
+ if ([dict objectForKey:@"sparkle:releaseNotesLink"])
+ [self setReleaseNotesURL:[NSURL URLWithString:[dict objectForKey:@"sparkle:releaseNotesLink"]]];
+ else if ([[self description] hasPrefix:@"http://"]) // if the description starts with http://, use that.
+ [self setReleaseNotesURL:[NSURL URLWithString:[self description]]];
+ else
+ [self setReleaseNotesURL:nil];
+ }
}
return self;
}

0 comments on commit 74337fb

Please sign in to comment.
Something went wrong with that request. Please try again.