Better, Faster, Freer

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: i386 ]
Version: HEAD ]

001 /*************************************************************************
002  *
003  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004  * 
005  * Copyright 2008 by Sun Microsystems, Inc.
006  *
007  * OpenOffice.org - a multi-platform office productivity suite
008  *
009  * $RCSfile: InfoDir.java,v $
010  * $Revision: 1.6 $
011  *
012  * This file is part of OpenOffice.org.
013  *
014  * OpenOffice.org is free software: you can redistribute it and/or modify
015  * it under the terms of the GNU Lesser General Public License version 3
016  * only, as published by the Free Software Foundation.
017  *
018  * OpenOffice.org is distributed in the hope that it will be useful,
019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021  * GNU Lesser General Public License version 3 for more details
022  * (a copy is included in the LICENSE file that accompanied this code).
023  *
024  * You should have received a copy of the GNU Lesser General Public License
025  * version 3 along with OpenOffice.org.  If not, see
026  * <http://www.openoffice.org/license.html>
027  * for a copy of the LGPLv3 License.
028  *
029  ************************************************************************/
030 
031 package org.openoffice.setup.Util;
032 
033 import org.openoffice.setup.InstallData;
034 import org.openoffice.setup.ResourceManager;
035 import java.io.File;
036 import java.util.Vector;
037 
038 public class InfoDir {
039     
040     private InfoDir() {
041     }
042 
043     static private String copySourceFile(String fileName) {
044         InstallData data = InstallData.getInstance();
045         File jarFile = data.getJarFilePath();
046         String destFile = null;
047         
048         if ( jarFile != null ) {
049             String sourceDir = jarFile.getParent();
050             File sourceFileFile = new File(sourceDir, fileName);
051             String sourceFile = sourceFileFile.getPath();
052             
053             // String jarFileName = jarFile.getName();
054             File destDir = new File(data.getInstallDefaultDir(), data.getProductDir());
055             File destFileFile = new File(destDir, fileName);
056             destFile = destFileFile.getPath();
057 
058             boolean success = SystemManager.copy(sourceFile, destFile);
059         }
060         
061         return destFile;
062     }
063 
064     static private void copyInstallDirectoryWithExtension(File destBaseDir, String subDirName, String fileExtension) {
065         InstallData data = InstallData.getInstance();
066         File sourceDir = data.getInfoRoot(subDirName);
067         if ( sourceDir != null ) {
068             File destDir = new File(destBaseDir, subDirName);
069             destDir.mkdir();
070             SystemManager.copyAllFiles(sourceDir, destDir, fileExtension);
071         }
072     }
073 
074     static private void copyInstallDirectoryWithExtension(File destBaseDir, String subDirName, String fileExtension, String unixRights) {
075         InstallData data = InstallData.getInstance();
076         File sourceDir = data.getInfoRoot(subDirName);
077         if ( sourceDir != null ) {
078             File destDir = new File(destBaseDir, subDirName);
079             destDir.mkdir();
080             SystemManager.copyAllFiles(sourceDir, destDir, fileExtension);
081             SystemManager.setUnixPrivilegesDirectory(destDir, fileExtension, unixRights);
082         }        
083     }
084 
085     static private void copyInstallDirectoryDoubleSubdir(File destBaseDir, String dir1, String dir2) {
086         InstallData data = InstallData.getInstance();
087         File sourceDir1 = data.getInfoRoot(dir1);
088         File sourceDir = new File(sourceDir1, dir2);
089         
090         destBaseDir.mkdir();
091         File destDir1 = new File(destBaseDir, dir1);
092         destDir1.mkdir();
093         File destDir = new File(destDir1, dir2);
094         destDir.mkdir();
095 
096         SystemManager.copyAllFiles(sourceDir, destDir);
097     }
098     
099     static private File createUninstallDir() {
100         InstallData data = InstallData.getInstance();
101         File baseDir = new File(data.getInstallDefaultDir(), data.getProductDir());
102         baseDir = new File(baseDir, data.getUninstallDirName());
103         baseDir.mkdir();
104         return baseDir;
105     }
106     
107     static private void copyGetUidSoFile(File dir) {
108         InstallData data = InstallData.getInstance();
109         String uidFileSource = data.getGetUidPath();
110         if ( uidFileSource != null ) {
111             // Copying the "getuid.so" file into installation
112             String fileName = "getuid.so";
113             File destFile = new File(dir, fileName);
114             String uidFileDest = destFile.getPath();
115             boolean success = SystemManager.copy(uidFileSource, uidFileDest);
116             data.setGetUidPath(uidFileDest);
117         }        
118     }
119     
120     static private void copyJreFile(File dir) {
121         InstallData data = InstallData.getInstance();
122         String jrefilename = System.getProperty("JRE_FILE");
123 
124         if ( jrefilename != null ) {
125             // For Solaris, JRE_FILE can already contain the complete path.
126             // Otherwise it contains only the filename
127             File jreFile = new File(jrefilename);
128             
129             if ( ! jreFile.exists()) {
130                 jreFile = new File(data.getPackagePath(), jrefilename);            
131             }
132 
133             if ( jreFile.exists() ) {
134                 String jreFileSource = jreFile.getPath();
135                 File destDir = new File(dir, "jre");
136                 destDir.mkdir();
137                 String onlyFileName = jreFile.getName();
138                 File destFile = new File(destDir, onlyFileName);
139                 
140                 // In maintenance mode the file already exists
141                 if ( ! destFile.exists() ) {
142                     String jreFileDest = destFile.getPath();
143                     boolean success = SystemManager.copy(jreFileSource, jreFileDest);        
144                 }
145             }
146         }       
147     }
148     
149     static private void moveAdminFiles(File dir) {
150         InstallData data = InstallData.getInstance();
151 
152         if ( data.getAdminFileNameReloc() != null ) {
153             File sourceFile = new File(data.getAdminFileNameReloc());
154             String fileName = sourceFile.getName();
155             File destFile = new File(dir, fileName);
156             boolean success = SystemManager.copy(sourceFile.getPath(), destFile.getPath());
157             data.setAdminFileNameReloc(destFile.getPath());
158             sourceFile.delete();
159         }
160         
161         if ( data.getAdminFileNameNoReloc() != null ) {
162             File sourceFile = new File(data.getAdminFileNameNoReloc());
163             String fileName = sourceFile.getName();
164             File destFile = new File(dir, fileName);
165             boolean success = SystemManager.copy(sourceFile.getPath(), destFile.getPath());
166             data.setAdminFileNameNoReloc(destFile.getPath());
167             sourceFile.delete();
168         }
169 
170     }
171     
172     static private void createInfoFile(File dir) {
173         Vector fileContent = new Vector();
174         String line = null;
175         InstallData data = InstallData.getInstance();
176         
177         line = "PackagePath=" + data.getPackagePath();
178         fileContent.add(line);
179         line = "InstallationPrivileges=" + data.getInstallationPrivileges();
180         fileContent.add(line);
181         line = "AdminFileReloc=" + data.getAdminFileNameReloc(); 
182         fileContent.add(line);
183         line = "AdminFileNoReloc=" + data.getAdminFileNameNoReloc(); 
184         fileContent.add(line);
185         line = "InstallationDir=" + data.getInstallDir();        
186         fileContent.add(line);
187         line = "DatabasePath=" + data.getDatabasePath();
188         fileContent.add(line);
189         line = "GetUidFile=" + data.getGetUidPath();
190         fileContent.add(line);
191         
192         String infoFileName = "infoFile";
193         File infoFile = new File(dir, infoFileName);
194         SystemManager.saveCharFileVector(infoFile.getPath(), fileContent);
195     }
196 
197     static private void removeSpecialFiles() {
198         InstallData data = InstallData.getInstance();
199         File jarFile = data.getJarFilePath();
200         SystemManager.deleteFile(jarFile);
201         
202         String jarFilePath = jarFile.getParent();
203         File setupFile = new File(jarFilePath, "setup");
204         SystemManager.deleteFile(setupFile);
205 
206         if ( ! data.getAdminFileNameReloc().equals("null") ) {
207             SystemManager.deleteFile(new File(data.getAdminFileNameReloc()));
208         }
209 
210         if ( ! data.getAdminFileNameNoReloc().equals("null") ) {
211             SystemManager.deleteFile(new File(data.getAdminFileNameNoReloc()));
212         }
213 
214         if ( ! data.getGetUidPath().equals("null") ) {
215             SystemManager.deleteFile(new File(data.getGetUidPath()));            
216         }
217     }
218 
219     static private void removeInforootSubdir(String dir1, String dir2) {
220         InstallData data = InstallData.getInstance();
221         File subdir1 = data.getInfoRoot(dir1);
222         File subdir2 = new File(subdir1, dir2);
223         if (subdir2 != null) {
224             if ( subdir2.exists() ) {
225                 SystemManager.removeDirectory(subdir2);
226             }
227         }
228     }
229 
230     static private void removeInforootSubdir(String dir) {
231         InstallData data = InstallData.getInstance();
232         File subdir = data.getInfoRoot(dir);
233         if (subdir != null) {
234             if ( subdir.exists() ) {
235                 SystemManager.removeDirectory(subdir);
236             }
237         }
238     }
239     
240     static private void removeInforoot() {
241         InstallData data = InstallData.getInstance();
242         SystemManager.removeDirectory(data.getInfoRoot());
243     }
244 
245     static public void prepareUninstallation() {
246         // additional tasks for uninstallation
247         // Directory destDir has to exist!
248         InstallData data = InstallData.getInstance();
249         File destDir = new File(data.getInstallDefaultDir(), data.getProductDir());
250         boolean directoryExists = true;
251 
252         if ( ! destDir.exists() ) {
253             try {
254                 directoryExists = SystemManager.create_directory(destDir.getPath());
255             }
256             catch (SecurityException ex) {
257                 String message = ResourceManager.getString("String_ChooseDirectory_No_Write_Access") + ": " + destDir.getPath();
258                 String title = ResourceManager.getString("String_Error");
259                 Informer.showErrorMessage(message, title);
260             }
261         }
262 
263         if ( directoryExists ) {
264             String setupPath = copySourceFile("setup");
265             SystemManager.setUnixPrivileges(setupPath, "775");
266             File jarFile = data.getJarFilePath();
267             copySourceFile(jarFile.getName());
268 
269             File uninstallDir = createUninstallDir();
270             copyInstallDirectoryWithExtension(uninstallDir, "xpd", "xpd");
271             copyInstallDirectoryWithExtension(uninstallDir, "html", "html");
272             copyInstallDirectoryWithExtension(uninstallDir, "images", "gif");
273             copyInstallDirectoryDoubleSubdir(uninstallDir, "html", "images");
274             copyGetUidSoFile(uninstallDir);
275             copyJreFile(uninstallDir);
276             moveAdminFiles(uninstallDir);
277             createInfoFile(uninstallDir);
278         }
279     }
280 
281     static public void removeUninstallationFiles() {
282         // removing selected File
283         removeSpecialFiles();
284         // removing directories html/images, html and xpd
285         removeInforootSubdir("html", "images");
286         removeInforootSubdir("html");
287         removeInforootSubdir("xpd");
288         removeInforootSubdir("images");
289         removeInforootSubdir("jre");
290         removeInforoot();
291     }
292 
293 }

source navigation ] diff markup ] identifier search ] general search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!