using System; using System.Collections.Generic; using System.Linq; using System.Text; using Component.All; using Microsoft.Win32; namespace Component.Binary.Java { public class InstallComponent : IInstallComponent , ISetup { #region IInstallComponent Members /// /// Get the Component bound to this IInstallComponent /// /// public ComponentConfig.Component GetComponent() { return Common.EmbeddedConfig.BinaryComponents.GetComponent("Java"); } /// /// We only want to install Java if an earlier version is installed /// /// true, if an earlier version or none is installed, false otherwise public bool BEFORE_INSTALLING_COMPONENT() { // If we get here, just in case always just install the java version // to make sure everything works as expected //string Version = GetLatestJavaVersionFromTheRegistry(); //if (!String.IsNullOrEmpty(Version)) //{ // int nCompare = String.Compare(Version, GetComponent().Version); // if (nCompare < 0) // return true; // else // return false; //} return true; } /// /// Installs Java on the system /// /// Returns true if the Component installs, false otherwise public bool INSTALL_COMPONENT() { Common.PSetupSpwan(GetComponent().TempFileNamesNPath[0], "/s /v \"/qn ADDLOCAL=ALL IEXPLORER=1 REBOOT=Supress\""); return true; } /// /// Make sure that the version in the registry matches the component /// /// true, if the version in the registry matches what we installed, false otherwise public bool AFTER_INSTALLING_COMPONENT() { string Version = GetLatestJavaVersionFromTheRegistry(); if (!String.IsNullOrEmpty(Version)) { int nCompare = String.Compare(GetComponent().Version, Version); if (nCompare != 0) return false; else return true; } return false; } /// /// Check to see, if this component supports uninstalling /// /// true, if uninstall is supported, false otherwise public bool SUPPORTS_UNINSTALL() { return true; } /// /// Check if we can uninstall the java version /// /// true, if version is installed, false otherwise public bool BEFORE_UNINSTALLING_COMPONENT() { string[] Versions = GetAllJavaVersionFromTheRegistry(); if (Versions != null && Versions.Length > 0) { if (Versions.Contains(GetComponent().Version)) return true; } return false; } /// /// Uninstalls Java on the system /// /// Returns true if the Component installs, false otherwise public bool UNINSTALL_COMPONENT() { Common.PSetupSpwan(GetComponent().TempFileNamesNPath[0], "/s /v \"/qn REBOOT=Supress\" /x"); return true; } /// /// Check to make sure that the version we uninstalled doesn't exist anymore /// /// true if version was removed, false otherwise public bool AFTER_UNINSTALLING_COMPONENT() { string[] Versions = GetAllJavaVersionFromTheRegistry(); if (Versions != null && Versions.Length > 0) { if (Versions.Contains(GetComponent().Version)) return false; } return true; } #endregion #region ISetup Members public void ComponentLoaded(ref SetupEvents subscribeToDesiredEvents) { subscribeToDesiredEvents.Before_Install += new SetupEvents.SetupEvent(subscribeToDesiredEvents_Before_Install); subscribeToDesiredEvents.After_Install += new SetupEvents.SetupEvent(subscribeToDesiredEvents_After_Install); } void subscribeToDesiredEvents_Before_Install() { } void subscribeToDesiredEvents_After_Install() { } #endregion #region Private Helpers /// /// Use this function to check the java version in the registry /// /// The Java Version found in the registry or String.Empty, if not found string GetLatestJavaVersionFromTheRegistry() { string[] Versions = GetAllJavaVersionFromTheRegistry(); if (Versions != null && Versions.Length > 0) { string strVersion = Versions[Versions.Length - 1]; if (!String.IsNullOrEmpty(strVersion)) return strVersion; } return String.Empty; } /// /// Use this function to check all the java versions in the registry /// /// The Java Versions found in the registry or null, if none found string[] GetAllJavaVersionFromTheRegistry() { bool bIsJavaInstalled = false; try { RegistryKey reg = Registry.LocalMachine.OpenSubKey("Software\\JavaSoft\\Java Plug-in", false); bIsJavaInstalled = (reg != null); if(reg == null) reg = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\JavaSoft\\Java Plug-in", false); bIsJavaInstalled = (reg != null); if (bIsJavaInstalled) { string[] SubKeys = reg.GetSubKeyNames(); if (SubKeys != null && SubKeys.Length > 0) return SubKeys; } } catch (Exception) { /* ignore */ } return null; } #endregion } }