xref: /aoo41x/main/tools/bootstrp/inimgr.cxx (revision 89b56da7)
1*89b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*89b56da7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*89b56da7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*89b56da7SAndrew Rist  * distributed with this work for additional information
6*89b56da7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*89b56da7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*89b56da7SAndrew Rist  * "License"); you may not use this file except in compliance
9*89b56da7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*89b56da7SAndrew Rist  *
11*89b56da7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*89b56da7SAndrew Rist  *
13*89b56da7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*89b56da7SAndrew Rist  * software distributed under the License is distributed on an
15*89b56da7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*89b56da7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*89b56da7SAndrew Rist  * specific language governing permissions and limitations
18*89b56da7SAndrew Rist  * under the License.
19*89b56da7SAndrew Rist  *
20*89b56da7SAndrew Rist  *************************************************************/
21*89b56da7SAndrew Rist 
22*89b56da7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir #if !defined( UNX )
27cdf0e10cSrcweir #include <direct.h>
28cdf0e10cSrcweir #else
29cdf0e10cSrcweir #include <sys/stat.h>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <stdlib.h>
32cdf0e10cSrcweir #include <stdio.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "bootstrp/inimgr.hxx"
36cdf0e10cSrcweir #include "bootstrp/appdef.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /****************************************************************************/
IniManager(ByteString & rDir,ByteString & rLocalDir)39cdf0e10cSrcweir IniManager::IniManager( ByteString &rDir, ByteString &rLocalDir )
40cdf0e10cSrcweir /****************************************************************************/
41cdf0e10cSrcweir 			: bUpdate( sal_True )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	sLocalPath = ByteString( getenv( "LOCALINI" ));
44cdf0e10cSrcweir 	if ( !sLocalPath.Len())
45cdf0e10cSrcweir 		sLocalPath = rLocalDir;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	sGlobalDir = rDir;
48cdf0e10cSrcweir #if !defined( UNX ) && !defined( OS2 )
49cdf0e10cSrcweir 	mkdir(( char * ) sLocalPath.GetBuffer());
50cdf0e10cSrcweir #else
51cdf0e10cSrcweir 	mkdir( sLocalPath.GetBuffer() ,00777 );
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir /****************************************************************************/
IniManager(ByteString & rDir)56cdf0e10cSrcweir IniManager::IniManager( ByteString &rDir )
57cdf0e10cSrcweir /****************************************************************************/
58cdf0e10cSrcweir 			: bUpdate( sal_True )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	sLocalPath = GetLocalIni();
61cdf0e10cSrcweir 	sGlobalDir = rDir;
62cdf0e10cSrcweir #if !defined( UNX ) && !defined( OS2 )
63cdf0e10cSrcweir 	mkdir(( char * ) sLocalPath.GetBuffer());
64cdf0e10cSrcweir #else
65cdf0e10cSrcweir 	mkdir( sLocalPath.GetBuffer() ,00777 );
66cdf0e10cSrcweir #endif
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir /****************************************************************************/
IniManager()70cdf0e10cSrcweir IniManager::IniManager()
71cdf0e10cSrcweir /****************************************************************************/
72cdf0e10cSrcweir 			: bUpdate( sal_True )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	sLocalPath = GetLocalIni();
75cdf0e10cSrcweir 
76cdf0e10cSrcweir #if !defined( UNX ) && !defined( OS2 )
77cdf0e10cSrcweir 	mkdir(( char * ) sLocalPath.GetBuffer());
78cdf0e10cSrcweir #else
79cdf0e10cSrcweir 	mkdir( sLocalPath.GetBuffer(), 00777 );
80cdf0e10cSrcweir #endif
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	sGlobalDir = GetGlobalIni();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir /****************************************************************************/
ToLocal(ByteString & rPath)86cdf0e10cSrcweir ByteString IniManager::ToLocal( ByteString &rPath )
87cdf0e10cSrcweir /****************************************************************************/
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	ByteString sTmp( rPath );
90cdf0e10cSrcweir #if !defined( UNX )
91cdf0e10cSrcweir 	ByteString sUnc( _INI_UNC );
92cdf0e10cSrcweir 	sUnc.ToUpperAscii();
93cdf0e10cSrcweir 	ByteString sOldUnc( _INI_UNC_OLD );
94cdf0e10cSrcweir 	sOldUnc.ToUpperAscii();
95cdf0e10cSrcweir 	sTmp.ToUpperAscii();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	sTmp.SearchAndReplace( sUnc, _INI_DRV );
98cdf0e10cSrcweir 	sTmp.SearchAndReplace( sOldUnc, _INI_DRV );
99cdf0e10cSrcweir 	sTmp.ToUpperAscii();
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	ByteString sIni( sGlobalDir );
102cdf0e10cSrcweir 	sIni.ToUpperAscii();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	sTmp.SearchAndReplace( sIni, sLocalPath );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	while ( sTmp.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) ;
107cdf0e10cSrcweir #else
108cdf0e10cSrcweir 	sTmp.SearchAndReplace( sGlobalDir, sLocalPath );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	ByteString sOldGlobalDir( GetIniRootOld() );
111cdf0e10cSrcweir 	sTmp.SearchAndReplace( sOldGlobalDir, sLocalPath );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	while ( sTmp.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) ;
114cdf0e10cSrcweir #endif
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	return sTmp;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir /****************************************************************************/
GetLocalIni()120cdf0e10cSrcweir ByteString IniManager::GetLocalIni()
121cdf0e10cSrcweir /****************************************************************************/
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	ByteString sLocalPath = ByteString( getenv( "LOCALINI" ));
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	if ( !sLocalPath.Len()) {
126cdf0e10cSrcweir #ifdef UNX
127cdf0e10cSrcweir 		ByteString sLocal( getenv( "HOME" ));
128cdf0e10cSrcweir 		sLocal += ByteString( "/localini" );
129cdf0e10cSrcweir #else
130cdf0e10cSrcweir 		ByteString sLocal( getenv( "TMP" ));
131cdf0e10cSrcweir 		sLocal += ByteString( "\\localini" );
132cdf0e10cSrcweir #endif
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 		sLocalPath = sLocal;
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	return sLocalPath;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir /****************************************************************************/
GetGlobalIni()141cdf0e10cSrcweir ByteString IniManager::GetGlobalIni()
142cdf0e10cSrcweir /****************************************************************************/
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	ByteString sGlobalPath = ByteString( GetEnv( "GLOBALINI" ));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	if ( !sGlobalPath.Len())
147cdf0e10cSrcweir 		sGlobalPath = ByteString( _INIROOT );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	return sGlobalPath;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir /****************************************************************************/
ForceUpdate()153cdf0e10cSrcweir void IniManager::ForceUpdate()
154cdf0e10cSrcweir /****************************************************************************/
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	UniString sUniGlobalDir( sGlobalDir, gsl_getSystemTextEncoding());
157cdf0e10cSrcweir 	DirEntry aPath( UniString( sGlobalDir, gsl_getSystemTextEncoding()));
158cdf0e10cSrcweir 	Dir aDir( aPath, FSYS_KIND_DIR | FSYS_KIND_FILE);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir #ifndef UNX
161cdf0e10cSrcweir 	sLocalPath.EraseTrailingChars( '\\' );
162cdf0e10cSrcweir 	sLocalPath += "\\";
163cdf0e10cSrcweir #else
164cdf0e10cSrcweir 	sLocalPath.EraseTrailingChars( '/' );
165cdf0e10cSrcweir 	sLocalPath += "/";
166cdf0e10cSrcweir #endif
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	for ( sal_uInt16 i=0; i < aDir.Count(); i++ ) {
169cdf0e10cSrcweir 		ByteString sEntry( aDir[i].GetName(), gsl_getSystemTextEncoding());
170cdf0e10cSrcweir 		if (( sEntry != "." ) &&
171cdf0e10cSrcweir 			( sEntry != ".." ))
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			if ( !FileStat( aDir[i] ).IsKind( FSYS_KIND_DIR )) {
174cdf0e10cSrcweir 				ByteString sSrc( aDir[i].GetFull(), gsl_getSystemTextEncoding());
175cdf0e10cSrcweir 				ByteString sDestination( sLocalPath );
176cdf0e10cSrcweir 				sDestination += sEntry;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 				UniString sUniDestination( sDestination, gsl_getSystemTextEncoding());
179cdf0e10cSrcweir 				DirEntry aDestEntry( sUniDestination );
180cdf0e10cSrcweir 				FileStat aDestStat( aDestEntry );
181cdf0e10cSrcweir 				FileStat aSrcStat( aDir[i] );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 				if (( !aDestEntry.Exists() ) ||
184cdf0e10cSrcweir 					( aSrcStat.IsYounger( aDestStat )))
185cdf0e10cSrcweir 				{
186cdf0e10cSrcweir 					FileCopier aFileCopier( aDir[ i ], aDestEntry );
187cdf0e10cSrcweir 					aFileCopier.Execute();
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 					while ( !aDestEntry.Exists())
190cdf0e10cSrcweir 						aFileCopier.Execute();
191cdf0e10cSrcweir 				}
192cdf0e10cSrcweir 			}
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir /****************************************************************************/
Update()198cdf0e10cSrcweir void IniManager::Update()
199cdf0e10cSrcweir /****************************************************************************/
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	if ( bUpdate )
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		ForceUpdate();
204cdf0e10cSrcweir 		bUpdate = sal_False;
205cdf0e10cSrcweir 	}
206cdf0e10cSrcweir }
207