3 Detection functions for all components
7 ;--------------------------------
12 ;Detect location of MiKTeX installation using initexmf
16 nsExec::ExecToStack "initexmf.exe --report"
20 ${WordFind2X} $R0 "BinDir: " "$\r" "+1" $PathLaTeX
26 !macro SearchMiKTeX24 ROOTKEY
28 ReadRegStr $PathLaTeX ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
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"
37 !macro IfKeyExists ROOT MAIN_KEY KEY
42 !define Index 'Line${__LINE__}'
48 EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1"
49 StrCmp $R0 "" "${Index}-False"
51 StrCmp $R0 "${KEY}" "${Index}-True" "${Index}-Loop"
72 ;--------------------------------
78 Call SearchGhostscript
79 Call SearchImageMagick
86 Function TrimBackslash
88 ;Trim a trailing backslash of a directory
106 Function GetPathPrefix
110 StrCpy $R0 "$INSTDIR\bin;$INSTDIR\python"
112 ${if} $PathLaTeX != ""
113 StrCpy $R0 "$R0;$PathLaTeX"
116 ${if} $PathGhostscript != ""
117 StrCpy $R0 "$R0;$PathGhostscript"
120 ${if} $PathImageMagick != ""
121 StrCpy $R0 "$R0;$PathImageMagick"
128 Function SearchViewer
133 !insertmacro CallFunc DetectViewerByExtension "pdf" $R0
134 !insertmacro CallFunc DetectViewerByExtension "ps" $R1
136 StrCpy $PathViewer ""
140 StrCpy $PathViewer "associated"
149 Function DetectViewerByExtension
151 ;Input on stack: file extension without dot
159 StrCpy $R1 "$PLUGINSDIR\ViewerDetect.$R0"
165 System::Call "shell32::FindExecutableA(t R1, n, t .R0)"
177 ;Search where MikTeX is installed
179 !insertmacro SearchMiKTeX25
181 ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
182 !insertmacro SearchMiKTeX24 HKCU
185 ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
186 !insertmacro SearchMiKTeX24 HKLM
189 ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
195 Function SearchLaTeXLocalRoot
197 ;Search for the MikTeX local root
198 ;Returns value on stack
204 !insertmacro IfKeyExists HKCU "Software\MiKTeX.org\MiKTeX" "2.5"
207 ${if} $R0 == ${FALSE}
208 !insertmacro IfKeyExists HKLM "Software\MiKTeX.org\MiKTeX" "2.5"
213 StrCpy $R0 "$APPDATA\MiKTeX\2.5"
218 ReadRegStr $R0 HKCU "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root"
220 ${unless} ${FileExists} $R0
221 ReadRegStr $R0 HKLM "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root"
230 Function SearchGhostscript
232 ;Search where Ghostscript is installed
236 Push $R2 ;Enum return
237 Push $R3 ;AFPL version
238 Push $R4 ;GPL version
243 ;Check the latest version of AFPL Ghostscript installed
249 EnumRegKey $R2 HKLM "Software\AFPL Ghostscript" $R1
252 ${VersionCompare} $R2 $R3 $R0
259 ${loopuntil} $R2 == ""
261 ;The same for GPL Ghostscript
267 EnumRegKey $R2 HKLM "Software\GPL Ghostscript" $R1
270 ${VersionCompare} $R2 $R4 $R0
277 ${loopuntil} $R2 == ""
280 ${VersionCompare} $R3 $R4 $R0
284 ReadRegStr $PathGhostscript HKLM "Software\AFPL Ghostscript\$R3" "GS_DLL"
286 ;GPL is newer or equal
287 ReadRegStr $PathGhostscript HKLM "Software\GPL Ghostscript\$R4" "GS_DLL"
290 ;Trim the DLL filename to get the path
291 ${GetParent} $PathGhostscript $PathGhostscript
293 ${unless} ${FileExists} "$PathGhostscript\${BIN_GHOSTSCRIPT}"
294 StrCpy $PathGhostscript ""
305 Function SearchImageMagick
307 ;Search where ImageMagick is installed
308 ReadRegStr $PathImageMagick HKLM "Software\ImageMagick\Current" "BinPath"
310 ${unless} ${FileExists} "$PathImageMagick\${BIN_IMAGEMAGICK}"
311 StrCpy $PathImageMagick ""