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 10cdf0e10cSrcweir * 11*9a1eeea9SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*9a1eeea9SAndrew Rist *************************************************************/ 21*9a1eeea9SAndrew Rist 22*9a1eeea9SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package org.openoffice.setup.Util; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import org.openoffice.setup.InstallData; 27cdf0e10cSrcweir import org.openoffice.setup.ResourceManager; 28cdf0e10cSrcweir import java.io.File; 29cdf0e10cSrcweir import java.util.Vector; 30cdf0e10cSrcweir 31cdf0e10cSrcweir public class InfoDir { 32cdf0e10cSrcweir InfoDir()33cdf0e10cSrcweir private InfoDir() { 34cdf0e10cSrcweir } 35cdf0e10cSrcweir copySourceFile(String fileName)36cdf0e10cSrcweir static private String copySourceFile(String fileName) { 37cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 38cdf0e10cSrcweir File jarFile = data.getJarFilePath(); 39cdf0e10cSrcweir String destFile = null; 40cdf0e10cSrcweir 41cdf0e10cSrcweir if ( jarFile != null ) { 42cdf0e10cSrcweir String sourceDir = jarFile.getParent(); 43cdf0e10cSrcweir File sourceFileFile = new File(sourceDir, fileName); 44cdf0e10cSrcweir String sourceFile = sourceFileFile.getPath(); 45cdf0e10cSrcweir 46cdf0e10cSrcweir // String jarFileName = jarFile.getName(); 47cdf0e10cSrcweir File destDir = new File(data.getInstallDefaultDir(), data.getProductDir()); 48cdf0e10cSrcweir File destFileFile = new File(destDir, fileName); 49cdf0e10cSrcweir destFile = destFileFile.getPath(); 50cdf0e10cSrcweir 51cdf0e10cSrcweir boolean success = SystemManager.copy(sourceFile, destFile); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir return destFile; 55cdf0e10cSrcweir } 56cdf0e10cSrcweir copyInstallDirectoryWithExtension(File destBaseDir, String subDirName, String fileExtension)57cdf0e10cSrcweir static private void copyInstallDirectoryWithExtension(File destBaseDir, String subDirName, String fileExtension) { 58cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 59cdf0e10cSrcweir File sourceDir = data.getInfoRoot(subDirName); 60cdf0e10cSrcweir if ( sourceDir != null ) { 61cdf0e10cSrcweir File destDir = new File(destBaseDir, subDirName); 62cdf0e10cSrcweir destDir.mkdir(); 63cdf0e10cSrcweir SystemManager.copyAllFiles(sourceDir, destDir, fileExtension); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir copyInstallDirectoryWithExtension(File destBaseDir, String subDirName, String fileExtension, String unixRights)67cdf0e10cSrcweir static private void copyInstallDirectoryWithExtension(File destBaseDir, String subDirName, String fileExtension, String unixRights) { 68cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 69cdf0e10cSrcweir File sourceDir = data.getInfoRoot(subDirName); 70cdf0e10cSrcweir if ( sourceDir != null ) { 71cdf0e10cSrcweir File destDir = new File(destBaseDir, subDirName); 72cdf0e10cSrcweir destDir.mkdir(); 73cdf0e10cSrcweir SystemManager.copyAllFiles(sourceDir, destDir, fileExtension); 74cdf0e10cSrcweir SystemManager.setUnixPrivilegesDirectory(destDir, fileExtension, unixRights); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir } 77cdf0e10cSrcweir copyInstallDirectoryDoubleSubdir(File destBaseDir, String dir1, String dir2)78cdf0e10cSrcweir static private void copyInstallDirectoryDoubleSubdir(File destBaseDir, String dir1, String dir2) { 79cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 80cdf0e10cSrcweir File sourceDir1 = data.getInfoRoot(dir1); 81cdf0e10cSrcweir File sourceDir = new File(sourceDir1, dir2); 82cdf0e10cSrcweir 83cdf0e10cSrcweir destBaseDir.mkdir(); 84cdf0e10cSrcweir File destDir1 = new File(destBaseDir, dir1); 85cdf0e10cSrcweir destDir1.mkdir(); 86cdf0e10cSrcweir File destDir = new File(destDir1, dir2); 87cdf0e10cSrcweir destDir.mkdir(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir SystemManager.copyAllFiles(sourceDir, destDir); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir createUninstallDir()92cdf0e10cSrcweir static private File createUninstallDir() { 93cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 94cdf0e10cSrcweir File baseDir = new File(data.getInstallDefaultDir(), data.getProductDir()); 95cdf0e10cSrcweir baseDir = new File(baseDir, data.getUninstallDirName()); 96cdf0e10cSrcweir baseDir.mkdir(); 97cdf0e10cSrcweir return baseDir; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir copyGetUidSoFile(File dir)100cdf0e10cSrcweir static private void copyGetUidSoFile(File dir) { 101cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 102cdf0e10cSrcweir String uidFileSource = data.getGetUidPath(); 103cdf0e10cSrcweir if ( uidFileSource != null ) { 104cdf0e10cSrcweir // Copying the "getuid.so" file into installation 105cdf0e10cSrcweir String fileName = "getuid.so"; 106cdf0e10cSrcweir File destFile = new File(dir, fileName); 107cdf0e10cSrcweir String uidFileDest = destFile.getPath(); 108cdf0e10cSrcweir boolean success = SystemManager.copy(uidFileSource, uidFileDest); 109cdf0e10cSrcweir data.setGetUidPath(uidFileDest); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir copyJreFile(File dir)113cdf0e10cSrcweir static private void copyJreFile(File dir) { 114cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 115cdf0e10cSrcweir String jrefilename = System.getProperty("JRE_FILE"); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if ( jrefilename != null ) { 118cdf0e10cSrcweir // For Solaris, JRE_FILE can already contain the complete path. 119cdf0e10cSrcweir // Otherwise it contains only the filename 120cdf0e10cSrcweir File jreFile = new File(jrefilename); 121cdf0e10cSrcweir 122cdf0e10cSrcweir if ( ! jreFile.exists()) { 123cdf0e10cSrcweir jreFile = new File(data.getPackagePath(), jrefilename); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir if ( jreFile.exists() ) { 127cdf0e10cSrcweir String jreFileSource = jreFile.getPath(); 128cdf0e10cSrcweir File destDir = new File(dir, "jre"); 129cdf0e10cSrcweir destDir.mkdir(); 130cdf0e10cSrcweir String onlyFileName = jreFile.getName(); 131cdf0e10cSrcweir File destFile = new File(destDir, onlyFileName); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // In maintenance mode the file already exists 134cdf0e10cSrcweir if ( ! destFile.exists() ) { 135cdf0e10cSrcweir String jreFileDest = destFile.getPath(); 136cdf0e10cSrcweir boolean success = SystemManager.copy(jreFileSource, jreFileDest); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir moveAdminFiles(File dir)142cdf0e10cSrcweir static private void moveAdminFiles(File dir) { 143cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 144cdf0e10cSrcweir 145cdf0e10cSrcweir if ( data.getAdminFileNameReloc() != null ) { 146cdf0e10cSrcweir File sourceFile = new File(data.getAdminFileNameReloc()); 147cdf0e10cSrcweir String fileName = sourceFile.getName(); 148cdf0e10cSrcweir File destFile = new File(dir, fileName); 149cdf0e10cSrcweir boolean success = SystemManager.copy(sourceFile.getPath(), destFile.getPath()); 150cdf0e10cSrcweir data.setAdminFileNameReloc(destFile.getPath()); 151cdf0e10cSrcweir sourceFile.delete(); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir if ( data.getAdminFileNameRelocNoDepends() != null ) { 155cdf0e10cSrcweir File sourceFile = new File(data.getAdminFileNameRelocNoDepends()); 156cdf0e10cSrcweir String fileName = sourceFile.getName(); 157cdf0e10cSrcweir File destFile = new File(dir, fileName); 158cdf0e10cSrcweir boolean success = SystemManager.copy(sourceFile.getPath(), destFile.getPath()); 159cdf0e10cSrcweir data.setAdminFileNameRelocNoDepends(destFile.getPath()); 160cdf0e10cSrcweir sourceFile.delete(); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir if ( data.getAdminFileNameNoReloc() != null ) { 164cdf0e10cSrcweir File sourceFile = new File(data.getAdminFileNameNoReloc()); 165cdf0e10cSrcweir String fileName = sourceFile.getName(); 166cdf0e10cSrcweir File destFile = new File(dir, fileName); 167cdf0e10cSrcweir boolean success = SystemManager.copy(sourceFile.getPath(), destFile.getPath()); 168cdf0e10cSrcweir data.setAdminFileNameNoReloc(destFile.getPath()); 169cdf0e10cSrcweir sourceFile.delete(); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir if ( data.getAdminFileNameNoRelocNoDepends() != null ) { 173cdf0e10cSrcweir File sourceFile = new File(data.getAdminFileNameNoRelocNoDepends()); 174cdf0e10cSrcweir String fileName = sourceFile.getName(); 175cdf0e10cSrcweir File destFile = new File(dir, fileName); 176cdf0e10cSrcweir boolean success = SystemManager.copy(sourceFile.getPath(), destFile.getPath()); 177cdf0e10cSrcweir data.setAdminFileNameNoRelocNoDepends(destFile.getPath()); 178cdf0e10cSrcweir sourceFile.delete(); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir } 181cdf0e10cSrcweir createInfoFile(File dir)182cdf0e10cSrcweir static private void createInfoFile(File dir) { 183cdf0e10cSrcweir Vector fileContent = new Vector(); 184cdf0e10cSrcweir String line = null; 185cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 186cdf0e10cSrcweir 187cdf0e10cSrcweir line = "PackagePath=" + data.getPackagePath(); 188cdf0e10cSrcweir fileContent.add(line); 189cdf0e10cSrcweir line = "InstallationPrivileges=" + data.getInstallationPrivileges(); 190cdf0e10cSrcweir fileContent.add(line); 191cdf0e10cSrcweir line = "AdminFileReloc=" + data.getAdminFileNameReloc(); 192cdf0e10cSrcweir fileContent.add(line); 193cdf0e10cSrcweir line = "AdminFileRelocNoDepends=" + data.getAdminFileNameRelocNoDepends(); 194cdf0e10cSrcweir fileContent.add(line); 195cdf0e10cSrcweir line = "AdminFileNoReloc=" + data.getAdminFileNameNoReloc(); 196cdf0e10cSrcweir fileContent.add(line); 197cdf0e10cSrcweir line = "AdminFileNoRelocNoDepends=" + data.getAdminFileNameNoRelocNoDepends(); 198cdf0e10cSrcweir fileContent.add(line); 199cdf0e10cSrcweir line = "InstallationDir=" + data.getInstallDir(); 200cdf0e10cSrcweir fileContent.add(line); 201cdf0e10cSrcweir line = "DatabasePath=" + data.getDatabasePath(); 202cdf0e10cSrcweir fileContent.add(line); 203cdf0e10cSrcweir line = "GetUidFile=" + data.getGetUidPath(); 204cdf0e10cSrcweir fileContent.add(line); 205cdf0e10cSrcweir 206cdf0e10cSrcweir String infoFileName = "infoFile"; 207cdf0e10cSrcweir File infoFile = new File(dir, infoFileName); 208cdf0e10cSrcweir SystemManager.saveCharFileVector(infoFile.getPath(), fileContent); 209cdf0e10cSrcweir } 210cdf0e10cSrcweir removeSpecialFiles()211cdf0e10cSrcweir static private void removeSpecialFiles() { 212cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 213cdf0e10cSrcweir File jarFile = data.getJarFilePath(); 214cdf0e10cSrcweir SystemManager.deleteFile(jarFile); 215cdf0e10cSrcweir 216cdf0e10cSrcweir String jarFilePath = jarFile.getParent(); 217cdf0e10cSrcweir File setupFile = new File(jarFilePath, "setup"); 218cdf0e10cSrcweir SystemManager.deleteFile(setupFile); 219cdf0e10cSrcweir 220cdf0e10cSrcweir if ( ! data.getAdminFileNameReloc().equals("null") ) { 221cdf0e10cSrcweir SystemManager.deleteFile(new File(data.getAdminFileNameReloc())); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir if ( ! data.getAdminFileNameRelocNoDepends().equals("null") ) { 225cdf0e10cSrcweir SystemManager.deleteFile(new File(data.getAdminFileNameRelocNoDepends())); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir if ( ! data.getAdminFileNameNoReloc().equals("null") ) { 229cdf0e10cSrcweir SystemManager.deleteFile(new File(data.getAdminFileNameNoReloc())); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir if ( ! data.getAdminFileNameNoRelocNoDepends().equals("null") ) { 233cdf0e10cSrcweir SystemManager.deleteFile(new File(data.getAdminFileNameNoRelocNoDepends())); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir if ( ! data.getGetUidPath().equals("null") ) { 237cdf0e10cSrcweir SystemManager.deleteFile(new File(data.getGetUidPath())); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir removeInforootSubdir(String dir1, String dir2)241cdf0e10cSrcweir static private void removeInforootSubdir(String dir1, String dir2) { 242cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 243cdf0e10cSrcweir File subdir1 = data.getInfoRoot(dir1); 244cdf0e10cSrcweir File subdir2 = new File(subdir1, dir2); 245cdf0e10cSrcweir if (subdir2 != null) { 246cdf0e10cSrcweir if ( subdir2.exists() ) { 247cdf0e10cSrcweir SystemManager.removeDirectory(subdir2); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir } 251cdf0e10cSrcweir removeInforootSubdir(String dir)252cdf0e10cSrcweir static private void removeInforootSubdir(String dir) { 253cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 254cdf0e10cSrcweir File subdir = data.getInfoRoot(dir); 255cdf0e10cSrcweir if (subdir != null) { 256cdf0e10cSrcweir if ( subdir.exists() ) { 257cdf0e10cSrcweir SystemManager.removeDirectory(subdir); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir removeInforoot()262cdf0e10cSrcweir static private void removeInforoot() { 263cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 264cdf0e10cSrcweir SystemManager.removeDirectory(data.getInfoRoot()); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir prepareUninstallation()267cdf0e10cSrcweir static public void prepareUninstallation() { 268cdf0e10cSrcweir // additional tasks for uninstallation 269cdf0e10cSrcweir // Directory destDir has to exist! 270cdf0e10cSrcweir InstallData data = InstallData.getInstance(); 271cdf0e10cSrcweir File destDir = new File(data.getInstallDefaultDir(), data.getProductDir()); 272cdf0e10cSrcweir boolean directoryExists = true; 273cdf0e10cSrcweir 274cdf0e10cSrcweir if ( ! destDir.exists() ) { 275cdf0e10cSrcweir try { 276cdf0e10cSrcweir directoryExists = SystemManager.create_directory(destDir.getPath()); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir catch (SecurityException ex) { 279cdf0e10cSrcweir String message = ResourceManager.getString("String_ChooseDirectory_No_Write_Access") + ": " + destDir.getPath(); 280cdf0e10cSrcweir String title = ResourceManager.getString("String_Error"); 281cdf0e10cSrcweir Informer.showErrorMessage(message, title); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir if ( directoryExists ) { 286cdf0e10cSrcweir String setupPath = copySourceFile("setup"); 287cdf0e10cSrcweir SystemManager.setUnixPrivileges(setupPath, "775"); 288cdf0e10cSrcweir File jarFile = data.getJarFilePath(); 289cdf0e10cSrcweir copySourceFile(jarFile.getName()); 290cdf0e10cSrcweir 291cdf0e10cSrcweir File uninstallDir = createUninstallDir(); 292cdf0e10cSrcweir copyInstallDirectoryWithExtension(uninstallDir, "xpd", "xpd"); 293cdf0e10cSrcweir copyInstallDirectoryWithExtension(uninstallDir, "html", "html"); 294cdf0e10cSrcweir copyInstallDirectoryWithExtension(uninstallDir, "images", "gif"); 295cdf0e10cSrcweir copyInstallDirectoryDoubleSubdir(uninstallDir, "html", "images"); 296cdf0e10cSrcweir copyGetUidSoFile(uninstallDir); 297cdf0e10cSrcweir copyJreFile(uninstallDir); 298cdf0e10cSrcweir moveAdminFiles(uninstallDir); 299cdf0e10cSrcweir createInfoFile(uninstallDir); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir removeUninstallationFiles()303cdf0e10cSrcweir static public void removeUninstallationFiles() { 304cdf0e10cSrcweir // removing selected File 305cdf0e10cSrcweir removeSpecialFiles(); 306cdf0e10cSrcweir // removing directories html/images, html and xpd 307cdf0e10cSrcweir removeInforootSubdir("html", "images"); 308cdf0e10cSrcweir removeInforootSubdir("html"); 309cdf0e10cSrcweir removeInforootSubdir("xpd"); 310cdf0e10cSrcweir removeInforootSubdir("images"); 311cdf0e10cSrcweir removeInforootSubdir("jre"); 312cdf0e10cSrcweir removeInforoot(); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir } 316