source: trunk/Sparkle/SUAppcastItem.m @ 1046

Revision 128, 5.8 KB checked in by speck, 4 years ago (diff)

Fixed missing display of update notes in Sparkle. Embedded Sparkle so subversion has the proper version instead of having to download Sparkle and apply several patches.

Line 
1//
2//  SUAppcastItem.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 "Sparkle.h"
10#import "SUAppcastItem.h"
11
12@implementation SUAppcastItem
13
14// Attack of accessors!
15
16- (NSString *)title { return [[title retain] autorelease]; }
17
18- (void)setTitle:(NSString *)aTitle
19{
20    if (title == aTitle) return;
21    [title release];
22    title = [aTitle copy];
23}
24
25
26- (NSDate *)date { return [[date retain] autorelease]; }
27
28- (void)setDate:(NSDate *)aDate
29{
30    if (date == aDate) return;
31    [date release];
32    date = [aDate copy];
33}
34
35
36- (NSString *)itemDescription { return [[itemDescription retain] autorelease]; }
37
38- (void)setItemDescription:(NSString *)anItemDescription
39{
40    if (itemDescription == anItemDescription) return;
41    [itemDescription release];
42    itemDescription = [anItemDescription copy];
43}
44
45
46- (NSURL *)releaseNotesURL { return [[releaseNotesURL retain] autorelease]; }
47
48- (void)setReleaseNotesURL:(NSURL *)aReleaseNotesURL
49{
50    if (releaseNotesURL == aReleaseNotesURL) return;
51    [releaseNotesURL release];
52    releaseNotesURL = [aReleaseNotesURL copy];
53}
54
55
56- (NSString *)DSASignature { return [[DSASignature retain] autorelease]; }
57
58- (void)setDSASignature:(NSString *)aDSASignature
59{
60    if (DSASignature == aDSASignature) return;
61    [DSASignature release];
62    DSASignature = [aDSASignature copy];
63}
64           
65
66- (NSURL *)fileURL { return [[fileURL retain] autorelease]; }
67
68- (void)setFileURL:(NSURL *)aFileURL
69{
70    if (fileURL == aFileURL) return;
71    [fileURL release];
72    fileURL = [aFileURL copy];
73}
74
75
76- (NSString *)versionString { return [[versionString retain] autorelease]; }
77
78- (void)setVersionString:(NSString *)s
79{
80    if (versionString == s) return;
81    [versionString release];
82    versionString = [s copy];
83}
84
85
86- (NSString *)displayVersionString { return [[displayVersionString retain] autorelease]; }
87
88- (void)setDisplayVersionString:(NSString *)s
89{
90    if (displayVersionString == s) return;
91    [displayVersionString release];
92    displayVersionString = [s copy];
93}
94
95
96- (NSString *)minimumSystemVersion { return [[minimumSystemVersion retain] autorelease]; }
97- (void)setMinimumSystemVersion:(NSString *)systemVersionString
98{
99    if (minimumSystemVersion == systemVersionString) return;
100    [minimumSystemVersion release];
101    minimumSystemVersion = [systemVersionString copy];
102}
103
104- initWithDictionary:(NSDictionary *)dict
105{
106    self = [super init];
107    if (self)
108    {
109        id enclosure = [dict objectForKey:@"enclosure"];
110       
111        // Try to find a version string.
112        // Finding the new version number from the RSS feed is a little bit hacky. There are two ways:
113        // 1. A "sparkle:version" attribute on the enclosure tag, an extension from the RSS spec.
114        // 2. If there isn't a version attribute, Sparkle will parse the path in the enclosure, expecting
115        //    that it will look like this: http://something.com/YourApp_0.5.zip. It'll read whatever's between the last
116        //    underscore and the last period as the version number. So name your packages like this: APPNAME_VERSION.extension.
117        //    The big caveat with this is that you can't have underscores in your version strings, as that'll confuse Sparkle.
118        //    Feel free to change the separator string to a hyphen or something more suited to your needs if you like.
119        NSString *newVersion = [enclosure objectForKey:@"sparkle:version"];
120        if (newVersion == nil) // no sparkle:version attribute
121        {
122            // Separate the url by underscores and take the last component, as that'll be closest to the end,
123            // then we remove the extension. Hopefully, this will be the version.
124            NSArray *fileComponents = [[enclosure objectForKey:@"url"] componentsSeparatedByString:@"_"];
125            if ([fileComponents count] > 1)
126                newVersion = [[fileComponents lastObject] stringByDeletingPathExtension];
127        }
128       
129        if (enclosure == nil || [enclosure objectForKey:@"url"] == nil || newVersion == nil)
130        {
131            [self release];
132            self = nil;
133        }
134        else
135        {
136            propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict];
137            [self setTitle:[dict objectForKey:@"title"]];
138            [self setDate:[dict objectForKey:@"pubDate"]];
139            [self setItemDescription:[dict objectForKey:@"description"]];
140           
141            [self setFileURL:[NSURL URLWithString:[[enclosure objectForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
142            [self setDSASignature:[enclosure objectForKey:@"sparkle:dsaSignature"]];       
143           
144            [self setVersionString:newVersion];
145            [self setMinimumSystemVersion:[dict objectForKey:@"sparkle:minimumSystemVersion"]];
146           
147            NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"];
148            if (shortVersionString)
149                [self setDisplayVersionString:shortVersionString];
150            else
151                [self setDisplayVersionString:[self versionString]];
152           
153            // Find the appropriate release notes URL.
154            if ([dict objectForKey:@"sparkle:releaseNotesLink"])
155                [self setReleaseNotesURL:[NSURL URLWithString:[dict objectForKey:@"sparkle:releaseNotesLink"]]];
156            else if ([[self itemDescription] hasPrefix:@"http://"]) // if the description starts with http://, use that.
157                [self setReleaseNotesURL:[NSURL URLWithString:[self itemDescription]]];
158            else
159                [self setReleaseNotesURL:nil];
160        }
161    }
162    return self;
163}
164
165- (void)dealloc
166{
167    [self setTitle:nil];
168    [self setDate:nil];
169    [self setItemDescription:nil];
170    [self setReleaseNotesURL:nil];
171    [self setDSASignature:nil];
172    [self setFileURL:nil];
173    [self setVersionString:nil];
174    [self setDisplayVersionString:nil];
175    [propertiesDictionary release];
176    [super dealloc];
177}
178
179- (NSDictionary *)propertiesDictionary
180{
181    return propertiesDictionary;
182}
183
184@end
Note: See TracBrowser for help on using the repository browser.