Revision: 3078
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3078&view=rev
Author:   hofman
Date:     2007-10-26 12:40:40 -0700 (Fri, 26 Oct 2007)

Log Message:
-----------
Allow automatic reloading of dvi fils. Apparantly those end with 6 'fl' 
characters.

Modified Paths:
--------------
    trunk/SKDocument.m

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2007-10-26 18:55:17 UTC (rev 3077)
+++ trunk/SKDocument.m  2007-10-26 19:40:40 UTC (rev 3078)
@@ -1040,11 +1040,12 @@
             }
             
             NSString *extension = [fileName pathExtension];
+            BOOL isDVI = NO;
             if (extension) {
                 NSString *theUTI = 
[(id)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, 
(CFStringRef)extension, NULL) autorelease];
-                if (theUTI && UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("application/x-dvi"))) {
-                    return;
-                } if (theUTI && UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("net.sourceforge.skim-app.pdfd"))) {
+                if ([extension caseInsensitiveCompare:@"dvi"] == NSOrderedSame 
|| (theUTI && UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("application/x-dvi")))) {
+                    isDVI = YES;
+                } if ([extension caseInsensitiveCompare:@"pdfd"] == 
NSOrderedSame || (theUTI && UTTypeConformsTo((CFStringRef)theUTI, 
CFSTR("net.sourceforge.skim-app.pdfd")))) {
                     NSString *pdfFile = [[NSFileManager defaultManager] 
subfileWithExtension:@"pdf" inPDFBundleAtPath:fileName];
                     if (pdfFile == nil) return;
                     fileName = [fileName 
stringByAppendingPathComponent:pdfFile];
@@ -1058,10 +1059,18 @@
             unsigned long long startPos = fileEnd < 1024 ? 0 : fileEnd - 1024;
             [fh seekToFileOffset:startPos];
             NSData *trailerData = [fh readDataToEndOfFile];
+            NSRange range = NSMakeRange(0, [trailerData length]);
             const char *pattern = "%%EOF";
             unsigned patternLength = strlen(pattern);
-            unsigned trailerIndex = [trailerData indexOfBytes:pattern 
length:patternLength options:NSBackwardsSearch];
+            unsigned trailerIndex;
             
+            if (isDVI) {
+                pattern = [[NSString stringWithFormat:@"%C%C%C%C%C%C", 0xFB02, 
0xFB02, 0xFB02, 0xFB02, 0xFB02, 0xFB02] 
cStringUsingEncoding:NSMacOSRomanStringEncoding];
+                patternLength = strlen(pattern);
+                range = NSMakeRange(patternLength, [trailerData length] - 
patternLength);
+            }
+            trailerIndex = [trailerData indexOfBytes:pattern 
length:strlen(pattern) options:NSBackwardsSearch range:range];
+            
             if (trailerIndex != NSNotFound) {
                 BOOL shouldAutoUpdate = autoUpdate || [[NSUserDefaults 
standardUserDefaults] boolForKey:SKAutoReloadFileUpdateKey];
                 if (disableAutoReload == NO && shouldAutoUpdate && [self 
isDocumentEdited] == NO && [[self notes] count] == 0) {


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

Reply via email to