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