; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.

[Aktionen]
requiredWinstVersion >= "4.10.3"
Message "installing Java Virtual Machine Sun 1.6 ..."
DefVar $ExitCode$
DefVar $INST_MsVersion$
DefVar $INST_SystemType$
DefVar $INST_architecture$
DefVar $JAVA32_16EXE$
DefVar $JAVA32_16VER$
DefVar $JAVA64_16EXE$
DefVar $JAVA64_16VER$
DefVar $UninstallCommand$
DefVar $DisplayName$
DefVar $InstallPlugins$
DefVar $MySystemRoot$

DefStringlist $INST_MsVersionMap$

Set $INST_SystemType$ = GetSystemType
set $INST_MsVersion$ = GetMsVersionInfo
set $INST_MsVersionMap$ = GetMSVersionMap
set $INST_architecture$ = GetProductProperty("install_architecture","system specific")
set $MySystemRoot$ = "%"+"systemroot"+"%"

set $JAVA32_16EXE$="jre-6u20-windows-i586-s.exe"
set $JAVA32_16VER$="jre1.6.0_20"
set $JAVA64_16EXE$="jre-6u20-windows-x64.exe"
set $JAVA64_16VER$="jre1.6.0_20"
set $InstallPlugins$ = "IEXPLORER=1 MOZILLA=1"

if not(HasMinimumSpace ("%SYSTEMDRIVE%", "200 MB"))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for Java 1.6"
	isFatalError
	; Stop process and set installation status to failed
endif

if $INST_MsVersion$ < "5.0"
	LogError "Minimum Windows 2000 is required for Java 1.6" 
	isFatalError
endif

ShowBitmap "%scriptpath%\java.png" "SUN Java VM"

if FileExists("%ScriptPath%\subdeljava.ins") 
	comment "start uninstall"
	sub "%ScriptPath%\subdeljava.ins"
endif

comment "installing"

if (($INST_SystemType$ = "x86 System") and ($INST_architecture$ = "system specific")) or ($INST_architecture$ = "both") or ($INST_architecture$ = "32 only")
	if ($INST_MsVersion$ = "6.0") and ("1" < getValue("product_type_nr",$INST_MsVersionMap$)) and ($INST_SystemType$ = "64 Bit System")
		LogWarning "silent installation on 2008x64 doesn't works at the moment"
	else
		Message "Installing Sun "+$JAVA32_16VER$+ " 32 Bit..."
		if $INST_SystemType$ = "64 Bit System"
			comment "registry hack for silent install 32 bit on 64 Bit Systems"
			; see http://www.myitforum.com/forums/tm.aspx?high=&m=215451&mpage=1#215451
			Registry_redirect_64_profile_image_to_32 /64bit
		endif
		Winbatch_sun_1_6_silent_install_32
		if $INST_SystemType$ = "64 Bit System"
			comment "registry hack for silent install 32 bit on 64 Bit Systems"
			Registry_redirect_64_profile_image_to_64 /64bit
		endif
		Sub_check_exitcode
		comment "disable auto updater"
		; see http://wpkg.org/Java
		Winbatch_sun_1_6_silent_disable_update
		;Sub_check_exitcode
		Registry_disable_update
	endif
endif ; 32 Bit

if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
	Message "Installing Sun "+$JAVA64_16VER$+ " 64 Bit..."
	Winbatch_sun_1_6_silent_install_64
	Sub_check_exitcode
	comment "disable auto updater"
	; see http://wpkg.org/Java
	Registry_disable_update /64Bit
endif ; 64 Bit


; custom specific stuff
if FileExists("%ScriptPath%\custom_ins_dir\custom.ins")
	sub "%ScriptPath%\custom_ins_dir\custom.ins"
endif


[Sub_check_exitcode]
comment "Test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
	comment "Looks good: setup program gives exitcode zero"
else
	comment "Setup program gives a exitcode unequal zero: " + $ExitCode$
	if ($ExitCode$ = "1605")
		comment "ERROR_UNKNOWN_PRODUCT	1605	This action is only valid for products that are currently installed."
		comment "Uninstall of a not installed product failed - no problem"
	else
		if ($ExitCode$ = "1641")
			comment "looks good: setup program gives exitcode 1641"
			comment "ERROR_SUCCESS_REBOOT_INITIATED	1641	The installer has initiated a restart. This message is indicative of a success."
		else
			if ($ExitCode$ = "3010")
				comment "looks good: setup program gives exitcode 3010"
				comment "ERROR_SUCCESS_REBOOT_REQUIRED	3010	A restart is required to complete the install. This message is indicative of a success."
			else
				logError "Fatal: Setup program gives an unknown exitcode unequal zero: " + $ExitCode$
				isFatalError
			endif
		endif
	endif
endif

[winbatch_start_taskmgr]
taskmgr.exe

[Winbatch_sun_1_6_silent_disable_update]
msiexec /x {4A03706F-666A-4037-7777-5F2748764D10} /qb-!

[Registry_redirect_64_profile_image_to_32]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18]
set "ProfileImagePath"=REG_EXPAND_SZ:"$MySystemRoot$\syswow64\config\systemprofile"

[Registry_redirect_64_profile_image_to_64]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18]
set "ProfileImagePath"=REG_EXPAND_SZ:"$MySystemRoot$\config\systemprofile"

[Registry_disable_update]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Update\Policy]
set "EnableJavaUpdate"=REG_DWORD:0

[Winbatch_sun_1_6_silent_install_32]
%SCRIPTPATH%\$JAVA32_16EXE$ /s /v"/qb-! /lie c:\tmp\$JAVA32_16VER$.log ADDLOCAL=ALL $InstallPlugins$  REBOOT=ReallySuppess SYSTRAY=0 JAVAUPDATE=0 JU=0 AUTOUPDATECHECK=0 ARPURLUPDATEINFO='http://www.opsi.org'"

[Winbatch_sun_1_6_silent_install_64]
%SCRIPTPATH%\$JAVA64_16EXE$ /s /v"/qb-! /lie c:\tmp\$JAVA32_16VER$.log ADDLOCAL=ALL $InstallPlugins$  REBOOT=ReallySuppess SYSTRAY=0 JAVAUPDATE=0 JU=0 AUTOUPDATECHECK=0 ARPURLUPDATEINFO='http://www.opsi.org'"

[Winbatch_sun_uninstall]
$UninstallCommand$

