lyx_mirror/development/Win32/pdfview/pdfview.nsi
Joost Verburg 9961524a85 New Windows PDF view helper application. It is now possible to keep Adobe Reader open without file locking problems.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@15552 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-25 20:58:23 +00:00

159 lines
3.6 KiB
Plaintext

/*
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
OutFile pdfview.exe
Icon "..\packaging\icons\lyx_32x32.ico"
SilentInstall silent
;--------------------------------
;Constants
!define FALSE 0
!define TRUE 1
;--------------------------------
;Variables
Var Dummy
Var FileName
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}`
CallInstDLL "$EXEDIR\nsExec.dll" Exec
Pop $Dummy
${if} $Dummy == "error"
MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
${endif}
!macroend
;--------------------------------
;PDF vieweing
Section "View PDF file"
;Command line parameters
Call GetParameters
Pop $FileName
;Trim quotes
StrCpy $Dummy $FileName 1
${if} $Dummy == '"'
StrCpy $FileName $FileName "" 1
${endif}
StrCpy $Dummy $FileName 1 -1
${if} $Dummy == '"'
StrCpy $FileName $FileName -1
${endif}
GetFullPathName $FileName $FileName
;Check whether the file will be opened with Adobe Reader or Adobe Acrobat
Push $FileName
!insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
Call GetFileName
Pop $Viewer
${if} $Viewer == "AcroRd32.exe"
${orif} $Viewer == "Acrobat.exe"
;Using Adobe viewer
;Close existing view
${if} ${fileexists} $FileName~
!insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$FileName~"'
${endif}
;Copy PDF to temporary file to allow LyX to overwrite the original
CopyFiles /SILENT $FileName $FileName~
;Open a new view
!insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$FileName~"'
;Monitor for updates of the original file
GetFileTime $FileName $OriginalTimeHigh $OriginalTimeLow
${do}
Sleep 500
FileOpen $Dummy $FileName~ a
${if} $Dummy != ""
;File no longer locked, reader closed
FileClose $Dummy
Delete $FileName~
Quit
${endif}
${unless} ${fileexists} $FileName
;Original no longer exists
Delete $FileName~
Quit
${endif}
GetFileTime $FileName $CurrentTimeHigh $CurrentTimeLow
${if} $OriginalTimeHigh != $CurrentTimeHigh
${orif} $OriginalTimeLow != $CurrentTimeLow
;Original has been modified, update!
StrCpy $OriginalTimeHigh $CurrentTimeHigh
StrCpy $OriginalTimeLow $CurrentTimeLow
!insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$FileName~"'
CopyFiles /SILENT $FileName $FileName~
!insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$FileName~"'
${endif}
${loop}
${else}
;Another PDF viewer like GSView is used
;No need for special actions, just forward to ShellExecute
ExecShell open $FileName
${endif}
SectionEnd