Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 185 lines (146 sloc) 5.93 kb
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
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
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 "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 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
20 if (title == aTitle) return;
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
21 [title release];
22 title = [aTitle copy];
23 }
24
25
26 - (NSDate *)date { return [[date retain] autorelease]; }
27
28 - (void)setDate:(NSDate *)aDate
29 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
30 if (date == aDate) return;
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
31 [date release];
32 date = [aDate copy];
33 }
34
35
724b4de Andy Matuschak Renamed SUAppcastItem's "description" key to "itemDescription" so as not...
andymatuschak authored
36 - (NSString *)itemDescription { return [[itemDescription retain] autorelease]; }
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
37
724b4de Andy Matuschak Renamed SUAppcastItem's "description" key to "itemDescription" so as not...
andymatuschak authored
38 - (void)setItemDescription:(NSString *)anItemDescription
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
39 {
724b4de Andy Matuschak Renamed SUAppcastItem's "description" key to "itemDescription" so as not...
andymatuschak authored
40 if (itemDescription == anItemDescription) return;
41 [itemDescription release];
42 itemDescription = [anItemDescription copy];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
43 }
44
45
46 - (NSURL *)releaseNotesURL { return [[releaseNotesURL retain] autorelease]; }
47
48 - (void)setReleaseNotesURL:(NSURL *)aReleaseNotesURL
49 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
50 if (releaseNotesURL == aReleaseNotesURL) return;
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
51 [releaseNotesURL release];
52 releaseNotesURL = [aReleaseNotesURL copy];
53 }
54
55
56 - (NSString *)DSASignature { return [[DSASignature retain] autorelease]; }
57
58 - (void)setDSASignature:(NSString *)aDSASignature
59 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
60 if (DSASignature == aDSASignature) return;
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
61 [DSASignature release];
62 DSASignature = [aDSASignature copy];
63 }
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
64
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
65
66 - (NSURL *)fileURL { return [[fileURL retain] autorelease]; }
67
68 - (void)setFileURL:(NSURL *)aFileURL
69 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
70 if (fileURL == aFileURL) return;
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
71 [fileURL release];
72 fileURL = [aFileURL copy];
73 }
74
75
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
76 - (NSString *)versionString { return [[versionString retain] autorelease]; }
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
77
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
78 - (void)setVersionString:(NSString *)s
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
79 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
80 if (versionString == s) return;
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
81 [versionString release];
82 versionString = [s copy];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
83 }
84
85
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
86 - (NSString *)displayVersionString { return [[displayVersionString retain] autorelease]; }
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
87
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
88 - (void)setDisplayVersionString:(NSString *)s
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
89 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
90 if (displayVersionString == s) return;
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
91 [displayVersionString release];
92 displayVersionString = [s copy];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
93 }
94
95
96 - (NSString *)minimumSystemVersion { return [[minimumSystemVersion retain] autorelease]; }
97 - (void)setMinimumSystemVersion:(NSString *)systemVersionString
98 {
a5dcf94 Andy Matuschak Fixed all setters to eliminate the possibility of accidentally releasing...
andymatuschak authored
99 if (minimumSystemVersion == systemVersionString) return;
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
100 [minimumSystemVersion release];
101 minimumSystemVersion = [systemVersionString copy];
102 }
103
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
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"];
74337fb Andy Matuschak Fixed 243883:
andymatuschak authored
120 if (newVersion == nil) // no sparkle:version attribute
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
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 }
74337fb Andy Matuschak Fixed 243883:
andymatuschak authored
128
129 if (enclosure == nil || [enclosure objectForKey:@"url"] == nil || newVersion == nil)
130 {
131 [self release];
132 self = nil;
133 }
134 else
135 {
3bccef8 Andy Matuschak Fixes 251963
andymatuschak authored
136 propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict];
74337fb Andy Matuschak Fixed 243883:
andymatuschak authored
137 [self setTitle:[dict objectForKey:@"title"]];
138 [self setDate:[dict objectForKey:@"pubDate"]];
724b4de Andy Matuschak Renamed SUAppcastItem's "description" key to "itemDescription" so as not...
andymatuschak authored
139 [self setItemDescription:[dict objectForKey:@"description"]];
74337fb Andy Matuschak Fixed 243883:
andymatuschak authored
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"]]];
724b4de Andy Matuschak Renamed SUAppcastItem's "description" key to "itemDescription" so as not...
andymatuschak authored
156 else if ([[self itemDescription] hasPrefix:@"http://"]) // if the description starts with http://, use that.
157 [self setReleaseNotesURL:[NSURL URLWithString:[self itemDescription]]];
74337fb Andy Matuschak Fixed 243883:
andymatuschak authored
158 else
159 [self setReleaseNotesURL:nil];
160 }
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
161 }
162 return self;
163 }
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
164
165 - (void)dealloc
166 {
167 [self setTitle:nil];
168 [self setDate:nil];
724b4de Andy Matuschak Renamed SUAppcastItem's "description" key to "itemDescription" so as not...
andymatuschak authored
169 [self setItemDescription:nil];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
170 [self setReleaseNotesURL:nil];
171 [self setDSASignature:nil];
172 [self setFileURL:nil];
bc3be9a Touched practically every line of code in a super-monster-awesome refact...
andym authored
173 [self setVersionString:nil];
174 [self setDisplayVersionString:nil];
5c32832 Andy Matuschak Fixes bug 228446
andymatuschak authored
175 [propertiesDictionary release];
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
176 [super dealloc];
177 }
178
5c32832 Andy Matuschak Fixes bug 228446
andymatuschak authored
179 - (NSDictionary *)propertiesDictionary
180 {
181 return propertiesDictionary;
182 }
183
9fa3da5 Holy restructuring, batman! Watch out for falling folders.
andym authored
184 @end
Something went wrong with that request. Please try again.