Revision: 2624
http://skim-app.svn.sourceforge.net/skim-app/?rev=2624&view=rev
Author: hofman
Date: 2007-08-08 02:31:47 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
Save disk image in the background, as we don't need any access to the app.
Modified Paths:
--------------
trunk/SKDocument.m
Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m 2007-08-07 21:01:10 UTC (rev 2623)
+++ trunk/SKDocument.m 2007-08-08 09:31:47 UTC (rev 2624)
@@ -549,19 +549,6 @@
contextInfo:NULL];
}
-#define RUN_TASK(cmd, args, curDir) \
- do { \
- NSTask *task = [[[NSTask alloc] init] autorelease]; \
- [task setLaunchPath:cmd]; \
- [task setCurrentDirectoryPath:curDir]; \
- [task setArguments:args]; \
- [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]]; \
- [task setStandardError:[NSFileHandle fileHandleWithNullDevice]]; \
- [task launch]; \
- if ([task isRunning]) [task waitUntilExit]; \
- success = success && 0 == [task terminationStatus]; \
- } while (0);
-
- (void)archiveSavePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo {
if (NSOKButton == returnCode && [self fileURL]) {
@@ -596,46 +583,36 @@
}
}
-- (void)diskImageSavePanelDidEnd:(NSSavePanel *)sheet
returnCode:(int)returnCode contextInfo:(void *)contextInfo {
-
- if (NSOKButton == returnCode && [self fileURL]) {
+- (void)saveDiskImageWithInfo:(NSDictionary *)info {
- if (progressSheet == nil) {
- if ([NSBundle loadNibNamed:@"ProgressSheet" owner:self]) {
- [progressBar setUsesThreadedAnimation:YES];
- } else {
- NSLog(@"Failed to load ProgressSheet.nib");
- return;
- }
- }
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
- [progressField setStringValue:[NSLocalizedString(@"Saving Disk Image",
@"Message for progress sheet") stringByAppendingEllipsis]];
- [progressBar setIndeterminate:YES];
- [progressBar startAnimation:self];
-
- [sheet orderOut:self];
- [NSApp beginSheet:progressSheet modalForWindow:[[self
mainWindowController] window] modalDelegate:nil didEndSelector:NULL
contextInfo:NULL];
-
- NSFileManager *fm = [NSFileManager defaultManager];
NSString *baseTmpDir = [NSTemporaryDirectory()
stringByAppendingPathComponent:@"net.sourceforge.skim-app.skim"];
NSString *tmpDir = baseTmpDir;
+ NSString *tmpDirName;
+ FSRef tmpRef;
+ FSRef tmpDirRef;
int i = 0;
- while ([fm fileExistsAtPath:tmpDir])
+ BOOL success = YES;
+
+ while (fnfErr != FSPathMakeRef((UInt8 *)[tmpDir
fileSystemRepresentation], &tmpDirRef, NULL))
tmpDir = [baseTmpDir stringByAppendingFormat:@"%i", ++i];
- NSString *sourcePath = [[self fileURL] path];
- NSString *path = [sheet filename];
+ tmpDirName = [tmpDir lastPathComponent];
+ success = noErr == FSPathMakeRef((UInt8 *)[NSTemporaryDirectory()
fileSystemRepresentation], &tmpRef, NULL);
+ if (success)
+ success = noErr == FSCreateDirectoryUnicode(&tmpRef, [tmpDirName
length], (const UniChar *)[tmpDirName
cStringUsingEncoding:NSUnicodeStringEncoding], kFSCatInfoNone, NULL,
&tmpDirRef, NULL, NULL);
+
+ NSString *sourcePath = [info objectForKey:@"sourcePath"];
+ NSString *path = [info objectForKey:@"targetPath"];
NSString *name = [[path lastPathComponent]
stringByDeletingPathExtension];
NSString *tmpName = [name caseInsensitiveCompare:@"tmp"] ==
NSOrderedSame ? @"tmp1" : @"tmp";
NSString *tmpDmgPath1 = [[tmpDir
stringByAppendingPathComponent:tmpName] stringByAppendingPathExtension:@"dmg"];
NSString *tmpDmgPath2 = [[tmpDir stringByAppendingPathComponent:name]
stringByAppendingPathExtension:@"dmg"];
NSString *tmpMountPath = [tmpDir
stringByAppendingPathComponent:tmpName];
NSString *tmpPath = [tmpMountPath
stringByAppendingPathComponent:[sourcePath lastPathComponent]];
- BOOL success = YES;
BOOL didAttach = NO;
- success = [fm createDirectoryAtPath:tmpDir attributes:nil];
-
@try {
if (success) {
success = [NSTask runTaskWithLaunchPath:@"/usr/bin/hdiutil"
@@ -653,10 +630,9 @@
}
if (success) {
- if ([fm fileExistsAtPath:tmpPath])
- success = [fm removeFileAtPath:tmpPath handler:nil];
- if (success)
- success = [fm copyPath:sourcePath toPath:tmpPath
handler:nil];
+ success = [NSTask runTaskWithLaunchPath:@"/bin/cp"
+ arguments:[NSArray
arrayWithObjects:@"-f", sourcePath, tmpPath, nil]
+ currentDirectoryPath:tmpDir];
}
if (didAttach) {
@@ -672,21 +648,47 @@
}
if (success) {
- if ([fm fileExistsAtPath:path])
- success = [fm removeFileAtPath:path handler:nil];
- if (success)
- success = [fm copyPath:tmpDmgPath2 toPath:path
handler:nil];
+ success = [NSTask runTaskWithLaunchPath:@"/bin/cp"
+ arguments:[NSArray
arrayWithObjects:@"-f", tmpDmgPath2, path, nil]
+ currentDirectoryPath:tmpDir];
}
+
+ [NSTask launchedTaskWithLaunchPath:@"/bin/rm" arguments:[NSArray
arrayWithObjects:@"-rf", tmpDir, nil]];
+
}
@catch(id exception) {
NSLog(@"caught exception %@ while archiving %@ to %@", exception,
sourcePath, path);
}
- [fm removeFileAtPath:tmpDir handler:nil];
+ [progressBar performSelectorOnMainThread:@selector(stopAnimation:)
withObject:nil waitUntilDone:NO];
+ [progressSheet performSelectorOnMainThread:@selector(orderOut:)
withObject:nil waitUntilDone:NO];
- [NSApp endSheet:progressSheet];
- [progressBar stopAnimation:self];
- [progressSheet orderOut:self];
+ [pool release];
+}
+
+- (void)diskImageSavePanelDidEnd:(NSSavePanel *)sheet
returnCode:(int)returnCode contextInfo:(void *)contextInfo {
+
+ if (NSOKButton == returnCode && [self fileURL]) {
+
+ if (progressSheet == nil) {
+ if ([NSBundle loadNibNamed:@"ProgressSheet" owner:self]) {
+ [progressBar setUsesThreadedAnimation:YES];
+ } else {
+ NSLog(@"Failed to load ProgressSheet.nib");
+ return;
+ }
+ }
+
+ [progressField setStringValue:[NSLocalizedString(@"Saving Disk Image",
@"Message for progress sheet") stringByAppendingEllipsis]];
+ [progressSheet setTitle:NSLocalizedString(@"Saving Disk Image",
@"Message for progress sheet")];
+ [progressBar setIndeterminate:YES];
+ [progressBar startAnimation:self];
+
+ [sheet orderOut:self];
+ [progressSheet orderFront:self];
+
+ NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:[[self
fileURL] path], @"sourcePath", [sheet filename], @"targetPath", nil];
+ [NSThread detachNewThreadSelector:@selector(saveDiskImageWithInfo:)
toTarget:self withObject:info];
}
}
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