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/
19 #--------------------------------
24 Icon "..\packaging\icons\lyx.ico"
27 #--------------------------------
28 # Windows Vista settings
30 RequestExecutionLevel user
32 #--------------------------------
38 !define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
39 !define WAIT_TIMEOUT 0x00000102
41 #--------------------------------
55 Var ChangeNotification
64 #--------------------------------
67 !macro SystemCall STACK
69 # Call a Windows API function
72 CallInstDLL "$EXEDIR\System.dll" Call
76 !macro HideConsole COMMAND_LINE
78 # Run an application and hide console output
80 Push `${COMMAND_LINE}`
81 CallInstDLL "$EXEDIR\Console.dll" Exec
84 ${If} $RunAppReturn == "error"
85 MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $PDFFile."
90 #--------------------------------
93 Section "View PDF file"
95 InitPluginsDir # Temporary directory for PDF file
97 # Command line parameters
98 ${GetParameters} $OriginalFile
101 StrCpy $Character $OriginalFile 1
102 ${If} $Character == '"'
103 StrCpy $OriginalFile $OriginalFile "" 1
105 StrCpy $Character $OriginalFile 1 -1
106 ${If} $Character == '"'
107 StrCpy $OriginalFile $OriginalFile -1
110 GetFullPathName $OriginalFile $OriginalFile
111 ${GetFileName} $OriginalFile $OriginalFileName
112 ${GetParent} $OriginalFile $OriginalDir # tmpbuf
113 ${GetParent} $OriginalDir $OriginalDir # tmpdir
115 SetOutPath $TEMP # The LyX tmpbuf should not be locked
117 StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
119 # Check whether the file will be opened with Adobe Reader or Adobe Acrobat
120 !insertmacro SystemCall "shell32::FindExecutable(t '$OriginalFile', t '', t .s)"
122 ${GetFileName} $ViewerFileName $Viewer
125 MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
126 Please install a PDF viewer such as Adobe Reader."
130 ${If} $Viewer == "AcroRd32.exe"
131 ${OrIf} $Viewer == "Acrobat.exe"
135 # Close existing view
136 ${If} ${FileExists} $PDFFile
137 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
140 # Copy PDF to temporary file to allow LyX to overwrite the original
141 CopyFiles /SILENT $OriginalFile $PDFFile
144 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
146 # Monitor for updates of the original file
147 GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
148 !insertmacro SystemCall "kernel32::FindFirstChangeNotification(t '$OriginalDir', \
149 i 1, i ${FILE_NOTIFY_CHANGE_LAST_WRITE}) i.s"
150 Pop $ChangeNotification
154 !insertmacro SystemCall "kernel32::WaitForSingleObject(i $ChangeNotification, i 10000) i.s"
157 # Check whether the lock is still active (if not, Adobe Reader is closed)
159 FileOpen $LockedFile $PDFFile a
161 ${If} $LockedFile != ""
162 # Quit this application
163 FileClose $LockedFile
165 !insertmacro SystemCall "kernel32::FindCloseChangeNotification(i $ChangeNotification)"
169 ${IfNot} $WaitReturn = ${WAIT_TIMEOUT}
171 # The LyX temporary directory has been updated
172 # Check whether it's the PDF file that has been updated
174 GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
176 ${If} $OriginalTimeHigh != $CurrentTimeHigh
177 ${OrIf} $OriginalTimeLow != $CurrentTimeLow
178 # PDF has been modified, update view
179 !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
180 CopyFiles /SILENT $OriginalFile $PDFFile
181 !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
184 StrCpy $OriginalTimeHigh $CurrentTimeHigh
185 StrCpy $OriginalTimeLow $CurrentTimeLow
189 !insertmacro SystemCall "kernel32::FindNextChangeNotification(i $ChangeNotification)"
197 # Another PDF viewer like GSView is used
198 # No need for special actions, just forward to ShellExecute
199 ExecShell open $OriginalFile