/* Detection functions for all components */ ;-------------------------------- ;Macros !macro SearchMiKTeX rootkey ReadRegStr $PathLaTeX ${rootkey} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root" ${if} $PathLaTeX != "" !insertmacro callfunc TrimBackslash $PathLaTeX $PathLaTeX ;Just in case it's installed in a root directory StrCpy $PathLaTeX "$PathLaTeX\miktex\bin" ${endif} !macroend ;-------------------------------- ;Functions Function SearchAll Call SearchLaTeX Call SearchGhostscript Call SearchImageMagick IfSilent +2 Call SearchViewer FunctionEnd Function TrimBackslash ;Trim a trailing backslash of a directory Exch $R0 Push $R1 StrCpy $R1 $R0 1 -1 ${if} $R1 == "\" StrLen $R1 $R0 IntOp $R1 $R1 - 1 StrCpy $R0 $R0 $R1 ${endif} Pop $R1 Exch $R0 FunctionEnd Function GetPathPrefix Push $R0 StrCpy $R0 "$INSTDIR\latextools;$INSTDIR\python;$INSTDIR\shell\bin" ${if} $PathLaTeX != "" StrCpy $R0 "$R0;$PathLaTeX" ${endif} ${if} $PathGhostscript != "" StrCpy $R0 "$R0;$PathGhostscript" ${endif} ${if} $PathImageMagick != "" StrCpy $R0 "$R0;$PathImageMagick" ${endif} Exch $R0 FunctionEnd Function SearchViewer Push $R0 Push $R1 !insertmacro CallFunc DetectViewerByExtension "pdf" $R0 !insertmacro CallFunc DetectViewerByExtension "ps" $R1 StrCpy $PathViewer "" ${if} $R0 != "" ${if} $R1 != "" StrCpy $PathViewer "associated" ${endif} ${endif} Pop $R1 Pop $R0 FunctionEnd Function DetectViewerByExtension ;Input on stack: file extension without dot Exch $R0 Push $R1 Push $R2 InitPluginsDir StrCpy $R1 "$PLUGINSDIR\ViewerDetect.$R0" FileOpen $R2 $R1 w FileClose $R2 StrCpy $R0 "" System::Call "shell32::FindExecutableA(t R1, n, t .R0)" Delete $R1 Pop $R2 Pop $R1 Exch $R0 FunctionEnd Function SearchLaTeX ;Search where MikTeX is installed ;Current user !insertmacro SearchMiKTeX HKCU ;All users ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}" !insertmacro SearchMiKTeX HKLM ${endif} ${unless} ${FileExists} "$PathLaTeX\${BIN_LATEX}" StrCpy $PathLatex "" ${endif} FunctionEnd Function SearchLaTeXLocalRoot ;Search for the MikTeX local root (localtexmf) ;Returns value on stack Push $R0 ;Current user ReadRegStr $R0 HKCU "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root" ;All users ${unless} ${FileExists} $R0 ReadRegStr $R0 HKLM "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root" ${endif} Exch $R0 FunctionEnd Function SearchGhostscript ;Search where Ghostscript is installed Push $R0 ;Temp Push $R1 ;Counter Push $R2 ;Enum return Push $R3 ;AFPL version Push $R4 ;GPL version StrCpy $R3 "" StrCpy $R4 "" ;Check the latest version of AFPL Ghostscript installed StrCpy $R1 0 ${do} EnumRegKey $R2 HKLM "Software\AFPL Ghostscript" $R1 ${if} $R2 != "" ${VersionCompare} $R2 $R3 $R0 ${if} $R0 == "1" StrCpy $R3 $R2 ${endif} IntOp $R1 $R1 + 1 ${endif} ${loopuntil} $R2 == "" ;The same for GPL Ghostscript StrCpy $R1 0 ${do} EnumRegKey $R2 HKLM "Software\GPL Ghostscript" $R1 ${if} $R2 != "" ${VersionCompare} $R2 $R4 $R0 ${if} $R0 == "1" StrCpy $R4 $R2 ${endif} IntOp $R1 $R1 + 1 ${endif} ${loopuntil} $R2 == "" ;Take the latest one ${VersionCompare} $R3 $R4 $R0 ${if} $R0 == "1" ;AFPL is newer ReadRegStr $PathGhostscript HKLM "Software\AFPL Ghostscript\$R3" "GS_DLL" ${else} ;GPL is newer or equal ReadRegStr $PathGhostscript HKLM "Software\GPL Ghostscript\$R4" "GS_DLL" ${endif} ;Trim the DLL filename to get the path ${GetParent} $PathGhostscript $PathGhostscript ${unless} ${FileExists} "$PathGhostscript\${BIN_GHOSTSCRIPT}" StrCpy $PathGhostscript "" ${endif} Pop $R4 Pop $R3 Pop $R2 Pop $R1 Pop $R0 FunctionEnd Function SearchImageMagick ;Search where ImageMagick is installed ReadRegStr $PathImageMagick HKLM "Software\ImageMagick\Current" "BinPath" ${unless} ${FileExists} "$PathImageMagick\${BIN_IMAGEMAGICK}" StrCpy $PathImageMagick "" ${endif} FunctionEnd