Revision: 2822
http://skim-app.svn.sourceforge.net/skim-app/?rev=2822&view=rev
Author: hofman
Date: 2007-09-04 04:49:06 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
Allow SkimNotesAgent to find notes in bundles with different file names for the
note files.
Modified Paths:
--------------
SkimNotesAgent/SkimNotesAgent.m
Modified: SkimNotesAgent/SkimNotesAgent.m
===================================================================
--- SkimNotesAgent/SkimNotesAgent.m 2007-09-04 11:30:21 UTC (rev 2821)
+++ SkimNotesAgent/SkimNotesAgent.m 2007-09-04 11:49:06 UTC (rev 2822)
@@ -83,6 +83,34 @@
[super dealloc];
}
+- (NSString *)notesFileWithExtension:(NSString *)extension atPath:(NSString
*)path error:(NSError **)error {
+ NSString *filePath = nil;
+
+ if ([extension caseInsensitiveCompare:@"skim"] == NSOrderedSame) {
+ NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];
+ NSString *filename = @"notes.skim";
+ if ([files containsObject:filename] == NO) {
+ filename = [[[path lastPathComponent]
stringByDeletingPathExtension] stringByAppendingPathExtension:extension];
+ if ([files containsObject:filename] == NO) {
+ unsigned index = [[files
valueForKeyPath:@"pathExtension.lowercaseString"] indexOfObject:@"skim"];
+ filename = index == NSNotFound ? nil : [files
objectAtIndex:index];
+ }
+ }
+ if (filename)
+ filePath = [path stringByAppendingPathComponent:filename];
+ } else {
+ NSString *skimFile = [self notesFileWithExtension:@"skim" atPath:path
error:error];
+ if (skimFile) {
+ filePath = [[skimFile stringByDeletingPathExtension]
stringByAppendingPathExtension:extension];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:filePath] ==
NO)
+ filePath = nil;
+ }
+ }
+ if (filePath == nil && error)
+ *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:ENOENT
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Notes file note found",
NSLocalizedDescriptionKey, nil]];
+ return filePath;
+}
+
- (bycopy NSData *)SkimNotesAtPath:(in bycopy NSString *)aFile;
{
NSError *error;
@@ -90,7 +118,9 @@
NSString *extension = [[aFile pathExtension] lastPathComponent];
if ([extension caseInsensitiveCompare:@"pdfd"] == NSOrderedSame) {
- data = [NSData dataWithContentsOfFile:[aFile
stringByAppendingPathComponent:@"notes.skim"] options:0 error:&error];
+ NSString *notePath = [self notesFileWithExtension:@"skim" atPath:aFile
error:&error];
+ if (notePath)
+ data = [NSData dataWithContentsOfFile:notePath options:0
error:&error];
if (nil == data)
fprintf(stderr, "SkimNotesAgent pid %d: error getting Skim notes
(%s)\n", getpid(), [[error description] UTF8String]);
} else if ([extension caseInsensitiveCompare:@"skim"] == NSOrderedSame) {
@@ -112,7 +142,9 @@
NSString *extension = [[aFile pathExtension] lastPathComponent];
if ([extension caseInsensitiveCompare:@"pdfd"] == NSOrderedSame) {
- data = [NSData dataWithContentsOfFile:[aFile
stringByAppendingPathComponent:@"notes.rtf"] options:0 error:&error];
+ NSString *notePath = [self notesFileWithExtension:@"rtf" atPath:aFile
error:&error];
+ if (notePath)
+ data = [NSData dataWithContentsOfFile:notePath options:0
error:&error];
if (nil == data)
fprintf(stderr, "SkimNotesAgent pid %d: error getting RTF notes
(%s)\n", getpid(), [[error description] UTF8String]);
} else {
@@ -130,7 +162,9 @@
NSString *extension = [[aFile pathExtension] lastPathComponent];
if ([extension caseInsensitiveCompare:@"pdfd"] == NSOrderedSame) {
- string = [NSString stringWithContentsOfFile:[aFile
stringByAppendingPathComponent:@"notes.txt"] encoding:NSUTF8StringEncoding
error:&error];
+ NSString *notePath = [self notesFileWithExtension:@"txt" atPath:aFile
error:&error];
+ if (notePath)
+ string = [NSString stringWithContentsOfFile:notePath
encoding:NSUTF8StringEncoding error:&error];
if (nil == string)
fprintf(stderr, "SkimNotesAgent pid %d: error getting text notes
(%s)\n", getpid(), [[error description] UTF8String]);
} else {
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: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit