1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.setup.Controller; 25 26 import org.openoffice.setup.InstallData; 27 import org.openoffice.setup.Installer.Installer; 28 import org.openoffice.setup.Installer.InstallerFactory; 29 import org.openoffice.setup.PanelController; 30 import org.openoffice.setup.Panel.UninstallationPrologue; 31 import org.openoffice.setup.SetupData.PackageDescription; 32 import org.openoffice.setup.SetupData.SetupDataProvider; 33 import org.openoffice.setup.Util.Converter; 34 import org.openoffice.setup.Util.Dumper; 35 import org.openoffice.setup.Util.Informer; 36 import org.openoffice.setup.Util.LogManager; 37 import org.openoffice.setup.Util.ModuleCtrl; 38 import org.openoffice.setup.Util.SystemManager; 39 import java.io.File; 40 import java.util.HashMap; 41 import java.util.Vector; 42 import org.openoffice.setup.ResourceManager; 43 44 public class UninstallationPrologueCtrl extends PanelController { 45 46 private String helpFile; 47 UninstallationPrologueCtrl()48 public UninstallationPrologueCtrl() { 49 super("UninstallationPrologue", new UninstallationPrologue()); 50 helpFile = "String_Helpfile_UninstallationPrologue"; 51 } 52 getNext()53 public String getNext() { 54 return new String("ChooseUninstallationType"); 55 } 56 getPrevious()57 public String getPrevious() { 58 return null; 59 } 60 getHelpFileName()61 public final String getHelpFileName () { 62 return this.helpFile; 63 } 64 getInfoFileData()65 private HashMap getInfoFileData() { 66 InstallData data = InstallData.getInstance(); 67 File infoRootDir = data.getInfoRoot(); 68 String infoFilename = "infoFile"; 69 File infoFile = new File(infoRootDir, infoFilename); 70 Vector infoFileContent = SystemManager.readCharFileVector(infoFile.getPath()); 71 HashMap map = Converter.convertVectorToHashmap(infoFileContent); 72 73 // for (int i = 0; i < infoFileContent.size(); i++) { 74 // System.out.println(infoFileContent.get(i)); 75 // } 76 77 // Iterator m = map.entrySet().iterator(); 78 // while ( m.hasNext() ) { 79 // Map.Entry entry = (Map.Entry) m.next(); 80 // System.out.println( "MAP:" + entry.getKey() + ":" + entry.getValue() ); 81 // } 82 83 return map; 84 } 85 setNewInstallData(HashMap map)86 private void setNewInstallData(HashMap map) { 87 InstallData data = InstallData.getInstance(); 88 // adding information to installData 89 data.setPackagePath((String)map.get("PackagePath")); 90 data.setAdminFileNameReloc((String)map.get("AdminFileReloc")); 91 data.setAdminFileNameRelocNoDepends((String)map.get("AdminFileRelocNoDepends")); 92 data.setAdminFileNameNoReloc((String)map.get("AdminFileNoReloc")); 93 data.setAdminFileNameNoRelocNoDepends((String)map.get("AdminFileNoRelocNoDepends")); 94 data.setDatabasePath((String)map.get("DatabasePath")); 95 data.setInstallDir((String)map.get("InstallationDir")); 96 data.setStoredInstallationPrivileges((String)map.get("InstallationPrivileges")); 97 data.setGetUidPath((String)map.get("GetUidFile")); 98 } 99 readInfoFile()100 private void readInfoFile() { 101 HashMap map = getInfoFileData(); 102 setNewInstallData(map); 103 Dumper.dumpNewInstallData(); 104 } 105 checkUninstallPrivileges()106 private void checkUninstallPrivileges() { 107 InstallData data = InstallData.getInstance(); 108 // data.setStoredInstallationPrivileges((String)map.get("InstallationPrivileges")); 109 String originalPrivileges = data.getStoredInstallationPrivileges(); 110 String currentPrivileges = data.getInstallationPrivileges(); 111 if ( ! currentPrivileges.equalsIgnoreCase(originalPrivileges) ) { 112 // aborting installation with error message 113 if ( currentPrivileges.equalsIgnoreCase("root")) { 114 String message = ResourceManager.getString("String_UninstallationPrologue_Wrong_Privileges_Current_Root"); 115 String title = ResourceManager.getString("String_Error"); 116 Informer.showErrorMessage(message, title); 117 String log = "<b>Error: Wrong uninstallation privileges (currently Root)!</b><br>"; 118 System.err.println(log); 119 // LogManager.addLogfileComment(log); 120 } else { 121 String message = ResourceManager.getString("String_UninstallationPrologue_Wrong_Privileges_Current_User"); 122 String title = ResourceManager.getString("String_Error"); 123 Informer.showErrorMessage(message, title); 124 String log = "<b>Error: Wrong uninstallation privileges (currently User)!</b><br>"; 125 System.err.println(log); 126 // LogManager.addLogfileComment(log); 127 } 128 System.exit(1); 129 } 130 131 } 132 beforeShow()133 public void beforeShow() { 134 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_PREVIOUS); 135 // System.err.println("\nUninstallation module state dump 1:"); 136 // PackageDescription packageData = SetupDataProvider.getPackageDescription(); 137 // ModuleCtrl.dumpModuleStates(packageData); 138 getSetupFrame().setButtonSelected(getSetupFrame().BUTTON_NEXT); 139 } 140 duringShow()141 public void duringShow() { 142 143 Thread t = new Thread() { 144 public void run() { 145 InstallData installData = InstallData.getInstance(); 146 if ( ! installData.databaseAnalyzed() ) { 147 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_NEXT); 148 149 // now it is time to read the infoFile in directory "installData.getInfoRoot()" 150 readInfoFile(); 151 152 // controlling the installation privileges. Are the original installation privileges 153 // identical with the current deinstallation privileges? 154 checkUninstallPrivileges(); 155 156 PackageDescription packageData = SetupDataProvider.getPackageDescription(); 157 Installer installer = InstallerFactory.getInstance(); 158 installer.preUninstall(packageData); 159 160 // searching in the database for already installed packages 161 LogManager.setCommandsHeaderLine("Analyzing system database"); 162 ModuleCtrl.setDatabaseSettings(packageData, installData, installer); 163 installData.setDatabaseAnalyzed(true); 164 ModuleCtrl.setDontUninstallFlags(packageData); 165 if ( installData.isRootInstallation() ) { ModuleCtrl.setDontUninstallUserInstallOnylFlags(packageData); } 166 ModuleCtrl.setParentDefaultModuleSettings(packageData); 167 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_NEXT); 168 getSetupFrame().setButtonSelected(getSetupFrame().BUTTON_NEXT); 169 } 170 } 171 }; 172 173 t.start(); 174 } 175 afterShow(boolean nextButtonPressed)176 public boolean afterShow(boolean nextButtonPressed) { 177 boolean repeatDialog = false; 178 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_PREVIOUS); 179 return repeatDialog; 180 } 181 182 } 183