+- (void)checkForUpdates {
+ @synchronized(self) {
+ if (!checkForUpdatesNotRunning)
+ return;
+ self.checkForUpdatesNotRunning = NO;
+ }
+ ASIHTTPRequest *checkForUpdatesRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"https://code.grnet.gr/projects/pithos-macos/repository/revisions/master/raw/pithos-macos/pithos-macos-Info.plist"]];
+ checkForUpdatesRequest.delegate = self;
+ checkForUpdatesRequest.didFinishSelector = @selector(checkForUpdatesRequestFinished:);
+ checkForUpdatesRequest.didFailSelector = @selector(checkForUpdatesRequestFailed:);
+ checkForUpdatesRequest.timeOutSeconds = 60;
+ checkForUpdatesRequest.numberOfTimesToRetryOnTimeout = 10;
+ [checkForUpdatesRequest startAsynchronous];
+}
+
+#pragma mark -
+#pragma mark ASIHTTPRequestDelegate
+
+- (void)checkForUpdatesRequestFinished:(ASIHTTPRequest *)request {
+ if (request.responseStatusCode == 200) {
+ NSError *error = nil;
+ NSDictionary *plistDictionary = [NSPropertyListSerialization propertyListWithData:[request.responseString dataUsingEncoding:NSUTF8StringEncoding]
+ options:NSPropertyListImmutable
+ format:NULL
+ error:&error];
+ if (!error) {
+ NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
+ NSString *newVersion = [plistDictionary objectForKey:@"CFBundleVersion"];
+ NSURL *distributionURL = [NSURL URLWithString:[plistDictionary objectForKey:@"PithosDistributionURL"]];
+ if (newVersion && currentVersion && distributionURL && ([newVersion doubleValue] > [currentVersion doubleValue])) {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:@"Updates Available"];
+ [alert setInformativeText:@"An updated version is available"];
+ [alert addButtonWithTitle:@"Download"];
+ [alert runModal];
+ [[NSWorkspace sharedWorkspace] openURL:distributionURL];
+ } else if (checkForUpdatesCalledFromMenu) {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:@"No Updates Available"];
+ [alert setInformativeText:@"You are running the latest version"];
+ [alert addButtonWithTitle:@"OK"];
+ [alert runModal];
+ checkForUpdatesCalledFromMenu = NO;
+ }
+ [NSTimer scheduledTimerWithTimeInterval:86400
+ target:self
+ selector:@selector(checkForUpdates)
+ userInfo:nil
+ repeats:YES];
+ self.checkForUpdatesNotRunning = YES;
+ return;
+ }
+ DLog(@"Check for update plist error: %@", error);
+ }
+}
+
+- (void)checkForUpdatesRequestFailed:(ASIHTTPRequest *)request {
+ if (checkForUpdatesCalledFromMenu) {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:@"Check for Updates Error"];
+ [alert setInformativeText:@"Cannot check for updates now, try again later"];
+ [alert addButtonWithTitle:@"OK"];
+ [alert runModal];
+ checkForUpdatesCalledFromMenu = NO;
+ }
+ [NSTimer scheduledTimerWithTimeInterval:600
+ target:self
+ selector:@selector(checkForUpdates)
+ userInfo:nil
+ repeats:YES];
+ self.checkForUpdatesNotRunning = YES;
+}
+