/** * Get the default path for Windows (i.e Program Files/...). Windows has a Setting for this in the * environment and in the registry. Just try to use the setting in the environment. If it fails * for whatever reason, we take the former solution (buildWindowsDefaultPathFromProps). * * @return The Windows default installation path for applications. */ private String buildWindowsDefaultPath() { try { // get value from environment... String prgFilesPath = IoHelper.getenv("ProgramFiles"); if (prgFilesPath != null && prgFilesPath.length() > 0) { return prgFilesPath; } else { return buildWindowsDefaultPathFromProps(); } } catch (Exception x) { x.printStackTrace(); return buildWindowsDefaultPathFromProps(); } }
/** * Loads the installation data. Also sets environment variables to <code>installdata</code>. All * system properties are available as $SYSTEM_<variable> where <variable> is the actual name _BUT_ * with all separators replaced by '_'. Properties with null values are never stored. Example: * $SYSTEM_java_version or $SYSTEM_os_name * * @param installdata Where to store the installation data. * @throws Exception Description of the Exception */ public void loadInstallData(AutomatedInstallData installdata) throws Exception { // Usefull variables InputStream in; ObjectInputStream objIn; int size; int i; // We load the variables Properties variables = null; in = InstallerBase.class.getResourceAsStream("/vars"); if (null != in) { objIn = new ObjectInputStream(in); variables = (Properties) objIn.readObject(); objIn.close(); } // We load the Info data in = InstallerBase.class.getResourceAsStream("/info"); objIn = new ObjectInputStream(in); Info inf = (Info) objIn.readObject(); objIn.close(); // We put the Info data as variables installdata.setVariable(ScriptParser.APP_NAME, inf.getAppName()); if (inf.getAppURL() != null) { installdata.setVariable(ScriptParser.APP_URL, inf.getAppURL()); } installdata.setVariable(ScriptParser.APP_VER, inf.getAppVersion()); if (inf.getUninstallerCondition() != null) { installdata.setVariable("UNINSTALLER_CONDITION", inf.getUninstallerCondition()); } // We read the panels order data in = InstallerBase.class.getResourceAsStream("/panelsOrder"); objIn = new ObjectInputStream(in); List panelsOrder = (List) objIn.readObject(); objIn.close(); // We read the packs data in = InstallerBase.class.getResourceAsStream("/packs.info"); objIn = new ObjectInputStream(in); size = objIn.readInt(); ArrayList availablePacks = new ArrayList(); ArrayList<Pack> allPacks = new ArrayList<Pack>(); for (i = 0; i < size; i++) { Pack pk = (Pack) objIn.readObject(); allPacks.add(pk); if (OsConstraint.oneMatchesCurrentSystem(pk.osConstraints)) { availablePacks.add(pk); } } objIn.close(); // We determine the operating system and the initial installation path String dir; String installPath; if (OsVersion.IS_WINDOWS) { dir = buildWindowsDefaultPath(); } else if (OsVersion.IS_OSX) { dir = "/Applications"; } else { if (new File("/usr/local/").canWrite()) { dir = "/usr/local"; } else { dir = System.getProperty("user.home"); } } // We determine the hostname and IPAdress String hostname; String IPAddress; try { InetAddress addr = InetAddress.getLocalHost(); // Get IP Address IPAddress = addr.getHostAddress(); // Get hostname hostname = addr.getHostName(); } catch (Exception e) { hostname = ""; IPAddress = ""; } installdata.setVariable("APPLICATIONS_DEFAULT_ROOT", dir); dir += File.separator; installdata.setVariable(ScriptParser.JAVA_HOME, System.getProperty("java.home")); installdata.setVariable(ScriptParser.CLASS_PATH, System.getProperty("java.class.path")); installdata.setVariable(ScriptParser.USER_HOME, System.getProperty("user.home")); installdata.setVariable(ScriptParser.USER_NAME, System.getProperty("user.name")); installdata.setVariable(ScriptParser.IP_ADDRESS, IPAddress); installdata.setVariable(ScriptParser.HOST_NAME, hostname); installdata.setVariable(ScriptParser.FILE_SEPARATOR, File.separator); Enumeration e = System.getProperties().keys(); while (e.hasMoreElements()) { String varName = (String) e.nextElement(); String varValue = System.getProperty(varName); if (varValue != null) { varName = varName.replace('.', '_'); installdata.setVariable("SYSTEM_" + varName, varValue); } } if (null != variables) { Enumeration enumeration = variables.keys(); String varName; String varValue; while (enumeration.hasMoreElements()) { varName = (String) enumeration.nextElement(); varValue = variables.getProperty(varName); installdata.setVariable(varName, varValue); } } installdata.info = inf; installdata.panelsOrder = panelsOrder; installdata.availablePacks = availablePacks; installdata.allPacks = allPacks; // get list of preselected packs Iterator pack_it = availablePacks.iterator(); while (pack_it.hasNext()) { Pack pack = (Pack) pack_it.next(); if (pack.preselected) { installdata.selectedPacks.add(pack); } } // Set the installation path in a default manner installPath = dir + inf.getAppName(); if (inf.getInstallationSubPath() != null) { // A subpath was defined, use it. installPath = IoHelper.translatePath( dir + inf.getInstallationSubPath(), new VariableSubstitutor(installdata.getVariables())); } installdata.setInstallPath(installPath); // Load custom action data. loadCustomData(installdata); }