001/* 002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved. 003 * 004 * http://www.izforge.com/izpack/ 005 * http://developer.berlios.de/projects/izpack/ 006 * 007 * Copyright 2004 Klaus Bartz 008 * 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 */ 021 022package com.izforge.izpack.event; 023 024import java.io.InputStream; 025import java.io.ObjectInputStream; 026import java.util.List; 027 028import com.coi.tools.os.win.NativeLibException; 029import com.izforge.izpack.util.AbstractUIProgressHandler; 030import com.izforge.izpack.util.TargetFactory; 031import com.izforge.izpack.util.os.RegistryHandler; 032import com.izforge.izpack.util.os.WrappedNativeLibException; 033 034/** 035 * Uninstaller custom action for handling registry entries. The needed configuration data are 036 * written at installation time from the corresponding installer custom action. An external 037 * definiton is not needed. 038 * 039 * @author Klaus Bartz 040 * 041 */ 042public class RegistryUninstallerListener extends NativeUninstallerListener 043{ 044 045 /** 046 * Default constructor 047 */ 048 public RegistryUninstallerListener() 049 { 050 super(); 051 } 052 053 /* 054 * (non-Javadoc) 055 * 056 * @see com.izforge.izpack.uninstaller.UninstallerListener#afterDeletion(java.util.List, 057 * com.izforge.izpack.util.AbstractUIProgressHandler) 058 */ 059 public void beforeDeletion(List files, AbstractUIProgressHandler handler) throws Exception 060 { 061 // Load the defined actions. 062 InputStream in = getClass().getResourceAsStream("/registryEntries"); 063 if (in == null) 064 { // No actions, nothing todo. 065 return; 066 } 067 ObjectInputStream objIn = new ObjectInputStream(in); 068 List allActions = (List) objIn.readObject(); 069 objIn.close(); 070 in.close(); 071 if (allActions == null || allActions.size() < 1) return; 072 try 073 { 074 RegistryHandler registryHandler = initializeRegistryHandler(); 075 if (registryHandler == null) return; 076 registryHandler.activateLogging(); 077 registryHandler.setLoggingInfo(allActions); 078 registryHandler.rewind(); 079 } 080 catch (Exception e) 081 { 082 if (e instanceof NativeLibException) 083 { 084 throw new WrappedNativeLibException(e); 085 } 086 else 087 throw e; 088 } 089 } 090 091 private RegistryHandler initializeRegistryHandler() throws Exception 092 { 093 RegistryHandler registryHandler = null; 094 try 095 { 096 registryHandler = (RegistryHandler) (TargetFactory.getInstance() 097 .makeObject("com.izforge.izpack.util.os.RegistryHandler")); 098 } 099 catch (Throwable exception) 100 { 101 exception.printStackTrace(); 102 registryHandler = null; // Do nothing, do not set permissions ... 103 } 104 if (registryHandler != null && (!registryHandler.good() || !registryHandler.doPerform())) 105 { 106 System.out.println("initializeRegistryHandler is Bad " + registryHandler.good() 107 + registryHandler.doPerform()); 108 registryHandler = null; 109 } 110 return (registryHandler); 111 } 112 113}