altosui: Make Windows java test "smarter"
[fw/altos] / altosui / Instdrv / NSIS / Includes / java.nsh
1 !include WordFunc.nsh
2
3 ; Definitions for Java Detection
4
5 !define JRE_VERSION "1.6"
6 !define JRE32_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52247&/jre-6u27-windows-i586.exe"
7 !define JRE64_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52249&/jre-6u27-windows-x64.exe"
8
9 Var JavaDownload
10 Var JavaBits
11
12 Function GetJRE
13         ${If} ${RunningX64}
14            StrCpy $JavaDownload ${JRE64_URL}
15            StrCpy $JavaBits "64"
16         ${Else}
17            StrCpy $JavaDownload ${JRE32_URL}
18            StrCpy $JavaBits "32"
19         ${EndIf}
20
21         MessageBox MB_OK "This product uses Java ${JRE_VERSION}, \
22                         $JavaBits bits, it will now \
23                         be downloaded and installed"
24
25         StrCpy $2 "$TEMP\Java Runtime Environment.exe"
26         nsisdl::download /TIMEOUT=30000 $JavaDownload $2
27         Pop $R0 ;Get the return value
28                 StrCmp $R0 "success" +3
29                 MessageBox MB_OK "Download failed: $R0"
30                 Quit
31         ExecWait $2
32         Delete $2
33 FunctionEnd
34
35 Function DoDetectJRE
36
37   DetailPrint "Desired Java version ${JRE_VERSION}"
38
39   ; Check in HKCU for CurrentVersion
40
41   ClearErrors
42   ReadRegStr $2 HKCU "SOFTWARE\JavaSoft\Java Runtime Environment" \
43              "CurrentVersion"
44
45   IfErrors hklm_version
46
47   DetailPrint "HKEY_CURRENT_USER Java version $2"
48
49   ${VersionCompare} $2 ${JRE_VERSION} $3
50
51   IntCmp $3 1 yes yes no
52
53 hklm_version:
54
55   ; Check in HKLM for CurrentVersion
56
57   ClearErrors
58   ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \
59              "CurrentVersion"
60   
61   IfErrors hkcu_any
62
63   DetailPrint "HKEY_LOCAL_MACHINE Java version $2"
64
65   ${VersionCompare} $2 ${JRE_VERSION} $3
66
67   IntCmp $3 1 yes yes no
68
69 hkcu_any:
70
71   ; Check in HKCU for any Java install
72
73   StrCpy $0 0
74
75 hkcu_any_loop:
76   EnumRegKey $1 HKCU "SOFTWARE\JavaSoft" $0
77
78   StrCmp $1 "Java Runtime Environment" found_hkcu
79
80   StrCmp $1 "" hklm_any
81   
82   IntOp $0 $0 + 1
83
84   Goto hkcu_any_loop
85   
86 found_hkcu:
87
88   DetailPrint "HKEY_CURRENT_USER has SOFTWARE\JavaSoft\$1"
89
90   Goto maybe
91
92 hklm_any:
93
94   ; Check in HKCU for any Java install
95
96   StrCpy $0 0
97
98 hklm_any_loop:
99   EnumRegKey $1 HKLM "SOFTWARE\JavaSoft" $0
100
101   StrCmp $1 "Java Runtime Environment" found_hklm
102
103   StrCmp $1 "" no
104   
105   IntOp $0 $0 + 1
106
107   Goto hklm_any_loop
108   
109 found_hklm:
110
111   DetailPrint "HKEY_CURRENT_USER has SOFTWARE\JavaSoft\$1"
112
113   Goto maybe
114
115 yes:
116   StrCpy $0 2
117   Goto done
118
119 maybe:
120   StrCpy $0 1
121   Goto done
122
123 no:
124   StrCpy $0 0
125   Goto done  
126
127 done:
128
129 FunctionEnd
130
131 var dialog
132 var hwnd
133 var null
134
135 var install
136 var quit
137 var skip
138
139 Function DetectJRE
140
141   Call DoDetectJRE
142
143   IntCmp $0 1 ask_maybe ask_no yes
144
145 ask_no:
146   StrCpy $0 "No Java detected. Download and install?"
147   Goto ask
148
149 ask_maybe:
150   StrCpy $0 "Cannot determine installed Java version. Download and install?"
151   Goto ask
152
153 ask:
154   MessageBox MB_YESNOCANCEL $0 IDYES do_java IDNO skip_java
155
156 bail:
157   Abort
158
159 do_java:
160   Call GetJRE
161
162
163 skip_java:
164 yes:
165
166 FunctionEnd