| package org.eclipse.epp.installer.internal.win32.core.operations; |
| |
| import java.io.File; |
| import java.util.Enumeration; |
| |
| import org.eclipse.epp.installer.core.model.ISequence; |
| import org.eclipse.epp.installer.core.model.ISingleton; |
| import org.eclipse.epp.installer.core.operations.CleanupRegisteredProductsOperation; |
| import org.eclipse.epp.installer.internal.core.operations.ProxyOperation; |
| import org.eclipse.epp.installer.internal.core.operations.StubOperation; |
| |
| import com.ice.jni.registry.Registry; |
| import com.ice.jni.registry.RegistryException; |
| import com.ice.jni.registry.RegistryKey; |
| |
| public class CleanupWin32RegistryOperation extends StubOperation implements |
| ISequence, ISingleton { |
| |
| private static String uninstallKeyString = "UninstallString"; |
| |
| private static String installLocation = "InstallLocation"; |
| |
| public CleanupWin32RegistryOperation(ProxyOperation operation) { |
| super(operation); |
| } |
| |
| /** |
| * Add needed sub oprtations to set of Prerequisites. |
| * |
| * @throws Exception |
| */ |
| public void prepare() throws Exception { |
| String uninstallJarName = ((CleanupRegisteredProductsOperation) this |
| .getProxyOperation()).getUninstallJarName(); |
| |
| String rootKeyPath = Win32RegisterProductOperation.REGISTRY_UNINSTALL_KEY; |
| try { |
| RegistryKey key = Registry.openSubkey(Registry.HKEY_LOCAL_MACHINE, |
| rootKeyPath, RegistryKey.ACCESS_READ); |
| |
| for (Enumeration e = key.keyElements(); e.hasMoreElements();) { |
| String subKeyName = (String) e.nextElement(); |
| |
| try { |
| RegistryKey subKey = key.openSubKey(subKeyName); |
| |
| String uninstallString = subKey |
| .getStringValue(uninstallKeyString); |
| int ind = uninstallString.indexOf(uninstallJarName); |
| if (ind != -1) { |
| File uninstaller = new File(uninstallString.substring( |
| uninstallString.indexOf(":") - 1, ind) |
| + uninstallJarName); |
| if (!uninstaller.exists()) { |
| |
| // System.out.println("Bad add/remove entry :" |
| // + uninstaller.getAbsolutePath()); |
| // System.out.println("key name " + subKeyName); |
| add(new RemoveRegistryKeyOperation(rootKeyPath, |
| subKeyName)); |
| } |
| } |
| subKey.closeKey(); |
| } catch (RegistryException e1) { |
| } |
| |
| } |
| key.closeKey(); |
| } catch (RegistryException e) { |
| } |
| |
| } |
| |
| } |