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 #--------------------------------
30 #Windows Vista settings
32 RequestExecutionLevel user
34 #--------------------------------
40 #--------------------------------
53 #--------------------------------
56 !macro SystemCall STACK
59 CallInstDLL "$EXEDIR\System.dll" Call
63 !macro HideConsole COMMAND_LINE
65 Push `${COMMAND_LINE}`
66 CallInstDLL "$EXEDIR\Console.dll" Exec
69 ${if} $Dummy == "error"
70 MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
75 #--------------------------------
78 Section "View PDF file"
80 InitPluginsDir #Temporary directory for PDF file
82 #Command line parameters
87 StrCpy $Dummy $OriginalFile 1
89 StrCpy $OriginalFile $OriginalFile "" 1
91 StrCpy $Dummy $OriginalFile 1 -1
93 StrCpy $OriginalFile $OriginalFile -1
96 GetFullPathName $OriginalFile $OriginalFile
101 SetOutPath $TEMP #The LyX tmpbuf should not be locked
103 StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
105 #Check whether the file will be opened with Adobe Reader or Adobe Acrobat
107 !insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
112 MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
113 Please install a PDF viewer such as Adobe Reader."
117 ${if} $Viewer == "AcroRd32.exe"
118 ${orif} $Viewer == "Acrobat.exe"
123 ${if} ${fileexists} $PDFFile
124 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
127 #Copy PDF to temporary file to allow LyX to overwrite the original
128 CopyFiles /SILENT $OriginalFile $PDFFile
131 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
133 #Monitor for updates of the original file
135 GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
141 FileOpen $Dummy $PDFFile a
144 #File no longer locked, reader closed
150 ${if} ${fileexists} $OriginalFile
152 GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
154 ${if} $OriginalTimeHigh != $CurrentTimeHigh
155 ${orif} $OriginalTimeLow != $CurrentTimeLow
157 #Original has been modified, update!
159 StrCpy $OriginalTimeHigh $CurrentTimeHigh
160 StrCpy $OriginalTimeLow $CurrentTimeLow
161 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
162 CopyFiles /SILENT $OriginalFile $PDFFile
163 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
173 #Another PDF viewer like GSView is used
174 #No need for special actions, just forward to ShellExecute
175 ExecShell open $OriginalFile