]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/detection.nsh
locate local MiKTeX root and install dvipost
[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 ReportReturn
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 $ReportReturn
30   Pop $CommandLineOutput
31
32   ${WordFind2X} $CommandLineOutput "BinDir: " "$\r" "+1" $PathLaTeX
33   ${WordFind2X} $CommandLineOutput "CommonData: " "$\r" "+1" $PathLaTeXLocal # Local root  
34
35 !macroend
36
37 !macro SEARCH_MIKTEX24 ROOTKEY
38
39   ReadRegStr $PathLaTeX ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
40   
41   ${If} $PathLaTeX != ""
42     StrCpy $LastChar $PathLaTeX 1 -1
43     
44     ${If} $LastChar == "\"
45       # Trim backslash
46       StrLen $PathLength $PathLaTeX
47       IntOp $PathLength $PathLength - 1
48       StrCpy $PathLaTeX $PathLaTeX $PathLength
49     ${EndIf}
50     
51     StrCpy $PathLaTeX "$PathLaTeX\miktex\bin"
52      
53     #Local root
54     ReadRegStr $PathLaTeXLocal ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root"
55     
56   ${EndIf}
57    
58 !macroend
59
60 Function SearchLaTeX
61
62   # Search where MikTeX is installed
63   
64   !insertmacro SEARCH_MIKTEX25
65   
66   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
67     !insertmacro SEARCH_MIKTEX24 HKCU
68   ${EndIf}
69
70   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
71     !insertmacro SEARCH_MIKTEX24 HKLM
72   ${EndIf}
73
74   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
75     StrCpy $PathLateX ""
76   ${EndIf}
77
78 FunctionEnd
79
80 #--------------------------------
81 # Ghostscript
82
83 Var Counter
84 Var EnumReturn
85 Var CompareReturn
86 Var AFPLVersion
87 Var GPLVersion
88
89 Function SearchGhostscript
90
91   # Search where Ghostscript is installed
92   
93   # Find the latest version of AFPL Ghostscript installed
94   
95   StrCpy $Counter 0
96     
97   ${do}
98   
99     EnumRegKey $EnumReturn HKLM "Software\AFPL Ghostscript" $Counter
100     
101     ${If} $EnumReturn != ""
102       ${VersionCompare} $EnumReturn $AFPLVersion $CompareReturn
103       ${If} $CompareReturn == "1"
104         StrCpy $AFPLVersion $EnumReturn
105       ${EndIf}
106       IntOp $Counter $Counter + 1
107     ${EndIf}
108     
109   ${loopuntil} $EnumReturn == ""
110     
111   # The same for GPL Ghostscript
112     
113   StrCpy $Counter 0
114   
115   ${do}
116
117     EnumRegKey $EnumReturn HKLM "Software\GPL Ghostscript" $Counter
118     
119     ${If} $EnumReturn != ""
120       ${VersionCompare} $EnumReturn $GPLVersion $CompareReturn
121       ${If} $CompareReturn == "1"
122         StrCpy $GPLVersion $EnumReturn
123       ${EndIf}
124       IntOp $Counter $Counter + 1
125     ${EndIf}
126   
127   ${loopuntil} $EnumReturn == ""  
128   
129   # Take the latest one
130   ${VersionCompare} $AFPLVersion $GPLVersion $CompareReturn
131
132   ${If} $CompareReturn = 1
133     # AFPL is newer
134     ReadRegStr $PathGhostscript HKLM "Software\AFPL Ghostscript\$R3" "GS_DLL"
135   ${Else}
136     # GPL is newer or equal
137     ReadRegStr $PathGhostscript HKLM "Software\GPL Ghostscript\$R4" "GS_DLL"
138   ${EndIf}
139   
140   # Trim the DLL filename to get the path
141   ${GetParent} $PathGhostscript $PathGhostscript
142   
143   ${IfNot} ${FileExists} "$PathGhostscript\${BIN_GHOSTSCRIPT}"
144     StrCpy $PathGhostscript ""  
145   ${EndIf}
146   
147 FunctionEnd
148
149 #--------------------------------
150 # ImageMagick
151
152 Function SearchImageMagick
153
154   # Search where ImageMagick is installed
155   ReadRegStr $PathImageMagick HKLM "Software\ImageMagick\Current" "BinPath"
156   
157   ${IfNot} ${FileExists} "$PathImageMagick\${BIN_IMAGEMAGICK}"
158     StrCpy $PathImageMagick ""  
159   ${EndIf}
160
161 FunctionEnd