From 401e696590e913da8f683d5b417dfe976564fbc8 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Sun, 21 Feb 2010 18:09:39 +0100 Subject: [PATCH] Restore support for enclosure-less appcast items. If they have a sparke:version tag at the same level as the enclosure would be (as opposed to as an attribute on the enclosure), and no enclosure, but a "link" tag, the link tag's contents will be used as the URL for a "More Info" button to replace the "install" button. Use this for paid updates, where you want to redirect users to your store page instead of installing an update they don't have a license key for. --- SUAppcastItem.m | 51 +++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/SUAppcastItem.m b/SUAppcastItem.m index a2ac876b..d7a211bf 100644 --- a/SUAppcastItem.m +++ b/SUAppcastItem.m @@ -128,14 +128,6 @@ { id enclosure = [dict objectForKey:@"enclosure"]; - if (!enclosure) - { - if (error) - *error = @"No enclosure in feed item"; - [self release]; - return nil; - } - // Try to find a version string. // Finding the new version number from the RSS feed is a little bit hacky. There are two ways: // 1. A "sparkle:version" attribute on the enclosure tag, an extension from the RSS spec. @@ -156,14 +148,6 @@ newVersion = [[fileComponents lastObject] stringByDeletingPathExtension]; } - if (![enclosure objectForKey:@"url"] ) - { - if (error) - *error = @"Feed item's enclosure lacks URL"; - [self release]; - return nil; - } - if(!newVersion ) { if (error) @@ -185,18 +169,39 @@ else [self setInfoURL:[NSURL URLWithString:theInfoURL]]; } - - [self setFileURL:[NSURL URLWithString:[[enclosure objectForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; - [self setDSASignature:[enclosure objectForKey:@"sparkle:dsaSignature"]]; - [self setVersionString:newVersion]; - [self setMinimumSystemVersion:[dict objectForKey:@"sparkle:minimumSystemVersion"]]; + // Need an info URL or an enclosure URL. Former to show "More Info" + // page, latter to download & install: + if( !enclosure && !theInfoURL ) + { + if (error) + *error = @"No enclosure in feed item"; + [self release]; + return nil; + } + + NSString* enclosureURLString = [enclosure objectForKey:@"url"]; + if( !enclosureURLString && !theInfoURL ) + { + if (error) + *error = @"Feed item's enclosure lacks URL"; + [self release]; + return nil; + } + + if( enclosureURLString ) + [self setFileURL: [NSURL URLWithString: [enclosureURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + if( enclosure ) + [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]; + [self setDisplayVersionString: shortVersionString]; else - [self setDisplayVersionString:[self versionString]]; + [self setDisplayVersionString: [self versionString]]; // Find the appropriate release notes URL. if ([dict objectForKey:@"sparkle:releaseNotesLink"])