1 22 23 package com.izforge.izpack.util.os; 24 25 import java.io.File ; 26 import java.io.FileOutputStream ; 27 import java.io.InputStream ; 28 import java.util.HashMap ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 import com.coi.tools.os.win.MSWinConstants; 33 import com.coi.tools.os.win.NativeLibException; 34 import com.coi.tools.os.win.RegDataContainer; 35 import com.izforge.izpack.installer.AutomatedInstallData; 36 import com.izforge.izpack.installer.ResourceManager; 37 import com.izforge.izpack.util.Debug; 38 import com.izforge.izpack.util.OSClassHelper; 39 40 48 public class RegistryHandler extends OSClassHelper implements MSWinConstants 49 { 50 51 public static final String UNINSTALL_ROOT = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"; 52 53 public static final Map ROOT_KEY_MAP = new HashMap (); 54 55 protected String uninstallName = null; 56 57 private static final String UNINSTALLER_ICON = "UninstallerIcon"; 58 59 private static RegistryHandler defaultHandler = null; 60 static 61 { 62 ROOT_KEY_MAP.put("HKCR", new Integer (HKEY_CLASSES_ROOT)); 63 ROOT_KEY_MAP.put("HKEY_CLASSES_ROOT", new Integer (HKEY_CLASSES_ROOT)); 64 ROOT_KEY_MAP.put("HKCU", new Integer (HKEY_CURRENT_USER)); 65 ROOT_KEY_MAP.put("HKEY_CURRENT_USER", new Integer (HKEY_CURRENT_USER)); 66 ROOT_KEY_MAP.put("HKLM", new Integer (HKEY_LOCAL_MACHINE)); 67 ROOT_KEY_MAP.put("HKEY_LOCAL_MACHINE", new Integer (HKEY_LOCAL_MACHINE)); 68 ROOT_KEY_MAP.put("HKU", new Integer (HKEY_USERS)); 69 ROOT_KEY_MAP.put("HKEY_USERS", new Integer (HKEY_USERS)); 70 ROOT_KEY_MAP.put("HKPD", new Integer (HKEY_PERFORMANCE_DATA)); 71 ROOT_KEY_MAP.put("HKEY_PERFORMANCE_DATA", new Integer (HKEY_PERFORMANCE_DATA)); 72 ROOT_KEY_MAP.put("HKCC", new Integer (HKEY_CURRENT_CONFIG)); 73 ROOT_KEY_MAP.put("HKEY_CURRENT_CONFIG", new Integer (HKEY_CURRENT_CONFIG)); 74 ROOT_KEY_MAP.put("HKDDS", new Integer (HKEY_DYN_DATA)); 75 ROOT_KEY_MAP.put("HKEY_DYN_DATA", new Integer (HKEY_DYN_DATA)); 76 77 } 78 79 82 public RegistryHandler() 83 { 84 super(); 85 } 86 87 92 public RegistryHandler(String className) 93 { 94 super(className); 95 setDefault(); 96 } 97 98 101 private synchronized void setDefault() 102 { 103 if (defaultHandler == null) defaultHandler = this; 104 } 105 106 116 public void setValue(String key, String value, String contents) throws NativeLibException 117 { 118 } 119 120 public void setValue(String key, String value, String [] contents) throws NativeLibException 121 { 122 } 123 124 134 public void setValue(String key, String value, byte[] contents) throws NativeLibException 135 { 136 } 137 138 148 public void setValue(String key, String value, long contents) throws NativeLibException 149 { 150 } 151 152 161 public RegDataContainer getValue(String key, String value, RegDataContainer defaultVal) throws NativeLibException 162 { 163 return (null); 164 } 165 166 173 public boolean keyExist(String key) throws NativeLibException 174 { 175 return (false); 176 } 177 178 186 public boolean valueExist(String key, String value) throws NativeLibException 187 { 188 return (false); 189 } 190 191 198 public String [] getSubkeys(String key) throws NativeLibException 199 { 200 return (null); 201 } 202 203 210 public String [] getValueNames(String key) throws NativeLibException 211 { 212 return (null); 213 } 214 215 223 public RegDataContainer getValue(String key, String value) throws NativeLibException 224 { 225 return (null); 226 } 227 228 234 public void createKey(String key) throws NativeLibException 235 { 236 } 237 238 243 public void deleteKey( String key) throws NativeLibException 244 { 245 } 246 247 253 public void deleteKeyIfEmpty(String key) throws NativeLibException 254 { 255 } 256 257 264 public void deleteValue(String key, String value) throws NativeLibException 265 { 266 } 267 268 274 public void setRoot(int i) throws NativeLibException 275 { 276 } 277 278 284 public int getRoot() throws NativeLibException 285 { 286 return (0); 287 } 288 289 294 public void activateLogging() throws NativeLibException 295 { 296 } 297 298 303 public void suspendLogging() throws NativeLibException 304 { 305 } 306 307 312 public void resetLogging() throws NativeLibException 313 { 314 } 315 316 public List getLoggingInfo() throws NativeLibException 317 { 318 return (null); 319 } 320 321 public void setLoggingInfo(List info) throws NativeLibException 322 { 323 } 324 325 public void addLoggingInfo(List info) throws NativeLibException 326 { 327 } 328 329 public void rewind() throws NativeLibException 330 { 331 } 332 333 public String getUninstallName() 334 { 335 if (uninstallName != null) return (uninstallName); 336 if (installdata == null) return (null); 337 return (installdata.getVariable("APP_NAME") + " " + installdata.getVariable("APP_VER")); 338 } 339 340 public boolean isProductRegistered() throws NativeLibException 341 { 342 String uninstallName = getUninstallName(); 343 if (uninstallName == null) return (false); 344 String keyName = UNINSTALL_ROOT + uninstallName; 345 int oldVal = getRoot(); 346 setRoot(HKEY_LOCAL_MACHINE); 347 boolean retval = keyExist(keyName); 348 setRoot(oldVal); 349 return (retval); 350 } 351 352 public void setUninstallName(String name) 353 { 354 uninstallName = name; 355 } 356 357 public void registerUninstallKey() throws NativeLibException 358 { 359 String uninstallName = getUninstallName(); 360 if (uninstallName == null) return; 361 String keyName = UNINSTALL_ROOT + uninstallName; 362 String cmd = "\"" + installdata.getVariable("JAVA_HOME") + "\\bin\\javaw.exe\" -jar \"" 363 + installdata.getVariable("INSTALL_PATH") + "\\uninstaller\\uninstaller.jar\""; 364 365 int oldVal = getRoot(); 366 setRoot(HKEY_LOCAL_MACHINE); 367 setValue(keyName, "DisplayName", uninstallName); 368 setValue(keyName, "UninstallString", cmd); 369 try 371 { 372 InputStream input = ResourceManager.getInstance().getInputStream(UNINSTALLER_ICON); 373 String iconPath = installdata.getVariable("INSTALL_PATH") + File.separator 374 + "Uninstaller" + File.separator + "UninstallerIcon.ico"; 375 FileOutputStream out = new FileOutputStream (iconPath); 376 byte[] buffer = new byte[5120]; 377 long bytesCopied = 0; 378 int bytesInBuffer; 379 while ((bytesInBuffer = input.read(buffer)) != -1) 380 { 381 out.write(buffer, 0, bytesInBuffer); 382 bytesCopied += bytesInBuffer; 383 } 384 input.close(); 385 out.close(); 386 setValue(keyName, "DisplayIcon", iconPath); 387 } 388 catch (Exception exception) 389 { Debug.trace(exception); 391 } 392 setRoot(oldVal); 393 } 394 395 398 public boolean verify(AutomatedInstallData idata) throws Exception 399 { 400 super.verify(idata); 401 return (true); 402 403 } 404 405 410 public boolean doPerform() 411 { 412 return true; 413 } 414 415 420 public RegistryHandler getDefaultHandler() 421 { 422 return defaultHandler; 423 } 424 425 } 426 | Popular Tags |