]> git.lyx.org Git - lyx.git/blobdiff - development/Win32/pdfview/pdfview.nsi
installer: uninstall fixes
[lyx.git] / development / Win32 / pdfview / pdfview.nsi
index fe99159cde9baad94652424dcf83bffa56f533fd..8bbdd470a7b362e0f7ab5120b51673204a2f4af3 100644 (file)
@@ -16,11 +16,6 @@ http://magic.aladdin.cs.cmu.edu/2005/07/15/pdfopen-and-pdfclose/
 !include LogicLib.nsh
 !include FileFunc.nsh
 
-# Functions from FileFunc.nsh
-!insertmacro GetParameters
-!insertmacro GetFileName
-!insertmacro GetParent
-
 #--------------------------------
 # Settings
 
@@ -54,7 +49,10 @@ Var OriginalFileName
 Var OriginalDir
 
 Var PDFFile
+Var ViewerFileName
 Var Viewer
+Var ViewerVersion
+Var DDEName
 
 Var ChangeNotification
 Var WaitReturn
@@ -113,7 +111,8 @@ Section "View PDF file"
 
   GetFullPathName $OriginalFile $OriginalFile
   ${GetFileName} $OriginalFile $OriginalFileName
-  ${GetParent} $OriginalFile $OriginalDir
+  ${GetParent} $OriginalFile $OriginalDir # tmpbuf
+  ${GetParent} $OriginalDir $OriginalDir # tmpdir
 
   SetOutPath $TEMP # The LyX tmpbuf should not be locked
 
@@ -121,8 +120,8 @@ Section "View PDF file"
 
   # Check whether the file will be opened with Adobe Reader or Adobe Acrobat
   !insertmacro SystemCall "shell32::FindExecutable(t '$OriginalFile', t '', t .s)"
-  Call GetFileName
-  Pop $Viewer
+  Pop $ViewerFileName
+  ${GetFileName} $ViewerFileName $Viewer
 
   ${If} $Viewer == ""
     MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
@@ -134,31 +133,49 @@ Section "View PDF file"
     ${OrIf} $Viewer == "Acrobat.exe"
     
     # Using Adobe viewer
-    
+
+    GetDLLVersion $ViewerFileName $R0 $R1
+    IntOp $R2 $R0 >> 16
+    IntOp $R2 $R2 & 0x0000FFFF ; $R2 now contains major version
+    IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
+    IntOp $R4 $R1 >> 16
+    IntOp $R4 $R4 & 0x0000FFFF ; $R4 now contains release
+    IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
+    StrCpy $ViewerVersion "$R2"
+
+    ${If} $ViewerVersion < 10
+      StrCpy $DDEName "AcroView"
+    ${Else}
+      ${If} $Viewer == "AcroRd32.exe"
+        StrCpy $DDEName "AcroViewR$ViewerVersion"
+      ${ElseIf} $Viewer == "Acrobat.exe"
+        StrCpy $DDEName "AcroViewA$ViewerVersion"
+      ${EndIf}
+    ${EndIf}
+
     # Close existing view
     ${If} ${FileExists} $PDFFile
-      !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
+      !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --reader "$ViewerFileName" --ddename "$DDEName" --file "$PDFFile"'
     ${EndIf}
     
     # Copy PDF to temporary file to allow LyX to overwrite the original
     CopyFiles /SILENT $OriginalFile $PDFFile
     
     # Open a new view
-    !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
+    !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --reader "$ViewerFileName" --ddename "$DDEName" --back --file "$PDFFile"'
     
     # Monitor for updates of the original file
     GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
     !insertmacro SystemCall "kernel32::FindFirstChangeNotification(t '$OriginalDir', \
-      i 0, i ${FILE_NOTIFY_CHANGE_LAST_WRITE}) i.s"
+      i 1, i ${FILE_NOTIFY_CHANGE_LAST_WRITE}) i.s"
     Pop $ChangeNotification
     
     ${Do}
     
       !insertmacro SystemCall "kernel32::WaitForSingleObject(i $ChangeNotification, i 10000) i.s"
-      Pop $WaitReturn    
-         
-      # Check whether a lock is still active.
-      # If not, Adode Reader is closed and we can close this application as well
+      Pop $WaitReturn
+           
+      # Check whether the lock is still active (if not, Adobe Reader is closed)
       
       FileOpen $LockedFile $PDFFile a
       
@@ -171,17 +188,18 @@ Section "View PDF file"
       ${EndIf}
       
       ${IfNot} $WaitReturn = ${WAIT_TIMEOUT}
-        # The LyX tmpbuf has been updated
+        
+        # The LyX temporary directory has been updated
         # Check whether it's the PDF file that has been updated
           
         GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
         
-        ${if} $OriginalTimeHigh != $CurrentTimeHigh
-          ${orif} $OriginalTimeLow != $CurrentTimeLow
+        ${If} $OriginalTimeHigh != $CurrentTimeHigh
+          ${OrIf} $OriginalTimeLow != $CurrentTimeLow
           # PDF has been modified, update view
-          !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
+          !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --reader "$ViewerFileName" --ddename "$DDEName" --file "$PDFFile"'
           CopyFiles /SILENT $OriginalFile $PDFFile
-          !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
+          !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --reader "$ViewerFileName" --ddename "$DDEName" --back --file "$PDFFile"'
           
           # Time of new file
           StrCpy $OriginalTimeHigh $CurrentTimeHigh