3 Windows PDF view helper
\r
4 Author: Joost Verburg
\r
6 This will be installed as pdfview.exe.
\r
8 The application will launch the default PDF viewer to display the PDF file,
\r
9 but works around the file locking problems of Adobe Reader.
\r
11 Source code of pdfopen/pdfclose is available at:
\r
12 http://magic.aladdin.cs.cmu.edu/2005/07/15/pdfopen-and-pdfclose/
\r
16 !include "LogicLib.nsh"
\r
17 !include "FileFunc.nsh"
\r
18 !insertmacro GetParameters
\r
19 !insertmacro GetFileName
\r
21 ;--------------------------------
\r
25 Icon "..\packaging\icons\lyx_32x32.ico"
\r
26 SilentInstall silent
\r
28 ;--------------------------------
\r
34 ;--------------------------------
\r
39 Var OriginalFileName
\r
42 Var OriginalTimeHigh
\r
47 ;--------------------------------
\r
50 !macro SystemCall STACK
\r
53 CallInstDLL "$EXEDIR\System.dll" Call
\r
57 !macro HideConsole COMMAND_LINE
\r
59 Push `${COMMAND_LINE}`
\r
60 CallInstDLL "$EXEDIR\nsExec.dll" Exec
\r
63 ${if} $Dummy == "error"
\r
64 MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
\r
69 ;--------------------------------
\r
72 Section "View PDF file"
\r
74 InitPluginsDir ;Temporary directory for PDF file
\r
76 ;Command line parameters
\r
81 StrCpy $Dummy $OriginalFile 1
\r
83 StrCpy $OriginalFile $OriginalFile "" 1
\r
85 StrCpy $Dummy $OriginalFile 1 -1
\r
87 StrCpy $OriginalFile $OriginalFile -1
\r
90 GetFullPathName $OriginalFile $OriginalFile
\r
93 Pop $OriginalFileName
\r
95 SetOutPath $TEMP ;The LyX tmpbuf should not be locked
\r
97 StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
\r
99 ;Check whether the file will be opened with Adobe Reader or Adobe Acrobat
\r
101 !insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
\r
105 ${if} $Viewer == "AcroRd32.exe"
\r
106 ${orif} $Viewer == "Acrobat.exe"
\r
108 ;Using Adobe viewer
\r
110 ;Close existing view
\r
111 ${if} ${fileexists} $PDFFile
\r
112 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
\r
115 ;Copy PDF to temporary file to allow LyX to overwrite the original
\r
116 CopyFiles /SILENT $OriginalFile $PDFFile
\r
119 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
\r
121 ;Monitor for updates of the original file
\r
123 GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
\r
129 FileOpen $Dummy $PDFFile a
\r
132 ;File no longer locked, reader closed
\r
138 ${if} ${fileexists} $OriginalFile
\r
140 GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
\r
142 ${if} $OriginalTimeHigh != $CurrentTimeHigh
\r
143 ${orif} $OriginalTimeLow != $CurrentTimeLow
\r
145 ;Original has been modified, update!
\r
147 StrCpy $OriginalTimeHigh $CurrentTimeHigh
\r
148 StrCpy $OriginalTimeLow $CurrentTimeLow
\r
149 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
\r
150 CopyFiles /SILENT $OriginalFile $PDFFile
\r
151 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
\r
161 ;Another PDF viewer like GSView is used
\r
162 ;No need for special actions, just forward to ShellExecute
\r
163 ExecShell open $OriginalFile
\r