Changeset 917 for trunk/Update Checker Sources
- Timestamp:
- 07/29/08 16:35:01 (4 months ago)
- Files:
-
- trunk/Update Checker Sources/UpdateCheckerAppDelegate.h (modified) (1 diff)
- trunk/Update Checker Sources/UpdateCheckerAppDelegate.m (modified) (4 diffs)
- trunk/Update Checker Sources/main.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Update Checker Sources/UpdateCheckerAppDelegate.h
r624 r917 18 18 #define UPDATE_URL_KEY @"UpdateFeedURL" 19 19 #define SKIPPED_VERSION_KEY @"SkippedVersion" 20 #define UPDATE_STATUS_NOTIFICATION @"org.perian.UpdateCheckStatus" 20 21 #define TIME_INTERVAL_TIL_NEXT_RUN 7*24*60*60 21 22 trunk/Update Checker Sources/UpdateCheckerAppDelegate.m
r913 r917 35 35 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 36 36 lastRunDate = [[defaults objectForKey:NEXT_RUN_KEY] retain]; 37 if (lastRunDate == nil || [lastRunDate laterDate:[NSDate date]] != lastRunDate) { 38 //this means we should in fact run 39 [defaults setObject:[NSDate dateWithTimeIntervalSinceNow:TIME_INTERVAL_TIL_NEXT_RUN] forKey:NEXT_RUN_KEY]; 40 manualRun = [defaults boolForKey:MANUAL_RUN_KEY]; 41 [defaults removeObjectForKey:MANUAL_RUN_KEY]; 42 [self doUpdateCheck]; 43 } else { 44 //another instance was already started and therefore we don't need to do this again 45 [[NSApplication sharedApplication] terminate:self]; 46 } 37 38 [defaults setObject:[NSDate dateWithTimeIntervalSinceNow:TIME_INTERVAL_TIL_NEXT_RUN] forKey:NEXT_RUN_KEY]; 39 manualRun = [defaults boolForKey:MANUAL_RUN_KEY]; 40 [defaults removeObjectForKey:MANUAL_RUN_KEY]; 41 [defaults synchronize]; 42 [self doUpdateCheck]; 47 43 } 48 44 … … 56 52 updateUrlString = [[updateUrlString substringToIndex:[updateUrlString length]-4] stringByAppendingFormat:@"-%@.xml", betaAppcastUrl]; 57 53 #endif 54 if(manualRun) 55 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"Starting"]; 58 56 59 57 SUAppcast *appcast = [[SUAppcast alloc] init]; … … 81 79 NSString *panePath = [[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; 82 80 updateAvailable = (updateAvailable && (SUStandardVersionComparison([latest fileVersion], [[NSBundle bundleWithPath:panePath] objectForInfoDictionaryKey:@"CFBundleVersion"]) == NSOrderedAscending)); 81 82 if (![panePath isEqualToString:@"Perian.prefPane"]) { 83 NSLog(@"The update checker needs to be run from inside the preference pane, quitting..."); 84 updateAvailable = 0; 85 } 86 83 87 NSString *skippedVersion = [[NSUserDefaults standardUserDefaults] objectForKey:SKIPPED_VERSION_KEY]; 84 88 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 85 89 if (updateAvailable && (!skippedVersion || 86 90 (skippedVersion && ![skippedVersion isEqualToString:[latest versionString]]))) { 91 if(manualRun) 92 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"YesUpdates"]; 87 93 [self showUpdatePanelForItem:latest]; 88 94 } else { 89 95 if(manualRun) 90 NSRunAlertPanel(SULocalizedString(@"No Update Found!", nil), SULocalizedString(@"Your copy of Perian is up to date", nil), nil, nil, nil);96 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"NoUpdates"]; 91 97 [[NSApplication sharedApplication] terminate:self]; 92 98 } … … 99 105 [self updateFailed]; 100 106 if(manualRun) 101 [ self showUpdateErrorAlertWithInfo:SULocalizedString(@"An error occurred while trying to load Perian's version info. Please try again later.", nil)];107 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"Error"]; 102 108 [appcast release]; 103 109 [[NSApplication sharedApplication] terminate:self]; trunk/Update Checker Sources/main.m
r913 r917 13 13 #define lockPath "/tmp/PerianUpdateLock" 14 14 15 static int fp = -1; 16 17 static void deleteLock() 18 { 19 close(fp); 20 unlink(lockPath); 21 } 22 15 23 int main(int argc, char *argv[]) 16 24 { 17 intfp = open(lockPath, O_CREAT | O_EXCL);25 fp = open(lockPath, O_CREAT | O_EXCL); 18 26 if(fp == -1) 19 27 { … … 31 39 if(fp == -1) 32 40 return 0; 41 42 atexit(deleteLock); 33 43 34 44 int ret = NSApplicationMain(argc, (const char **) argv); 35 45 36 close(fp);37 unlink(lockPath);38 39 46 return ret; 40 47 }
