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.Util; 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.Panel.ChooseDirectory; 34 import org.openoffice.setup.ResourceManager; 35 import org.openoffice.setup.SetupData.PackageDescription; 36 import org.openoffice.setup.SetupData.SetupDataProvider; 37 import java.util.Enumeration; 38 39 40 public class InstallChangeCtrl { 41 42 private InstallChangeCtrl() { 43 } 44 45 static private void setUpdatePackage(PackageDescription packageData, InstallData installData) { 46 if (( packageData.isUpdatePackage() == true )) { 47 installData.setUpdatePackage(packageData); 48 } else { 49 for (Enumeration e = packageData.children(); e.hasMoreElements(); ) { 50 PackageDescription child = (PackageDescription) e.nextElement(); 51 setUpdatePackage(child, installData); 52 } 53 } 54 } 55 56 static private void setChangeInstallDir(InstallData installData, Installer installer) { 57 // setting the new install dir after analyzing the installation directory 58 // of the installed update package. 59 if ( installData.isRootInstallation() ) { 60 String changeInstallDir = "/"; 61 installData.setInstallDir(changeInstallDir); 62 } else { 63 String changeInstallDir = installer.getChangeInstallDir(installData.getUpdatePackage()); 64 installData.setInstallDir(changeInstallDir); 65 } 66 } 67 68 // static public void checkInstallChange(InstallData data, ChooseDirectory panel) { 69 static public void checkInstallChange(InstallData data) { 70 71 Installer installer = InstallerFactory.getInstance(); 72 PackageDescription packageData = SetupDataProvider.getPackageDescription(); 73 74 if ( data.getUpdatePackage() == null ) { 75 setUpdatePackage(packageData, data); 76 } 77 78 if ( data.getUpdatePackage() != null ) { 79 80 // resetting values, if database was changed during user installation 81 data.setOlderVersionExists(false); 82 data.setNewerVersionExists(false); 83 data.setSameVersionExists(false); 84 85 boolean packageIsInstalled = installer.isPackageInstalled(data.getUpdatePackage(), data); 86 if ( packageIsInstalled ) { 87 88 // Checking version of installed package: 89 // If installed package is older: Force update mode, no selection of packages 90 // If installed package is equal: Force maintenance mode, only selection of packages 91 // If installed package is newer: Abort installation with message 92 93 // Setting specific values for the different update scenarios 94 if ( installer.isInstalledPackageOlder(data.getUpdatePackage(), data) ) { 95 data.setOlderVersionExists(true); 96 // All installed packages will be updated -> determining which packages are installed 97 System.err.println("An older product is installed"); 98 // But if this is a kind of Major Upgrade with different Minor and therefore different package names, 99 // it is necessary to remove the old product. 100 if ( data.getProductMinor() > data.getInstalledProductMinor() ) 101 { 102 data.setMajorUpgrade(true); 103 System.err.println("Major Upgrade"); 104 } 105 } else if ( installer.isInstallSetPackageOlder(data.getUpdatePackage(), data) ) { 106 data.setNewerVersionExists(true); 107 System.err.println("A newer product is installed"); 108 } else { 109 data.setSameVersionExists(true); 110 System.err.println("Same product is installed"); 111 } 112 113 // If installed package is older or equal, the installdir has to be fixed 114 // if this is a root installation 115 if ( data.isRootInstallation() ) { 116 setChangeInstallDir(data, installer); 117 data.setIsChangeInstallation(true); 118 } 119 120 // Exit installation, if update is not wanted and this is a root installation. 121 // In installations without root privileges, the user can choose another installation 122 // directory (ChooseDirectoryCtrl.java). 123 if ( data.isRootInstallation() && data.dontUpdate() && data.olderVersionExists() ) { 124 System.err.println("Error: An older version is already installed in directory " + data.getInstallDir() + "!"); 125 String message1 = ResourceManager.getString("String_Older_Version_Installed_Found") 126 + "\n" + data.getInstallDir() + "\n"; 127 String message2 = ResourceManager.getString("String_Older_Version_Installed_Remove"); 128 String message = message1 + "\n" + message2; 129 String title = ResourceManager.getString("String_Error"); 130 Informer.showErrorMessage(message, title); 131 System.exit(1); 132 } 133 } 134 } 135 } 136 137 } 138