altosui: Make Windows java test "smarter"
authorKeith Packard <keithp@keithp.com>
Thu, 26 Jun 2014 23:29:37 +0000 (16:29 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 18 Aug 2014 04:01:16 +0000 (21:01 -0700)
Or at least have it try more options, and then finally ask the user
before downloading and installing java

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/Instdrv/NSIS/Includes/java.nsh
altosui/Makefile.am

index ebf1c5b96071223146a54f441ed021ecd1884557..cd47c1b53337ff5205256dae4d05c872d7f12f7f 100644 (file)
@@ -32,19 +32,135 @@ Function GetJRE
         Delete $2
 FunctionEnd
 
-Function DetectJRE
+Function DoDetectJRE
+
+  DetailPrint "Desired Java version ${JRE_VERSION}"
+
+  ; Check in HKCU for CurrentVersion
+
+  ClearErrors
+  ReadRegStr $2 HKCU "SOFTWARE\JavaSoft\Java Runtime Environment" \
+             "CurrentVersion"
+
+  IfErrors hklm_version
+
+  DetailPrint "HKEY_CURRENT_USER Java version $2"
+
+  ${VersionCompare} $2 ${JRE_VERSION} $3
+
+  IntCmp $3 1 yes yes no
+
+hklm_version:
+
+  ; Check in HKLM for CurrentVersion
+
+  ClearErrors
   ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" \
              "CurrentVersion"
+  
+  IfErrors hkcu_any
 
-  DetailPrint "Desired Java version ${JRE_VERSION}"
-  DetailPrint "Actual Java version $2"
+  DetailPrint "HKEY_LOCAL_MACHINE Java version $2"
 
   ${VersionCompare} $2 ${JRE_VERSION} $3
 
-  IntCmp $3 1 done done
+  IntCmp $3 1 yes yes no
 
-  Call GetJRE
+hkcu_any:
+
+  ; Check in HKCU for any Java install
+
+  StrCpy $0 0
+
+hkcu_any_loop:
+  EnumRegKey $1 HKCU "SOFTWARE\JavaSoft" $0
+
+  StrCmp $1 "Java Runtime Environment" found_hkcu
+
+  StrCmp $1 "" hklm_any
+  
+  IntOp $0 $0 + 1
+
+  Goto hkcu_any_loop
+  
+found_hkcu:
+
+  DetailPrint "HKEY_CURRENT_USER has SOFTWARE\JavaSoft\$1"
+
+  Goto maybe
+
+hklm_any:
+
+  ; Check in HKCU for any Java install
+
+  StrCpy $0 0
+
+hklm_any_loop:
+  EnumRegKey $1 HKLM "SOFTWARE\JavaSoft" $0
+
+  StrCmp $1 "Java Runtime Environment" found_hklm
+
+  StrCmp $1 "" no
+  
+  IntOp $0 $0 + 1
+
+  Goto hklm_any_loop
+  
+found_hklm:
+
+  DetailPrint "HKEY_CURRENT_USER has SOFTWARE\JavaSoft\$1"
+
+  Goto maybe
+
+yes:
+  StrCpy $0 2
+  Goto done
+
+maybe:
+  StrCpy $0 1
+  Goto done
+
+no:
+  StrCpy $0 0
+  Goto done  
 
 done:
 
 FunctionEnd
+
+var dialog
+var hwnd
+var null
+
+var install
+var quit
+var skip
+
+Function DetectJRE
+
+  Call DoDetectJRE
+
+  IntCmp $0 1 ask_maybe ask_no yes
+
+ask_no:
+  StrCpy $0 "No Java detected. Download and install?"
+  Goto ask
+
+ask_maybe:
+  StrCpy $0 "Cannot determine installed Java version. Download and install?"
+  Goto ask
+
+ask:
+  MessageBox MB_YESNOCANCEL $0 IDYES do_java IDNO skip_java
+
+bail:
+  Abort
+
+do_java:
+  Call GetJRE
+
+
+skip_java:
+yes:
+
+FunctionEnd
index 44258fd2eb19a7a3911a13defefab9d3e4312fd5..77be164082d93a5b2b23e5b0163600dd77eae46a 100644 (file)
@@ -354,6 +354,6 @@ $(MACOSX_DIST): $(MACOSX_FILES) $(MACOSX_EXTRA) Makefile
        cp -p $(MACOSX_EXTRA) macosx/AltOS-$(VERSION)
        genisoimage -D -V AltOS-$(VERSION) -no-pad -r -apple -o $@ macosx
 
-$(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi
+$(WINDOWS_DIST): $(WINDOWS_FILES) altos-windows.nsi Instdrv/NSIS/Includes/java.nsh
        -rm -f $@
        makensis -Oaltos-windows.log "-XOutFile $@" "-DVERSION=$(VERSION)" altos-windows.nsi || (cat altos-windows.log && exit 1)