001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.izforge.izpack.uninstaller;
021:
022: import javax.swing.*;
023: import java.lang.reflect.Method;
024:
025: /**
026: * The uninstaller class.
027: *
028: * @author Julien Ponge
029: */
030: public class Uninstaller {
031:
032: /**
033: * The main method (program entry point).
034: *
035: * @param args The arguments passed on the command line.
036: */
037: public static void main(String[] args) {
038: boolean cmduninstall = false;
039: for (String arg : args) {
040: if (arg.equals("-c")) {
041: cmduninstall = true;
042: }
043: }
044: if (cmduninstall)
045: System.out.println("Command line uninstaller.\n");
046: try {
047: Class<Uninstaller> clazz = Uninstaller.class;
048: Method target;
049: if (cmduninstall)
050: target = clazz.getMethod("cmduninstall",
051: new Class[] { String[].class });
052: else
053: target = clazz.getMethod("uninstall",
054: new Class[] { String[].class });
055: new SelfModifier(target).invoke(args);
056: } catch (Exception ioeOrTypo) {
057: System.err.println(ioeOrTypo.getMessage());
058: ioeOrTypo.printStackTrace();
059: System.err.println("Unable to exec java as a subprocess.");
060: System.err.println("The uninstall may not fully complete.");
061: uninstall(args);
062: }
063: }
064:
065: public static void cmduninstall(String[] args) {
066: try {
067: UninstallerConsole uco = new UninstallerConsole();
068: boolean force = false;
069: for (String arg : args) {
070: if (arg.equals("-f")) {
071: force = true;
072: }
073: }
074: System.out.println("Force deletion: " + force);
075: uco.runUninstall(force);
076: } catch (Exception err) {
077: System.err.println("- Error -");
078: err.printStackTrace();
079: System.exit(0);
080: }
081: }
082:
083: public static void uninstall(final String[] args) {
084: SwingUtilities.invokeLater(new Runnable() {
085: public void run() {
086: try {
087: boolean displayForceOption = true;
088: boolean forceOptionState = false;
089:
090: for (String arg : args) {
091: if (arg.equals("-f")) {
092: forceOptionState = true;
093: } else if (arg.equals("-x")) {
094: displayForceOption = false;
095: }
096: }
097:
098: UIManager.setLookAndFeel(UIManager
099: .getSystemLookAndFeelClassName());
100: new UninstallerFrame(displayForceOption,
101: forceOptionState);
102: } catch (Exception err) {
103: System.err.println("- Error -");
104: err.printStackTrace();
105: System.exit(0);
106: }
107: }
108: });
109: }
110: }
|