]> git.lyx.org Git - lyx.git/blob - development/Win32/pdfview/pdfview.nsi
Increase the file format, now every \\begin_deeper has a corresponding \\end_deeper.
[lyx.git] / development / Win32 / pdfview / pdfview.nsi
1 /*
2
3 Windows PDF view helper
4 Author: Joost Verburg
5
6 This will be installed as pdfview.exe.
7
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.
10
11 Source code of pdfopen/pdfclose is available at:
12 http://magic.aladdin.cs.cmu.edu/2005/07/15/pdfopen-and-pdfclose/
13
14 */
15
16 !include "LogicLib.nsh"
17 !include "FileFunc.nsh"
18 !insertmacro GetParameters
19 !insertmacro GetFileName
20
21 #--------------------------------
22 #Settings
23
24 Caption "PDF Viewer"
25 OutFile pdfview.exe
26 Icon "..\packaging\icons\lyx_32x32.ico"
27 SilentInstall silent
28
29 #--------------------------------
30 #Windows Vista settings
31
32 RequestExecutionLevel user
33
34 #--------------------------------
35 #Constants
36
37 !define FALSE 0
38 !define TRUE 1
39
40 #--------------------------------
41 #Variables
42
43 Var Dummy
44 Var OriginalFile
45 Var OriginalFileName
46 Var PDFFile
47 Var Viewer
48 Var OriginalTimeHigh
49 Var OriginalTimeLow
50 Var CurrentTimeHigh
51 Var CurrentTimeLow
52
53 #--------------------------------
54 #Macros
55
56 !macro SystemCall STACK
57
58   Push `${STACK}`
59   CallInstDLL "$EXEDIR\System.dll" Call
60
61 !macroend
62
63 !macro HideConsole COMMAND_LINE
64
65   Push `${COMMAND_LINE}`
66   CallInstDLL "$EXEDIR\Console.dll" Exec
67   Pop $Dummy
68   
69   ${if} $Dummy == "error"
70     MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $R0."
71   ${endif}
72
73 !macroend
74
75 #--------------------------------
76 #PDF vieweing
77
78 Section "View PDF file"
79
80   InitPluginsDir #Temporary directory for PDF file
81
82   #Command line parameters
83   Call GetParameters
84   Pop $OriginalFile
85
86   #Trim quotes
87   StrCpy $Dummy $OriginalFile 1
88   ${if} $Dummy == '"'
89     StrCpy $OriginalFile $OriginalFile "" 1
90   ${endif}
91   StrCpy $Dummy $OriginalFile 1 -1
92   ${if} $Dummy == '"'
93     StrCpy $OriginalFile $OriginalFile -1
94   ${endif}
95
96   GetFullPathName $OriginalFile $OriginalFile
97   Push $OriginalFile
98   Call GetFileName
99   Pop $OriginalFileName
100
101   SetOutPath $TEMP #The LyX tmpbuf should not be locked
102
103   StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
104
105   #Check whether the file will be opened with Adobe Reader or Adobe Acrobat
106   Push $OriginalFile
107   !insertmacro SystemCall "shell32::FindExecutable(t s, t '', t .s)"
108   Call GetFileName
109   Pop $Viewer
110
111   ${if} $Viewer == ""
112     MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
113         Please install a PDF viewer such as Adobe Reader."
114     Quit        
115   ${endif}
116
117   ${if} $Viewer == "AcroRd32.exe"
118     ${orif} $Viewer == "Acrobat.exe"
119     
120     #Using Adobe viewer
121     
122     #Close existing view
123     ${if} ${fileexists} $PDFFile
124       !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
125     ${endif}
126     
127     #Copy PDF to temporary file to allow LyX to overwrite the original
128     CopyFiles /SILENT $OriginalFile $PDFFile
129     
130     #Open a new view
131     !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
132     
133     #Monitor for updates of the original file
134     
135     GetFileTime $OriginalFile $OriginalTimeHigh $OriginalTimeLow
136     
137     ${do}
138     
139       Sleep 500
140       
141       FileOpen $Dummy $PDFFile a
142       
143       ${if} $Dummy != ""
144         #File no longer locked, reader closed
145         FileClose $Dummy
146         Delete $PDFFile
147         Quit
148       ${endif}
149       
150       ${if} ${fileexists} $OriginalFile
151         
152         GetFileTime $OriginalFile $CurrentTimeHigh $CurrentTimeLow
153         
154         ${if} $OriginalTimeHigh != $CurrentTimeHigh
155           ${orif} $OriginalTimeLow != $CurrentTimeLow
156           
157           #Original has been modified, update!
158           
159           StrCpy $OriginalTimeHigh $CurrentTimeHigh
160           StrCpy $OriginalTimeLow  $CurrentTimeLow
161           !insertmacro HideConsole '"$EXEDIR\pdfclose.exe" --file "$PDFFile"'
162           CopyFiles /SILENT $OriginalFile $PDFFile
163           !insertmacro HideConsole '"$EXEDIR\pdfopen.exe" --back --file "$PDFFile"'
164           
165         ${endif}
166         
167       ${endif}
168     
169     ${loop}
170     
171   ${else}
172   
173     #Another PDF viewer like GSView is used
174     #No need for special actions, just forward to ShellExecute
175     ExecShell open $OriginalFile
176     
177   ${endif}
178     
179 SectionEnd