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