root/branches/perian-1.1/Update Checker Sources/SUAppcastItem.m

Revision 269, 5.3 kB (checked in by durin42, 2 years ago)

Initial non-working updater app - it gets as far as downloading an update, but
it doesn't know how to unarchive yet. I've grabbed a bunch of sources from
Sparkle (duh from the filenames) but this is all we'll use from there, as from
here on out our mission is quite different from theirs. I've not yet tested
the appcast support very thoroughly, but it seems to be working in my initial
tests. I need to change it from NSUserDefaults to CFPreferencesCopyAppValue,
and fix the appcast URL in the Info.plist (note to other devs: the current URL
resolves to a nonroutable IP - you've been warned!).
I'll do unarchiving in a bit - but first I need to think about some things. I
think the solution Graham offered of using a shell script and exec() will be best.

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