KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > Uninstall


1 /**
2  * $RCSfile: Uninstall.java,v $
3  * @creation 26/01/00
4  * @modification $Date: 2005/05/13 21:01:10 $
5  */

6
7 package com.memoire.vainstall;
8
9 import java.awt.Color JavaDoc;
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.lang.reflect.Method JavaDoc;
14 import java.util.Properties JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 import javax.swing.LookAndFeel JavaDoc;
18 import javax.swing.UIManager JavaDoc;
19 import javax.swing.UnsupportedLookAndFeelException JavaDoc;
20
21 import com.ice.jni.registry.Registry;
22 import com.ice.jni.registry.RegistryKey;
23
24 /**
25  * @version $Id: Uninstall.java,v 1.15 2005/05/13 21:01:10 deniger Exp $
26  * @author Axel von Arnim
27  */

28
29 public class Uninstall
30 // extends Setup
31
extends AbstractInstall
32 {
33   private File JavaDoc uninstlog_;
34   private String JavaDoc customPrePostClassName_;
35
36   public Uninstall(
37     String JavaDoc uiMode,
38     String JavaDoc uiBluescreen,
39     String JavaDoc uiBluescreenColor,
40     String JavaDoc appName,
41     String JavaDoc appVersion,
42     String JavaDoc destPath
43     )
44   {
45     super();
46
47     VAGlobals.UI_MODE=System.getProperty("uimode", uiMode);
48     if( "no".equals(uiBluescreen) ) VAGlobals.UI_BLUESCREEN=false;
49     else VAGlobals.UI_BLUESCREEN=true;
50     String JavaDoc bsVar=System.getProperty("bluescreen");
51     if( bsVar!=null ) {
52       if( "no".equalsIgnoreCase(bsVar) )
53         VAGlobals.UI_BLUESCREEN=false;
54       else
55         VAGlobals.UI_BLUESCREEN=true;
56     }
57     if( (uiBluescreenColor==null)||
58         ("".equals(uiBluescreenColor))||
59         ("null".equals(uiBluescreenColor)) )
60       VAGlobals.UI_BLUESCREEN_COLOR=null;
61     else
62       VAGlobals.UI_BLUESCREEN_COLOR=
63         new Color JavaDoc(Integer.parseInt(uiBluescreenColor, 16));
64     // image is forced to this location now
65
VAGlobals.IMAGE="com/memoire/vainstall/resources/banner.gif";
66     VAGlobals.APP_NAME=appName;
67     VAGlobals.APP_VERSION=appVersion;
68     VAGlobals.DEST_PATH=destPath;
69     VAGlobals.OPERATION=VAGlobals.UNINSTALL;
70
71     // get vainstall.properties
72
InputStream JavaDoc pin = getClass().getResourceAsStream("resources/vainstall.properties");
73     Properties JavaDoc prop = new Properties JavaDoc();
74 // String language = null;
75
try
76     {
77       prop.load(pin);
78       pin.close();
79     }
80     catch(IOException JavaDoc exc)
81     {
82       // ignore at the moment
83
}
84     VAStepFactory.setLnf(VAGlobals.UI_MODE,prop,getClass(),null);
85     language = prop.getProperty("vainstall.destination.language");
86     if(language != null)
87     {
88       VAGlobals.setLanguage(language);
89     }
90     else
91     {
92       VAGlobals.setLanguage("default");
93     }
94
95     // class name for pre/post install
96
customPrePostClassName_ = prop.getProperty(
97     "vainstall.install.customprepost.className");
98     ui_=VAStepFactory.createUI(VAGlobals.UI_MODE, this);
99     VAGlobals.printDebug("UI created");
100     uninstlog_=new File JavaDoc(destPath+File.separator+"uninstall.vai");
101     if( (!uninstlog_.exists())||(!uninstlog_.canRead()) ) {
102       exitOnError(new IOException JavaDoc(uninstlog_.getName()+" "+VAGlobals.i18n("Uninstall_NotBeRead")));
103     }
104     nextStep();
105     ui_.activateUI();
106   }
107
108   public void nextStep()
109   {
110     switch( state_ ) {
111     case START: {
112       state_=WELCOME;
113       setActionEnabled(NEXT|CANCEL);
114       step_=ui_.createWelcomeStep();
115       break;
116     }
117     case WELCOME: {
118       state_=INSTALL;
119       setActionEnabled(BACK|NEXT|CANCEL);
120       step_=ui_.createInstallStep();
121       break;
122     }
123     case INSTALL: {
124       setActionEnabled(0);
125       startUninstall();
126       setActionEnabled(NEXT);
127       state_=END;
128       setActionEnabled(FINISH);
129       step_=ui_.createEndStep();
130       ((VAEndStep)step_).setStats(stats_);
131       break;
132     }
133     case END: {
134       ui_.quitUI();
135       quit();
136     }
137     }
138   }
139
140   public void previousStep()
141   {
142     switch( state_ ) {
143     case INSTALL: {
144       VAGlobals.printDebug("WELCOME");
145       state_=WELCOME;
146       setActionEnabled(NEXT|CANCEL);
147       step_=ui_.createWelcomeStep();
148       break;
149     }
150     default: {
151       VAGlobals.printDebug("can't go back...");
152       break;
153     }
154     }
155   }
156
157   private void startUninstall()
158   {
159     VAInstallStep step=(VAInstallStep)step_;
160     try {
161       step.setProgression(0);
162       if (customPrePostClassName_.length() > 0)
163         callCustom("preUninstall", step, VAGlobals.i18n("Custom_Preparing..."));
164       step.status(VAGlobals.i18n("Uninstall_DeletingFiles"));
165       Vector JavaDoc directories=deleteFiles(uninstlog_);
166       step.setProgression(50);
167       step.status(VAGlobals.i18n("Uninstall_DeletingDirectories"));
168       deleteDirectories(directories);
169       step.setProgression(60);
170       cleanShortcuts(uninstlog_.getParentFile());
171       step.setProgression(90);
172       step.status(VAGlobals.i18n("Uninstall_DeletingUninstallDirectory"));
173       deleteDirRecursive(new File JavaDoc(VAGlobals.DEST_PATH));
174       step.setProgression(100);
175       if( IS_WIN ) {
176         step.status(VAGlobals.i18n("Uninstall_UpdatingWindowsRegistry"));
177         updateWindowsRegistry();
178         ui_.uiSleep(2000);
179         step.status(VAGlobals.i18n("Uninstall_WindowsRegistryUpdated"));
180         ui_.uiSleep(1000);
181         new File JavaDoc("ICE_JNIRegistry.dll").delete();
182       }
183       if (customPrePostClassName_.length() > 0)
184         callCustom("postUninstall", step, VAGlobals.i18n("Custom_Mopping..."));
185       step.status(VAGlobals.i18n("Uninstall_UninstallationComplete"));
186     } catch( Exception JavaDoc e ) {
187       exitOnError(e);
188     }
189   }
190
191   public void redoStep()
192   {
193     switch( state_ ) {
194
195     case START: {
196       setActionEnabled(NEXT|CANCEL);
197       step_=ui_.createSetupLanguageStep();
198       break;
199     }
200
201     case WELCOME: {
202       {
203         setActionEnabled(BACK|NEXT|CANCEL);
204       }
205       step_=ui_.createWelcomeStep();
206       break;
207     }
208     case INSTALL: {
209       setActionEnabled(BACK|NEXT|CANCEL);
210       step_=ui_.createInstallStep();
211       break;
212     }
213     case END: {
214       setActionEnabled(FINISH);
215       step_=ui_.createEndStep();
216       ((VAEndStep)step_).setStats(stats_);
217       break;
218     }
219     }
220
221   }
222
223   
224
225   protected void updateWindowsRegistry() throws IOException JavaDoc
226   {
227     try {
228       RegistryKey uninstallKey=Registry.HKEY_LOCAL_MACHINE.openSubKey(
229         "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", RegistryKey.ACCESS_WRITE);
230       uninstallKey.deleteSubKey(VAGlobals.APP_NAME+" "+VAGlobals.APP_VERSION);
231       uninstallKey.closeKey();
232     } catch( Exception JavaDoc e ) {
233       throw new IOException JavaDoc(""+e);
234     }
235   }
236
237   private void callCustom(String JavaDoc method_name, VAInstallStep step, String JavaDoc msg)
238     throws Exception JavaDoc
239   {
240     step.status(msg);
241     VAGlobals.printDebug("begin custom " + method_name);
242     Class JavaDoc custom = Class.forName(customPrePostClassName_);
243     Method JavaDoc method = custom.getMethod(method_name,
244       new Class JavaDoc[] { VAInstallStep.class });
245     boolean rc = Setup.callReflect (method, new Object JavaDoc[] { step });
246     if (! rc)
247     {
248        VAGlobals.printDebug("custom pre/post-uninstall returned false");
249        throw new IOException JavaDoc(VAGlobals.i18n("Uninstall_CustomFailed"));
250     }
251     VAGlobals.printDebug("end custom " + method_name);
252   }
253 // do nothing
254
//public void redoStep(){}
255

256 }
257
Popular Tags