Example #1
0
  /** Does install of JRE */
  public static void install() {

    // Hide the JNLP Clients installer window and show own
    Config.getInstallService().hideStatusWindow();
    showInstallerWindow();

    // Make sure the destination exists.
    String path = Config.getInstallService().getInstallPath();
    if (Config.isWindowsInstall()) {
      String defaultLocation = "C:\\Program Files\\Java\\j2re" + Config.getJavaVersion() + "\\";
      File defaultDir = new File(defaultLocation);
      if (!defaultDir.exists()) {
        defaultDir.mkdirs();
      }
      if (defaultDir.exists() && defaultDir.canWrite()) {
        path = defaultLocation; // use default if you can
      }
    }

    File installDir = new File(path);

    if (!installDir.exists()) {
      installDir.mkdirs();
      if (!installDir.exists()) {
        // The installFailed string is only for debugging. No localization needed
        installFailed("couldntCreateDirectory", null);
        return;
      }
    }

    // Show license if neccesary
    enableStep(STEP_LICENSE);
    if (!showLicensing()) {
      // The installFailed string is only for debugging. No localization needed
      installFailed("Licensing was not accepted", null);
    }
    ;

    // Make sure that the data JAR is downloaded
    enableStep(STEP_DOWNLOAD);
    if (!downloadInstallerComponent()) {
      // The installFailed string is only for debugging. No localization needed
      installFailed("Unable to download data component", null);
    }

    String nativeLibName = Config.getNativeLibName();
    File installerFile = null;

    try {
      // Load native library into process if found
      if (nativeLibName != null && !Config.isSolarisInstall()) {
        System.loadLibrary(nativeLibName);
      }

      // Unpack installer
      enableStep(STEP_UNPACK);
      String installResource = Config.getInstallerResource();
      Config.trace("Installer resource: " + installResource);
      installerFile = unpackInstaller(installResource);

      // To clean-up downloaded files
      Config.trace("Unpacked installer to: " + installerFile);
      if (installerFile == null) {
        // The installFailed string is only for debugging. No localization needed
        installFailed("Could not unpack installer components", null);
        return;
      }

      enableStep(STEP_INSTALL);
      setStepText(STEP_INSTALL, Config.getWindowStepWait(STEP_INSTALL));

      boolean success = false;
      if (Config.isSolarisInstall()) {
        success = runSolarisInstaller(path, installerFile);
      } else {
        success = runWindowsInstaller(path, installerFile);
      }

      if (!success) {
        // The installFailed string is only for debugging. No localization needed
        installFailed("Could not run installer", null);
        return;
      }
    } catch (UnsatisfiedLinkError ule) {
      // The installFailed string is only for debugging. No localization needed
      installFailed("Unable to load library: " + nativeLibName, null);
      return;
    } finally {
      if (installerFile != null) {
        installerFile.delete();
      }
    }

    setStepText(STEP_INSTALL, Config.getWindowStep(STEP_INSTALL));
    enableStep(STEP_DONE);

    String execPath = path + Config.getJavaPath();
    Config.trace(execPath);

    /** Remove installer JAR from cache */
    removeInstallerComponent();

    // If we're running anything after 1.0.1 or not on Windows, just call
    // finishedInstall.  Otherwise, deny ExitVM permission so that we can
    // return here and do a reboot.  We have to do this because we need to
    // call ExtensionInstallerService.finishedInstall(), which registers
    // that our extension (the JRE) is installed.  Unfortunately pre-1.2 it
    // also does not understand that we are requesting a reboot, and calls
    // System.exit().  So for pre 1.2 we want to deny the permission to
    // exit the VM so we can return here and perform a reboot.
    boolean ispre12 = false;
    String version = Config.getJavaWSVersion();
    // get first tuple
    String v = version.substring(version.indexOf('-') + 1);
    int i2 = v.indexOf('.');
    int v1 = Integer.parseInt(v.substring(0, i2));
    // get second tuple
    v = v.substring(i2 + 1);
    i2 = v.indexOf('.');
    if (i2 == -1) i2 = v.indexOf('-');
    if (i2 == -1) i2 = v.indexOf('[');
    if (i2 == -1) i2 = v.length();
    int v2 = Integer.parseInt(v.substring(0, i2));
    // are we pre 1.2?
    if (v1 < 1 || (v1 == 1 && v2 < 2)) ispre12 = true;

    if (Config.isWindowsInstall() && ispre12 && Config.isHopper()) {
      // deny ExitVM permission then call finishedInstall
      ProtectionDomain pd = (new Object()).getClass().getProtectionDomain();
      CodeSource cs = pd.getCodeSource();
      AllPermissionExceptExitVM perm = new AllPermissionExceptExitVM();
      PermissionCollection newpc = perm.newPermissionCollection();
      newpc.add(perm);

      // run finishedInstall within the new context which excluded
      // just the ExitVM permission
      ProtectionDomain newpd = new ProtectionDomain(cs, newpc);
      AccessControlContext newacc = new AccessControlContext(new ProtectionDomain[] {newpd});
      final String fExecPath = execPath;
      try {
        AccessController.doPrivileged(
            new PrivilegedExceptionAction() {
              public Object run() throws SecurityException {
                finishedInstall(fExecPath);
                return null;
              }
            },
            newacc);
      } catch (PrivilegedActionException pae) {
        // swallow the exception because we want ExitVM to fail silent
      } catch (SecurityException se) {
        // swallow the exception because we want ExitVM to fail silent
      }
    } else {
      // just call finished Install
      finishedInstall(execPath);
    }

    if (Config.isWindowsInstall() && WindowsInstaller.IsRebootNecessary()) {
      // reboot
      if (!WindowsInstaller.askUserForReboot()) System.exit(0);
    } else {
      System.exit(0);
    }
  }
Example #2
0
  /** Runs a Windows installer */
  public static boolean runWindowsInstaller(String installPath, File installFile) {
    boolean deleteHopperKey = false;
    boolean deleteMerlinKey = false;
    // If Hopper, and JavaWS can update, ask the user if they want
    // to update.
    if (Config.isHopper()
        && !WinRegistry.doesSubKeyExist(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_HOPPER_KEY)) {
      int res =
          JOptionPane.showConfirmDialog(
              _installerFrame,
              Config.getJavaWSConfirmMessage(),
              Config.getJavaWSConfirmTitle(),
              JOptionPane.YES_NO_OPTION);
      if (res == JOptionPane.NO_OPTION) {
        // create the registry key so that JavaWS will not install
        WinRegistry.setStringValue(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_HOPPER_KEY, "Home", "");
        // flag to delete the key later
        deleteHopperKey = true;
      }
    }

    // If Merlin, never update JavaWS.  1.0.1_02 bundled with Merlin does
    // not have the ability to update while JavaWS is running.  So just
    // prevent the update by spoofing the registry key.
    if (Config.isMerlin()) {
      WinRegistry.setStringValue(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_MERLIN_KEY, "Home", "");
      deleteMerlinKey = true;
    }

    /** Build temp. script file */
    boolean success = false;
    File iss = null;
    try {
      String[] args = new String[2];
      args[0] = installFile.getAbsolutePath();
      if (Config.getJavaVersion().startsWith("1.4.2")) {
        args[1] = "/s /v\"/qn WEBSTARTICON=1 INSTALLDIR=\\\"" + installPath + "\\\"\"";

      } else {
        iss = WindowsInstaller.createTempISSScript(installPath, Config.getJavaVersion());
        args[1] = iss.getAbsolutePath();
      }
      String execString = getExecuteString(args);
      success = WindowsInstaller.execute(execString);
    } catch (IOException ioe) {
      return false;
    } finally {
      if (iss != null) iss.delete();
    }

    // delete any spoofed keys we created earlier
    if (deleteHopperKey) {
      WinRegistry.deleteKey(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_HOPPER_KEY);
    }
    if (deleteMerlinKey) {
      WinRegistry.deleteKey(WinRegistry.HKEY_LOCAL_MACHINE, JAVAWS_MERLIN_KEY);
    }

    // 4662215 cannot reboot here because the config hasn't been written
    // by JavaWS yet.  Reboot later, after installSucceeded has been
    // called.
    // WindowsInstaller.rebootIfNecessary();

    return success;
  }