1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package org.openoffice.setup.Controller; 29 30 import org.openoffice.setup.InstallData; 31 import org.openoffice.setup.Installer.Installer; 32 import org.openoffice.setup.Installer.InstallerFactory; 33 import org.openoffice.setup.PanelController; 34 import org.openoffice.setup.Panel.UninstallationPrologue; 35 import org.openoffice.setup.SetupData.PackageDescription; 36 import org.openoffice.setup.SetupData.SetupDataProvider; 37 import org.openoffice.setup.Util.Converter; 38 import org.openoffice.setup.Util.Dumper; 39 import org.openoffice.setup.Util.Informer; 40 import org.openoffice.setup.Util.LogManager; 41 import org.openoffice.setup.Util.ModuleCtrl; 42 import org.openoffice.setup.Util.SystemManager; 43 import java.io.File; 44 import java.util.HashMap; 45 import java.util.Vector; 46 import org.openoffice.setup.ResourceManager; 47 48 public class UninstallationPrologueCtrl extends PanelController { 49 50 private String helpFile; 51 52 public UninstallationPrologueCtrl() { 53 super("UninstallationPrologue", new UninstallationPrologue()); 54 helpFile = "String_Helpfile_UninstallationPrologue"; 55 } 56 57 public String getNext() { 58 return new String("ChooseUninstallationType"); 59 } 60 61 public String getPrevious() { 62 return null; 63 } 64 65 public final String getHelpFileName () { 66 return this.helpFile; 67 } 68 69 private HashMap getInfoFileData() { 70 InstallData data = InstallData.getInstance(); 71 File infoRootDir = data.getInfoRoot(); 72 String infoFilename = "infoFile"; 73 File infoFile = new File(infoRootDir, infoFilename); 74 Vector infoFileContent = SystemManager.readCharFileVector(infoFile.getPath()); 75 HashMap map = Converter.convertVectorToHashmap(infoFileContent); 76 77 // for (int i = 0; i < infoFileContent.size(); i++) { 78 // System.out.println(infoFileContent.get(i)); 79 // } 80 81 // Iterator m = map.entrySet().iterator(); 82 // while ( m.hasNext() ) { 83 // Map.Entry entry = (Map.Entry) m.next(); 84 // System.out.println( "MAP:" + entry.getKey() + ":" + entry.getValue() ); 85 // } 86 87 return map; 88 } 89 90 private void setNewInstallData(HashMap map) { 91 InstallData data = InstallData.getInstance(); 92 // adding information to installData 93 data.setPackagePath((String)map.get("PackagePath")); 94 data.setAdminFileNameReloc((String)map.get("AdminFileReloc")); 95 data.setAdminFileNameRelocNoDepends((String)map.get("AdminFileRelocNoDepends")); 96 data.setAdminFileNameNoReloc((String)map.get("AdminFileNoReloc")); 97 data.setAdminFileNameNoRelocNoDepends((String)map.get("AdminFileNoRelocNoDepends")); 98 data.setDatabasePath((String)map.get("DatabasePath")); 99 data.setInstallDir((String)map.get("InstallationDir")); 100 data.setStoredInstallationPrivileges((String)map.get("InstallationPrivileges")); 101 data.setGetUidPath((String)map.get("GetUidFile")); 102 } 103 104 private void readInfoFile() { 105 HashMap map = getInfoFileData(); 106 setNewInstallData(map); 107 Dumper.dumpNewInstallData(); 108 } 109 110 private void checkUninstallPrivileges() { 111 InstallData data = InstallData.getInstance(); 112 // data.setStoredInstallationPrivileges((String)map.get("InstallationPrivileges")); 113 String originalPrivileges = data.getStoredInstallationPrivileges(); 114 String currentPrivileges = data.getInstallationPrivileges(); 115 if ( ! currentPrivileges.equalsIgnoreCase(originalPrivileges) ) { 116 // aborting installation with error message 117 if ( currentPrivileges.equalsIgnoreCase("root")) { 118 String message = ResourceManager.getString("String_UninstallationPrologue_Wrong_Privileges_Current_Root"); 119 String title = ResourceManager.getString("String_Error"); 120 Informer.showErrorMessage(message, title); 121 String log = "<b>Error: Wrong uninstallation privileges (currently Root)!</b><br>"; 122 System.err.println(log); 123 // LogManager.addLogfileComment(log); 124 } else { 125 String message = ResourceManager.getString("String_UninstallationPrologue_Wrong_Privileges_Current_User"); 126 String title = ResourceManager.getString("String_Error"); 127 Informer.showErrorMessage(message, title); 128 String log = "<b>Error: Wrong uninstallation privileges (currently User)!</b><br>"; 129 System.err.println(log); 130 // LogManager.addLogfileComment(log); 131 } 132 System.exit(1); 133 } 134 135 } 136 137 public void beforeShow() { 138 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_PREVIOUS); 139 // System.err.println("\nUninstallation module state dump 1:"); 140 // PackageDescription packageData = SetupDataProvider.getPackageDescription(); 141 // ModuleCtrl.dumpModuleStates(packageData); 142 getSetupFrame().setButtonSelected(getSetupFrame().BUTTON_NEXT); 143 } 144 145 public void duringShow() { 146 147 Thread t = new Thread() { 148 public void run() { 149 InstallData installData = InstallData.getInstance(); 150 if ( ! installData.databaseAnalyzed() ) { 151 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_NEXT); 152 153 // now it is time to read the infoFile in directory "installData.getInfoRoot()" 154 readInfoFile(); 155 156 // controlling the installation privileges. Are the original installation privileges 157 // identical with the current deinstallation privileges? 158 checkUninstallPrivileges(); 159 160 PackageDescription packageData = SetupDataProvider.getPackageDescription(); 161 Installer installer = InstallerFactory.getInstance(); 162 installer.preUninstall(packageData); 163 164 // searching in the database for already installed packages 165 LogManager.setCommandsHeaderLine("Analyzing system database"); 166 ModuleCtrl.setDatabaseSettings(packageData, installData, installer); 167 installData.setDatabaseAnalyzed(true); 168 ModuleCtrl.setDontUninstallFlags(packageData); 169 if ( installData.isRootInstallation() ) { ModuleCtrl.setDontUninstallUserInstallOnylFlags(packageData); } 170 ModuleCtrl.setParentDefaultModuleSettings(packageData); 171 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_NEXT); 172 getSetupFrame().setButtonSelected(getSetupFrame().BUTTON_NEXT); 173 } 174 } 175 }; 176 177 t.start(); 178 } 179 180 public boolean afterShow(boolean nextButtonPressed) { 181 boolean repeatDialog = false; 182 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_PREVIOUS); 183 return repeatDialog; 184 } 185 186 } 187