Revision: 3299
http://skim-app.svn.sourceforge.net/skim-app/?rev=3299&view=rev
Author: hofman
Date: 2007-12-02 13:01:05 -0800 (Sun, 02 Dec 2007)
Log Message:
-----------
Search for DVI conversion tool in a class method on the main thread. Allows
using NSFileManager and only searches once.
Modified Paths:
--------------
trunk/SKPSProgressController.m
Modified: trunk/SKPSProgressController.m
===================================================================
--- trunk/SKPSProgressController.m 2007-12-02 18:28:46 UTC (rev 3298)
+++ trunk/SKPSProgressController.m 2007-12-02 21:01:05 UTC (rev 3299)
@@ -275,6 +275,32 @@
@implementation SKDVIProgressController
++ (NSString *)dviToolPath {
+ static NSString *dviToolPath = nil;
+
+ if (dviToolPath == nil) {
+ NSString *commandPath = [[NSUserDefaults standardUserDefaults]
stringForKey:SKDviConversionCommandKey];
+ NSString *commandName = commandPath ? [commandPath lastPathComponent]
: @"dvips";
+ NSArray *paths = [NSArray arrayWithObjects:@"/usr/texbin",
@"/usr/local/teTeX/bin/powerpc-apple-darwin-current", @"/sw/bin",
@"/opt/local/bin", @"/usr/local/bin", nil];
+ int i = 0, count = [paths count];
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSSet *supportedTools = [NSSet setWithObjects:@"dvips", @"dvipdf",
@"dvipdfm", @"dvipdfmx", nil];
+
+ NSAssert1([supportedTools containsObject:commandName], @"DVI converter
%@ is not supported", commandName);
+
+ while ([fm isExecutableFileAtPath:commandPath]) {
+ if (i >= count) {
+ commandPath = nil;
+ break;
+ }
+ commandPath = [[paths objectAtIndex:i++]
stringByAppendingPathComponent:commandName];
+ }
+ dviToolPath = [commandPath retain];
+ }
+
+ return dviToolPath;
+}
+
- (IBAction)cancel:(id)sender
{
if (convertingPS) {
@@ -290,17 +316,22 @@
}
- (NSData *)PDFDataWithDVIFile:(NSString *)dviFile {
- NSMutableData *pdfData = [[NSMutableData alloc] init];
+ NSString *dviToolPath = [[self class] dviToolPath];
+ NSMutableData *pdfData = nil;
- NSDictionary *dictionary = [NSDictionary
dictionaryWithObjectsAndKeys:dviFile, @"dviFile", pdfData, @"pdfData", nil];
-
- int rv = [self runModalConversionWithInfo:dictionary];
-
- if (rv != SKConversionSucceeded) {
- [pdfData release];
- pdfData = nil;
+ if (dviToolPath) {
+ NSDictionary *dictionary = [NSDictionary
dictionaryWithObjectsAndKeys:dviFile, @"dviFile", pdfData, @"pdfData",
dviToolPath, @"dviToolPath", nil];
+ pdfData = [[NSMutableData alloc] init];
+
+ int rv = [self runModalConversionWithInfo:dictionary];
+
+ if (rv != SKConversionSucceeded) {
+ [pdfData release];
+ pdfData = nil;
+ }
+ } else {
+ NSBeep();
}
-
return [pdfData autorelease];
}
@@ -314,28 +345,13 @@
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *dviFile = [info objectForKey:@"dviFile"];
- NSString *commandPath = [[NSUserDefaults standardUserDefaults]
stringForKey:SKDviConversionCommandKey];
- NSString *commandName = commandPath ? [commandPath lastPathComponent] :
@"dvips";
- NSArray *paths = [NSArray arrayWithObjects:@"/usr/texbin",
@"/usr/local/teTeX/bin/powerpc-apple-darwin-current", @"/sw/bin",
@"/opt/local/bin", @"/usr/local/bin", nil];
- int i = 0, count = [paths count];
-
- NSAssert1(commandName == nil || [commandName isEqualToString:@"dvips"] ||
[commandName isEqualToString:@"dvipdf"] || [commandName
isEqualToString:@"dvipdfm"] || [commandName isEqualToString:@"dvipdfmx"], @"DVI
converter %@ is not supported", commandName);
-
- // should we also check executable permissions? That would require a
thread safe version of isExecutableFileAtPath:
- // but the paths we check should be executable or it's the user's
responsibility
- while (SKFileExistsAtPath(commandPath) == NO) {
- if (i >= count) {
- commandPath = nil;
- break;
- }
- commandPath = [[paths objectAtIndex:i++]
stringByAppendingPathComponent:commandName];
- }
-
+ NSString *commandPath = [info objectForKey:@"dviToolPath"];
+ NSString *commandName = [commandPath lastPathComponent];
NSString *tmpDir = SKUniqueDirectoryCreating(NSTemporaryDirectory(), YES);
BOOL outputPS = [commandName isEqualToString:@"dvips"];
NSString *outFile = [tmpDir stringByAppendingPathComponent:[[dviFile
lastPathComponent] stringByReplacingPathExtension:outputPS ? @"ps" : @"pdf"]];
NSArray *arguments = [commandName isEqualToString:@"dvipdf"] ? [NSArray
arrayWithObjects:dviFile, outFile, nil] : [NSArray arrayWithObjects:@"-o",
outFile, dviFile, nil];
- BOOL success = commandPath != nil && SKFileExistsAtPath(dviFile);
+ BOOL success = SKFileExistsAtPath(dviFile);
NSMethodSignature *ms;
NSInvocation *invocation;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit