Revision: 4463
http://skim-app.svn.sourceforge.net/skim-app/?rev=4463&view=rev
Author: hofman
Date: 2008-08-27 21:42:41 +0000 (Wed, 27 Aug 2008)
Log Message:
-----------
Revert removal of code running spotlight importer on app update. Apparently
this is needed, even though the docs explicitly say differently.
Modified Paths:
--------------
trunk/SKApplicationController.h
trunk/SKApplicationController.m
Modified: trunk/SKApplicationController.h
===================================================================
--- trunk/SKApplicationController.h 2008-08-27 21:09:59 UTC (rev 4462)
+++ trunk/SKApplicationController.h 2008-08-27 21:42:41 UTC (rev 4463)
@@ -61,6 +61,8 @@
- (IBAction)editBookmarks:(id)sender;
- (IBAction)openBookmark:(id)sender;
+- (void)doSpotlightImportIfNeeded;
+
- (NSArray *)applicationSupportDirectories;
- (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString
*)extension;
- (NSString *)pathForApplicationSupportFile:(NSString *)file ofType:(NSString
*)extension inDirectory:(NSString *)subpath;
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2008-08-27 21:09:59 UTC (rev 4462)
+++ trunk/SKApplicationController.m 2008-08-27 21:42:41 UTC (rev 4463)
@@ -86,7 +86,11 @@
static NSString *SKCurrentDocumentSetupKey = @"currentDocumentSetup";
+static NSString *SKSpotlightVersionInfoKey = @"SKSpotlightVersionInfo";
+static NSString *SKSpotlightLastImporterVersionKey = @"lastImporterVersion";
+static NSString *SKSpotlightLastSysVersionKey = @"lastSysVersion";
+
@implementation SKApplicationController
+ (void)initialize{
@@ -182,6 +186,8 @@
[self showReleaseNotes:nil];
[sud setObject:versionString forKey:SKLastVersionLaunchedKey];
}
+
+ [self doSpotlightImportIfNeeded];
RemoteControlContainer *container = nil;
if ([sud boolForKey:SKEnableAppleRemoteKey]) {
@@ -408,6 +414,45 @@
}
}
+- (void)doSpotlightImportIfNeeded {
+
+ // This code finds the spotlight importer and re-runs it if the importer
or app version has changed since the last time we launched.
+ NSArray *pathComponents = [NSArray arrayWithObjects:[[NSBundle mainBundle]
bundlePath], @"Contents", @"Library", @"Spotlight", @"SkimImporter", nil];
+ NSString *importerPath = [[NSString pathWithComponents:pathComponents]
stringByAppendingPathExtension:@"mdimporter"];
+
+ NSBundle *importerBundle = [NSBundle bundleWithPath:importerPath];
+ NSString *importerVersion = [importerBundle
objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
+ if (importerVersion) {
+ SKVersionNumber *importerVersionNumber = [SKVersionNumber
versionNumberWithVersionString:importerVersion];
+ NSDictionary *versionInfo = [[NSUserDefaults standardUserDefaults]
dictionaryForKey:SKSpotlightVersionInfoKey];
+
+ long sysVersion;
+ OSStatus err = Gestalt(gestaltSystemVersion, &sysVersion);
+
+ BOOL runImporter = NO;
+ if ([versionInfo count] == 0) {
+ runImporter = YES;
+ } else {
+ NSString *lastImporterVersion = [versionInfo
objectForKey:SKSpotlightLastImporterVersionKey];
+ SKVersionNumber *lastImporterVersionNumber = [SKVersionNumber
versionNumberWithVersionString:lastImporterVersion];
+
+ long lastSysVersion = [[versionInfo
objectForKey:SKSpotlightLastSysVersionKey] longValue];
+
+ runImporter = noErr == err ? ([lastImporterVersionNumber
compareToVersionNumber:importerVersionNumber] == NSOrderedAscending ||
sysVersion > lastSysVersion) : YES;
+ }
+ if (runImporter) {
+ NSString *mdimportPath = @"/usr/bin/mdimport";
+ if ([[NSFileManager defaultManager]
isExecutableFileAtPath:mdimportPath]) {
+ [NSTask launchedTaskWithLaunchPath:mdimportPath
arguments:[NSArray arrayWithObjects:@"-r", importerPath, nil]];
+
+ NSDictionary *info = [NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber numberWithLong:sysVersion],
SKSpotlightLastSysVersionKey, importerVersion,
SKSpotlightLastImporterVersionKey, nil];
+ [[NSUserDefaults standardUserDefaults] setObject:info
forKey:SKSpotlightVersionInfoKey];
+
+ } else NSLog(@"%@ not found!", mdimportPath);
+ }
+ }
+}
+
- (NSArray *)applicationSupportDirectories {
static NSArray *applicationSupportDirectories = nil;
if (applicationSupportDirectories == nil) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit