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
24 Caption "PDF Viewer"
\r
26 Icon "..\packaging\icons\lyx_32x32.ico"
\r
27 SilentInstall silent
\r
29 ;--------------------------------
\r
35 ;--------------------------------
\r
40 Var OriginalFileName
\r
43 Var OriginalTimeHigh
\r
48 ;--------------------------------
\r
51 !macro SystemCall STACK
\r
54 CallInstDLL "$EXEDIR\System.dll" Call
\r
58 !macro HideConsole COMMAND_LINE
\r
60 Push `${COMMAND_LINE}`
\r
61 CallInstDLL "$EXEDIR\Console.dll" Exec
\r
64 ${if} $Dummy == "error"
\r
65 MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
\r
70 ;--------------------------------
\r
73 Section "View PDF file"
\r
75 InitPluginsDir ;Temporary directory for PDF file
\r
77 ;Command line parameters
\r
82 StrCpy $Dummy $OriginalFile 1
\r
84 StrCpy $OriginalFile $OriginalFile "" 1
\r
86 StrCpy $Dummy $OriginalFile 1 -1
\r
88 StrCpy $OriginalFile $OriginalFile -1
\r
91 GetFullPathName $OriginalFile $OriginalFile
\r
94 Pop $OriginalFileName
\r
96 SetOutPath $TEMP ;The LyX tmpbuf should not be locked
\r
98 StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
\r
100 ;Check whether the file will be opened with Adobe Reader or Adobe Acrobat
\r
102 !insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
\r
106 ${if} $Viewer == ""
\r
107 MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
\r
108 Please install a PDF viewer such as Adobe Reader."
\r
112 ${if} $Viewer == "AcroRd32.exe"
\r
113 ${orif} $Viewer == "Acrobat.exe"
\r
115 ;Using Adobe viewer
\r
117 ;Close existing view
\r
118 ${if} ${fileexists} $PDFFile
\r
119 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
\r
122 ;Copy PDF to temporary file to allow LyX to overwrite the original
\r
123 CopyFiles /SILENT $OriginalFile $PDFFile
\r
126 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
\r
128 ;Monitor for updates of the original file
\r
130 GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
\r
136 FileOpen $Dummy $PDFFile a
\r
139 ;File no longer locked, reader closed
\r
145 ${if} ${fileexists} $OriginalFile
\r
147 GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
\r
149 ${if} $OriginalTimeHigh != $CurrentTimeHigh
\r
150 ${orif} $OriginalTimeLow != $CurrentTimeLow
\r
152 ;Original has been modified, update!
\r
154 StrCpy $OriginalTimeHigh $CurrentTimeHigh
\r
155 StrCpy $OriginalTimeLow $CurrentTimeLow
\r
156 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
\r
157 CopyFiles /SILENT $OriginalFile $PDFFile
\r
158 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
\r
168 ;Another PDF viewer like GSView is used
\r
169 ;No need for special actions, just forward to ShellExecute
\r
170 ExecShell open $OriginalFile
\r