Revision: 2823 http://skim-app.svn.sourceforge.net/skim-app/?rev=2823&view=rev Author: hofman Date: 2007-09-04 05:05:34 -0700 (Tue, 04 Sep 2007)
Log Message: ----------- Save files in PDF bundle with filename derived from bundle filename, except for the spotlight data. Modified Paths: -------------- trunk/SKDocument.m Modified: trunk/SKDocument.m =================================================================== --- trunk/SKDocument.m 2007-09-04 11:49:06 UTC (rev 2822) +++ trunk/SKDocument.m 2007-09-04 12:05:34 UTC (rev 2823) @@ -62,16 +62,8 @@ #import "Files_SKExtensions.h" #import "NSTask_SKExtensions.h" -// maximum length of xattr value recommended by Apple -#define MAX_XATTR_LENGTH 2048 +#define BUNDLE_DATA_FILENAME @"data" -#define WRAPPER_PDF_FILENAME @"data.pdf" -#define WRAPPER_TEXT_FILENAME @"data.txt" -#define WRAPPER_PLIST_FILENAME @"data.plist" -#define WRAPPER_SKIM_FILENAME @"notes.skim" -#define WRAPPER_TXT_FILENAME @"notes.txt" -#define WRAPPER_RTF_FILENAME @"notes.rtf" - NSString *SKDocumentErrorDomain = @"SKDocumentErrorDomain"; NSString *SKDocumentWillSaveNotification = @"SKDocumentWillSaveNotification"; @@ -330,25 +322,28 @@ didWrite = [pdfData writeToURL:absoluteURL options:NSAtomicWrite error:outError] && [self saveNotesToExtendedAttributesAtURL:absoluteURL error:outError]; } else if ([typeName isEqualToString:SKPDFBundleDocumentType]) { - NSData *textData = [[[self pdfDocument] string] dataUsingEncoding:NSUTF8StringEncoding]; NSData *notesData = [[self notes] count] ? [NSKeyedArchiver archivedDataWithRootObject:[[self notes] valueForKey:@"dictionaryValue"]] : nil; NSData *notesTextData = [[self notesString] dataUsingEncoding:NSUTF8StringEncoding]; NSData *notesRTFData = [self notesRTFData]; + NSData *textData = [[[self pdfDocument] string] dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *info = [[SKInfoWindowController sharedInstance] infoForDocument:self]; NSData *infoData = [NSPropertyListSerialization dataFromPropertyList:info format:NSPropertyListXMLFormat_v1_0 errorDescription:NULL]; NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:[NSDictionary dictionary]]; - [fileWrapper addRegularFileWithContents:pdfData preferredFilename:WRAPPER_PDF_FILENAME]; - if (textData) - [fileWrapper addRegularFileWithContents:textData preferredFilename:WRAPPER_TEXT_FILENAME]; - if (infoData) - [fileWrapper addRegularFileWithContents:infoData preferredFilename:WRAPPER_PLIST_FILENAME]; + NSString *name = [[[absoluteURL path] lastPathComponent] stringByDeletingPathExtension]; + if ([name caseInsensitiveCompare:BUNDLE_DATA_FILENAME] == NSOrderedSame) + name = [name stringByAppendingString:@"1"]; + [fileWrapper addRegularFileWithContents:pdfData preferredFilename:[name stringByAppendingPathExtension:@"pdf"]]; if (notesData) - [fileWrapper addRegularFileWithContents:notesData preferredFilename:WRAPPER_SKIM_FILENAME]; + [fileWrapper addRegularFileWithContents:notesData preferredFilename:[name stringByAppendingPathExtension:@"skim"]]; if (notesTextData) - [fileWrapper addRegularFileWithContents:notesTextData preferredFilename:WRAPPER_TXT_FILENAME]; + [fileWrapper addRegularFileWithContents:notesTextData preferredFilename:[name stringByAppendingPathExtension:@"txt"]]; if (notesRTFData) - [fileWrapper addRegularFileWithContents:notesRTFData preferredFilename:WRAPPER_RTF_FILENAME]; - didWrite = [fileWrapper writeToFile:[absoluteURL path] atomically:YES updateFilenames:NO]; + [fileWrapper addRegularFileWithContents:notesRTFData preferredFilename:[name stringByAppendingPathExtension:@"rtf"]]; + if (textData) + [fileWrapper addRegularFileWithContents:textData preferredFilename:[BUNDLE_DATA_FILENAME stringByAppendingPathExtension:@"txt"]]; + if (infoData) + [fileWrapper addRegularFileWithContents:infoData preferredFilename:[BUNDLE_DATA_FILENAME stringByAppendingPathExtension:@"plist"]]; + didWrite = [fileWrapper writeToFile:[absoluteURL path] atomically:NO updateFilenames:NO]; [fileWrapper release]; } else if ([typeName isEqualToString:SKEmbeddedPDFDocumentType]) { [[self mainWindowController] removeTemporaryAnnotations]; @@ -529,11 +524,11 @@ NSArray *noteArray = nil; NSFileWrapper *fw; - if ((fw = [fileWrappers objectForKey:WRAPPER_PDF_FILENAME]) && [fw isRegularFile]) { + if ((fw = [fileWrappers objectForKey:BUNDLE_DATA_FILENAME]) && [fw isRegularFile]) { data = [[fw regularFileContents] retain]; pdfDoc = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:[[absoluteURL path] stringByAppendingPathComponent:[fw filename]]]]; } - if ((fw = [fileWrappers objectForKey:WRAPPER_SKIM_FILENAME]) && [fw isRegularFile]) { + if ((fw = [fileWrappers objectForKey:BUNDLE_DATA_FILENAME]) && [fw isRegularFile]) { if (noteArray = [NSKeyedUnarchiver unarchiveObjectWithData:[fw regularFileContents]]) [self setNoteDicts:noteArray]; } 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 Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit