Revision: 7771
http://skim-app.svn.sourceforge.net/skim-app/?rev=7771&view=rev
Author: hofman
Date: 2012-11-02 11:22:26 +0000 (Fri, 02 Nov 2012)
Log Message:
-----------
Use filemanager methods to create unique temporary 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-02 10:44:23 UTC (rev 7770)
+++ trunk/NSFileManager_SKExtensions.h 2012-11-02 11:22:26 UTC (rev 7771)
@@ -48,11 +48,6 @@
- (NSArray *)applicationSupportDirectoryURLs;
- (NSURL *)uniqueFileURL:(NSURL *)fileURL;
+- (NSURL *)uniqueChewableItemsDirectoryURL;
@end
-
-// These functions are thread safe
-
-extern NSURL *SKChewableItemsDirectoryURL();
-extern NSURL *SKUniqueTemporaryDirectoryURL();
-extern NSURL *SKUniqueChewableItemsDirectoryURL();
Modified: trunk/NSFileManager_SKExtensions.m
===================================================================
--- trunk/NSFileManager_SKExtensions.m 2012-11-02 10:44:23 UTC (rev 7770)
+++ trunk/NSFileManager_SKExtensions.m 2012-11-02 11:22:26 UTC (rev 7771)
@@ -80,67 +80,28 @@
return uniqueFileURL;
}
-@end
-
-static NSURL *SKUniqueDirectoryURL(NSURL *baseURL) {
+- (NSURL *)uniqueChewableItemsDirectoryURL {
+ // chewable items are automatically cleaned up at restart, and it's hidden
from the user
+ static NSURL *chewableItemsDirectoryURL = nil;
+ if (chewableItemsDirectoryURL == nil) {
+ FSRef chewableRef;
+ if (noErr == FSFindFolder(kUserDomain, kChewableItemsFolderType, TRUE,
&chewableRef)) {
+ NSURL *chewableURL = (NSURL
*)CFURLCreateFromFSRef(kCFAllocatorDefault, &chewableRef);
+ chewableItemsDirectoryURL = [[chewableURL
URLByAppendingPathComponent:@"Skim"] copy];
+ if ([self fileExistsAtURL:chewableItemsDirectoryURL] == NO)
+ [self createDirectoryAtPath:[chewableItemsDirectoryURL path]
withIntermediateDirectories:NO attributes:nil error:NULL];
+ [chewableURL release];
+ }
+ }
+
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *tmpDirName = [(NSString *)CFUUIDCreateString(NULL, uuid)
autorelease];
CFRelease(uuid);
+ NSURL *uniqueURL = [chewableItemsDirectoryURL
URLByAppendingPathComponent:tmpDirName];
- BOOL success = YES;
- FSRef tmpRef;
- UniCharCount length = [tmpDirName length];
- UniChar *tmpName = (UniChar *)NSZoneMalloc(NULL, length * sizeof(UniChar));
- [tmpDirName getCharacters:tmpName];
- success = CFURLGetFSRef((CFURLRef)baseURL, &tmpRef) &&
- noErr == FSCreateDirectoryUnicode(&tmpRef, length, tmpName,
kFSCatInfoNone, NULL, NULL, NULL, NULL);
- NSZoneFree(NULL, tmpName);
-
- return success ? [baseURL URLByAppendingPathComponent:tmpDirName] : nil;
+ [self createDirectoryAtPath:[uniqueURL path]
withIntermediateDirectories:NO attributes:nil error:NULL];
+
+ return uniqueURL;
}
-NSURL *SKChewableItemsDirectoryURL() {
- // chewable items are automatically cleaned up at restart, and it's hidden
from the user
- NSURL *chewableItemsDirectoryURL = nil;
- FSRef chewableRef;
- OSErr err = FSFindFolder(kUserDomain, kChewableItemsFolderType, TRUE,
&chewableRef);
-
- CFAllocatorRef alloc = CFAllocatorGetDefault();
- CFURLRef chewableURL = NULL;
- if (noErr == err) {
- chewableURL = CFURLCreateFromFSRef(alloc, &chewableRef);
-
- CFStringRef baseName =
CFStringCreateWithFileSystemRepresentation(alloc, "Skim");
- CFURLRef newURL = CFURLCreateCopyAppendingPathComponent(alloc,
chewableURL, baseName, TRUE);
- FSRef newRef;
-
- if (chewableURL) CFRelease(chewableURL);
-
- assert(NULL != newURL);
-
- if (CFURLGetFSRef(newURL, &newRef) == false) {
- CFIndex nameLength = CFStringGetLength(baseName);
- UniChar *nameBuf = CFAllocatorAllocate(alloc, nameLength *
sizeof(UniChar), 0);
- CFStringGetCharacters(baseName, CFRangeMake(0, nameLength),
nameBuf);
- err = FSCreateDirectoryUnicode(&chewableRef, nameLength, nameBuf,
kFSCatInfoNone, NULL, NULL, NULL, NULL);
- CFAllocatorDeallocate(alloc, nameBuf);
- }
-
- if (noErr == err)
- chewableItemsDirectoryURL = (NSURL *)newURL;
- else if (newURL)
- CFRelease(newURL);
- if (baseName) CFRelease(baseName);
-
- assert(nil != chewableItemsDirectoryURL);
- }
- return chewableItemsDirectoryURL;
-}
-
-NSURL *SKUniqueTemporaryDirectoryURL() {
- return SKUniqueDirectoryURL([NSURL
fileURLWithPath:NSTemporaryDirectory()]);
-}
-
-NSURL *SKUniqueChewableItemsDirectoryURL() {
- return SKUniqueDirectoryURL(SKChewableItemsDirectoryURL());
-}
+@end
Modified: trunk/SKConversionProgressController.m
===================================================================
--- trunk/SKConversionProgressController.m 2012-11-02 10:44:23 UTC (rev
7770)
+++ trunk/SKConversionProgressController.m 2012-11-02 11:22:26 UTC (rev
7771)
@@ -322,18 +322,17 @@
- (void)doDVIConversionWithInfo:(NSDictionary *)info {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
NSURL *dviURL = [info objectForKey:INPUTURL_KEY];
NSString *dviFile = [dviURL path];
NSString *commandPath = [info objectForKey:TOOLPATH_KEY];
NSString *commandName = [commandPath lastPathComponent];
- NSURL *tmpDirURL = SKUniqueTemporaryDirectoryURL();
+ NSURL *tmpDirURL = [fm URLForDirectory:NSItemReplacementDirectory
inDomain:NSUserDomainMask appropriateForURL:dviURL create:YES error:NULL];
BOOL outputPS = [commandName isEqualToString:@"dvips"];
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;
- NSFileManager *fm = [[[NSFileManager alloc] init] autorelease];
-
if ([self shouldKeepRunning] && [fm fileExistsAtPath:dviFile]) {
NSTask *task = [NSTask launchedTaskWithLaunchPath:commandPath
arguments:arguments currentDirectoryPath:[dviFile
stringByDeletingLastPathComponent]];
if (task) {
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2012-11-02 10:44:23 UTC (rev 7770)
+++ trunk/SKMainDocument.m 2012-11-02 11:22:26 UTC (rev 7771)
@@ -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 = SKUniqueTemporaryDirectoryURL();
+ tmpURL = [fm URLForDirectory:NSItemReplacementDirectory
inDomain:NSUserDomainMask appropriateForURL:fileURL create:YES error:NULL];
[fm copyItemAtURL:url toURL:[tmpURL
URLByAppendingPathComponent:[url lastPathComponent]] error:NULL];
}
}
@@ -1228,7 +1228,7 @@
- (IBAction)emailArchive:(id)sender {
NSString *path = [[self fileURL] path];
if (path && [[NSFileManager defaultManager] fileExistsAtPath:path] &&
[self isDocumentEdited] == NO) {
- NSURL *tmpDirURL = SKUniqueChewableItemsDirectoryURL();
+ NSURL *tmpDirURL = [[NSFileManager defaultManager]
uniqueChewableItemsDirectoryURL];
NSURL *tmpFileURL = [tmpDirURL URLByAppendingPathComponent:[[self
fileURL] lastPathComponentReplacingPathExtension:@"tgz"]];
if ([self saveArchiveToURL:tmpFileURL] == NO || [self
emailAttachmentAtURL:tmpFileURL] == NO)
NSBeep();
@@ -1285,7 +1285,7 @@
- (IBAction)emailDiskImage:(id)sender {
NSString *path = [[self fileURL] path];
if (path && [[NSFileManager defaultManager] fileExistsAtPath:path] &&
[self isDocumentEdited] == NO) {
- NSURL *tmpDirURL = SKUniqueChewableItemsDirectoryURL();
+ NSURL *tmpDirURL = [[NSFileManager defaultManager]
uniqueChewableItemsDirectoryURL];
NSURL *tmpFileURL = [tmpDirURL URLByAppendingPathComponent:[[self
fileURL] lastPathComponentReplacingPathExtension:@"dmg"]];
[self saveDiskImageToURL:tmpFileURL email:YES];
} else {
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