3 Windows PDF view helper
6 This will be installed as pdfview.exe.
8 The application will launch the default PDF viewer to display the PDF file,
9 but works around the file locking problems of Adobe Reader.
11 Source code of pdfopen/pdfclose is available at:
12 http://magic.aladdin.cs.cmu.edu/2005/07/15/pdfopen-and-pdfclose/
16 !include "LogicLib.nsh"
17 !include "FileFunc.nsh"
18 !insertmacro GetParameters
19 !insertmacro GetFileName
21 ;--------------------------------
26 Icon "..\packaging\icons\lyx_32x32.ico"
29 ;--------------------------------
35 ;--------------------------------
48 ;--------------------------------
51 !macro SystemCall STACK
54 CallInstDLL "$EXEDIR\System.dll" Call
58 !macro HideConsole COMMAND_LINE
60 Push `${COMMAND_LINE}`
61 CallInstDLL "$EXEDIR\Console.dll" Exec
64 ${if} $Dummy == "error"
65 MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
70 ;--------------------------------
73 Section "View PDF file"
75 InitPluginsDir ;Temporary directory for PDF file
77 ;Command line parameters
82 StrCpy $Dummy $OriginalFile 1
84 StrCpy $OriginalFile $OriginalFile "" 1
86 StrCpy $Dummy $OriginalFile 1 -1
88 StrCpy $OriginalFile $OriginalFile -1
91 GetFullPathName $OriginalFile $OriginalFile
96 SetOutPath $TEMP ;The LyX tmpbuf should not be locked
98 StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
100 ;Check whether the file will be opened with Adobe Reader or Adobe Acrobat
102 !insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
107 MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
108 Please install a PDF viewer such as Adobe Reader."
112 ${if} $Viewer == "AcroRd32.exe"
113 ${orif} $Viewer == "Acrobat.exe"
118 ${if} ${fileexists} $PDFFile
119 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
122 ;Copy PDF to temporary file to allow LyX to overwrite the original
123 CopyFiles /SILENT $OriginalFile $PDFFile
126 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
128 ;Monitor for updates of the original file
130 GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
136 FileOpen $Dummy $PDFFile a
139 ;File no longer locked, reader closed
145 ${if} ${fileexists} $OriginalFile
147 GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
149 ${if} $OriginalTimeHigh != $CurrentTimeHigh
150 ${orif} $OriginalTimeLow != $CurrentTimeLow
152 ;Original has been modified, update!
154 StrCpy $OriginalTimeHigh $CurrentTimeHigh
155 StrCpy $OriginalTimeLow $CurrentTimeLow
156 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
157 CopyFiles /SILENT $OriginalFile $PDFFile
158 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
168 ;Another PDF viewer like GSView is used
169 ;No need for special actions, just forward to ShellExecute
170 ExecShell open $OriginalFile