From: <ama...@us...> - 2007-01-17 06:02:36
|
Revision: 9273 http://svn.sourceforge.net/bibdesk/?rev=9273&view=rev Author: amaxwell Date: 2007-01-16 22:02:36 -0800 (Tue, 16 Jan 2007) Log Message: ----------- Run our Spotlight importer whenever we have a new application version or OS version. This requirement is not documented. Modified Paths: -------------- trunk/bibdesk/BibAppController.m Modified: trunk/bibdesk/BibAppController.m =================================================================== --- trunk/bibdesk/BibAppController.m 2007-01-17 06:01:01 UTC (rev 9272) +++ trunk/bibdesk/BibAppController.m 2007-01-17 06:02:36 UTC (rev 9273) @@ -153,6 +153,44 @@ searchKeys = fixLegacyTableColumnIdentifiers(searchKeys); [[OFPreferenceWrapper sharedPreferenceWrapper] setObject:searchKeys forKey:BDSKQuickSearchKeys]; } + + // This code finds the spotlight importer and re-runs it if the importer or app version has changed since the last time we launched. + NSString *importerPath = [[[[[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"Spotlight"] stringByAppendingPathComponent:@"BibImporter"] stringByAppendingPathExtension:@"mdimporter"]; + NSBundle *importerBundle = [NSBundle bundleWithPath:importerPath]; + NSString *importerVersion = [importerBundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; + if (importerVersion) { + OFVersionNumber *importerVersionNumber = [[[OFVersionNumber alloc] initWithVersionString:importerVersion] autorelease]; + NSDictionary *versionInfo = [[OFPreferenceWrapper sharedPreferenceWrapper] objectForKey:@"BDSKSpotlightVersionInfo"]; + + long sysVersion; + OSStatus err = Gestalt(gestaltSystemVersion, &sysVersion); + + BOOL runImporter = NO; + if (nil == versionInfo) { + runImporter = YES; + } else { + NSString *lastImporterVersion = [versionInfo objectForKey:@"lastImporterVersion"]; + OFVersionNumber *lastImporterVersionNumber = [[[OFVersionNumber alloc] initWithVersionString:lastImporterVersion] autorelease]; + + long lastSysVersion = [[versionInfo objectForKey:@"lastSysVersion"] longValue]; + + runImporter = noErr == err ? ([lastImporterVersionNumber compareToVersionNumber:importerVersionNumber] == NSOrderedAscending || sysVersion > lastSysVersion) : YES; + } + if (runImporter) { + NSString *mdimportPath = @"/usr/bin/mdimport"; + if ([[NSFileManager defaultManager] isExecutableFileAtPath:mdimportPath]) { + NSTask *importerTask = [[[NSTask alloc] init] autorelease]; + [importerTask setLaunchPath:mdimportPath]; + [importerTask setArguments:[NSArray arrayWithObjects:@"-r", importerPath, nil]]; + [importerTask launch]; + + NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithLong:sysVersion], @"lastSysVersion", importerVersion, @"lastImporterVersion", nil]; + [[OFPreferenceWrapper sharedPreferenceWrapper] setObject:info forKey:@"BDSKSpotlightVersionInfo"]; + + } + else NSLog(@"/usr/bin/mdimport not found!"); + } + } } - (id)init This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |