]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/include/detection.nsh
detect JabRef and put in path_prefix (for new menu item to edit BibTeX database)
[lyx.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 SearchBibTeXEditor
12   !ifndef BUNDLE_IMAGEMAGICK
13     Call SearchImageMagick
14   !endif
15   !ifndef BUNDLE_GHOSTSCRIPT
16     Call SearchGhostscript
17   !endif
18 FunctionEnd
19
20 #--------------------------------
21 # MiKTeX
22
23 Var ReportReturn
24 Var CommandLineOutput
25 Var LastChar
26 Var PathLength
27
28 !macro SEARCH_MIKTEX25
29
30   # Search location of MiKTeX installation using initexmf
31   # Works for version 2.5 and later
32   
33   nsExec::ExecToStack "initexmf.exe --report"
34   Pop $ReportReturn
35   Pop $CommandLineOutput
36
37   ${WordFind2X} $CommandLineOutput "BinDir: " "$\r" "+1" $PathLaTeX
38   ${WordFind2X} $CommandLineOutput "CommonData: " "$\r" "+1" $PathLaTeXLocal # Local root  
39
40 !macroend
41
42 !macro SEARCH_MIKTEX24 ROOTKEY
43
44   ReadRegStr $PathLaTeX ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
45   
46   ${If} $PathLaTeX != ""
47     StrCpy $LastChar $PathLaTeX 1 -1
48     
49     ${If} $LastChar == "\"
50       # Trim backslash
51       StrLen $PathLength $PathLaTeX
52       IntOp $PathLength $PathLength - 1
53       StrCpy $PathLaTeX $PathLaTeX $PathLength
54     ${EndIf}
55     
56     StrCpy $PathLaTeX "$PathLaTeX\miktex\bin"
57      
58     #Local root
59     ReadRegStr $PathLaTeXLocal ${ROOTKEY} "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Local Root"
60     
61   ${EndIf}
62    
63 !macroend
64
65 Function SearchLaTeX
66
67   # Search where MikTeX is installed
68   
69   !insertmacro SEARCH_MIKTEX25
70   
71   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
72     !insertmacro SEARCH_MIKTEX24 HKCU
73   ${EndIf}
74
75   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
76     !insertmacro SEARCH_MIKTEX24 HKLM
77   ${EndIf}
78
79   ${IfNot} ${FileExists} "$PathLaTeX\${BIN_LATEX}"
80     StrCpy $PathLateX ""
81   ${EndIf}
82
83 FunctionEnd
84
85 #--------------------------------
86 # Ghostscript
87
88 !ifndef BUNDLE_GHOSTSCRIPT
89
90 !insertmacro GetParent
91 !insertmacro VersionCompare
92
93 Var Counter
94 Var EnumReturn
95 Var CompareReturn
96 Var AFPLVersion
97 Var GPLVersion
98
99 Function SearchGhostscript
100
101   # Search where Ghostscript is installed
102   
103   # Find the latest version of AFPL Ghostscript installed
104   
105   StrCpy $Counter 0
106     
107   ${do}
108   
109     EnumRegKey $EnumReturn HKLM "Software\AFPL Ghostscript" $Counter
110     
111     ${If} $EnumReturn != ""
112       ${VersionCompare} $EnumReturn $AFPLVersion $CompareReturn
113       ${If} $CompareReturn == "1"
114         StrCpy $AFPLVersion $EnumReturn
115       ${EndIf}
116       IntOp $Counter $Counter + 1
117     ${EndIf}
118     
119   ${loopuntil} $EnumReturn == ""
120     
121   # The same for GPL Ghostscript
122     
123   StrCpy $Counter 0
124   
125   ${do}
126
127     EnumRegKey $EnumReturn HKLM "Software\GPL Ghostscript" $Counter
128     
129     ${If} $EnumReturn != ""
130       ${VersionCompare} $EnumReturn $GPLVersion $CompareReturn
131       ${If} $CompareReturn == "1"
132         StrCpy $GPLVersion $EnumReturn
133       ${EndIf}
134       IntOp $Counter $Counter + 1
135     ${EndIf}
136   
137   ${loopuntil} $EnumReturn == ""  
138   
139   # Take the latest one
140   ${VersionCompare} $AFPLVersion $GPLVersion $CompareReturn
141
142   ${If} $CompareReturn = 1
143     # AFPL is newer
144     ReadRegStr $PathGhostscript HKLM "Software\AFPL Ghostscript\$R3" "GS_DLL"
145   ${Else}
146     # GPL is newer or equal
147     ReadRegStr $PathGhostscript HKLM "Software\GPL Ghostscript\$R4" "GS_DLL"
148   ${EndIf}
149   
150   # Trim the DLL filename to get the path
151   ${GetParent} $PathGhostscript $PathGhostscript
152   
153   ${IfNot} ${FileExists} "$PathGhostscript\${BIN_GHOSTSCRIPT}"
154     StrCpy $PathGhostscript ""  
155   ${EndIf}
156   
157 FunctionEnd
158
159 !endif
160
161 #--------------------------------
162 # ImageMagick
163
164 !ifndef BUNDLE_IMAGEMAGICK
165
166 Function SearchImageMagick
167
168   # Search where ImageMagick is installed
169   ReadRegStr $PathImageMagick HKLM "Software\ImageMagick\Current" "BinPath"
170   
171   ${IfNot} ${FileExists} "$PathImageMagick\${BIN_IMAGEMAGICK}"
172     StrCpy $PathImageMagick ""  
173   ${EndIf}
174
175 FunctionEnd
176
177 !endif
178
179 #--------------------------------
180 # JabRef
181
182 Function SearchBibTeXEditor
183
184   # Search where JabRef is installed
185   ReadRegStr $PathBibTeXEditor HKCU "Software\JabRef" "Path"
186
187   ${IfNot} ${FileExists} "$PathBibTeXEditor\${BIN_BIBTEXEDITOR}"
188     ReadRegStr $PathBibTeXEditor HKLM "Software\JabRef" "Path"
189   ${EndIf}
190
191   ${IfNot} ${FileExists} "$PathBibTeXEditor\${BIN_BIBTEXEDITOR}"
192     StrCpy $PathBibTeXEditor ""  
193   ${EndIf}
194
195 FunctionEnd