コード例 #1
0
ファイル: Main.java プロジェクト: sidwubf/java-config
  /** 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;
  }