From 489d6c7b99d6c77c2d84cb5f85103735f9327b20 Mon Sep 17 00:00:00 2001 From: yene Date: Thu, 10 Sep 2015 20:52:19 +0200 Subject: [PATCH] creating in memory XML for the sparkle framework code --- Sparkle/SUAppcast.m | 56 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 67bcd61e2..18c3cf4ff 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -98,13 +98,55 @@ - (void)downloadDidFinish:(NSURLDownload *)__unused aDownload BOOL failed = NO; NSArray *xmlItems = nil; NSMutableArray *appcastItems = [NSMutableArray array]; - NSDictionary *json; if (self.downloadFilename) { + // convert json to xml NSData *fileContent = [NSData dataWithContentsOfFile:self.downloadFilename]; - json = [NSJSONSerialization JSONObjectWithData:fileContent options:0 error:&error]; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:fileContent options:0 error:&error]; + // convert ISO 8601 to RFC1123 + NSDate *dateISO = [NSDate dateWithNaturalLanguageString:json[@"published_at"]]; + NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; + [dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"]; + NSString *dateRFC = [dateFormat stringFromDate:dateISO]; + + NSDictionary *download = json[@"assets"][0]; + NSString *version = [json[@"tag_name"] stringByReplacingOccurrencesOfString:@"v" withString:@""]; + + NSString *xmlContent = [NSString stringWithFormat:@"\n" + "\n" + "\n" + "Github Sparkle\n" + "http://sparkle-project.org/files/sparkletestcast.xml\n" + "Most recent changes with links to updates.\n" + "en\n" + "\n" + "%@\n" + "\n" + "" + "\n" + "%@\n" + "\n" + "\n" + + "\n" + "\n", + json[@"name"], + json[@"body"], + dateRFC, + download[@"browser_download_url"], + version, + download[@"size"] + ]; + + + NSUInteger options = 0; + options = NSXMLNodeOptionsNone; + document = [[NSXMLDocument alloc] initWithXMLString:xmlContent options:options error:&error]; + [[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil]; self.downloadFilename = nil; } @@ -113,10 +155,18 @@ - (void)downloadDidFinish:(NSURLDownload *)__unused aDownload failed = YES; } - if (nil == json) + if (nil == document) { failed = YES; } + else + { + xmlItems = [document nodesForXPath:@"/rss/channel/item" error:&error]; + if (nil == xmlItems) + { + failed = YES; + } + } if (failed == NO) {