001: /**
002: * $RCSfile: Uninstall.java,v $
003: * @creation 26/01/00
004: * @modification $Date: 2005/05/13 21:01:10 $
005: */package com.memoire.vainstall;
006:
007: import java.awt.Color;
008: import java.io.File;
009: import java.io.IOException;
010: import java.io.InputStream;
011: import java.lang.reflect.Method;
012: import java.util.Properties;
013: import java.util.Vector;
014:
015: import javax.swing.LookAndFeel;
016: import javax.swing.UIManager;
017: import javax.swing.UnsupportedLookAndFeelException;
018:
019: import com.ice.jni.registry.Registry;
020: import com.ice.jni.registry.RegistryKey;
021:
022: /**
023: * @version $Id: Uninstall.java,v 1.15 2005/05/13 21:01:10 deniger Exp $
024: * @author Axel von Arnim
025: */
026:
027: public class Uninstall
028: // extends Setup
029: extends AbstractInstall {
030: private File uninstlog_;
031: private String customPrePostClassName_;
032:
033: public Uninstall(String uiMode, String uiBluescreen,
034: String uiBluescreenColor, String appName,
035: String appVersion, String destPath) {
036: super ();
037:
038: VAGlobals.UI_MODE = System.getProperty("uimode", uiMode);
039: if ("no".equals(uiBluescreen))
040: VAGlobals.UI_BLUESCREEN = false;
041: else
042: VAGlobals.UI_BLUESCREEN = true;
043: String bsVar = System.getProperty("bluescreen");
044: if (bsVar != null) {
045: if ("no".equalsIgnoreCase(bsVar))
046: VAGlobals.UI_BLUESCREEN = false;
047: else
048: VAGlobals.UI_BLUESCREEN = true;
049: }
050: if ((uiBluescreenColor == null)
051: || ("".equals(uiBluescreenColor))
052: || ("null".equals(uiBluescreenColor)))
053: VAGlobals.UI_BLUESCREEN_COLOR = null;
054: else
055: VAGlobals.UI_BLUESCREEN_COLOR = new Color(Integer.parseInt(
056: uiBluescreenColor, 16));
057: // image is forced to this location now
058: VAGlobals.IMAGE = "com/memoire/vainstall/resources/banner.gif";
059: VAGlobals.APP_NAME = appName;
060: VAGlobals.APP_VERSION = appVersion;
061: VAGlobals.DEST_PATH = destPath;
062: VAGlobals.OPERATION = VAGlobals.UNINSTALL;
063:
064: // get vainstall.properties
065: InputStream pin = getClass().getResourceAsStream(
066: "resources/vainstall.properties");
067: Properties prop = new Properties();
068: // String language = null;
069: try {
070: prop.load(pin);
071: pin.close();
072: } catch (IOException exc) {
073: // ignore at the moment
074: }
075: VAStepFactory.setLnf(VAGlobals.UI_MODE, prop, getClass(), null);
076: language = prop.getProperty("vainstall.destination.language");
077: if (language != null) {
078: VAGlobals.setLanguage(language);
079: } else {
080: VAGlobals.setLanguage("default");
081: }
082:
083: // class name for pre/post install
084: customPrePostClassName_ = prop
085: .getProperty("vainstall.install.customprepost.className");
086: ui_ = VAStepFactory.createUI(VAGlobals.UI_MODE, this );
087: VAGlobals.printDebug("UI created");
088: uninstlog_ = new File(destPath + File.separator
089: + "uninstall.vai");
090: if ((!uninstlog_.exists()) || (!uninstlog_.canRead())) {
091: exitOnError(new IOException(uninstlog_.getName() + " "
092: + VAGlobals.i18n("Uninstall_NotBeRead")));
093: }
094: nextStep();
095: ui_.activateUI();
096: }
097:
098: public void nextStep() {
099: switch (state_) {
100: case START: {
101: state_ = WELCOME;
102: setActionEnabled(NEXT | CANCEL);
103: step_ = ui_.createWelcomeStep();
104: break;
105: }
106: case WELCOME: {
107: state_ = INSTALL;
108: setActionEnabled(BACK | NEXT | CANCEL);
109: step_ = ui_.createInstallStep();
110: break;
111: }
112: case INSTALL: {
113: setActionEnabled(0);
114: startUninstall();
115: setActionEnabled(NEXT);
116: state_ = END;
117: setActionEnabled(FINISH);
118: step_ = ui_.createEndStep();
119: ((VAEndStep) step_).setStats(stats_);
120: break;
121: }
122: case END: {
123: ui_.quitUI();
124: quit();
125: }
126: }
127: }
128:
129: public void previousStep() {
130: switch (state_) {
131: case INSTALL: {
132: VAGlobals.printDebug("WELCOME");
133: state_ = WELCOME;
134: setActionEnabled(NEXT | CANCEL);
135: step_ = ui_.createWelcomeStep();
136: break;
137: }
138: default: {
139: VAGlobals.printDebug("can't go back...");
140: break;
141: }
142: }
143: }
144:
145: private void startUninstall() {
146: VAInstallStep step = (VAInstallStep) step_;
147: try {
148: step.setProgression(0);
149: if (customPrePostClassName_.length() > 0)
150: callCustom("preUninstall", step, VAGlobals
151: .i18n("Custom_Preparing..."));
152: step.status(VAGlobals.i18n("Uninstall_DeletingFiles"));
153: Vector directories = deleteFiles(uninstlog_);
154: step.setProgression(50);
155: step
156: .status(VAGlobals
157: .i18n("Uninstall_DeletingDirectories"));
158: deleteDirectories(directories);
159: step.setProgression(60);
160: cleanShortcuts(uninstlog_.getParentFile());
161: step.setProgression(90);
162: step.status(VAGlobals
163: .i18n("Uninstall_DeletingUninstallDirectory"));
164: deleteDirRecursive(new File(VAGlobals.DEST_PATH));
165: step.setProgression(100);
166: if (IS_WIN) {
167: step.status(VAGlobals
168: .i18n("Uninstall_UpdatingWindowsRegistry"));
169: updateWindowsRegistry();
170: ui_.uiSleep(2000);
171: step.status(VAGlobals
172: .i18n("Uninstall_WindowsRegistryUpdated"));
173: ui_.uiSleep(1000);
174: new File("ICE_JNIRegistry.dll").delete();
175: }
176: if (customPrePostClassName_.length() > 0)
177: callCustom("postUninstall", step, VAGlobals
178: .i18n("Custom_Mopping..."));
179: step.status(VAGlobals
180: .i18n("Uninstall_UninstallationComplete"));
181: } catch (Exception e) {
182: exitOnError(e);
183: }
184: }
185:
186: public void redoStep() {
187: switch (state_) {
188:
189: case START: {
190: setActionEnabled(NEXT | CANCEL);
191: step_ = ui_.createSetupLanguageStep();
192: break;
193: }
194:
195: case WELCOME: {
196: {
197: setActionEnabled(BACK | NEXT | CANCEL);
198: }
199: step_ = ui_.createWelcomeStep();
200: break;
201: }
202: case INSTALL: {
203: setActionEnabled(BACK | NEXT | CANCEL);
204: step_ = ui_.createInstallStep();
205: break;
206: }
207: case END: {
208: setActionEnabled(FINISH);
209: step_ = ui_.createEndStep();
210: ((VAEndStep) step_).setStats(stats_);
211: break;
212: }
213: }
214:
215: }
216:
217: protected void updateWindowsRegistry() throws IOException {
218: try {
219: RegistryKey uninstallKey = Registry.HKEY_LOCAL_MACHINE
220: .openSubKey(
221: "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
222: RegistryKey.ACCESS_WRITE);
223: uninstallKey.deleteSubKey(VAGlobals.APP_NAME + " "
224: + VAGlobals.APP_VERSION);
225: uninstallKey.closeKey();
226: } catch (Exception e) {
227: throw new IOException("" + e);
228: }
229: }
230:
231: private void callCustom(String method_name, VAInstallStep step,
232: String msg) throws Exception {
233: step.status(msg);
234: VAGlobals.printDebug("begin custom " + method_name);
235: Class custom = Class.forName(customPrePostClassName_);
236: Method method = custom.getMethod(method_name,
237: new Class[] { VAInstallStep.class });
238: boolean rc = Setup.callReflect(method, new Object[] { step });
239: if (!rc) {
240: VAGlobals
241: .printDebug("custom pre/post-uninstall returned false");
242: throw new IOException(VAGlobals
243: .i18n("Uninstall_CustomFailed"));
244: }
245: VAGlobals.printDebug("end custom " + method_name);
246: }
247: // do nothing
248: //public void redoStep(){}
249:
250: }
|