2007-02-08 21:09:30 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Windows PDF view helper
|
2012-11-20 00:07:08 +00:00
|
|
|
Author: Joost Verburg and Uwe Stöhr
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
This will be installed as pdfview.exe.
|
|
|
|
|
|
|
|
The application will launch the default PDF viewer to display the PDF file,
|
2012-11-20 00:07:08 +00:00
|
|
|
but works around the file locking problems of Adobe Reader and Acrobat.
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
The files pdfopen/pdfclose are part of this archive:
|
|
|
|
http://www.tex.ac.uk/tex-archive/systems/win32/w32tex/pdftex-w32.tar.xz
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
!include LogicLib.nsh
|
|
|
|
!include FileFunc.nsh
|
|
|
|
|
2007-06-28 17:00:30 +00:00
|
|
|
#--------------------------------
|
2008-04-06 16:35:00 +00:00
|
|
|
# Settings
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
Caption "PDF Viewer"
|
2015-05-21 00:04:41 +00:00
|
|
|
OutFile pdfview-old.exe
|
2008-04-07 18:35:10 +00:00
|
|
|
Icon "..\packaging\icons\lyx.ico"
|
2007-02-08 21:09:30 +00:00
|
|
|
SilentInstall silent
|
|
|
|
|
2007-06-28 17:00:30 +00:00
|
|
|
#--------------------------------
|
2012-11-20 00:07:08 +00:00
|
|
|
# Windows Vista (and later) settings
|
2007-06-28 17:00:30 +00:00
|
|
|
|
|
|
|
RequestExecutionLevel user
|
|
|
|
|
|
|
|
#--------------------------------
|
2008-04-06 16:35:00 +00:00
|
|
|
# Constants
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
!define FALSE 0
|
|
|
|
!define TRUE 1
|
|
|
|
|
2012-11-20 20:58:44 +00:00
|
|
|
# see http://msdn.microsoft.com/en-us/library/windows/desktop/aa364417%28v=vs.85%29.aspx
|
2008-04-06 16:35:00 +00:00
|
|
|
!define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
|
2012-11-20 20:58:44 +00:00
|
|
|
# see http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx
|
2008-04-06 16:35:00 +00:00
|
|
|
!define WAIT_TIMEOUT 0x00000102
|
|
|
|
|
2007-06-28 17:00:30 +00:00
|
|
|
#--------------------------------
|
2008-04-06 16:35:00 +00:00
|
|
|
# Variables
|
|
|
|
|
|
|
|
Var Character
|
|
|
|
Var RunAppReturn
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
Var OriginalFile
|
|
|
|
Var OriginalFileName
|
2008-04-06 16:35:00 +00:00
|
|
|
Var OriginalDir
|
|
|
|
|
2007-02-08 21:09:30 +00:00
|
|
|
Var PDFFile
|
2009-08-21 22:31:06 +00:00
|
|
|
Var ViewerFileName
|
2007-02-08 21:09:30 +00:00
|
|
|
Var Viewer
|
2008-04-06 16:35:00 +00:00
|
|
|
|
|
|
|
Var ChangeNotification
|
|
|
|
Var WaitReturn
|
|
|
|
Var LockedFile
|
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
Var TimeDiff
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2007-06-28 17:00:30 +00:00
|
|
|
#--------------------------------
|
2008-04-06 16:35:00 +00:00
|
|
|
# Macros
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
!macro SystemCall STACK
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Call a Windows API function
|
|
|
|
|
2007-02-08 21:09:30 +00:00
|
|
|
Push `${STACK}`
|
|
|
|
CallInstDLL "$EXEDIR\System.dll" Call
|
|
|
|
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
!macro HideConsole COMMAND_LINE
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Run an application and hide console output
|
|
|
|
|
2007-02-08 21:09:30 +00:00
|
|
|
Push `${COMMAND_LINE}`
|
|
|
|
CallInstDLL "$EXEDIR\Console.dll" Exec
|
2008-04-06 16:35:00 +00:00
|
|
|
Pop $RunAppReturn
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${If} $RunAppReturn == "error"
|
|
|
|
MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $PDFFile."
|
|
|
|
${EndIf}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
!macroend
|
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# all following macros and functions are from
|
|
|
|
# http://nsis.sourceforge.net/FileTimeDiff
|
|
|
|
!define GetFileTimeS "!insertmacro _GetFileTimeS"
|
|
|
|
|
|
|
|
!macro _GetFileTimeS _Time_ _File_
|
|
|
|
|
|
|
|
Push "${_File_}"
|
|
|
|
Call GetFileTimeS
|
|
|
|
Pop ${_Time_}
|
|
|
|
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
Function GetFileTimeS
|
|
|
|
|
2012-12-31 17:34:49 +00:00
|
|
|
Exch $0 # File / hi
|
|
|
|
Push $1 # lo
|
2012-11-20 00:07:08 +00:00
|
|
|
|
|
|
|
ClearErrors
|
|
|
|
GetFileTime "$0" $0 $1
|
|
|
|
IfErrors err
|
|
|
|
System::Call '*(i r1, i r0) i .r0'
|
|
|
|
System::Call '*$0(l .r0)'
|
2012-12-31 17:34:49 +00:00
|
|
|
System::Int64Op $0 / 10000000 # Conversion From '100 ns' to '1 sec' unit
|
2012-11-20 00:07:08 +00:00
|
|
|
Goto end
|
|
|
|
|
|
|
|
err:
|
|
|
|
Push ""
|
|
|
|
SetErrors
|
|
|
|
Goto +3
|
|
|
|
end:
|
|
|
|
System::Free $0
|
|
|
|
Exch 2
|
|
|
|
Pop $0
|
|
|
|
Pop $1
|
|
|
|
|
|
|
|
FunctionEnd
|
|
|
|
|
|
|
|
!define FileTimeDiff "!insertmacro _FileTimeDiff"
|
|
|
|
|
|
|
|
!macro _FileTimeDiff _RetVal_ _FileA_ _FileB_
|
|
|
|
|
|
|
|
Push "${_FileB_}"
|
|
|
|
Push "${_FileA_}"
|
|
|
|
Call FileTimeDiff
|
|
|
|
Pop ${_RetVal_}
|
|
|
|
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
Function FileTimeDiff
|
2012-12-31 17:34:49 +00:00
|
|
|
Exch $0 # FileA
|
2012-11-20 00:07:08 +00:00
|
|
|
Exch
|
2012-12-31 17:34:49 +00:00
|
|
|
Exch $1 # FileB
|
2012-11-20 00:07:08 +00:00
|
|
|
|
|
|
|
${GetFileTimeS} $0 "$0"
|
|
|
|
IfErrors err
|
|
|
|
${GetFileTimeS} $1 "$1"
|
|
|
|
IfErrors err
|
|
|
|
System::Int64Op $0 - $1
|
|
|
|
Goto end
|
|
|
|
|
|
|
|
err:
|
|
|
|
Push ""
|
|
|
|
SetErrors
|
|
|
|
end:
|
|
|
|
Exch 2
|
|
|
|
Pop $0
|
|
|
|
Pop $1
|
|
|
|
|
|
|
|
FunctionEnd
|
|
|
|
|
2007-06-28 17:00:30 +00:00
|
|
|
#--------------------------------
|
2008-04-23 01:33:21 +00:00
|
|
|
# PDF viewing
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
Section "View PDF file"
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
InitPluginsDir # Temporary directory for PDF file
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Command line parameters
|
|
|
|
${GetParameters} $OriginalFile
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Trim quotes
|
|
|
|
StrCpy $Character $OriginalFile 1
|
|
|
|
${If} $Character == '"'
|
2007-02-08 21:09:30 +00:00
|
|
|
StrCpy $OriginalFile $OriginalFile "" 1
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
|
|
|
StrCpy $Character $OriginalFile 1 -1
|
|
|
|
${If} $Character == '"'
|
2007-02-08 21:09:30 +00:00
|
|
|
StrCpy $OriginalFile $OriginalFile -1
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
GetFullPathName $OriginalFile $OriginalFile
|
2008-04-06 16:35:00 +00:00
|
|
|
${GetFileName} $OriginalFile $OriginalFileName
|
2008-04-24 10:51:56 +00:00
|
|
|
${GetParent} $OriginalFile $OriginalDir # tmpbuf
|
|
|
|
${GetParent} $OriginalDir $OriginalDir # tmpdir
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
SetOutPath $TEMP # The LyX tmpbuf should not be locked
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Check whether the file will be opened with Adobe Reader or Adobe Acrobat
|
|
|
|
!insertmacro SystemCall "shell32::FindExecutable(t '$OriginalFile', t '', t .s)"
|
2009-08-21 22:31:06 +00:00
|
|
|
Pop $ViewerFileName
|
|
|
|
${GetFileName} $ViewerFileName $Viewer
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${If} $Viewer == ""
|
2007-02-08 21:09:30 +00:00
|
|
|
MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
|
|
|
|
Please install a PDF viewer such as Adobe Reader."
|
|
|
|
Quit
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${If} $Viewer == "AcroRd32.exe"
|
2012-11-20 00:07:08 +00:00
|
|
|
${OrIf} $Viewer == "Acrobat.exe"
|
2012-11-20 20:58:44 +00:00
|
|
|
|
|
|
|
# get the version of Acrobat - currenly not necessary
|
|
|
|
#GetDLLVersion $ViewerFileName $R0 $R1
|
|
|
|
#IntOp $R2 $R0 >> 16
|
|
|
|
#IntOp $R2 $R2 & 0x0000FFFF ; $R2 now contains major version
|
|
|
|
#IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
|
|
|
|
#IntOp $R4 $R1 >> 16
|
|
|
|
#IntOp $R4 $R4 & 0x0000FFFF ; $R4 now contains release
|
|
|
|
#IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
|
|
|
|
#StrCpy $ViewerVersion "$R2"
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Close existing view
|
|
|
|
${If} ${FileExists} $PDFFile
|
2012-11-20 00:07:08 +00:00
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Copy PDF to temporary file to allow LyX to overwrite the original
|
2007-02-08 21:09:30 +00:00
|
|
|
CopyFiles /SILENT $OriginalFile $PDFFile
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Open a new view
|
2012-11-20 00:07:08 +00:00
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --file "$PDFFile"'
|
|
|
|
|
|
|
|
# check if a file in LyX's temp folder has been changed
|
2008-04-06 16:35:00 +00:00
|
|
|
!insertmacro SystemCall "kernel32::FindFirstChangeNotification(t '$OriginalDir', \
|
2008-04-24 10:51:56 +00:00
|
|
|
i 1, i ${FILE_NOTIFY_CHANGE_LAST_WRITE}) i.s"
|
2008-04-06 16:35:00 +00:00
|
|
|
Pop $ChangeNotification
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${Do}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# wait until the folder is not changed anymore, if so a "0" is returned
|
|
|
|
# otherwise a "258" (0x00000102) is returned
|
2008-04-06 16:35:00 +00:00
|
|
|
!insertmacro SystemCall "kernel32::WaitForSingleObject(i $ChangeNotification, i 10000) i.s"
|
2008-04-23 20:40:46 +00:00
|
|
|
Pop $WaitReturn
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# Check whether the lock of the PDF file is still active (if not, Adobe Reader is closed)
|
2008-04-06 16:35:00 +00:00
|
|
|
FileOpen $LockedFile $PDFFile a
|
|
|
|
${If} $LockedFile != ""
|
|
|
|
# Quit this application
|
|
|
|
FileClose $LockedFile
|
2007-02-08 21:09:30 +00:00
|
|
|
Delete $PDFFile
|
2008-04-06 16:35:00 +00:00
|
|
|
!insertmacro SystemCall "kernel32::FindCloseChangeNotification(i $ChangeNotification)"
|
2007-02-08 21:09:30 +00:00
|
|
|
Quit
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# if the folder is (for now) not changed anymore
|
2008-04-06 16:35:00 +00:00
|
|
|
${IfNot} $WaitReturn = ${WAIT_TIMEOUT}
|
2012-11-20 00:07:08 +00:00
|
|
|
|
|
|
|
# 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"
|
2008-04-24 10:51:56 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# if the file is older than 1 second
|
|
|
|
${If} $TimeDiff < -1
|
|
|
|
# close the PDF
|
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
|
2008-04-06 16:35:00 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# 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
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
# open the new file
|
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --file "$PDFFile"'
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
|
|
|
|
|
|
|
#Monitor again
|
|
|
|
!insertmacro SystemCall "kernel32::FindNextChangeNotification(i $ChangeNotification)"
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2012-11-20 00:07:08 +00:00
|
|
|
${EndIf} # end ifnot
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${Loop}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${Else}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
# Another PDF viewer like GSView is used
|
|
|
|
# No need for special actions, just forward to ShellExecute
|
2007-02-08 21:09:30 +00:00
|
|
|
ExecShell open $OriginalFile
|
|
|
|
|
2008-04-06 16:35:00 +00:00
|
|
|
${EndIf}
|
2007-02-08 21:09:30 +00:00
|
|
|
|
|
|
|
SectionEnd
|