2006-10-25 20:58:23 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Windows PDF view helper
|
|
|
|
Author: Joost Verburg
|
|
|
|
|
|
|
|
This will be installed as pdfview.exe.
|
|
|
|
|
|
|
|
The application will launch the default PDF viewer to display the PDF file,
|
|
|
|
but works around the file locking problems of Adobe Reader.
|
|
|
|
|
|
|
|
Source code of pdfopen/pdfclose is available at:
|
|
|
|
http://magic.aladdin.cs.cmu.edu/2005/07/15/pdfopen-and-pdfclose/
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
!include "LogicLib.nsh"
|
|
|
|
!include "FileFunc.nsh"
|
|
|
|
!insertmacro GetParameters
|
|
|
|
!insertmacro GetFileName
|
|
|
|
|
|
|
|
;--------------------------------
|
|
|
|
;Settings
|
|
|
|
|
2006-11-06 21:48:00 +00:00
|
|
|
Caption "PDF Viewer"
|
2006-10-25 20:58:23 +00:00
|
|
|
OutFile pdfview.exe
|
|
|
|
Icon "..\packaging\icons\lyx_32x32.ico"
|
|
|
|
SilentInstall silent
|
|
|
|
|
2007-06-28 17:05:08 +00:00
|
|
|
;--------------------------------
|
|
|
|
;Windows Vista settings
|
|
|
|
|
|
|
|
RequestExecutionLevel user
|
|
|
|
|
2006-10-25 20:58:23 +00:00
|
|
|
;--------------------------------
|
|
|
|
;Constants
|
|
|
|
|
|
|
|
!define FALSE 0
|
|
|
|
!define TRUE 1
|
|
|
|
|
|
|
|
;--------------------------------
|
|
|
|
;Variables
|
|
|
|
|
|
|
|
Var Dummy
|
2006-11-04 23:05:32 +00:00
|
|
|
Var OriginalFile
|
|
|
|
Var OriginalFileName
|
|
|
|
Var PDFFile
|
2006-10-25 20:58:23 +00:00
|
|
|
Var Viewer
|
|
|
|
Var OriginalTimeHigh
|
|
|
|
Var OriginalTimeLow
|
|
|
|
Var CurrentTimeHigh
|
|
|
|
Var CurrentTimeLow
|
|
|
|
|
|
|
|
;--------------------------------
|
|
|
|
;Macros
|
|
|
|
|
|
|
|
!macro SystemCall STACK
|
|
|
|
|
|
|
|
Push `${STACK}`
|
|
|
|
CallInstDLL "$EXEDIR\System.dll" Call
|
|
|
|
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
!macro HideConsole COMMAND_LINE
|
|
|
|
|
|
|
|
Push `${COMMAND_LINE}`
|
2006-11-06 21:48:00 +00:00
|
|
|
CallInstDLL "$EXEDIR\Console.dll" Exec
|
2006-10-25 20:58:23 +00:00
|
|
|
Pop $Dummy
|
|
|
|
|
|
|
|
${if} $Dummy == "error"
|
|
|
|
MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
|
|
|
|
${endif}
|
|
|
|
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
;--------------------------------
|
|
|
|
;PDF vieweing
|
|
|
|
|
|
|
|
Section "View PDF file"
|
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
InitPluginsDir ;Temporary directory for PDF file
|
|
|
|
|
2006-10-25 20:58:23 +00:00
|
|
|
;Command line parameters
|
|
|
|
Call GetParameters
|
2006-11-04 23:05:32 +00:00
|
|
|
Pop $OriginalFile
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
;Trim quotes
|
2006-11-04 23:05:32 +00:00
|
|
|
StrCpy $Dummy $OriginalFile 1
|
2006-10-25 20:58:23 +00:00
|
|
|
${if} $Dummy == '"'
|
2006-11-04 23:05:32 +00:00
|
|
|
StrCpy $OriginalFile $OriginalFile "" 1
|
2006-10-25 20:58:23 +00:00
|
|
|
${endif}
|
2006-11-04 23:05:32 +00:00
|
|
|
StrCpy $Dummy $OriginalFile 1 -1
|
2006-10-25 20:58:23 +00:00
|
|
|
${if} $Dummy == '"'
|
2006-11-04 23:05:32 +00:00
|
|
|
StrCpy $OriginalFile $OriginalFile -1
|
2006-10-25 20:58:23 +00:00
|
|
|
${endif}
|
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
GetFullPathName $OriginalFile $OriginalFile
|
|
|
|
Push $OriginalFile
|
|
|
|
Call GetFileName
|
|
|
|
Pop $OriginalFileName
|
|
|
|
|
|
|
|
SetOutPath $TEMP ;The LyX tmpbuf should not be locked
|
|
|
|
|
|
|
|
StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
;Check whether the file will be opened with Adobe Reader or Adobe Acrobat
|
2006-11-04 23:05:32 +00:00
|
|
|
Push $OriginalFile
|
2006-10-25 20:58:23 +00:00
|
|
|
!insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
|
|
|
|
Call GetFileName
|
|
|
|
Pop $Viewer
|
2006-11-06 21:48:00 +00:00
|
|
|
|
|
|
|
${if} $Viewer == ""
|
|
|
|
MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
|
|
|
|
Please install a PDF viewer such as Adobe Reader."
|
|
|
|
Quit
|
|
|
|
${endif}
|
|
|
|
|
2006-10-25 20:58:23 +00:00
|
|
|
${if} $Viewer == "AcroRd32.exe"
|
|
|
|
${orif} $Viewer == "Acrobat.exe"
|
|
|
|
|
|
|
|
;Using Adobe viewer
|
|
|
|
|
|
|
|
;Close existing view
|
2006-11-04 23:05:32 +00:00
|
|
|
${if} ${fileexists} $PDFFile
|
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
|
2006-10-25 20:58:23 +00:00
|
|
|
${endif}
|
|
|
|
|
|
|
|
;Copy PDF to temporary file to allow LyX to overwrite the original
|
2006-11-04 23:05:32 +00:00
|
|
|
CopyFiles /SILENT $OriginalFile $PDFFile
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
;Open a new view
|
2006-11-04 23:05:32 +00:00
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
;Monitor for updates of the original file
|
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
${do}
|
|
|
|
|
|
|
|
Sleep 500
|
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
FileOpen $Dummy $PDFFile a
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
${if} $Dummy != ""
|
|
|
|
;File no longer locked, reader closed
|
|
|
|
FileClose $Dummy
|
2006-11-04 23:05:32 +00:00
|
|
|
Delete $PDFFile
|
2006-10-25 20:58:23 +00:00
|
|
|
Quit
|
|
|
|
${endif}
|
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
${if} ${fileexists} $OriginalFile
|
2006-10-25 20:58:23 +00:00
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
|
2006-10-25 20:58:23 +00:00
|
|
|
|
2006-11-04 23:05:32 +00:00
|
|
|
${if} $OriginalTimeHigh != $CurrentTimeHigh
|
|
|
|
${orif} $OriginalTimeLow != $CurrentTimeLow
|
|
|
|
|
|
|
|
;Original has been modified, update!
|
|
|
|
|
|
|
|
StrCpy $OriginalTimeHigh $CurrentTimeHigh
|
|
|
|
StrCpy $OriginalTimeLow $CurrentTimeLow
|
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
|
|
|
|
CopyFiles /SILENT $OriginalFile $PDFFile
|
|
|
|
!insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
|
|
|
|
|
|
|
|
${endif}
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
${endif}
|
|
|
|
|
|
|
|
${loop}
|
|
|
|
|
|
|
|
${else}
|
|
|
|
|
|
|
|
;Another PDF viewer like GSView is used
|
|
|
|
;No need for special actions, just forward to ShellExecute
|
2006-11-04 23:05:32 +00:00
|
|
|
ExecShell open $OriginalFile
|
2006-10-25 20:58:23 +00:00
|
|
|
|
|
|
|
${endif}
|
|
|
|
|
|
|
|
SectionEnd
|