Revision: 7769
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7769&view=rev
Author:   hofman
Date:     2012-11-02 01:10:25 +0000 (Fri, 02 Nov 2012)
Log Message:
-----------
Replace more path based code by URL based code, unique directories

Modified Paths:
--------------
    trunk/NSFileManager_SKExtensions.h
    trunk/NSFileManager_SKExtensions.m
    trunk/SKConversionProgressController.m
    trunk/SKMainDocument.m

Modified: trunk/NSFileManager_SKExtensions.h
===================================================================
--- trunk/NSFileManager_SKExtensions.h  2012-11-01 23:44:27 UTC (rev 7768)
+++ trunk/NSFileManager_SKExtensions.h  2012-11-02 01:10:25 UTC (rev 7769)
@@ -53,6 +53,6 @@
 
 // These functions are thread safe
 
-extern NSString *SKChewableItemsDirectory();
-extern NSString *SKUniqueTemporaryDirectory();
-extern NSString *SKUniqueChewableItemsDirectory();
+extern NSURL *SKChewableItemsDirectoryURL();
+extern NSURL *SKUniqueTemporaryDirectoryURL();
+extern NSURL *SKUniqueChewableItemsDirectoryURL();

Modified: trunk/NSFileManager_SKExtensions.m
===================================================================
--- trunk/NSFileManager_SKExtensions.m  2012-11-01 23:44:27 UTC (rev 7768)
+++ trunk/NSFileManager_SKExtensions.m  2012-11-02 01:10:25 UTC (rev 7769)
@@ -81,7 +81,7 @@
 
 @end
 
-static NSString *SKUniqueDirectory(NSString *basePath) {
+static NSURL *SKUniqueDirectoryURL(NSURL *baseURL) {
     CFUUIDRef uuid = CFUUIDCreate(NULL);
     NSString *tmpDirName = [(NSString *)CFUUIDCreateString(NULL, uuid) 
autorelease];
     CFRelease(uuid);
@@ -91,16 +91,16 @@
     UniCharCount length = [tmpDirName length];
     UniChar *tmpName = (UniChar *)NSZoneMalloc(NULL, length * sizeof(UniChar));
     [tmpDirName getCharacters:tmpName];
-    success = noErr == FSPathMakeRef((UInt8 *)[basePath 
fileSystemRepresentation], &tmpRef, NULL) &&
+    success = CFURLGetFSRef((CFURLRef)baseURL, &tmpRef) &&
               noErr == FSCreateDirectoryUnicode(&tmpRef, length, tmpName, 
kFSCatInfoNone, NULL, NULL, NULL, NULL);
     NSZoneFree(NULL, tmpName);
     
-    return success ? [basePath stringByAppendingPathComponent:tmpDirName] : 
nil;
+    return success ? [baseURL URLByAppendingPathComponent:tmpDirName] : nil;
 }
 
-NSString *SKChewableItemsDirectory() {
+NSURL *SKChewableItemsDirectoryURL() {
     // chewable items are automatically cleaned up at restart, and it's hidden 
from the user
-    NSString *chewableItemsDirectory = nil;
+    NSURL *chewableItemsDirectoryURL = nil;
     FSRef chewableRef;
     OSErr err = FSFindFolder(kUserDomain, kChewableItemsFolderType, TRUE, 
&chewableRef);
     
@@ -126,20 +126,20 @@
         }
         
         if (noErr == err)
-            chewableItemsDirectory = (NSString 
*)CFURLCopyFileSystemPath(newURL, kCFURLPOSIXPathStyle);
-        
-        if (newURL) CFRelease(newURL);
+            chewableItemsDirectoryURL = (NSURL *)newURL;
+        else if (newURL)
+            CFRelease(newURL);
         if (baseName) CFRelease(baseName);
         
-        assert(nil != chewableItemsDirectory);
+        assert(nil != chewableItemsDirectoryURL);
     }
-    return chewableItemsDirectory;
+    return chewableItemsDirectoryURL;
 }
 
-NSString *SKUniqueTemporaryDirectory() {
-    return SKUniqueDirectory(NSTemporaryDirectory());
+NSURL *SKUniqueTemporaryDirectoryURL() {
+    return SKUniqueDirectoryURL([NSURL 
fileURLWithPath:NSTemporaryDirectory()]);
 }
 
-NSString *SKUniqueChewableItemsDirectory() {
-    return SKUniqueDirectory(SKChewableItemsDirectory());
+NSURL *SKUniqueChewableItemsDirectoryURL() {
+    return SKUniqueDirectoryURL(SKChewableItemsDirectoryURL());
 }

Modified: trunk/SKConversionProgressController.m
===================================================================
--- trunk/SKConversionProgressController.m      2012-11-01 23:44:27 UTC (rev 
7768)
+++ trunk/SKConversionProgressController.m      2012-11-02 01:10:25 UTC (rev 
7769)
@@ -326,9 +326,9 @@
     NSString *dviFile = [dviURL path];
     NSString *commandPath = [info objectForKey:TOOLPATH_KEY];
     NSString *commandName = [commandPath lastPathComponent];
-    NSString *tmpDir = SKUniqueTemporaryDirectory();
+    NSURL *tmpDirURL = SKUniqueTemporaryDirectoryURL();
     BOOL outputPS = [commandName isEqualToString:@"dvips"];
-    NSString *outFile = [tmpDir stringByAppendingPathComponent:[dviURL 
lastPathComponentReplacingPathExtension:outputPS ? @"ps" : @"pdf"]];
+    NSString *outFile = [[tmpDirURL URLByAppendingPathComponent:[dviURL 
lastPathComponentReplacingPathExtension:outputPS ? @"ps" : @"pdf"]] path];
     NSArray *arguments = [commandName isEqualToString:@"dvipdf"] ? [NSArray 
arrayWithObjects:dviFile, outFile, nil] : [NSArray arrayWithObjects:@"-o", 
outFile, dviFile, nil];
     BOOL success = NO;
     
@@ -374,7 +374,7 @@
         [self stopModalOnMainThread:success];
     }
     
-    [fm removeItemAtPath:tmpDir error:NULL];
+    [fm removeItemAtURL:tmpDirURL error:NULL];
     
     [pool release];
 }

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2012-11-01 23:44:27 UTC (rev 7768)
+++ trunk/SKMainDocument.m      2012-11-02 01:10:25 UTC (rev 7769)
@@ -106,8 +106,8 @@
 #define CALLBACK_KEY        @"callback"
 #define TMPURL_KEY          @"tmpURL"
 
-#define SOURCEPATH_KEY  @"sourcePath"
-#define TARGETPATH_KEY  @"targetPath"
+#define SOURCEURL_KEY   @"sourceURL"
+#define TARGETURL_KEY   @"targetURL"
 #define EMAIL_KEY       @"email"
 
 #define SKPresentationOptionsKey    @"PresentationOptions"
@@ -568,7 +568,7 @@
         for (NSURL *url in [fm contentsOfDirectoryAtURL:fileURL 
includingPropertiesForKeys:nil options:0 error:NULL]) {
             if ([ourExtensions containsObject:[[url pathExtension] 
lowercaseString]] == NO) {
                 if (tmpURL == nil)
-                    tmpURL = [NSURL 
fileURLWithPath:SKUniqueTemporaryDirectory()];
+                    tmpURL = SKUniqueTemporaryDirectoryURL();
                 [fm copyItemAtURL:url toURL:[tmpURL 
URLByAppendingPathComponent:[url lastPathComponent]] error:NULL];
             }
         }
@@ -1131,9 +1131,9 @@
     [alert beginSheetModalForWindow:[self windowForSheet] modalDelegate:self 
didEndSelector:@selector(convertNotesSheetDidEnd:returnCode:contextInfo:) 
contextInfo:NULL];
 }
 
-- (BOOL)saveArchiveToFile:(NSString *)fileName {
+- (BOOL)saveArchiveToURL:(NSURL *)fileURL {
     return [NSTask runTaskWithLaunchPath:@"/usr/bin/tar"
-                               arguments:[NSArray arrayWithObjects:@"-czf", 
fileName, [[self fileURL] lastPathComponent], nil]
+                               arguments:[NSArray arrayWithObjects:@"-czf", 
[fileURL path], [[self fileURL] lastPathComponent], nil]
                     currentDirectoryPath:[[[self fileURL] path] 
stringByDeletingLastPathComponent]];
 }
 
@@ -1146,7 +1146,7 @@
         [sp setNameFieldStringValue:[fileURL 
lastPathComponentReplacingPathExtension:@"tgz"]];
         [sp beginSheetModalForWindow:[self windowForSheet] 
completionHandler:^(NSInteger result){
                 if (NSFileHandlingPanelOKButton == result && [self fileURL])
-                    [self saveArchiveToFile:[[sp URL] path]];
+                    [self saveArchiveToURL:[sp URL]];
             }];
     } else {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"You 
must save this file first", @"Alert text when trying to create archive for 
unsaved document") defaultButton:nil alternateButton:nil otherButton:nil 
informativeTextWithFormat:NSLocalizedString(@"The document has unsaved changes, 
or has not previously been saved to disk.", @"Informative text in alert 
dialog")];
@@ -1154,7 +1154,7 @@
     }
 }
 
-- (BOOL)emailAttachmentFile:(NSString *)fileName {
+- (BOOL)emailAttachmentAtURL:(NSURL *)fileURL {
     NSString *scriptFormat = nil;
     NSString *mailAppID = [(NSString 
*)LSCopyDefaultHandlerForURLScheme(CFSTR("mailto")) autorelease];
     
@@ -1211,7 +1211,7 @@
     }
     
     
-    NSString *scriptString = [NSString stringWithFormat:scriptFormat, [self 
displayName], fileName];
+    NSString *scriptString = [NSString stringWithFormat:scriptFormat, [self 
displayName], [fileURL path]];
     NSAppleScript *script = [[[NSAppleScript alloc] 
initWithSource:scriptString] autorelease];
     NSDictionary *errorDict = nil;
     if ([script compileAndReturnError:&errorDict] == NO) {
@@ -1228,9 +1228,9 @@
 - (IBAction)emailArchive:(id)sender {
     NSString *path = [[self fileURL] path];
     if (path && [[NSFileManager defaultManager] fileExistsAtPath:path] && 
[self isDocumentEdited] == NO) {
-        NSString *tmpDir = SKUniqueChewableItemsDirectory();
-        NSString *tmpFile = [tmpDir stringByAppendingPathComponent:[[self 
fileURL] lastPathComponentReplacingPathExtension:@"tgz"]];
-        if ([self saveArchiveToFile:tmpFile] == NO || [self 
emailAttachmentFile:tmpFile] == NO)
+        NSURL *tmpDirURL = SKUniqueChewableItemsDirectoryURL();
+        NSURL *tmpFileURL = [tmpDirURL URLByAppendingPathComponent:[[self 
fileURL] lastPathComponentReplacingPathExtension:@"tgz"]];
+        if ([self saveArchiveToURL:tmpFileURL] == NO || [self 
emailAttachmentAtURL:tmpFileURL] == NO)
             NSBeep();
     } else {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"You 
must save this file first", @"Alert text when trying to create archive for 
unsaved document") defaultButton:nil alternateButton:nil otherButton:nil 
informativeTextWithFormat:NSLocalizedString(@"The document has unsaved changes, 
or has not previously been saved to disk.", @"Informative text in alert 
dialog")];
@@ -1242,26 +1242,26 @@
     
     NSAutoreleasePool *pool = [NSAutoreleasePool new];
     
-    NSString *sourcePath = [[[info objectForKey:SOURCEPATH_KEY] copy] 
autorelease];
-    NSString *targetPath = [[[info objectForKey:TARGETPATH_KEY] copy] 
autorelease];
-    NSArray *arguments = [NSArray arrayWithObjects:@"create", @"-srcfolder", 
sourcePath, @"-format", @"UDZO", @"-volname", [[targetPath lastPathComponent] 
stringByDeletingPathExtension], targetPath, nil];
+    NSURL *sourceURL = [[[info objectForKey:SOURCEURL_KEY] copy] autorelease];
+    NSURL *targetURL = [[[info objectForKey:TARGETURL_KEY] copy] autorelease];
+    NSArray *arguments = [NSArray arrayWithObjects:@"create", @"-srcfolder", 
[sourceURL path], @"-format", @"UDZO", @"-volname", [[targetURL 
lastPathComponent] stringByDeletingPathExtension], [targetURL path], nil];
     
-    if ([NSTask runTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:arguments 
currentDirectoryPath:[sourcePath stringByDeletingLastPathComponent]] == NO)
+    if ([NSTask runTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:arguments 
currentDirectoryPath:[[sourceURL URLByDeletingLastPathComponent] path]] == NO)
         NSBeep();
     
     [[self progressController] performSelectorOnMainThread:@selector(hide) 
withObject:nil waitUntilDone:NO];
     
     if ([[info objectForKey:EMAIL_KEY] boolValue])
-        [self performSelectorOnMainThread:@selector(emailAttachmentFile:) 
withObject:targetPath waitUntilDone:NO];
+        [self performSelectorOnMainThread:@selector(emailAttachmentAtURL:) 
withObject:targetURL waitUntilDone:NO];
     
     [pool release];
 }
 
-- (void)saveDiskImageToFile:(NSString *)fileName email:(BOOL)email {
+- (void)saveDiskImageToURL:(NSURL *)fileURL email:(BOOL)email {
     [[self progressController] setMessage:[NSLocalizedString(@"Saving Disk 
Image", @"Message for progress sheet") stringByAppendingEllipsis]];
     [[self progressController] show];
     
-    NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:[[self 
fileURL] path], SOURCEPATH_KEY, fileName, TARGETPATH_KEY, [NSNumber 
numberWithBool:email], EMAIL_KEY, nil];
+    NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:[self 
fileURL], SOURCEURL_KEY, fileURL, TARGETURL_KEY, [NSNumber 
numberWithBool:email], EMAIL_KEY, nil];
     [NSThread detachNewThreadSelector:@selector(saveDiskImageWithInfo:) 
toTarget:self withObject:info];
 }
 
@@ -1274,7 +1274,7 @@
         [sp setNameFieldStringValue:[fileURL 
lastPathComponentReplacingPathExtension:@"dmg"]];
         [sp beginSheetModalForWindow:[self windowForSheet] 
completionHandler:^(NSInteger result){
                 if (NSFileHandlingPanelOKButton == result && [self fileURL])
-                    [self saveDiskImageToFile:[[sp URL] path] email:NO];
+                    [self saveDiskImageToURL:[sp URL] email:NO];
             }];
     } else {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"You 
must save this file first", @"Alert text when trying to create archive for 
unsaved document") defaultButton:nil alternateButton:nil otherButton:nil 
informativeTextWithFormat:NSLocalizedString(@"The document has unsaved changes, 
or has not previously been saved to disk.", @"Informative text in alert 
dialog")];
@@ -1285,9 +1285,9 @@
 - (IBAction)emailDiskImage:(id)sender {
     NSString *path = [[self fileURL] path];
     if (path && [[NSFileManager defaultManager] fileExistsAtPath:path] && 
[self isDocumentEdited] == NO) {
-        NSString *tmpDir = SKUniqueChewableItemsDirectory();
-        NSString *tmpFile = [tmpDir stringByAppendingPathComponent:[[self 
fileURL] lastPathComponentReplacingPathExtension:@"dmg"]];
-        [self saveDiskImageToFile:tmpFile email:YES];
+        NSURL *tmpDirURL = SKUniqueChewableItemsDirectoryURL();
+        NSURL *tmpFileURL = [tmpDirURL URLByAppendingPathComponent:[[self 
fileURL] lastPathComponentReplacingPathExtension:@"dmg"]];
+        [self saveDiskImageToURL:tmpFileURL email:YES];
     } else {
         NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"You 
must save this file first", @"Alert text when trying to create archive for 
unsaved document") defaultButton:nil alternateButton:nil otherButton:nil 
informativeTextWithFormat:NSLocalizedString(@"The document has unsaved changes, 
or has not previously been saved to disk.", @"Informative text in alert 
dialog")];
         [alert beginSheetModalForWindow:[self windowForSheet] 
modalDelegate:nil didEndSelector:NULL contextInfo:NULL];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to