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.InstallationOngoing; 31 import org.openoffice.setup.ResourceManager; 32 import org.openoffice.setup.SetupData.PackageDescription; 33 import org.openoffice.setup.Util.LogManager; 34 import org.openoffice.setup.Util.InfoDir; 35 import org.openoffice.setup.Util.PackageCollector; 36 import org.openoffice.setup.Util.SystemManager; 37 import java.io.File; 38 import java.util.Collections; 39 import java.util.Vector; 40 41 public class InstallationOngoingCtrl extends PanelController { 42 43 private String helpFile; 44 private String nextDialog = new String("InstallationCompleted"); 45 private String previousDialog = new String("InstallationImminent"); 46 InstallationOngoingCtrl()47 public InstallationOngoingCtrl() { 48 super("InstallationOngoing", new InstallationOngoing()); 49 helpFile = "String_Helpfile_InstallationOngoing"; 50 } 51 getNext()52 public String getNext() { 53 return new String("InstallationCompleted"); 54 } 55 getPrevious()56 public String getPrevious() { 57 return new String("InstallationImminent"); 58 } 59 getHelpFileName()60 public final String getHelpFileName () { 61 return this.helpFile; 62 } 63 beforeShow()64 public void beforeShow() { 65 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_PREVIOUS); 66 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_NEXT); 67 getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_CANCEL); 68 getSetupFrame().setButtonSelected(getSetupFrame().BUTTON_HELP); 69 70 InstallationOngoing panel = (InstallationOngoing)getPanel(); 71 panel.setStopButtonActionCommand(getSetupFrame().ACTION_STOP); 72 panel.addStopButtonActionListener(getSetupFrame().getSetupActionListener()); 73 74 // creating sorted list of packages to install 75 InstallData installData = InstallData.getInstance(); 76 Vector installPackages = installData.getInstallPackages(); 77 78 Vector sortedPackages = new Vector(); 79 PackageCollector.sortPackages(installPackages, sortedPackages, "install"); 80 installData.setInstallPackages(sortedPackages); 81 82 if ( installData.isMajorUpgrade() ) { 83 // PackageCollector.findOldPackages(installData); 84 // Sorting for correct order of uninstallation 85 Vector sortedUninstallPackages = new Vector(); 86 PackageCollector.sortPackages(installData.getOldPackages(), sortedUninstallPackages, "uninstall"); 87 installData.setOldPackages(sortedUninstallPackages); 88 } 89 90 Installer installer = InstallerFactory.getInstance(); 91 installer.preInstallationOngoing(); 92 } 93 duringShow()94 public void duringShow() { 95 96 Thread t = new Thread() { 97 98 InstallData installData = InstallData.getInstance(); 99 InstallationOngoing panel = (InstallationOngoing)getPanel(); 100 Vector installPackages = installData.getInstallPackages(); 101 Vector removePackages = installData.getOldPackages(); 102 private Vector installedPackages = new Vector(); 103 104 public void run() { 105 boolean ignoreMajorUpgrade = false; 106 LogManager.setCommandsHeaderLine("Installation"); 107 Installer installer = InstallerFactory.getInstance(); 108 String titleText = ResourceManager.getString("String_InstallationOngoing1"); 109 panel.setTitle(titleText); 110 111 for (int i = 0; i < installPackages.size(); i++) { 112 PackageDescription packageData = (PackageDescription) installPackages.get(i); 113 int progress = java.lang.Math.round((100*(i+1))/installPackages.size()); 114 panel.setProgressValue(progress); 115 panel.setProgressText(packageData.getPackageName()); 116 117 // Creating an upgrade process for Solaris packages 118 if ( installData.getOSType().equalsIgnoreCase("SunOS") ) { 119 if ( installer.isPackageInstalled(packageData, installData) ) { 120 if ( installer.isInstalledPackageOlder(packageData, installData) ) { 121 packageData.setIgnoreDependsForUninstall(true); 122 installer.uninstallPackage(packageData); 123 } else { 124 continue; // no downgrading 125 } 126 } 127 } 128 129 installer.installPackage(packageData); 130 installedPackages.add(packageData); 131 132 if (( installData.isAbortedInstallation() ) || ( installData.isErrorInstallation() )) { 133 ignoreMajorUpgrade = true; 134 break; 135 } 136 } 137 138 if (( installData.isMajorUpgrade() ) && ( ! ignoreMajorUpgrade )) { 139 for (int i = 0; i < removePackages.size(); i++) { 140 PackageDescription packageData = (PackageDescription) removePackages.get(i); 141 installer.uninstallPackage(packageData); 142 } 143 } 144 145 if (( installData.isAbortedInstallation() ) || ( installData.isErrorInstallation() )) { 146 // undoing the installation 147 if ( installData.isAbortedInstallation() ) { 148 LogManager.setCommandsHeaderLine("Installation aborted!"); 149 titleText = ResourceManager.getString("String_UninstallationOngoing1"); 150 } else { 151 LogManager.setCommandsHeaderLine("Error during installation!"); 152 titleText = ResourceManager.getString("String_UninstallationOngoing1"); 153 } 154 panel.setTitle(titleText); 155 panel.setStopButtonEnabled(false); 156 157 LogManager.setCommandsHeaderLine("Uninstallation"); 158 159 // Inverting the package order for uninstallation 160 Collections.reverse(installedPackages); 161 162 for (int i = 0; i < installedPackages.size(); i++) { 163 PackageDescription packageData = (PackageDescription) installedPackages.get(i); 164 int progress = java.lang.Math.round(100/installedPackages.size()) * (i+1); 165 panel.setProgressValue(progress); 166 panel.setProgressText(packageData.getPackageName()); 167 if ( i == 0 ) { 168 installData.setIsFirstPackage(true); 169 } else { 170 installData.setIsFirstPackage(false); 171 } 172 installer.uninstallPackage(packageData); 173 } 174 175 // removing already created helper files (admin files) 176 Vector removeFiles = installData.getRemoveFiles(); 177 for (int i = 0; i < removeFiles.size(); i++) { 178 File removeFile = new File((String)removeFiles.get(i)); 179 SystemManager.deleteFile(removeFile); 180 } 181 } 182 183 installer.postInstallationOngoing(); 184 185 String next = getNext(); 186 getSetupFrame().setCurrentPanel(next, false, true); 187 } 188 }; 189 190 t.start(); 191 } 192 afterShow(boolean nextButtonPressed)193 public boolean afterShow(boolean nextButtonPressed) { 194 boolean repeatDialog = false; 195 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_PREVIOUS); 196 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_NEXT); 197 getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_CANCEL); 198 199 InstallData installData = InstallData.getInstance(); 200 if (( ! installData.isAbortedInstallation() ) && ( ! installData.isErrorInstallation() )) { 201 InfoDir.prepareUninstallation(); 202 } 203 204 return repeatDialog; 205 } 206 207 } 208