- !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --file "$PDFFile"'
-
- # check if a file in LyX's temp folder has been changed
- !insertmacro SystemCall "kernel32::FindFirstChangeNotification(t '$OriginalDir', \
- i 1, i ${FILE_NOTIFY_CHANGE_LAST_WRITE}) i.s"
- Pop $ChangeNotification
-
- ${Do}
-
- # wait until the folder is not changed anymore, if so a "0" is returned
- # otherwise a "258" (0x00000102) is returned
- !insertmacro SystemCall "kernel32::WaitForSingleObject(i $ChangeNotification, i 10000) i.s"
- Pop $WaitReturn
-
- # Check whether the lock of the PDF file is still active (if not, Adobe Reader is closed)
- FileOpen $LockedFile $PDFFile a
- ${If} $LockedFile != ""
- # Quit this application
- FileClose $LockedFile
- Delete $PDFFile
- !insertmacro SystemCall "kernel32::FindCloseChangeNotification(i $ChangeNotification)"
- Quit
- ${EndIf}
-
- # if the folder is (for now) not changed anymore
- ${IfNot} $WaitReturn = ${WAIT_TIMEOUT}
-
- # check if the PDF-file in our temp directory is older than the one
- # in LyX's temp folder because then it has been changed by LaTeX
- ${FileTimeDiff} $TimeDiff "$PDFFile" "$OriginalFile"
-
- # if the file is older than 1 second
- ${If} $TimeDiff < -1
- # close the PDF
- !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
-
- # The problem is now that LaTeX might need several runs and therefore the PDF can
- # also be rewritten consecutively several times.
- # If we would directly open the file we will get in troubles as the PDF can be
- # unreadable. We also don't know the time of a LaTeX run.
- # (As example take UserGuide.lyx, view it, then remove a letter in a section heading
- # and finally update the view.)
- # We therefore loop until the PDF is no longer changed and wait some time in each loop.
- ${Do}
- CopyFiles /SILENT $OriginalFile $PDFFile
- # wait 1.666 seconds (is empirically enough time that the PDF can be changed)
- Sleep 1666
- ${FileTimeDiff} $TimeDiff "$PDFFile" "$OriginalFile"
- ${LoopUntil} $TimeDiff = 0
-
- # open the new file
- !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --file "$PDFFile"'
- ${EndIf}
-
- #Monitor again
- !insertmacro SystemCall "kernel32::FindNextChangeNotification(i $ChangeNotification)"
-
- ${EndIf} # end ifnot
-
- ${Loop}