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.Prologue;
31 import org.openoffice.setup.SetupData.PackageDescription;
32 import org.openoffice.setup.SetupData.SetupDataProvider;
33 import org.openoffice.setup.Util.Controller;
34 import org.openoffice.setup.Util.Dumper;
35 import org.openoffice.setup.Util.ModuleCtrl;
36 import org.openoffice.setup.Util.SystemManager;
37 
38 public class PrologueCtrl extends PanelController {
39 
40     private String helpFile;
41 
PrologueCtrl()42     public PrologueCtrl() {
43         super("Prologue", new Prologue());
44         helpFile = "String_Helpfile_Prologue";
45     }
46 
47     // public void beforeShow() {
duringShow()48     public void duringShow() {
49         getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_PREVIOUS);
50 
51         Thread t = new Thread() {
52             public void run() {
53                 InstallData installData = InstallData.getInstance();
54                 if ( ! installData.preInstallDone() ) {
55                     getSetupFrame().setButtonEnabled(false, getSetupFrame().BUTTON_NEXT);
56 
57                     Controller.checkPackagePathExistence(installData);
58                     Controller.checkPackageFormat(installData);
59 
60                     if (( installData.getOSType().equalsIgnoreCase("SunOS") ) && ( installData.isMultiLingual() )) {
61                         Controller.collectSystemLanguages(installData);
62                     }
63 
64                     PackageDescription packageData = SetupDataProvider.getPackageDescription();
65                     Installer installer = InstallerFactory.getInstance();
66                     installer.preInstall(packageData);
67 
68                     installData.setPreInstallDone(true);
69 
70                     if ( SystemManager.logModuleStates() ) {
71                         installData.setLogModuleStates(true);
72                     }
73 
74                     if ( installData.logModuleStates() ) {
75                         Dumper.logModuleStates(packageData, "Prologue Dialog");
76                     }
77 
78                     if (( installData.getOSType().equalsIgnoreCase("SunOS") ) && ( installData.isMultiLingual() )) {
79                         ModuleCtrl.checkLanguagesPackages(packageData, installData);
80 
81                         // int count = installData.getPreselectedLanguages();
82                         // System.err.println("Number of preselected language packages: " + count);
83 
84                         if ( installData.getPreselectedLanguages() == 0 ) {
85                             // Something misterious happened. Setting all languages again.
86                             ModuleCtrl.setLanguagesPackages(packageData);
87                         }
88 
89                         if ( installData.logModuleStates() ) {
90                             Dumper.logModuleStates(packageData, "Prologue Dialog Language Selection");
91                         }
92                     }
93 
94                     if ( ! installData.isMultiLingual() ) {
95                         ModuleCtrl.setHiddenLanguageModuleDefaultSettings(packageData);
96 
97                         if ( installData.logModuleStates() ) {
98                             Dumper.logModuleStates(packageData, "after setHiddenLanguageModuleDefaultSettings");
99                         }
100                     }
101 
102                     if (( installData.isRootInstallation() ) && ( installData.getOSType().equalsIgnoreCase("SunOS") )) {
103                         // Check, if root has write access in /usr and /etc .
104                         // In sparse zones with imported directories this is not always the case.
105                         if ( Controller.reducedRootWritePrivileges() ) {
106                             ModuleCtrl.setIgnoreNonRelocatablePackages(packageData);
107                         }
108 
109                         if ( installData.logModuleStates() ) {
110                             Dumper.logModuleStates(packageData, "after setIgnoreNonRelocatablePackages");
111                         }
112                     }
113 
114                     if ( installData.isRootInstallation() ) {
115 
116                         // Setting installation directory!
117                         String dir = "/";
118                         installData.setInstallDir(dir);
119                         installData.setInstallDefaultDir(installData.getDefaultDir());
120 
121                         Controller.checkForNewerVersion(installData);
122 
123                         // Check Write privileges in installation directory (installData.getInstallDefaultDir())
124                         // If the directory exists, is has to be tested, whether the user has write access
125                         dir = installData.getInstallDefaultDir();
126 
127                         if ( SystemManager.exists_directory(dir) ) {
128                             if ( ! Controller.createdSubDirectory(dir) ) {
129                                 System.err.println("ERROR: No write privileges inside directory: " + dir);
130                                 System.exit(1);
131                             }
132                         }
133 
134                         // If the directory does not exist, is has to be tested, whether the user can create it
135                         if ( ! SystemManager.exists_directory(dir)) {
136                             if ( ! Controller.createdDirectory(dir) ) {
137                                 System.err.println("ERROR: No privileges to create directory: " + dir);
138                                 System.exit(1);
139                             }
140                         }
141 
142                         // Setting macro
143                         SetupDataProvider.setNewMacro("DIR", dir); // important for string replacement
144 
145                         // Calculate available disc space
146                         int discSpace = SystemManager.calculateDiscSpace(dir);
147                         installData.setAvailableDiscSpace(discSpace);
148 
149                         if ( ! installData.databaseAnalyzed()) {
150                             ModuleCtrl.defaultDatabaseAnalysis(installData);
151                             installData.setDatabaseAnalyzed(true);
152                         }
153                     }
154 
155                     getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_NEXT);
156                 }
157             }
158         };
159         t.start();
160     }
161 
afterShow(boolean nextButtonPressed)162     public boolean afterShow(boolean nextButtonPressed) {
163         boolean repeatDialog = false;
164         getSetupFrame().setButtonEnabled(true, getSetupFrame().BUTTON_PREVIOUS);
165         return repeatDialog;
166     }
167 
getNext()168     public String getNext() {
169         InstallData data = InstallData.getInstance();
170 
171         if ( data.hideEula() ) {
172             if ( data.isRootInstallation() ) {
173                 if ( data.olderVersionExists() ) {
174                     return new String("InstallationImminent");
175                 } else if ( data.sameVersionExists() ) {
176                     return new String("ChooseComponents");
177                 } else {
178                     return new String("ChooseInstallationType");
179                 }
180             } else {
181                 return new String("ChooseDirectory");
182             }
183         } else {
184             return new String("AcceptLicense");
185         }
186     }
187 
getPrevious()188     public String getPrevious() {
189         return null;
190     }
191 
getHelpFileName()192     public final String getHelpFileName() {
193         return this.helpFile;
194     }
195 
196 }
197