Update ooo320-m1
[ooovba.git] / tools / bootstrp / inimgr.cxx
blob25486ea5d94fc9109aa4f4e3aff9d414a1973f25
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inimgr.cxx,v $
10 * $Revision: 1.10.40.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
33 #if !defined( UNX )
34 #include <direct.h>
35 #else
36 #include <sys/stat.h>
37 #endif
38 #include <stdlib.h>
39 #include <stdio.h>
42 #include "bootstrp/inimgr.hxx"
43 #include "bootstrp/appdef.hxx"
45 /****************************************************************************/
46 IniManager::IniManager( ByteString &rDir, ByteString &rLocalDir )
47 /****************************************************************************/
48 : bUpdate( TRUE )
50 sLocalPath = ByteString( getenv( "LOCALINI" ));
51 if ( !sLocalPath.Len())
52 sLocalPath = rLocalDir;
54 sGlobalDir = rDir;
55 #if !defined( UNX ) && !defined( OS2 )
56 mkdir(( char * ) sLocalPath.GetBuffer());
57 #else
58 mkdir( sLocalPath.GetBuffer() ,00777 );
59 #endif
62 /****************************************************************************/
63 IniManager::IniManager( ByteString &rDir )
64 /****************************************************************************/
65 : bUpdate( TRUE )
67 sLocalPath = GetLocalIni();
68 sGlobalDir = rDir;
69 #if !defined( UNX ) && !defined( OS2 )
70 mkdir(( char * ) sLocalPath.GetBuffer());
71 #else
72 mkdir( sLocalPath.GetBuffer() ,00777 );
73 #endif
76 /****************************************************************************/
77 IniManager::IniManager()
78 /****************************************************************************/
79 : bUpdate( TRUE )
81 sLocalPath = GetLocalIni();
83 #if !defined( UNX ) && !defined( OS2 )
84 mkdir(( char * ) sLocalPath.GetBuffer());
85 #else
86 mkdir( sLocalPath.GetBuffer(), 00777 );
87 #endif
89 sGlobalDir = GetGlobalIni();
92 /****************************************************************************/
93 ByteString IniManager::ToLocal( ByteString &rPath )
94 /****************************************************************************/
96 ByteString sTmp( rPath );
97 #if !defined( UNX )
98 ByteString sUnc( _INI_UNC );
99 sUnc.ToUpperAscii();
100 ByteString sOldUnc( _INI_UNC_OLD );
101 sOldUnc.ToUpperAscii();
102 sTmp.ToUpperAscii();
104 sTmp.SearchAndReplace( sUnc, _INI_DRV );
105 sTmp.SearchAndReplace( sOldUnc, _INI_DRV );
106 sTmp.ToUpperAscii();
108 ByteString sIni( sGlobalDir );
109 sIni.ToUpperAscii();
111 sTmp.SearchAndReplace( sIni, sLocalPath );
113 while ( sTmp.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) ;
114 #else
115 sTmp.SearchAndReplace( sGlobalDir, sLocalPath );
117 ByteString sOldGlobalDir( GetIniRootOld() );
118 sTmp.SearchAndReplace( sOldGlobalDir, sLocalPath );
120 while ( sTmp.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) ;
121 #endif
123 return sTmp;
126 /****************************************************************************/
127 ByteString IniManager::GetLocalIni()
128 /****************************************************************************/
130 ByteString sLocalPath = ByteString( getenv( "LOCALINI" ));
132 if ( !sLocalPath.Len()) {
133 #ifdef UNX
134 ByteString sLocal( getenv( "HOME" ));
135 sLocal += ByteString( "/localini" );
136 #else
137 ByteString sLocal( getenv( "TMP" ));
138 sLocal += ByteString( "\\localini" );
139 #endif
141 sLocalPath = sLocal;
144 return sLocalPath;
147 /****************************************************************************/
148 ByteString IniManager::GetGlobalIni()
149 /****************************************************************************/
151 ByteString sGlobalPath = ByteString( GetEnv( "GLOBALINI" ));
153 if ( !sGlobalPath.Len())
154 sGlobalPath = ByteString( _INIROOT );
156 return sGlobalPath;
159 /****************************************************************************/
160 void IniManager::ForceUpdate()
161 /****************************************************************************/
163 UniString sUniGlobalDir( sGlobalDir, gsl_getSystemTextEncoding());
164 DirEntry aPath( UniString( sGlobalDir, gsl_getSystemTextEncoding()));
165 Dir aDir( aPath, FSYS_KIND_DIR | FSYS_KIND_FILE);
167 #ifndef UNX
168 sLocalPath.EraseTrailingChars( '\\' );
169 sLocalPath += "\\";
170 #else
171 sLocalPath.EraseTrailingChars( '/' );
172 sLocalPath += "/";
173 #endif
175 for ( USHORT i=0; i < aDir.Count(); i++ ) {
176 ByteString sEntry( aDir[i].GetName(), gsl_getSystemTextEncoding());
177 if (( sEntry != "." ) &&
178 ( sEntry != ".." ))
180 if ( !FileStat( aDir[i] ).IsKind( FSYS_KIND_DIR )) {
181 ByteString sSrc( aDir[i].GetFull(), gsl_getSystemTextEncoding());
182 ByteString sDestination( sLocalPath );
183 sDestination += sEntry;
185 UniString sUniDestination( sDestination, gsl_getSystemTextEncoding());
186 DirEntry aDestEntry( sUniDestination );
187 FileStat aDestStat( aDestEntry );
188 FileStat aSrcStat( aDir[i] );
190 if (( !aDestEntry.Exists() ) ||
191 ( aSrcStat.IsYounger( aDestStat )))
193 FileCopier aFileCopier( aDir[ i ], aDestEntry );
194 aFileCopier.Execute();
196 while ( !aDestEntry.Exists())
197 aFileCopier.Execute();
204 /****************************************************************************/
205 void IniManager::Update()
206 /****************************************************************************/
208 if ( bUpdate )
210 ForceUpdate();
211 bUpdate = FALSE;