-/*
+/*
Windows PDF view helper
-Author: Joost Verburg
+Author: Uwe Stöhr and Joost Verburg
This will be installed as pdfview.exe.
The application will launch the default PDF viewer to display the PDF file,
-but works around the file locking problems of Adobe Reader.
-
-Source code of pdfopen/pdfclose is available at:
-http://magic.aladdin.cs.cmu.edu/2005/07/15/pdfopen-and-pdfclose/
+but works around the file locking problems of Adobe Reader and Acrobat.
*/
-!include "LogicLib.nsh"
-!include "FileFunc.nsh"
-!insertmacro GetParameters
-!insertmacro GetFileName
+Unicode true
+
+!include LogicLib.nsh
+!include FileFunc.nsh
#--------------------------------
-#Settings
+# Settings
Caption "PDF Viewer"
OutFile pdfview.exe
-Icon "..\packaging\icons\lyx_32x32.ico"
+Icon "..\packaging\icons\lyx.ico"
SilentInstall silent
#--------------------------------
-#Windows Vista settings
+# Windows Vista (and later) settings
RequestExecutionLevel user
#--------------------------------
-#Constants
-
-!define FALSE 0
-!define TRUE 1
+# Variables
-#--------------------------------
-#Variables
+Var Character
-Var Dummy
Var OriginalFile
Var OriginalFileName
+
Var PDFFile
+Var ViewerFileName
Var Viewer
-Var OriginalTimeHigh
-Var OriginalTimeLow
-Var CurrentTimeHigh
-Var CurrentTimeLow
+Var ViewerHandle
+Var ViewerVersion
#--------------------------------
-#Macros
-
-!macro SystemCall STACK
-
- Push `${STACK}`
- CallInstDLL "$EXEDIR\System.dll" Call
-
-!macroend
-
-!macro HideConsole COMMAND_LINE
-
- Push `${COMMAND_LINE}`
- CallInstDLL "$EXEDIR\Console.dll" Exec
- Pop $Dummy
-
- ${if} $Dummy == "error"
- MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
- ${endif}
-
-!macroend
-
-#--------------------------------
-#PDF vieweing
+# PDF viewing
Section "View PDF file"
- InitPluginsDir #Temporary directory for PDF file
+ InitPluginsDir # Temporary directory for PDF file
- #Command line parameters
- Call GetParameters
- Pop $OriginalFile
+ # Command line parameters
+ ${GetParameters} $OriginalFileName
- #Trim quotes
- StrCpy $Dummy $OriginalFile 1
- ${if} $Dummy == '"'
- StrCpy $OriginalFile $OriginalFile "" 1
- ${endif}
- StrCpy $Dummy $OriginalFile 1 -1
- ${if} $Dummy == '"'
- StrCpy $OriginalFile $OriginalFile -1
- ${endif}
+ # Trim quotes
+ StrCpy $Character $OriginalFileName 1
+ ${If} $Character == '"'
+ StrCpy $OriginalFileName $OriginalFileName "" 1
+ ${EndIf}
+ StrCpy $Character $OriginalFileName 1 -1
+ ${If} $Character == '"'
+ StrCpy $OriginalFileName $OriginalFileName -1
+ ${EndIf}
- GetFullPathName $OriginalFile $OriginalFile
- Push $OriginalFile
- Call GetFileName
- Pop $OriginalFileName
+ GetFullPathName $OriginalFile $OriginalFileName
- SetOutPath $TEMP #The LyX tmpbuf should not be locked
+ SetOutPath $TEMP # The LyX tmpbuf should not be locked
StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
- #Check whether the file will be opened with Adobe Reader or Adobe Acrobat
- Push $OriginalFile
- !insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
- Call GetFileName
- Pop $Viewer
+ # Check whether the file will be opened with Adobe Reader or Adobe Acrobat
+
+ FileOpen $R0 "$PLUGINSDIR\a.pdf" "w" #create a temp pdf file with a simple name
+ FileClose $R0
+
+ #find stadard executable for "a.pdf", writes result in $0 (".r0" below)
+ System::Call "shell32::FindExecutable(t '$PLUGINSDIR\a.pdf', t '', t .r0)"
+ StrCpy $ViewerFileName $0
+ ${GetFileName} $ViewerFileName $Viewer
- ${if} $Viewer == ""
+ ${If} $Viewer == ""
MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
Please install a PDF viewer such as Adobe Reader."
Quit
- ${endif}
-
+ ${EndIf}
+
${if} $Viewer == "AcroRd32.exe"
- ${orif} $Viewer == "Acrobat.exe"
+ ${orif} $Viewer == "AcroRd64.exe"
+ ${orif} $Viewer == "Acrobat.exe"
- #Using Adobe viewer
+ # get the version of Acrobat - currenly not necessary
+ 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
- #Close existing view
- ${if} ${fileexists} $PDFFile
- !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
+ # check if there is a windows open containing the PDF
+ ${if} $Viewer == "AcroRd32.exe"
+ ${orif} $Viewer == "AcroRd64.exe"
+ ${if} $ViewerVersion > 14
+ FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Reader DC"
+ ${else}
+ FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Reader"
+ ${endif}
+ ${elseif} $Viewer == "Acrobat.exe"
+ FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat"
+ ${if} $ViewerHandle == "0"
+ FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Pro"
+ ${endif}
+ ${endif}
+ ${if} $ViewerHandle <> "0" # close the window
+ SendMessage $ViewerHandle 16 0 0
${endif}
- #Copy PDF to temporary file to allow LyX to overwrite the original
+ # 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"'
-
- #Monitor for updates of the original file
-
- GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
-
- ${do}
-
- Sleep 500
-
- FileOpen $Dummy $PDFFile a
-
- ${if} $Dummy != ""
- #File no longer locked, reader closed
- FileClose $Dummy
- Delete $PDFFile
- Quit
- ${endif}
-
- ${if} ${fileexists} $OriginalFile
-
- GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
-
- ${if} $OriginalTimeHigh != $CurrentTimeHigh
- ${orif} $OriginalTimeLow != $CurrentTimeLow
-
- #Original has been modified, update!
-
- StrCpy $OriginalTimeHigh $CurrentTimeHigh
- StrCpy $OriginalTimeLow $CurrentTimeLow
- !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
- CopyFiles /SILENT $OriginalFile $PDFFile
- !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
-
- ${endif}
-
- ${endif}
-
- ${loop}
+ # Open a new view
+ ExecWait '"$ViewerFileName" "$PDFFile"'
- ${else}
+ ${Else}
- #Another PDF viewer like GSView is used
- #No need for special actions, just forward to ShellExecute
+ # Another PDF viewer like GSView is used
+ # No need for special actions, just forward to ShellExecute
ExecShell open $OriginalFile
- ${endif}
+ ${EndIf}
SectionEnd