]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/detection.nsh
Change windows installer comments from ; to #
[features.git] / development / Win32 / packaging / installer / include / detection.nsh
1 /*
2
3 Detection functions for all components
4
5 */
6
7 #--------------------------------
8 #Macros
9
10 !macro SearchMiKTeX25
11
12   #Detect location of MiKTeX installation using initexmf
13   
14   Push $R0
15   
16   nsExec::ExecToStack "initexmf.exe --report"
17   Pop $R0 ;Return value
18   Pop $R0 ;Output
19   
20   ${WordFind2X} $R0 "BinDir: " "$\r" "+1" $PathLaTeX
21   
22   Pop $R0
23
24 !macroend
25
26 !macro SearchMiKTeX24 ROOTKEY
27
28   ReadRegStr $PathLaTeX ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
29   
30   ${if} $PathLaTeX != ""
31     !insertmacro callfunc TrimBackslash $PathLaTeX $PathLaTeX ;Just in case it's installed in a root directory
32     StrCpy $PathLaTeX "$PathLaTeX\miktex\bin"
33   ${endif}
34   
35 !macroend
36
37 !macro IfKeyExists ROOT MAIN_KEY KEY
38
39   Push $R0
40   Push $R1
41  
42   !define Index 'Line${__LINE__}'
43  
44   StrCpy $R1 0
45  
46   "${Index}-Loop:"
47   #Check for key
48   EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1"
49   StrCmp $R0 "" "${Index}-False"
50   IntOp $R1 $R1 + 1
51   StrCmp $R0 "${KEY}" "${Index}-True" "${Index}-Loop"
52  
53   "${Index}-True:"
54   #Found
55   Push ${TRUE}
56   Goto "${Index}-End"
57  
58   "${Index}-False:"
59   #Not found
60   Push ${FALSE}
61   goto "${Index}-End"
62  
63   "${Index}-End:"
64   !undef Index
65   
66   Exch 2
67   Pop $R0
68   Pop $R1
69
70 !macroend
71
72 #--------------------------------
73 #Functions
74
75 Function SearchAll
76
77   Call SearchLaTeX
78   Call SearchGhostscript
79   Call SearchImageMagick
80   
81   IfSilent +2
82     Call SearchViewer
83
84 FunctionEnd
85
86 Function TrimBackslash
87
88   #Trim a trailing backslash of a directory
89
90   Exch $R0
91   Push $R1
92   
93   StrCpy $R1 $R0 1 -1
94   
95   ${if} $R1 == "\"
96     StrLen $R1 $R0
97     IntOp $R1 $R1 - 1
98     StrCpy $R0 $R0 $R1
99   ${endif}
100   
101   Pop $R1
102   Exch $R0
103   
104 FunctionEnd
105
106 Function GetPathPrefix
107
108   Push $R0
109
110   StrCpy $R0 "$INSTDIR\bin;$INSTDIR\python"
111   
112   ${if} $PathLaTeX != ""
113     StrCpy $R0 "$R0;$PathLaTeX"
114   ${endif}
115   
116   ${if} $PathGhostscript != ""
117     StrCpy $R0 "$R0;$PathGhostscript"
118   ${endif}
119   
120   ${if} $PathImageMagick != ""
121     StrCpy $R0 "$R0;$PathImageMagick"
122   ${endif}
123   
124   Exch $R0
125   
126 FunctionEnd
127
128 Function SearchViewer
129
130   Push $R0
131   Push $R1
132
133   !insertmacro CallFunc DetectViewerByExtension "pdf" $R0
134   !insertmacro CallFunc DetectViewerByExtension "ps" $R1
135
136   StrCpy $PathViewer ""
137   
138   ${if} $R0 != ""
139     ${if} $R1 != ""
140       StrCpy $PathViewer "associated"
141     ${endif}      
142   ${endif}
143   
144   Pop $R1
145   Pop $R0
146   
147 FunctionEnd  
148
149 Function DetectViewerByExtension
150
151   #Input on stack: file extension without dot
152
153   Exch $R0
154   Push $R1
155   Push $R2
156   
157   InitPluginsDir
158   
159   StrCpy $R1 "$PLUGINSDIR\ViewerDetect.$R0"
160   FileOpen $R2 $R1 w
161   FileClose $R2
162   
163   StrCpy $R0 ""
164
165   System::Call "shell32::FindExecutableA(t R1, n, t .R0)"
166   
167   Delete $R1
168   
169   Pop $R2
170   Pop $R1
171   Exch $R0
172   
173 FunctionEnd
174
175 Function SearchLaTeX
176
177   #Search where MikTeX is installed
178   
179   !insertmacro SearchMiKTeX25
180   
181   ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
182     !insertmacro SearchMiKTeX24 HKCU
183   ${endif}
184
185   ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
186     !insertmacro SearchMiKTeX24 HKLM
187   ${endif}
188
189   ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
190     StrCpy $PathLatex ""
191   ${endif}
192
193 FunctionEnd
194
195 Function SearchLaTeXLocalRoot
196
197   #Search for the MikTeX local root
198   #Returns value on stack
199
200   Push $R0
201   
202   #MikTeX 2.5
203   
204   !insertmacro IfKeyExists HKCU "Software\MiKTeX.org\MiKTeX" "2.5"
205   Pop $R0
206   
207   ${if} $R0 == ${FALSE}
208     !insertmacro IfKeyExists HKLM "Software\MiKTeX.org\MiKTeX" "2.5"
209     Pop $R0
210   ${endif}
211   
212   ${if} $R0 == ${TRUE}
213     StrCpy $R0 "$APPDATA\MiKTeX\2.5"
214   ${else}
215   
216     #MiKTeX 2.4
217     
218     ReadRegStr $R0 HKCU "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root"
219     
220     ${unless} ${FileExists} $R0
221       ReadRegStr $R0 HKLM "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root"
222     ${endif}
223     
224   ${endif}
225   
226   Exch $R0
227
228 FunctionEnd
229
230 Function SearchGhostscript
231
232   #Search where Ghostscript is installed
233   
234   Push $R0 ;Temp
235   Push $R1 ;Counter
236   Push $R2 ;Enum return
237   Push $R3 ;AFPL version
238   Push $R4 ;GPL version
239
240   StrCpy $R3 ""
241   StrCpy $R4 ""
242
243   #Check the latest version of AFPL Ghostscript installed
244   
245   StrCpy $R1 0
246   
247   ${do}
248   
249     EnumRegKey $R2 HKLM "Software\AFPL Ghostscript" $R1
250     
251     ${if} $R2 != ""
252       ${VersionCompare} $R2 $R3 $R0
253       ${if} $R0 == "1"
254         StrCpy $R3 $R2
255       ${endif}
256       IntOp $R1 $R1 + 1
257     ${endif}
258     
259   ${loopuntil} $R2 == ""
260     
261   #The same for GPL Ghostscript
262     
263   StrCpy $R1 0
264   
265   ${do}
266
267     EnumRegKey $R2 HKLM "Software\GPL Ghostscript" $R1
268     
269     ${if} $R2 != ""
270       ${VersionCompare} $R2 $R4 $R0
271       ${if} $R0 == "1"
272         StrCpy $R4 $R2
273       ${endif}
274       IntOp $R1 $R1 + 1
275     ${endif}    
276   
277   ${loopuntil} $R2 == ""  
278   
279   #Take the latest one
280   ${VersionCompare} $R3 $R4 $R0
281
282   ${if} $R0 == "1"
283     #AFPL is newer
284     ReadRegStr $PathGhostscript HKLM "Software\AFPL Ghostscript\$R3" "GS_DLL"
285   ${else}
286     #GPL is newer or equal
287     ReadRegStr $PathGhostscript HKLM "Software\GPL Ghostscript\$R4" "GS_DLL"
288   ${endif}
289   
290   #Trim the DLL filename to get the path
291   ${GetParent} $PathGhostscript $PathGhostscript
292   
293   ${unless} ${FileExists} "$PathGhostscript\${BIN_GHOSTSCRIPT}"
294     StrCpy $PathGhostscript ""  
295   ${endif}
296     
297   Pop $R4
298   Pop $R3
299   Pop $R2
300   Pop $R1
301   Pop $R0
302   
303 FunctionEnd
304
305 Function SearchImageMagick
306
307   #Search where ImageMagick is installed
308   ReadRegStr $PathImageMagick HKLM "Software\ImageMagick\Current" "BinPath"
309   
310   ${unless} ${FileExists} "$PathImageMagick\${BIN_IMAGEMAGICK}"
311     StrCpy $PathImageMagick ""  
312   ${endif}
313
314 FunctionEnd