2010-10-14 01:27:31 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 11:07:07 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 07:04:55 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-11 07:04:55 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-11 07:04:55 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-11 07:04:55 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-11 07:04:55 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-11 07:04:55 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 18:48:19 -05:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_tools.hxx"
|
2004-06-11 06:11:30 -05:00
|
|
|
#if !defined( UNX )
|
2000-09-18 11:07:07 -05:00
|
|
|
#include <direct.h>
|
|
|
|
#else
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2006-06-19 07:20:04 -05:00
|
|
|
#include "bootstrp/inimgr.hxx"
|
|
|
|
#include "bootstrp/appdef.hxx"
|
2000-09-18 11:07:07 -05:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
IniManager::IniManager( ByteString &rDir, ByteString &rLocalDir )
|
|
|
|
/****************************************************************************/
|
2010-07-28 21:56:19 -05:00
|
|
|
: bUpdate( sal_True )
|
2000-09-18 11:07:07 -05:00
|
|
|
{
|
|
|
|
sLocalPath = ByteString( getenv( "LOCALINI" ));
|
|
|
|
if ( !sLocalPath.Len())
|
|
|
|
sLocalPath = rLocalDir;
|
|
|
|
|
|
|
|
sGlobalDir = rDir;
|
2007-11-02 06:58:41 -05:00
|
|
|
#if !defined( UNX ) && !defined( OS2 )
|
2000-09-18 11:07:07 -05:00
|
|
|
mkdir(( char * ) sLocalPath.GetBuffer());
|
|
|
|
#else
|
|
|
|
mkdir( sLocalPath.GetBuffer() ,00777 );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
IniManager::IniManager( ByteString &rDir )
|
|
|
|
/****************************************************************************/
|
2010-07-28 21:56:19 -05:00
|
|
|
: bUpdate( sal_True )
|
2000-09-18 11:07:07 -05:00
|
|
|
{
|
|
|
|
sLocalPath = GetLocalIni();
|
|
|
|
sGlobalDir = rDir;
|
2007-11-02 06:58:41 -05:00
|
|
|
#if !defined( UNX ) && !defined( OS2 )
|
2000-09-18 11:07:07 -05:00
|
|
|
mkdir(( char * ) sLocalPath.GetBuffer());
|
|
|
|
#else
|
|
|
|
mkdir( sLocalPath.GetBuffer() ,00777 );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
IniManager::IniManager()
|
|
|
|
/****************************************************************************/
|
2010-07-28 21:56:19 -05:00
|
|
|
: bUpdate( sal_True )
|
2000-09-18 11:07:07 -05:00
|
|
|
{
|
|
|
|
sLocalPath = GetLocalIni();
|
|
|
|
|
2007-11-02 06:58:41 -05:00
|
|
|
#if !defined( UNX ) && !defined( OS2 )
|
2000-09-18 11:07:07 -05:00
|
|
|
mkdir(( char * ) sLocalPath.GetBuffer());
|
|
|
|
#else
|
|
|
|
mkdir( sLocalPath.GetBuffer(), 00777 );
|
|
|
|
#endif
|
|
|
|
|
2001-10-24 04:24:42 -05:00
|
|
|
sGlobalDir = GetGlobalIni();
|
2000-09-18 11:07:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
ByteString IniManager::ToLocal( ByteString &rPath )
|
|
|
|
/****************************************************************************/
|
|
|
|
{
|
|
|
|
ByteString sTmp( rPath );
|
|
|
|
#if !defined( UNX )
|
|
|
|
ByteString sUnc( _INI_UNC );
|
|
|
|
sUnc.ToUpperAscii();
|
|
|
|
ByteString sOldUnc( _INI_UNC_OLD );
|
|
|
|
sOldUnc.ToUpperAscii();
|
|
|
|
sTmp.ToUpperAscii();
|
|
|
|
|
|
|
|
sTmp.SearchAndReplace( sUnc, _INI_DRV );
|
|
|
|
sTmp.SearchAndReplace( sOldUnc, _INI_DRV );
|
|
|
|
sTmp.ToUpperAscii();
|
|
|
|
|
|
|
|
ByteString sIni( sGlobalDir );
|
|
|
|
sIni.ToUpperAscii();
|
|
|
|
|
|
|
|
sTmp.SearchAndReplace( sIni, sLocalPath );
|
|
|
|
|
2008-10-10 08:02:43 -05:00
|
|
|
while ( sTmp.SearchAndReplace( "\\\\", "\\" ) != STRING_NOTFOUND ) ;
|
2000-09-18 11:07:07 -05:00
|
|
|
#else
|
|
|
|
sTmp.SearchAndReplace( sGlobalDir, sLocalPath );
|
|
|
|
|
|
|
|
ByteString sOldGlobalDir( GetIniRootOld() );
|
|
|
|
sTmp.SearchAndReplace( sOldGlobalDir, sLocalPath );
|
|
|
|
|
2008-10-10 08:02:43 -05:00
|
|
|
while ( sTmp.SearchAndReplace( "//", "/" ) != STRING_NOTFOUND ) ;
|
2000-09-18 11:07:07 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return sTmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
ByteString IniManager::GetLocalIni()
|
|
|
|
/****************************************************************************/
|
|
|
|
{
|
|
|
|
ByteString sLocalPath = ByteString( getenv( "LOCALINI" ));
|
|
|
|
|
|
|
|
if ( !sLocalPath.Len()) {
|
|
|
|
#ifdef UNX
|
|
|
|
ByteString sLocal( getenv( "HOME" ));
|
|
|
|
sLocal += ByteString( "/localini" );
|
|
|
|
#else
|
|
|
|
ByteString sLocal( getenv( "TMP" ));
|
|
|
|
sLocal += ByteString( "\\localini" );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sLocalPath = sLocal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sLocalPath;
|
|
|
|
}
|
|
|
|
|
2001-10-24 04:24:42 -05:00
|
|
|
/****************************************************************************/
|
|
|
|
ByteString IniManager::GetGlobalIni()
|
|
|
|
/****************************************************************************/
|
|
|
|
{
|
2003-03-27 10:05:12 -06:00
|
|
|
ByteString sGlobalPath = ByteString( GetEnv( "GLOBALINI" ));
|
2001-10-24 04:24:42 -05:00
|
|
|
|
|
|
|
if ( !sGlobalPath.Len())
|
|
|
|
sGlobalPath = ByteString( _INIROOT );
|
|
|
|
|
|
|
|
return sGlobalPath;
|
|
|
|
}
|
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
/****************************************************************************/
|
|
|
|
void IniManager::ForceUpdate()
|
|
|
|
/****************************************************************************/
|
|
|
|
{
|
|
|
|
UniString sUniGlobalDir( sGlobalDir, gsl_getSystemTextEncoding());
|
|
|
|
DirEntry aPath( UniString( sGlobalDir, gsl_getSystemTextEncoding()));
|
|
|
|
Dir aDir( aPath, FSYS_KIND_DIR | FSYS_KIND_FILE);
|
|
|
|
|
|
|
|
#ifndef UNX
|
|
|
|
sLocalPath.EraseTrailingChars( '\\' );
|
|
|
|
sLocalPath += "\\";
|
|
|
|
#else
|
|
|
|
sLocalPath.EraseTrailingChars( '/' );
|
|
|
|
sLocalPath += "/";
|
|
|
|
#endif
|
|
|
|
|
2010-07-28 21:56:19 -05:00
|
|
|
for ( sal_uInt16 i=0; i < aDir.Count(); i++ ) {
|
2000-09-18 11:07:07 -05:00
|
|
|
ByteString sEntry( aDir[i].GetName(), gsl_getSystemTextEncoding());
|
|
|
|
if (( sEntry != "." ) &&
|
|
|
|
( sEntry != ".." ))
|
|
|
|
{
|
|
|
|
if ( !FileStat( aDir[i] ).IsKind( FSYS_KIND_DIR )) {
|
|
|
|
ByteString sSrc( aDir[i].GetFull(), gsl_getSystemTextEncoding());
|
|
|
|
ByteString sDestination( sLocalPath );
|
|
|
|
sDestination += sEntry;
|
|
|
|
|
|
|
|
UniString sUniDestination( sDestination, gsl_getSystemTextEncoding());
|
|
|
|
DirEntry aDestEntry( sUniDestination );
|
|
|
|
FileStat aDestStat( aDestEntry );
|
|
|
|
FileStat aSrcStat( aDir[i] );
|
|
|
|
|
|
|
|
if (( !aDestEntry.Exists() ) ||
|
|
|
|
( aSrcStat.IsYounger( aDestStat )))
|
|
|
|
{
|
|
|
|
FileCopier aFileCopier( aDir[ i ], aDestEntry );
|
|
|
|
aFileCopier.Execute();
|
|
|
|
|
|
|
|
while ( !aDestEntry.Exists())
|
|
|
|
aFileCopier.Execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
void IniManager::Update()
|
|
|
|
/****************************************************************************/
|
|
|
|
{
|
|
|
|
if ( bUpdate )
|
|
|
|
{
|
|
|
|
ForceUpdate();
|
2010-07-28 21:56:19 -05:00
|
|
|
bUpdate = sal_False;
|
2000-09-18 11:07:07 -05:00
|
|
|
}
|
|
|
|
}
|
2010-10-14 01:27:31 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|