KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > uninstaller > Uninstaller


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.izforge.izpack.uninstaller;
21
22 import javax.swing.*;
23 import java.lang.reflect.Method JavaDoc;
24
25 /**
26  * The uninstaller class.
27  *
28  * @author Julien Ponge
29  */

30 public class Uninstaller
31 {
32
33     /**
34      * The main method (program entry point).
35      *
36      * @param args The arguments passed on the command line.
37      */

38     public static void main(String JavaDoc[] args)
39     {
40         boolean cmduninstall = false;
41         for (int q = 0; q < args.length; q++) if (args[q].equals("-c")) cmduninstall = true;
42         if (cmduninstall) System.out.println("Command line uninstaller.\n");
43         try
44         {
45             Class JavaDoc clazz = Uninstaller.class;
46             Method JavaDoc target;
47             if (cmduninstall)
48                 target = clazz.getMethod("cmduninstall", new Class JavaDoc[]{String JavaDoc[].class});
49             else
50                 target = clazz.getMethod("uninstall", new Class JavaDoc[]{String JavaDoc[].class});
51             new SelfModifier(target).invoke(args);
52         }
53         catch (Exception JavaDoc ioeOrTypo)
54         {
55             System.err.println(ioeOrTypo.getMessage());
56             ioeOrTypo.printStackTrace();
57             System.err.println("Unable to exec java as a subprocess.");
58             System.err.println("The uninstall may not fully complete.");
59             uninstall(args);
60         }
61     }
62
63     public static void cmduninstall(String JavaDoc[] args)
64     {
65         try
66         {
67             UninstallerConsole uco = new UninstallerConsole();
68             boolean force = false;
69             for (int q = 0; q < args.length; q++) if (args[q].equals("-f")) force = true;
70             System.out.println("Force deletion: " + force);
71             uco.runUninstall(force);
72         }
73         catch (Exception JavaDoc err)
74         {
75             System.err.println("- Error -");
76             err.printStackTrace();
77             System.exit(0);
78         }
79     }
80
81     public static void uninstall(String JavaDoc[] args)
82     {
83         SwingUtilities.invokeLater(new Runnable JavaDoc()
84         {
85             public void run()
86             {
87                 try
88                 {
89                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
90                     new UninstallerFrame();
91                 }
92                 catch (Exception JavaDoc err)
93                 {
94                     System.err.println("- Error -");
95                     err.printStackTrace();
96                     System.exit(0);
97                 }
98             }
99         });
100     }
101 }
102
Popular Tags