xref: /AOO41X/main/tools/bootstrp/inimgr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_tools.hxx"
30*cdf0e10cSrcweir #if !defined( UNX )
31*cdf0e10cSrcweir #include <direct.h>
32*cdf0e10cSrcweir #else
33*cdf0e10cSrcweir #include <sys/stat.h>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir #include <stdlib.h>
36*cdf0e10cSrcweir #include <stdio.h>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "bootstrp/inimgr.hxx"
40*cdf0e10cSrcweir #include "bootstrp/appdef.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir /****************************************************************************/
43*cdf0e10cSrcweir IniManager::IniManager( ByteString &rDir, ByteString &rLocalDir )
44*cdf0e10cSrcweir /****************************************************************************/
45*cdf0e10cSrcweir 			: bUpdate( sal_True )
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir 	sLocalPath = ByteString( getenv( "LOCALINI" ));
48*cdf0e10cSrcweir 	if ( !sLocalPath.Len())
49*cdf0e10cSrcweir 		sLocalPath = rLocalDir;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 	sGlobalDir = rDir;
52*cdf0e10cSrcweir #if !defined( UNX ) && !defined( OS2 )
53*cdf0e10cSrcweir 	mkdir(( char * ) sLocalPath.GetBuffer());
54*cdf0e10cSrcweir #else
55*cdf0e10cSrcweir 	mkdir( sLocalPath.GetBuffer() ,00777 );
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir /****************************************************************************/
60*cdf0e10cSrcweir IniManager::IniManager( ByteString &rDir )
61*cdf0e10cSrcweir /****************************************************************************/
62*cdf0e10cSrcweir 			: bUpdate( sal_True )
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	sLocalPath = GetLocalIni();
65*cdf0e10cSrcweir 	sGlobalDir = rDir;
66*cdf0e10cSrcweir #if !defined( UNX ) && !defined( OS2 )
67*cdf0e10cSrcweir 	mkdir(( char * ) sLocalPath.GetBuffer());
68*cdf0e10cSrcweir #else
69*cdf0e10cSrcweir 	mkdir( sLocalPath.GetBuffer() ,00777 );
70*cdf0e10cSrcweir #endif
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir /****************************************************************************/
74*cdf0e10cSrcweir IniManager::IniManager()
75*cdf0e10cSrcweir /****************************************************************************/
76*cdf0e10cSrcweir 			: bUpdate( sal_True )
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 	sLocalPath = GetLocalIni();
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir #if !defined( UNX ) && !defined( OS2 )
81*cdf0e10cSrcweir 	mkdir(( char * ) sLocalPath.GetBuffer());
82*cdf0e10cSrcweir #else
83*cdf0e10cSrcweir 	mkdir( sLocalPath.GetBuffer(), 00777 );
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	sGlobalDir = GetGlobalIni();
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir /****************************************************************************/
90*cdf0e10cSrcweir ByteString IniManager::ToLocal( ByteString &rPath )
91*cdf0e10cSrcweir /****************************************************************************/
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir 	ByteString sTmp( rPath );
94*cdf0e10cSrcweir #if !defined( UNX )
95*cdf0e10cSrcweir 	ByteString sUnc( _INI_UNC );
96*cdf0e10cSrcweir 	sUnc.ToUpperAscii();
97*cdf0e10cSrcweir 	ByteString sOldUnc( _INI_UNC_OLD );
98*cdf0e10cSrcweir 	sOldUnc.ToUpperAscii();
99*cdf0e10cSrcweir 	sTmp.ToUpperAscii();
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	sTmp.SearchAndReplace( sUnc, _INI_DRV );
102*cdf0e10cSrcweir 	sTmp.SearchAndReplace( sOldUnc, _INI_DRV );
103*cdf0e10cSrcweir 	sTmp.ToUpperAscii();
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	ByteString sIni( sGlobalDir );
106*cdf0e10cSrcweir 	sIni.ToUpperAscii();
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	sTmp.SearchAndReplace( sIni, sLocalPath );
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	while ( sTmp.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) ;
111*cdf0e10cSrcweir #else
112*cdf0e10cSrcweir 	sTmp.SearchAndReplace( sGlobalDir, sLocalPath );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	ByteString sOldGlobalDir( GetIniRootOld() );
115*cdf0e10cSrcweir 	sTmp.SearchAndReplace( sOldGlobalDir, sLocalPath );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	while ( sTmp.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) ;
118*cdf0e10cSrcweir #endif
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	return sTmp;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir /****************************************************************************/
124*cdf0e10cSrcweir ByteString IniManager::GetLocalIni()
125*cdf0e10cSrcweir /****************************************************************************/
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir 	ByteString sLocalPath = ByteString( getenv( "LOCALINI" ));
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	if ( !sLocalPath.Len()) {
130*cdf0e10cSrcweir #ifdef UNX
131*cdf0e10cSrcweir 		ByteString sLocal( getenv( "HOME" ));
132*cdf0e10cSrcweir 		sLocal += ByteString( "/localini" );
133*cdf0e10cSrcweir #else
134*cdf0e10cSrcweir 		ByteString sLocal( getenv( "TMP" ));
135*cdf0e10cSrcweir 		sLocal += ByteString( "\\localini" );
136*cdf0e10cSrcweir #endif
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 		sLocalPath = sLocal;
139*cdf0e10cSrcweir 	}
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	return sLocalPath;
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir /****************************************************************************/
145*cdf0e10cSrcweir ByteString IniManager::GetGlobalIni()
146*cdf0e10cSrcweir /****************************************************************************/
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	ByteString sGlobalPath = ByteString( GetEnv( "GLOBALINI" ));
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	if ( !sGlobalPath.Len())
151*cdf0e10cSrcweir 		sGlobalPath = ByteString( _INIROOT );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	return sGlobalPath;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir /****************************************************************************/
157*cdf0e10cSrcweir void IniManager::ForceUpdate()
158*cdf0e10cSrcweir /****************************************************************************/
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir 	UniString sUniGlobalDir( sGlobalDir, gsl_getSystemTextEncoding());
161*cdf0e10cSrcweir 	DirEntry aPath( UniString( sGlobalDir, gsl_getSystemTextEncoding()));
162*cdf0e10cSrcweir 	Dir aDir( aPath, FSYS_KIND_DIR | FSYS_KIND_FILE);
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir #ifndef UNX
165*cdf0e10cSrcweir 	sLocalPath.EraseTrailingChars( '\\' );
166*cdf0e10cSrcweir 	sLocalPath += "\\";
167*cdf0e10cSrcweir #else
168*cdf0e10cSrcweir 	sLocalPath.EraseTrailingChars( '/' );
169*cdf0e10cSrcweir 	sLocalPath += "/";
170*cdf0e10cSrcweir #endif
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	for ( sal_uInt16 i=0; i < aDir.Count(); i++ ) {
173*cdf0e10cSrcweir 		ByteString sEntry( aDir[i].GetName(), gsl_getSystemTextEncoding());
174*cdf0e10cSrcweir 		if (( sEntry != "." ) &&
175*cdf0e10cSrcweir 			( sEntry != ".." ))
176*cdf0e10cSrcweir 		{
177*cdf0e10cSrcweir 			if ( !FileStat( aDir[i] ).IsKind( FSYS_KIND_DIR )) {
178*cdf0e10cSrcweir 				ByteString sSrc( aDir[i].GetFull(), gsl_getSystemTextEncoding());
179*cdf0e10cSrcweir 				ByteString sDestination( sLocalPath );
180*cdf0e10cSrcweir 				sDestination += sEntry;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 				UniString sUniDestination( sDestination, gsl_getSystemTextEncoding());
183*cdf0e10cSrcweir 				DirEntry aDestEntry( sUniDestination );
184*cdf0e10cSrcweir 				FileStat aDestStat( aDestEntry );
185*cdf0e10cSrcweir 				FileStat aSrcStat( aDir[i] );
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 				if (( !aDestEntry.Exists() ) ||
188*cdf0e10cSrcweir 					( aSrcStat.IsYounger( aDestStat )))
189*cdf0e10cSrcweir 				{
190*cdf0e10cSrcweir 					FileCopier aFileCopier( aDir[ i ], aDestEntry );
191*cdf0e10cSrcweir 					aFileCopier.Execute();
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 					while ( !aDestEntry.Exists())
194*cdf0e10cSrcweir 						aFileCopier.Execute();
195*cdf0e10cSrcweir 				}
196*cdf0e10cSrcweir 			}
197*cdf0e10cSrcweir 		}
198*cdf0e10cSrcweir 	}
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir /****************************************************************************/
202*cdf0e10cSrcweir void IniManager::Update()
203*cdf0e10cSrcweir /****************************************************************************/
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir 	if ( bUpdate )
206*cdf0e10cSrcweir 	{
207*cdf0e10cSrcweir 		ForceUpdate();
208*cdf0e10cSrcweir 		bUpdate = sal_False;
209*cdf0e10cSrcweir 	}
210*cdf0e10cSrcweir }
211