Beispiel #1
0
 /**
  * Attempts to relaunch the uninstaller with elevated permissions.
  *
  * @param platform the current platform
  * @return <tt>true</tt> if the relaunch was successful, otherwise <tt>false</tt>
  */
 private static boolean relaunchWithElevatedRights(Platform platform) {
   boolean result = false;
   PrivilegedRunner runner = new PrivilegedRunner(platform);
   if (runner.isPlatformSupported()) {
     try {
       if (runner.relaunchWithElevatedRights() == 0) {
         result = true;
       }
     } catch (Exception exception) {
       exception.printStackTrace();
     }
     if (!result) {
       JOptionPane.showMessageDialog(
           null,
           "The uninstaller could not launch itself with administrator permissions.\n"
               + "The uninstallation will still continue but you may encounter problems due to insufficient permissions.");
     }
   } else {
     JOptionPane.showMessageDialog(
         null,
         "This uninstaller should be run by an administrator.\n"
             + "The uninstallation will still continue but you may encounter problems due to insufficient permissions.");
   }
   return result;
 }
Beispiel #2
0
 /**
  * Determines if permission elevation is required to uninstall the application.
  *
  * <p>Permission elevation is required if:
  *
  * <ul>
  *   <li>the <em>exec-admin</em> resource exists; and
  *   <li>the current user doesn't have permission to write to the install path
  * </ul>
  *
  * @param platform the current platform
  * @return <tt>true</tt> if elevation is needed
  * @throws IOException if the installation path cannot be determined
  */
 private static boolean isElevationRequired(Platform platform) throws IOException {
   boolean result = false;
   if (Uninstaller.class.getResource(EXEC_ADMIN) != null) {
     String path = InstallLog.getInstallPath(new DefaultResources());
     PrivilegedRunner runner = new PrivilegedRunner(platform);
     result = runner.isElevationNeeded(path);
   }
   return result;
 }
Beispiel #3
0
  /**
   * The main method (program entry point).
   *
   * @param args The arguments passed on the command line.
   */
  public static void main(String[] args) {
    // relaunch the uninstaller with elevated permissions if required
    Platform platform = new Platforms().getCurrentPlatform();

    try {
      if (!PrivilegedRunner.isPrivilegedMode() && isElevationRequired(platform)) {
        if (relaunchWithElevatedRights(platform)) {
          System.exit(0);
        }
      }
    } catch (IOException exception) {
      logger.log(Level.SEVERE, exception.getMessage(), exception);
      System.exit(1);
    }

    boolean console = false;
    for (String arg : args) {
      if (arg.equals("-c")) {
        console = true;
      }
    }
    if (console) {
      System.out.println("Command line uninstaller.\n");
    }
    try {
      Class<Uninstaller> clazz = Uninstaller.class;
      Method target;
      if (console) {
        target = clazz.getMethod("consoleUninstall", new Class[] {String[].class});
      } else {
        target = clazz.getMethod("uninstall", new Class[] {String[].class});
      }
      new SelfModifier(target).invoke(args);
    } catch (Exception ioeOrTypo) {
      System.err.println(ioeOrTypo.getMessage());
      ioeOrTypo.printStackTrace();
      System.err.println("Unable to exec java as a subprocess.");
      System.err.println("The uninstall may not fully complete.");
      uninstall(args);
    }
  }
Beispiel #4
0
  /**
   * Puts the uninstaller skeleton.
   *
   * @param installdata
   * @param pathResolver
   * @param outJar
   * @throws Exception Description of the Exception
   */
  public void writeJarSkeleton(
      AutomatedInstallData installdata, PathResolver pathResolver, JarOutputStream outJar)
      throws Exception {
    // get the uninstaller base, returning if not found so that
    // installData.uninstallOutJar remains null

    List<Mergeable> uninstallerMerge =
        pathResolver.getMergeableFromPath("com/izforge/izpack/uninstaller/");
    uninstallerMerge.addAll(
        pathResolver.getMergeableFromPath("uninstaller-META-INF/", "META-INF/"));
    uninstallerMerge.addAll(pathResolver.getMergeableFromPath("com/izforge/izpack/api/"));
    uninstallerMerge.addAll(pathResolver.getMergeableFromPath("com/izforge/izpack/util/"));
    uninstallerMerge.addAll(pathResolver.getMergeableFromPath("com/izforge/izpack/gui/"));
    uninstallerMerge.addAll(pathResolver.getMergeableFromPath("com/izforge/izpack/img/"));

    // The uninstaller extension is facultative; it will be exist only
    // if a native library was marked for uninstallation.
    // REFACTOR Change uninstaller methods of merge and get

    // Me make the .uninstaller directory
    // We copy the uninstallers
    for (Mergeable mergeable : uninstallerMerge) {
      mergeable.merge(outJar);
    }

    // Should we relaunch the uninstaller with privileges?
    if (PrivilegedRunner.isPrivilegedMode()
        && installdata.getInfo().isPrivilegedExecutionRequiredUninstaller()) {
      outJar.putNextEntry(new JarEntry("exec-admin"));
      outJar.closeEntry();
    }

    // We put the langpack
    List<Mergeable> langPack =
        pathResolver.getMergeableFromPath(
            "resources/langpacks/" + installdata.getLocaleISO3() + ".xml", "langpack.xml");
    for (Mergeable mergeable : langPack) {
      mergeable.merge(outJar);
    }
  }