]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/detection.nsh
lots of installer improvements:
[features.git] / development / Win32 / packaging / installer / include / detection.nsh
1 /*
2
3 detection.nsh
4
5 Detection of external component locations
6
7 */
8
9 Function SearchExternal
10   Call SearchLaTeX
11   Call SearchGhostscript
12   Call SearchImageMagick
13 FunctionEnd
14
15 #--------------------------------
16 # MiKTeX
17
18 Var ProcessReturn
19 Var CommandLineOutput
20 Var LastChar
21 Var PathLength
22
23 !macro SEARCH_MIKTEX25
24
25   # Search location of MiKTeX installation using initexmf
26   # Works for version 2.5 and later
27   
28   nsExec::ExecToStack "initexmf.exe --report"
29   Pop $ProcessReturn
30   Pop $CommandLineOutput
31   
32   ${WordFind2X} $CommandLineOutput "BinDir: " "$\r" "+1" $PathLaTeX
33
34 !macroend
35
36 !macro SEARCH_MIKTEX24 ROOTKEY
37
38   ReadRegStr $PathLaTeX ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
39   
40   ${If} $PathLaTeX != ""
41     StrCpy $LastChar $PathLaTeX 1 -1  
42     ${If} $LastChar == "\"
43       # Trim backslash
44       StrLen $PathLength $PathLaTeX
45       IntOp $PathLength $PathLength - 1
46       StrCpy $PathLaTeX $PathLaTeX $PathLength
47     ${EndIf}
48     StrCpy $PathLaTeX "$PathLaTeX\miktex\bin"
49   ${EndIf}
50   
51 !macroend
52
53 Function SearchLaTeX
54
55   # Search where MikTeX is installed
56   
57   !insertmacro SEARCH_MIKTEX25
58   
59   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
60     !insertmacro SEARCH_MIKTEX24 HKCU
61   ${EndIf}
62
63   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
64     !insertmacro SEARCH_MIKTEX24 HKLM
65   ${EndIf}
66
67   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
68     StrCpy $PathLatex ""
69   ${EndIf}
70
71 FunctionEnd
72
73 #--------------------------------
74 # Ghostscript
75
76 Var Counter
77 Var EnumReturn
78 Var CompareReturn
79 Var AFPLVersion
80 Var GPLVersion
81
82 Function SearchGhostscript
83
84   # Search where Ghostscript is installed
85   
86   # Find the latest version of AFPL Ghostscript installed
87   
88   StrCpy $Counter 0
89     
90   ${do}
91   
92     EnumRegKey $EnumReturn HKLM "Software\AFPL Ghostscript" $Counter
93     
94     ${If} $EnumReturn != ""
95       ${VersionCompare} $EnumReturn $AFPLVersion $CompareReturn
96       ${If} $CompareReturn == "1"
97         StrCpy $AFPLVersion $EnumReturn
98       ${EndIf}
99       IntOp $Counter $Counter + 1
100     ${EndIf}
101     
102   ${loopuntil} $EnumReturn == ""
103     
104   # The same for GPL Ghostscript
105     
106   StrCpy $Counter 0
107   
108   ${do}
109
110     EnumRegKey $EnumReturn HKLM "Software\GPL Ghostscript" $Counter
111     
112     ${If} $EnumReturn != ""
113       ${VersionCompare} $EnumReturn $GPLVersion $CompareReturn
114       ${If} $CompareReturn == "1"
115         StrCpy $GPLVersion $EnumReturn
116       ${EndIf}
117       IntOp $Counter $Counter + 1
118     ${EndIf}
119   
120   ${loopuntil} $EnumReturn == ""  
121   
122   # Take the latest one
123   ${VersionCompare} $AFPLVersion $GPLVersion $CompareReturn
124
125   ${If} $CompareReturn = 1
126     # AFPL is newer
127     ReadRegStr $PathGhostscript HKLM "Software\AFPL Ghostscript\$R3" "GS_DLL"
128   ${Else}
129     # GPL is newer or equal
130     ReadRegStr $PathGhostscript HKLM "Software\GPL Ghostscript\$R4" "GS_DLL"
131   ${EndIf}
132   
133   # Trim the DLL filename to get the path
134   ${GetParent} $PathGhostscript $PathGhostscript
135   
136   ${IfNot} ${FileExists} "$PathGhostscript\${BIN_GHOSTSCRIPT}"
137     StrCpy $PathGhostscript ""  
138   ${EndIf}
139   
140 FunctionEnd
141
142 #--------------------------------
143 # ImageMagick
144
145 Function SearchImageMagick
146
147   # Search where ImageMagick is installed
148   ReadRegStr $PathImageMagick HKLM "Software\ImageMagick\Current" "BinPath"
149   
150   ${IfNot} ${FileExists} "$PathImageMagick\${BIN_IMAGEMAGICK}"
151     StrCpy $PathImageMagick ""  
152   ${EndIf}
153
154 FunctionEnd