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