1 6 7 package com.memoire.vainstall; 8 9 import java.awt.Color ; 10 import java.io.File ; 11 import java.io.IOException ; 12 import java.io.InputStream ; 13 import java.lang.reflect.Method ; 14 import java.util.Properties ; 15 import java.util.Vector ; 16 17 import javax.swing.LookAndFeel ; 18 import javax.swing.UIManager ; 19 import javax.swing.UnsupportedLookAndFeelException ; 20 21 import com.ice.jni.registry.Registry; 22 import com.ice.jni.registry.RegistryKey; 23 24 28 29 public class Uninstall 30 extends AbstractInstall 32 { 33 private File uninstlog_; 34 private String customPrePostClassName_; 35 36 public Uninstall( 37 String uiMode, 38 String uiBluescreen, 39 String uiBluescreenColor, 40 String appName, 41 String appVersion, 42 String 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 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 (Integer.parseInt(uiBluescreenColor, 16)); 64 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 InputStream pin = getClass().getResourceAsStream("resources/vainstall.properties"); 73 Properties prop = new Properties (); 74 try 76 { 77 prop.load(pin); 78 pin.close(); 79 } 80 catch(IOException exc) 81 { 82 } 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 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 (destPath+File.separator+"uninstall.vai"); 101 if( (!uninstlog_.exists())||(!uninstlog_.canRead()) ) { 102 exitOnError(new IOException (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 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 (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 ("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 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  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 e ) { 233 throw new IOException (""+e); 234 } 235 } 236 237 private void callCustom(String method_name, VAInstallStep step, String msg) 238 throws Exception  239 { 240 step.status(msg); 241 VAGlobals.printDebug("begin custom " + method_name); 242 Class custom = Class.forName(customPrePostClassName_); 243 Method method = custom.getMethod(method_name, 244 new Class [] { VAInstallStep.class }); 245 boolean rc = Setup.callReflect (method, new Object [] { step }); 246 if (! rc) 247 { 248 VAGlobals.printDebug("custom pre/post-uninstall returned false"); 249 throw new IOException (VAGlobals.i18n("Uninstall_CustomFailed")); 250 } 251 VAGlobals.printDebug("end custom " + method_name); 252 } 253 256 } 257
| Popular Tags
|