1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
42 #include "bootstrp/inimgr.hxx"
43 #include "bootstrp/appdef.hxx"
45 /****************************************************************************/
46 IniManager::IniManager( ByteString
&rDir
, ByteString
&rLocalDir
)
47 /****************************************************************************/
50 sLocalPath
= ByteString( getenv( "LOCALINI" ));
51 if ( !sLocalPath
.Len())
52 sLocalPath
= rLocalDir
;
55 #if !defined( UNX ) && !defined( OS2 )
56 mkdir(( char * ) sLocalPath
.GetBuffer());
58 mkdir( sLocalPath
.GetBuffer() ,00777 );
62 /****************************************************************************/
63 IniManager::IniManager( ByteString
&rDir
)
64 /****************************************************************************/
67 sLocalPath
= GetLocalIni();
69 #if !defined( UNX ) && !defined( OS2 )
70 mkdir(( char * ) sLocalPath
.GetBuffer());
72 mkdir( sLocalPath
.GetBuffer() ,00777 );
76 /****************************************************************************/
77 IniManager::IniManager()
78 /****************************************************************************/
81 sLocalPath
= GetLocalIni();
83 #if !defined( UNX ) && !defined( OS2 )
84 mkdir(( char * ) sLocalPath
.GetBuffer());
86 mkdir( sLocalPath
.GetBuffer(), 00777 );
89 sGlobalDir
= GetGlobalIni();
92 /****************************************************************************/
93 ByteString
IniManager::ToLocal( ByteString
&rPath
)
94 /****************************************************************************/
96 ByteString
sTmp( rPath
);
98 ByteString
sUnc( _INI_UNC
);
100 ByteString
sOldUnc( _INI_UNC_OLD
);
101 sOldUnc
.ToUpperAscii();
104 sTmp
.SearchAndReplace( sUnc
, _INI_DRV
);
105 sTmp
.SearchAndReplace( sOldUnc
, _INI_DRV
);
108 ByteString
sIni( sGlobalDir
);
111 sTmp
.SearchAndReplace( sIni
, sLocalPath
);
113 while ( sTmp
.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND
) ;
115 sTmp
.SearchAndReplace( sGlobalDir
, sLocalPath
);
117 ByteString
sOldGlobalDir( GetIniRootOld() );
118 sTmp
.SearchAndReplace( sOldGlobalDir
, sLocalPath
);
120 while ( sTmp
.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND
) ;
126 /****************************************************************************/
127 ByteString
IniManager::GetLocalIni()
128 /****************************************************************************/
130 ByteString sLocalPath
= ByteString( getenv( "LOCALINI" ));
132 if ( !sLocalPath
.Len()) {
134 ByteString
sLocal( getenv( "HOME" ));
135 sLocal
+= ByteString( "/localini" );
137 ByteString
sLocal( getenv( "TMP" ));
138 sLocal
+= ByteString( "\\localini" );
147 /****************************************************************************/
148 ByteString
IniManager::GetGlobalIni()
149 /****************************************************************************/
151 ByteString sGlobalPath
= ByteString( GetEnv( "GLOBALINI" ));
153 if ( !sGlobalPath
.Len())
154 sGlobalPath
= ByteString( _INIROOT
);
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
);
168 sLocalPath
.EraseTrailingChars( '\\' );
171 sLocalPath
.EraseTrailingChars( '/' );
175 for ( USHORT i
=0; i
< aDir
.Count(); i
++ ) {
176 ByteString
sEntry( aDir
[i
].GetName(), gsl_getSystemTextEncoding());
177 if (( 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 /****************************************************************************/