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 31*cdf0e10cSrcweir #define _CONFIG_CXX 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <cstddef> 34*cdf0e10cSrcweir #include <cstdlib> 35*cdf0e10cSrcweir #include <limits> 36*cdf0e10cSrcweir #include <new> 37*cdf0e10cSrcweir #include <string.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #ifdef WNT 40*cdf0e10cSrcweir #include "stdlib.h" 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir #include <osl/file.hxx> 43*cdf0e10cSrcweir #include <tools/stream.hxx> 44*cdf0e10cSrcweir #include <tools/debug.hxx> 45*cdf0e10cSrcweir #include <tools/config.hxx> 46*cdf0e10cSrcweir #include <osl/security.h> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #define MAXBUFLEN 1024 // Fuer Buffer bei VOS-Funktionen 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ----------------- 51*cdf0e10cSrcweir // - ImplConfigData - 52*cdf0e10cSrcweir // ----------------- 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir struct ImplKeyData 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir ImplKeyData* mpNext; 57*cdf0e10cSrcweir ByteString maKey; 58*cdf0e10cSrcweir ByteString maValue; 59*cdf0e10cSrcweir sal_Bool mbIsComment; 60*cdf0e10cSrcweir }; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir struct ImplGroupData 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir ImplGroupData* mpNext; 65*cdf0e10cSrcweir ImplKeyData* mpFirstKey; 66*cdf0e10cSrcweir ByteString maGroupName; 67*cdf0e10cSrcweir sal_uInt16 mnEmptyLines; 68*cdf0e10cSrcweir }; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir struct ImplConfigData 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir ImplGroupData* mpFirstGroup; 73*cdf0e10cSrcweir XubString maFileName; 74*cdf0e10cSrcweir sal_uIntPtr mnDataUpdateId; 75*cdf0e10cSrcweir sal_uIntPtr mnTimeStamp; 76*cdf0e10cSrcweir LineEnd meLineEnd; 77*cdf0e10cSrcweir sal_uInt16 mnRefCount; 78*cdf0e10cSrcweir sal_Bool mbModified; 79*cdf0e10cSrcweir sal_Bool mbRead; 80*cdf0e10cSrcweir sal_Bool mbIsUTF8BOM; 81*cdf0e10cSrcweir }; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir // ======================================================================= 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir static ByteString& getEmptyByteString() 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir static ByteString aEmpty; 88*cdf0e10cSrcweir return aEmpty; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir // ======================================================================= 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir static String toUncPath( const String& rPath ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir ::rtl::OUString aFileURL; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // check if rFileName is already a URL; if not make it so 98*cdf0e10cSrcweir if( rPath.CompareToAscii( "file://", 7 ) == COMPARE_EQUAL ) 99*cdf0e10cSrcweir aFileURL = rPath; 100*cdf0e10cSrcweir else if( ::osl::FileBase::getFileURLFromSystemPath( rPath, aFileURL ) != ::osl::FileBase::E_None ) 101*cdf0e10cSrcweir aFileURL = rPath; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir return aFileURL; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir static sal_uIntPtr ImplSysGetConfigTimeStamp( const XubString& rFileName ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir sal_uIntPtr nTimeStamp = 0; 109*cdf0e10cSrcweir ::osl::DirectoryItem aItem; 110*cdf0e10cSrcweir ::osl::FileStatus aStatus( osl_FileStatus_Mask_ModifyTime ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir int nError = 0; 113*cdf0e10cSrcweir if( ( nError = ::osl::DirectoryItem::get( rFileName, aItem ) ) == ::osl::FileBase::E_None && 114*cdf0e10cSrcweir aItem.getFileStatus( aStatus ) == ::osl::FileBase::E_None ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir nTimeStamp = aStatus.getModifyTime().Seconds; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir return nTimeStamp; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir // ----------------------------------------------------------------------- 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir static sal_uInt8* ImplSysReadConfig( const XubString& rFileName, 125*cdf0e10cSrcweir sal_uInt64& rRead, sal_Bool& rbRead, sal_Bool& rbIsUTF8BOM, sal_uIntPtr& rTimeStamp ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir sal_uInt8* pBuf = NULL; 128*cdf0e10cSrcweir ::osl::File aFile( rFileName ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir if( aFile.open( osl_File_OpenFlag_Read ) == ::osl::FileBase::E_None ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir sal_uInt64 nPos = 0, nRead = 0; 133*cdf0e10cSrcweir if( aFile.getSize( nPos ) == ::osl::FileBase::E_None ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir if (nPos > std::numeric_limits< std::size_t >::max()) { 136*cdf0e10cSrcweir aFile.close(); 137*cdf0e10cSrcweir return 0; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir pBuf = new sal_uInt8[static_cast< std::size_t >(nPos)]; 140*cdf0e10cSrcweir if( aFile.read( pBuf, nPos, nRead ) == ::osl::FileBase::E_None && nRead == nPos ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir //skip the byte-order-mark 0xEF 0xBB 0xBF, if it was UTF8 files 143*cdf0e10cSrcweir unsigned char BOM[3] = {0xEF, 0xBB, 0xBF}; 144*cdf0e10cSrcweir if (nRead > 2 && memcmp(pBuf, BOM, 3) == 0) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir nRead -= 3; 147*cdf0e10cSrcweir rtl_moveMemory(pBuf, pBuf + 3, sal::static_int_cast<sal_Size>(nRead * sizeof(sal_uInt8)) ); 148*cdf0e10cSrcweir rbIsUTF8BOM = sal_True; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir rTimeStamp = ImplSysGetConfigTimeStamp( rFileName ); 152*cdf0e10cSrcweir rbRead = sal_True; 153*cdf0e10cSrcweir rRead = nRead; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir else 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir delete[] pBuf; 158*cdf0e10cSrcweir pBuf = NULL; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir aFile.close(); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir return pBuf; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // ----------------------------------------------------------------------- 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir static sal_Bool ImplSysWriteConfig( const XubString& rFileName, 170*cdf0e10cSrcweir const sal_uInt8* pBuf, sal_uIntPtr nBufLen, sal_Bool rbIsUTF8BOM, sal_uIntPtr& rTimeStamp ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 173*cdf0e10cSrcweir sal_Bool bUTF8BOMSuccess = sal_False; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir ::osl::File aFile( rFileName ); 176*cdf0e10cSrcweir ::osl::FileBase::RC eError = aFile.open( osl_File_OpenFlag_Write | osl_File_OpenFlag_Create ); 177*cdf0e10cSrcweir if( eError != ::osl::FileBase::E_None ) 178*cdf0e10cSrcweir eError = aFile.open( osl_File_OpenFlag_Write ); 179*cdf0e10cSrcweir if( eError == ::osl::FileBase::E_None ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir // truncate 182*cdf0e10cSrcweir aFile.setSize( 0 ); 183*cdf0e10cSrcweir sal_uInt64 nWritten; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir //write the the byte-order-mark 0xEF 0xBB 0xBF first , if it was UTF8 files 186*cdf0e10cSrcweir if ( rbIsUTF8BOM ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir unsigned char BOM[3] = {0xEF, 0xBB, 0xBF}; 189*cdf0e10cSrcweir sal_uInt64 nUTF8BOMWritten; 190*cdf0e10cSrcweir if( aFile.write( BOM, 3, nUTF8BOMWritten ) == ::osl::FileBase::E_None && 3 == nUTF8BOMWritten ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir bUTF8BOMSuccess = sal_True; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if( aFile.write( pBuf, nBufLen, nWritten ) == ::osl::FileBase::E_None && nWritten == nBufLen ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir bSuccess = sal_True; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir if ( rbIsUTF8BOM ? bSuccess && bUTF8BOMSuccess : bSuccess ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir rTimeStamp = ImplSysGetConfigTimeStamp( rFileName ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir return rbIsUTF8BOM ? bSuccess && bUTF8BOMSuccess : bSuccess; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // ----------------------------------------------------------------------- 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir static String ImplMakeConfigName( const XubString* pFileName, 212*cdf0e10cSrcweir const XubString* pPathName ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir ::rtl::OUString aFileName; 215*cdf0e10cSrcweir ::rtl::OUString aPathName; 216*cdf0e10cSrcweir if ( pFileName ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir #ifdef UNX 219*cdf0e10cSrcweir aFileName = ::rtl::OUString::createFromAscii( "." ); 220*cdf0e10cSrcweir aFileName += *pFileName; 221*cdf0e10cSrcweir aFileName += ::rtl::OUString::createFromAscii( "rc" ); 222*cdf0e10cSrcweir #else 223*cdf0e10cSrcweir aFileName = *pFileName; 224*cdf0e10cSrcweir aFileName += ::rtl::OUString::createFromAscii( ".ini" ); 225*cdf0e10cSrcweir #endif 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir else 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir #ifdef UNX 230*cdf0e10cSrcweir aFileName = ::rtl::OUString::createFromAscii( ".sversionrc" ); 231*cdf0e10cSrcweir #else 232*cdf0e10cSrcweir aFileName = ::rtl::OUString::createFromAscii( "sversion.ini" ); 233*cdf0e10cSrcweir #endif 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // #88208# in case pPathName is set but empty and pFileName is set 237*cdf0e10cSrcweir // and not empty just return the filename; on the default case 238*cdf0e10cSrcweir // prepend default path as usual 239*cdf0e10cSrcweir if ( pPathName && pPathName->Len() ) 240*cdf0e10cSrcweir aPathName = toUncPath( *pPathName ); 241*cdf0e10cSrcweir else if( pPathName && pFileName && pFileName->Len() ) 242*cdf0e10cSrcweir return aFileName; 243*cdf0e10cSrcweir else 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir oslSecurity aSec = osl_getCurrentSecurity(); 246*cdf0e10cSrcweir osl_getConfigDir( aSec, &aPathName.pData ); 247*cdf0e10cSrcweir osl_freeSecurityHandle( aSec ); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir ::rtl::OUString aName( aPathName ); 251*cdf0e10cSrcweir aName += ::rtl::OUString::createFromAscii( "/" ); 252*cdf0e10cSrcweir aName += aFileName; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir return aName; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // ----------------------------------------------------------------------- 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir namespace { 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir ByteString makeByteString(sal_uInt8 const * p, sal_uInt64 n) { 262*cdf0e10cSrcweir if (n > STRING_MAXLEN) { 263*cdf0e10cSrcweir #ifdef WNT 264*cdf0e10cSrcweir abort(); 265*cdf0e10cSrcweir #else 266*cdf0e10cSrcweir ::std::abort(); //TODO: handle this gracefully 267*cdf0e10cSrcweir #endif 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir return ByteString( 270*cdf0e10cSrcweir reinterpret_cast< char const * >(p), 271*cdf0e10cSrcweir sal::static_int_cast< xub_StrLen >(n)); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir static void ImplMakeConfigList( ImplConfigData* pData, 277*cdf0e10cSrcweir const sal_uInt8* pBuf, sal_uInt64 nLen ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir // kein Buffer, keine Daten 280*cdf0e10cSrcweir if ( !nLen ) 281*cdf0e10cSrcweir return; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // Buffer parsen und Liste zusammenbauen 284*cdf0e10cSrcweir sal_uInt64 nStart; 285*cdf0e10cSrcweir sal_uInt64 nLineLen; 286*cdf0e10cSrcweir xub_StrLen nNameLen; 287*cdf0e10cSrcweir xub_StrLen nKeyLen; 288*cdf0e10cSrcweir sal_uInt64 i; 289*cdf0e10cSrcweir const sal_uInt8* pLine; 290*cdf0e10cSrcweir ImplKeyData* pPrevKey = NULL; 291*cdf0e10cSrcweir ImplKeyData* pKey; 292*cdf0e10cSrcweir ImplGroupData* pPrevGroup = NULL; 293*cdf0e10cSrcweir ImplGroupData* pGroup = NULL; 294*cdf0e10cSrcweir i = 0; 295*cdf0e10cSrcweir while ( i < nLen ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir // Ctrl+Z 298*cdf0e10cSrcweir if ( pBuf[i] == 0x1A ) 299*cdf0e10cSrcweir break; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // Spaces und Tabs entfernen 302*cdf0e10cSrcweir while ( (pBuf[i] == ' ') || (pBuf[i] == '\t') ) 303*cdf0e10cSrcweir i++; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir // Zeilenanfang merken 306*cdf0e10cSrcweir nStart = i; 307*cdf0e10cSrcweir pLine = pBuf+i; 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir // Zeilenende suchen 310*cdf0e10cSrcweir while ( (i < nLen) && pBuf[i] && (pBuf[i] != '\r') && (pBuf[i] != '\n') && 311*cdf0e10cSrcweir (pBuf[i] != 0x1A) ) 312*cdf0e10cSrcweir i++; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir nLineLen = i-nStart; 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir // Wenn Zeilenende (CR/LF), dann noch einen weiterschalten 317*cdf0e10cSrcweir if ( (i+1 < nLen) && 318*cdf0e10cSrcweir (pBuf[i] != pBuf[i+1]) && 319*cdf0e10cSrcweir ((pBuf[i+1] == '\r') || (pBuf[i+1] == '\n')) ) 320*cdf0e10cSrcweir i++; 321*cdf0e10cSrcweir i++; 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir // Zeile auswerten 324*cdf0e10cSrcweir if ( *pLine == '[' ) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir pGroup = new ImplGroupData; 327*cdf0e10cSrcweir pGroup->mpNext = NULL; 328*cdf0e10cSrcweir pGroup->mpFirstKey = NULL; 329*cdf0e10cSrcweir pGroup->mnEmptyLines = 0; 330*cdf0e10cSrcweir if ( pPrevGroup ) 331*cdf0e10cSrcweir pPrevGroup->mpNext = pGroup; 332*cdf0e10cSrcweir else 333*cdf0e10cSrcweir pData->mpFirstGroup = pGroup; 334*cdf0e10cSrcweir pPrevGroup = pGroup; 335*cdf0e10cSrcweir pPrevKey = NULL; 336*cdf0e10cSrcweir pKey = NULL; 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir // Gruppennamen rausfiltern 339*cdf0e10cSrcweir pLine++; 340*cdf0e10cSrcweir nLineLen--; 341*cdf0e10cSrcweir // Spaces und Tabs entfernen 342*cdf0e10cSrcweir while ( (*pLine == ' ') || (*pLine == '\t') ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir nLineLen--; 345*cdf0e10cSrcweir pLine++; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir nNameLen = 0; 348*cdf0e10cSrcweir while ( (nNameLen < nLineLen) && (pLine[nNameLen] != ']') ) 349*cdf0e10cSrcweir nNameLen++; 350*cdf0e10cSrcweir if ( nNameLen ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir while ( (pLine[nNameLen-1] == ' ') || (pLine[nNameLen-1] == '\t') ) 353*cdf0e10cSrcweir nNameLen--; 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir pGroup->maGroupName = ByteString( (const sal_Char*)pLine, nNameLen ); 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir else 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir if ( nLineLen ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir // Wenn noch keine Gruppe existiert, dann alle Keys in die 362*cdf0e10cSrcweir // Default-Gruppe 363*cdf0e10cSrcweir if ( !pGroup ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir pGroup = new ImplGroupData; 366*cdf0e10cSrcweir pGroup->mpNext = NULL; 367*cdf0e10cSrcweir pGroup->mpFirstKey = NULL; 368*cdf0e10cSrcweir pGroup->mnEmptyLines = 0; 369*cdf0e10cSrcweir if ( pPrevGroup ) 370*cdf0e10cSrcweir pPrevGroup->mpNext = pGroup; 371*cdf0e10cSrcweir else 372*cdf0e10cSrcweir pData->mpFirstGroup = pGroup; 373*cdf0e10cSrcweir pPrevGroup = pGroup; 374*cdf0e10cSrcweir pPrevKey = NULL; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir // Falls Leerzeile vorhanden, dann anhaengen 378*cdf0e10cSrcweir if ( pPrevKey ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir while ( pGroup->mnEmptyLines ) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir pKey = new ImplKeyData; 383*cdf0e10cSrcweir pKey->mbIsComment = sal_True; 384*cdf0e10cSrcweir pPrevKey->mpNext = pKey; 385*cdf0e10cSrcweir pPrevKey = pKey; 386*cdf0e10cSrcweir pGroup->mnEmptyLines--; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir // Neuen Key erzeugen 391*cdf0e10cSrcweir pKey = new ImplKeyData; 392*cdf0e10cSrcweir pKey->mpNext = NULL; 393*cdf0e10cSrcweir if ( pPrevKey ) 394*cdf0e10cSrcweir pPrevKey->mpNext = pKey; 395*cdf0e10cSrcweir else 396*cdf0e10cSrcweir pGroup->mpFirstKey = pKey; 397*cdf0e10cSrcweir pPrevKey = pKey; 398*cdf0e10cSrcweir if ( pLine[0] == ';' ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir pKey->maValue = makeByteString(pLine, nLineLen); 401*cdf0e10cSrcweir pKey->mbIsComment = sal_True; 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir else 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir pKey->mbIsComment = sal_False; 406*cdf0e10cSrcweir nNameLen = 0; 407*cdf0e10cSrcweir while ( (nNameLen < nLineLen) && (pLine[nNameLen] != '=') ) 408*cdf0e10cSrcweir nNameLen++; 409*cdf0e10cSrcweir nKeyLen = nNameLen; 410*cdf0e10cSrcweir // Spaces und Tabs entfernen 411*cdf0e10cSrcweir if ( nNameLen ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir while ( (pLine[nNameLen-1] == ' ') || (pLine[nNameLen-1] == '\t') ) 414*cdf0e10cSrcweir nNameLen--; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir pKey->maKey = ByteString( (const sal_Char*)pLine, nNameLen ); 417*cdf0e10cSrcweir nKeyLen++; 418*cdf0e10cSrcweir if ( nKeyLen < nLineLen ) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir pLine += nKeyLen; 421*cdf0e10cSrcweir nLineLen -= nKeyLen; 422*cdf0e10cSrcweir // Spaces und Tabs entfernen 423*cdf0e10cSrcweir while ( (*pLine == ' ') || (*pLine == '\t') ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir nLineLen--; 426*cdf0e10cSrcweir pLine++; 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir if ( nLineLen ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir while ( (pLine[nLineLen-1] == ' ') || (pLine[nLineLen-1] == '\t') ) 431*cdf0e10cSrcweir nLineLen--; 432*cdf0e10cSrcweir pKey->maValue = makeByteString(pLine, nLineLen); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir else 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir // Leerzeilen werden nur gezaehlt und beim Erzeugen des 440*cdf0e10cSrcweir // naechsten Keys angehaengt, da wir Leerzeilen am Ende 441*cdf0e10cSrcweir // einer Gruppe auch nach hinzufuegen von neuen Keys nur 442*cdf0e10cSrcweir // am Ende der Gruppe wieder speichern wollen 443*cdf0e10cSrcweir if ( pGroup ) 444*cdf0e10cSrcweir pGroup->mnEmptyLines++; 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir // ----------------------------------------------------------------------- 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir static sal_uInt8* ImplGetConfigBuffer( const ImplConfigData* pData, sal_uIntPtr& rLen ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir sal_uInt8* pWriteBuf; 455*cdf0e10cSrcweir sal_uInt8* pBuf; 456*cdf0e10cSrcweir sal_uInt8 aLineEndBuf[2] = {0, 0}; 457*cdf0e10cSrcweir ImplKeyData* pKey; 458*cdf0e10cSrcweir ImplGroupData* pGroup; 459*cdf0e10cSrcweir unsigned int nBufLen; 460*cdf0e10cSrcweir sal_uInt16 nValueLen; 461*cdf0e10cSrcweir sal_uInt16 nKeyLen; 462*cdf0e10cSrcweir sal_uInt16 nLineEndLen; 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir if ( pData->meLineEnd == LINEEND_CR ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir aLineEndBuf[0] = _CR; 467*cdf0e10cSrcweir nLineEndLen = 1; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir else if ( pData->meLineEnd == LINEEND_LF ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir aLineEndBuf[0] = _LF; 472*cdf0e10cSrcweir nLineEndLen = 1; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir else 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir aLineEndBuf[0] = _CR; 477*cdf0e10cSrcweir aLineEndBuf[1] = _LF; 478*cdf0e10cSrcweir nLineEndLen = 2; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir // Buffergroesse ermitteln 482*cdf0e10cSrcweir nBufLen = 0; 483*cdf0e10cSrcweir pGroup = pData->mpFirstGroup; 484*cdf0e10cSrcweir while ( pGroup ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir // Leere Gruppen werden nicht geschrieben 487*cdf0e10cSrcweir if ( pGroup->mpFirstKey ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir nBufLen += pGroup->maGroupName.Len() + nLineEndLen + 2; 490*cdf0e10cSrcweir pKey = pGroup->mpFirstKey; 491*cdf0e10cSrcweir while ( pKey ) 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir nValueLen = pKey->maValue.Len(); 494*cdf0e10cSrcweir if ( pKey->mbIsComment ) 495*cdf0e10cSrcweir nBufLen += nValueLen + nLineEndLen; 496*cdf0e10cSrcweir else 497*cdf0e10cSrcweir nBufLen += pKey->maKey.Len() + nValueLen + nLineEndLen + 1; 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir pKey = pKey->mpNext; 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir // Leerzeile nach jeder Gruppe auch wieder speichern 503*cdf0e10cSrcweir if ( !pGroup->mnEmptyLines ) 504*cdf0e10cSrcweir pGroup->mnEmptyLines = 1; 505*cdf0e10cSrcweir nBufLen += nLineEndLen * pGroup->mnEmptyLines; 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir pGroup = pGroup->mpNext; 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir // Laenge dem Aufrufer mitteilen 512*cdf0e10cSrcweir rLen = nBufLen; 513*cdf0e10cSrcweir if ( !nBufLen ) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir pWriteBuf = new sal_uInt8[nLineEndLen]; 516*cdf0e10cSrcweir if ( pWriteBuf ) 517*cdf0e10cSrcweir { 518*cdf0e10cSrcweir pWriteBuf[0] = aLineEndBuf[0]; 519*cdf0e10cSrcweir if ( nLineEndLen == 2 ) 520*cdf0e10cSrcweir pWriteBuf[1] = aLineEndBuf[1]; 521*cdf0e10cSrcweir return pWriteBuf; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir else 524*cdf0e10cSrcweir return 0; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir // Schreibbuffer anlegen (wird vom Aufrufer zerstoert) 528*cdf0e10cSrcweir pWriteBuf = new sal_uInt8[nBufLen]; 529*cdf0e10cSrcweir if ( !pWriteBuf ) 530*cdf0e10cSrcweir return 0; 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir // Buffer fuellen 533*cdf0e10cSrcweir pBuf = pWriteBuf; 534*cdf0e10cSrcweir pGroup = pData->mpFirstGroup; 535*cdf0e10cSrcweir while ( pGroup ) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir // Leere Gruppen werden nicht geschrieben 538*cdf0e10cSrcweir if ( pGroup->mpFirstKey ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir *pBuf = '['; pBuf++; 541*cdf0e10cSrcweir memcpy( pBuf, pGroup->maGroupName.GetBuffer(), pGroup->maGroupName.Len() ); 542*cdf0e10cSrcweir pBuf += pGroup->maGroupName.Len(); 543*cdf0e10cSrcweir *pBuf = ']'; pBuf++; 544*cdf0e10cSrcweir *pBuf = aLineEndBuf[0]; pBuf++; 545*cdf0e10cSrcweir if ( nLineEndLen == 2 ) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir *pBuf = aLineEndBuf[1]; pBuf++; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir pKey = pGroup->mpFirstKey; 550*cdf0e10cSrcweir while ( pKey ) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir nValueLen = pKey->maValue.Len(); 553*cdf0e10cSrcweir if ( pKey->mbIsComment ) 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir if ( nValueLen ) 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir memcpy( pBuf, pKey->maValue.GetBuffer(), nValueLen ); 558*cdf0e10cSrcweir pBuf += nValueLen; 559*cdf0e10cSrcweir } 560*cdf0e10cSrcweir *pBuf = aLineEndBuf[0]; pBuf++; 561*cdf0e10cSrcweir if ( nLineEndLen == 2 ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir *pBuf = aLineEndBuf[1]; pBuf++; 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir else 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir nKeyLen = pKey->maKey.Len(); 569*cdf0e10cSrcweir memcpy( pBuf, pKey->maKey.GetBuffer(), nKeyLen ); 570*cdf0e10cSrcweir pBuf += nKeyLen; 571*cdf0e10cSrcweir *pBuf = '='; pBuf++; 572*cdf0e10cSrcweir memcpy( pBuf, pKey->maValue.GetBuffer(), nValueLen ); 573*cdf0e10cSrcweir pBuf += nValueLen; 574*cdf0e10cSrcweir *pBuf = aLineEndBuf[0]; pBuf++; 575*cdf0e10cSrcweir if ( nLineEndLen == 2 ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir *pBuf = aLineEndBuf[1]; pBuf++; 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir pKey = pKey->mpNext; 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // Leerzeile nach jeder Gruppe auch wieder speichern 585*cdf0e10cSrcweir sal_uInt16 nEmptyLines = pGroup->mnEmptyLines; 586*cdf0e10cSrcweir while ( nEmptyLines ) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir *pBuf = aLineEndBuf[0]; pBuf++; 589*cdf0e10cSrcweir if ( nLineEndLen == 2 ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir *pBuf = aLineEndBuf[1]; pBuf++; 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir nEmptyLines--; 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir pGroup = pGroup->mpNext; 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir return pWriteBuf; 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir // ----------------------------------------------------------------------- 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir static void ImplReadConfig( ImplConfigData* pData ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir sal_uIntPtr nTimeStamp = 0; 608*cdf0e10cSrcweir sal_uInt64 nRead = 0; 609*cdf0e10cSrcweir sal_Bool bRead = sal_False; 610*cdf0e10cSrcweir sal_Bool bIsUTF8BOM =sal_False; 611*cdf0e10cSrcweir sal_uInt8* pBuf = ImplSysReadConfig( pData->maFileName, nRead, bRead, bIsUTF8BOM, nTimeStamp ); 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir // Aus dem Buffer die Config-Verwaltungsliste aufbauen 614*cdf0e10cSrcweir if ( pBuf ) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir ImplMakeConfigList( pData, pBuf, nRead ); 617*cdf0e10cSrcweir delete[] pBuf; 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir pData->mnTimeStamp = nTimeStamp; 620*cdf0e10cSrcweir pData->mbModified = sal_False; 621*cdf0e10cSrcweir if ( bRead ) 622*cdf0e10cSrcweir pData->mbRead = sal_True; 623*cdf0e10cSrcweir if ( bIsUTF8BOM ) 624*cdf0e10cSrcweir pData->mbIsUTF8BOM = sal_True; 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir // ----------------------------------------------------------------------- 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir static void ImplWriteConfig( ImplConfigData* pData ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir #ifdef DBG_UTIL 632*cdf0e10cSrcweir if ( DbgIsAssert() ) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir if ( pData->mnTimeStamp != ImplSysGetConfigTimeStamp( pData->maFileName ) ) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir DBG_ERROR1( "Config overwrites modified configfile:\n %s", ByteString( pData->maFileName, RTL_TEXTENCODING_UTF8 ).GetBuffer() ); 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir #endif 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir // Aus der Config-Liste einen Buffer zusammenbauen 642*cdf0e10cSrcweir sal_uIntPtr nBufLen; 643*cdf0e10cSrcweir sal_uInt8* pBuf = ImplGetConfigBuffer( pData, nBufLen ); 644*cdf0e10cSrcweir if ( pBuf ) 645*cdf0e10cSrcweir { 646*cdf0e10cSrcweir if ( ImplSysWriteConfig( pData->maFileName, pBuf, nBufLen, pData->mbIsUTF8BOM, pData->mnTimeStamp ) ) 647*cdf0e10cSrcweir pData->mbModified = sal_False; 648*cdf0e10cSrcweir delete[] pBuf; 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir else 651*cdf0e10cSrcweir pData->mbModified = sal_False; 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir // ----------------------------------------------------------------------- 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir static void ImplDeleteConfigData( ImplConfigData* pData ) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir ImplKeyData* pTempKey; 659*cdf0e10cSrcweir ImplKeyData* pKey; 660*cdf0e10cSrcweir ImplGroupData* pTempGroup; 661*cdf0e10cSrcweir ImplGroupData* pGroup = pData->mpFirstGroup; 662*cdf0e10cSrcweir while ( pGroup ) 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir pTempGroup = pGroup->mpNext; 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir // Alle Keys loeschen 667*cdf0e10cSrcweir pKey = pGroup->mpFirstKey; 668*cdf0e10cSrcweir while ( pKey ) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir pTempKey = pKey->mpNext; 671*cdf0e10cSrcweir delete pKey; 672*cdf0e10cSrcweir pKey = pTempKey; 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir // Gruppe loeschen und weiterschalten 676*cdf0e10cSrcweir delete pGroup; 677*cdf0e10cSrcweir pGroup = pTempGroup; 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir pData->mpFirstGroup = NULL; 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir // ======================================================================= 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir static ImplConfigData* ImplGetConfigData( const XubString& rFileName ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir ImplConfigData* pData; 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir pData = new ImplConfigData; 690*cdf0e10cSrcweir pData->maFileName = rFileName; 691*cdf0e10cSrcweir pData->mpFirstGroup = NULL; 692*cdf0e10cSrcweir pData->mnDataUpdateId = 0; 693*cdf0e10cSrcweir pData->meLineEnd = LINEEND_CRLF; 694*cdf0e10cSrcweir pData->mnRefCount = 0; 695*cdf0e10cSrcweir pData->mbRead = sal_False; 696*cdf0e10cSrcweir pData->mbIsUTF8BOM = sal_False; 697*cdf0e10cSrcweir ImplReadConfig( pData ); 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir return pData; 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir // ----------------------------------------------------------------------- 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir static void ImplFreeConfigData( ImplConfigData* pDelData ) 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir ImplDeleteConfigData( pDelData ); 707*cdf0e10cSrcweir delete pDelData; 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir // ======================================================================= 711*cdf0e10cSrcweir 712*cdf0e10cSrcweir sal_Bool Config::ImplUpdateConfig() const 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir // Wenn sich TimeStamp unterscheidet, dann Datei neu einlesen 715*cdf0e10cSrcweir if ( mpData->mnTimeStamp != ImplSysGetConfigTimeStamp( maFileName ) ) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir ImplDeleteConfigData( mpData ); 718*cdf0e10cSrcweir ImplReadConfig( mpData ); 719*cdf0e10cSrcweir mpData->mnDataUpdateId++; 720*cdf0e10cSrcweir return sal_True; 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir else 723*cdf0e10cSrcweir return sal_False; 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir // ----------------------------------------------------------------------- 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir ImplGroupData* Config::ImplGetGroup() const 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir if ( !mpActGroup || (mnDataUpdateId != mpData->mnDataUpdateId) ) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir ImplGroupData* pPrevGroup = NULL; 733*cdf0e10cSrcweir ImplGroupData* pGroup = mpData->mpFirstGroup; 734*cdf0e10cSrcweir while ( pGroup ) 735*cdf0e10cSrcweir { 736*cdf0e10cSrcweir if ( pGroup->maGroupName.EqualsIgnoreCaseAscii( maGroupName ) ) 737*cdf0e10cSrcweir break; 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir pPrevGroup = pGroup; 740*cdf0e10cSrcweir pGroup = pGroup->mpNext; 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir // Falls Gruppe noch nicht existiert, dann dazufuegen 744*cdf0e10cSrcweir if ( !pGroup ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir pGroup = new ImplGroupData; 747*cdf0e10cSrcweir pGroup->mpNext = NULL; 748*cdf0e10cSrcweir pGroup->mpFirstKey = NULL; 749*cdf0e10cSrcweir pGroup->mnEmptyLines = 1; 750*cdf0e10cSrcweir if ( pPrevGroup ) 751*cdf0e10cSrcweir pPrevGroup->mpNext = pGroup; 752*cdf0e10cSrcweir else 753*cdf0e10cSrcweir mpData->mpFirstGroup = pGroup; 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir // Gruppenname immer uebernehmen, da er auch in dieser Form 757*cdf0e10cSrcweir // geschrieben werden soll. Ausserdem die Cache-Members der 758*cdf0e10cSrcweir // Config-Klasse updaten 759*cdf0e10cSrcweir pGroup->maGroupName = maGroupName; 760*cdf0e10cSrcweir ((Config*)this)->mnDataUpdateId = mpData->mnDataUpdateId; 761*cdf0e10cSrcweir ((Config*)this)->mpActGroup = pGroup; 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir return mpActGroup; 765*cdf0e10cSrcweir } 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir // ======================================================================= 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir Config::Config() 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir // Daten initialisieren und einlesen 772*cdf0e10cSrcweir maFileName = ImplMakeConfigName( NULL, NULL ); 773*cdf0e10cSrcweir mpData = ImplGetConfigData( maFileName ); 774*cdf0e10cSrcweir mpActGroup = NULL; 775*cdf0e10cSrcweir mnDataUpdateId = 0; 776*cdf0e10cSrcweir mnLockCount = 1; 777*cdf0e10cSrcweir mbPersistence = sal_True; 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir #ifdef DBG_UTIL 780*cdf0e10cSrcweir DBG_TRACE( "Config::Config()" ); 781*cdf0e10cSrcweir #endif 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir // ----------------------------------------------------------------------- 785*cdf0e10cSrcweir 786*cdf0e10cSrcweir Config::Config( const XubString& rFileName ) 787*cdf0e10cSrcweir { 788*cdf0e10cSrcweir // Daten initialisieren und einlesen 789*cdf0e10cSrcweir maFileName = toUncPath( rFileName ); 790*cdf0e10cSrcweir mpData = ImplGetConfigData( maFileName ); 791*cdf0e10cSrcweir mpActGroup = NULL; 792*cdf0e10cSrcweir mnDataUpdateId = 0; 793*cdf0e10cSrcweir mnLockCount = 1; 794*cdf0e10cSrcweir mbPersistence = sal_True; 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir #ifdef DBG_UTIL 797*cdf0e10cSrcweir ByteString aTraceStr( "Config::Config( " ); 798*cdf0e10cSrcweir aTraceStr += ByteString( maFileName, RTL_TEXTENCODING_UTF8 ); 799*cdf0e10cSrcweir aTraceStr += " )"; 800*cdf0e10cSrcweir DBG_TRACE( aTraceStr.GetBuffer() ); 801*cdf0e10cSrcweir #endif 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir // ----------------------------------------------------------------------- 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir Config::~Config() 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir #ifdef DBG_UTIL 809*cdf0e10cSrcweir DBG_TRACE( "Config::~Config()" ); 810*cdf0e10cSrcweir #endif 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir Flush(); 813*cdf0e10cSrcweir ImplFreeConfigData( mpData ); 814*cdf0e10cSrcweir } 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir // ----------------------------------------------------------------------- 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir String Config::GetDefDirectory() 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir ::rtl::OUString aDefConfig; 821*cdf0e10cSrcweir oslSecurity aSec = osl_getCurrentSecurity(); 822*cdf0e10cSrcweir osl_getConfigDir( aSec, &aDefConfig.pData ); 823*cdf0e10cSrcweir osl_freeSecurityHandle( aSec ); 824*cdf0e10cSrcweir 825*cdf0e10cSrcweir return aDefConfig; 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir // ----------------------------------------------------------------------- 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir XubString Config::GetConfigName( const XubString& rPath, 831*cdf0e10cSrcweir const XubString& rBaseName ) 832*cdf0e10cSrcweir { 833*cdf0e10cSrcweir return ImplMakeConfigName( &rBaseName, &rPath ); 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir // ----------------------------------------------------------------------- 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir void Config::SetGroup( const ByteString& rGroup ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir // Wenn neue Gruppe gesetzt wird, muss beim naechsten mal die 841*cdf0e10cSrcweir // Gruppe neu ermittelt werden 842*cdf0e10cSrcweir if ( maGroupName != rGroup ) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir maGroupName = rGroup; 845*cdf0e10cSrcweir mnDataUpdateId = mpData->mnDataUpdateId-1; 846*cdf0e10cSrcweir } 847*cdf0e10cSrcweir } 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir // ----------------------------------------------------------------------- 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir void Config::DeleteGroup( const ByteString& rGroup ) 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir // Config-Daten evt. updaten 854*cdf0e10cSrcweir if ( !mnLockCount || !mpData->mbRead ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir ImplUpdateConfig(); 857*cdf0e10cSrcweir mpData->mbRead = sal_True; 858*cdf0e10cSrcweir } 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir ImplGroupData* pPrevGroup = NULL; 861*cdf0e10cSrcweir ImplGroupData* pGroup = mpData->mpFirstGroup; 862*cdf0e10cSrcweir while ( pGroup ) 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir if ( pGroup->maGroupName.EqualsIgnoreCaseAscii( rGroup ) ) 865*cdf0e10cSrcweir break; 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir pPrevGroup = pGroup; 868*cdf0e10cSrcweir pGroup = pGroup->mpNext; 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir if ( pGroup ) 872*cdf0e10cSrcweir { 873*cdf0e10cSrcweir // Alle Keys loeschen 874*cdf0e10cSrcweir ImplKeyData* pTempKey; 875*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 876*cdf0e10cSrcweir while ( pKey ) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir pTempKey = pKey->mpNext; 879*cdf0e10cSrcweir delete pKey; 880*cdf0e10cSrcweir pKey = pTempKey; 881*cdf0e10cSrcweir } 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir // Gruppe weiterschalten und loeschen 884*cdf0e10cSrcweir if ( pPrevGroup ) 885*cdf0e10cSrcweir pPrevGroup->mpNext = pGroup->mpNext; 886*cdf0e10cSrcweir else 887*cdf0e10cSrcweir mpData->mpFirstGroup = pGroup->mpNext; 888*cdf0e10cSrcweir delete pGroup; 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir // Config-Datei neu schreiben 891*cdf0e10cSrcweir if ( !mnLockCount && mbPersistence ) 892*cdf0e10cSrcweir ImplWriteConfig( mpData ); 893*cdf0e10cSrcweir else 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir mpData->mbModified = sal_True; 896*cdf0e10cSrcweir } 897*cdf0e10cSrcweir 898*cdf0e10cSrcweir // Gruppen auf ungluetig setzen 899*cdf0e10cSrcweir mnDataUpdateId = mpData->mnDataUpdateId; 900*cdf0e10cSrcweir mpData->mnDataUpdateId++; 901*cdf0e10cSrcweir } 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir // ----------------------------------------------------------------------- 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir ByteString Config::GetGroupName( sal_uInt16 nGroup ) const 907*cdf0e10cSrcweir { 908*cdf0e10cSrcweir // Config-Daten evt. updaten 909*cdf0e10cSrcweir if ( !mnLockCount ) 910*cdf0e10cSrcweir ImplUpdateConfig(); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir ImplGroupData* pGroup = mpData->mpFirstGroup; 913*cdf0e10cSrcweir sal_uInt16 nGroupCount = 0; 914*cdf0e10cSrcweir ByteString aGroupName; 915*cdf0e10cSrcweir while ( pGroup ) 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir if ( nGroup == nGroupCount ) 918*cdf0e10cSrcweir { 919*cdf0e10cSrcweir aGroupName = pGroup->maGroupName; 920*cdf0e10cSrcweir break; 921*cdf0e10cSrcweir } 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir nGroupCount++; 924*cdf0e10cSrcweir pGroup = pGroup->mpNext; 925*cdf0e10cSrcweir } 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir return aGroupName; 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir // ----------------------------------------------------------------------- 931*cdf0e10cSrcweir 932*cdf0e10cSrcweir sal_uInt16 Config::GetGroupCount() const 933*cdf0e10cSrcweir { 934*cdf0e10cSrcweir // Config-Daten evt. updaten 935*cdf0e10cSrcweir if ( !mnLockCount ) 936*cdf0e10cSrcweir ImplUpdateConfig(); 937*cdf0e10cSrcweir 938*cdf0e10cSrcweir ImplGroupData* pGroup = mpData->mpFirstGroup; 939*cdf0e10cSrcweir sal_uInt16 nGroupCount = 0; 940*cdf0e10cSrcweir while ( pGroup ) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir nGroupCount++; 943*cdf0e10cSrcweir pGroup = pGroup->mpNext; 944*cdf0e10cSrcweir } 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir return nGroupCount; 947*cdf0e10cSrcweir } 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir // ----------------------------------------------------------------------- 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir sal_Bool Config::HasGroup( const ByteString& rGroup ) const 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir // Config-Daten evt. updaten 954*cdf0e10cSrcweir if ( !mnLockCount ) 955*cdf0e10cSrcweir ImplUpdateConfig(); 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir ImplGroupData* pGroup = mpData->mpFirstGroup; 958*cdf0e10cSrcweir sal_Bool bRet = sal_False; 959*cdf0e10cSrcweir 960*cdf0e10cSrcweir while( pGroup ) 961*cdf0e10cSrcweir { 962*cdf0e10cSrcweir if( pGroup->maGroupName.EqualsIgnoreCaseAscii( rGroup ) ) 963*cdf0e10cSrcweir { 964*cdf0e10cSrcweir bRet = sal_True; 965*cdf0e10cSrcweir break; 966*cdf0e10cSrcweir } 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir pGroup = pGroup->mpNext; 969*cdf0e10cSrcweir } 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir return bRet; 972*cdf0e10cSrcweir } 973*cdf0e10cSrcweir 974*cdf0e10cSrcweir // ----------------------------------------------------------------------- 975*cdf0e10cSrcweir 976*cdf0e10cSrcweir ByteString Config::ReadKey( const ByteString& rKey ) const 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir return ReadKey( rKey, getEmptyByteString() ); 979*cdf0e10cSrcweir } 980*cdf0e10cSrcweir 981*cdf0e10cSrcweir // ----------------------------------------------------------------------- 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir UniString Config::ReadKey( const ByteString& rKey, rtl_TextEncoding eEncoding ) const 984*cdf0e10cSrcweir { 985*cdf0e10cSrcweir if ( mpData->mbIsUTF8BOM ) 986*cdf0e10cSrcweir eEncoding = RTL_TEXTENCODING_UTF8; 987*cdf0e10cSrcweir return UniString( ReadKey( rKey ), eEncoding ); 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir 990*cdf0e10cSrcweir // ----------------------------------------------------------------------- 991*cdf0e10cSrcweir 992*cdf0e10cSrcweir ByteString Config::ReadKey( const ByteString& rKey, const ByteString& rDefault ) const 993*cdf0e10cSrcweir { 994*cdf0e10cSrcweir #ifdef DBG_UTIL 995*cdf0e10cSrcweir ByteString aTraceStr( "Config::ReadKey( " ); 996*cdf0e10cSrcweir aTraceStr += rKey; 997*cdf0e10cSrcweir aTraceStr += " ) from "; 998*cdf0e10cSrcweir aTraceStr += GetGroup(); 999*cdf0e10cSrcweir aTraceStr += " in "; 1000*cdf0e10cSrcweir aTraceStr += ByteString( maFileName, RTL_TEXTENCODING_UTF8 ); 1001*cdf0e10cSrcweir DBG_TRACE( aTraceStr.GetBuffer() ); 1002*cdf0e10cSrcweir #endif 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir // Config-Daten evt. updaten 1005*cdf0e10cSrcweir if ( !mnLockCount ) 1006*cdf0e10cSrcweir ImplUpdateConfig(); 1007*cdf0e10cSrcweir 1008*cdf0e10cSrcweir // Key suchen und Value zurueckgeben 1009*cdf0e10cSrcweir ImplGroupData* pGroup = ImplGetGroup(); 1010*cdf0e10cSrcweir if ( pGroup ) 1011*cdf0e10cSrcweir { 1012*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 1013*cdf0e10cSrcweir while ( pKey ) 1014*cdf0e10cSrcweir { 1015*cdf0e10cSrcweir if ( !pKey->mbIsComment && pKey->maKey.EqualsIgnoreCaseAscii( rKey ) ) 1016*cdf0e10cSrcweir return pKey->maValue; 1017*cdf0e10cSrcweir 1018*cdf0e10cSrcweir pKey = pKey->mpNext; 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir } 1021*cdf0e10cSrcweir 1022*cdf0e10cSrcweir return rDefault; 1023*cdf0e10cSrcweir } 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir void Config::WriteKey( const ByteString& rKey, const ByteString& rStr ) 1028*cdf0e10cSrcweir { 1029*cdf0e10cSrcweir #ifdef DBG_UTIL 1030*cdf0e10cSrcweir ByteString aTraceStr( "Config::WriteKey( " ); 1031*cdf0e10cSrcweir aTraceStr += rKey; 1032*cdf0e10cSrcweir aTraceStr += ", "; 1033*cdf0e10cSrcweir aTraceStr += rStr; 1034*cdf0e10cSrcweir aTraceStr += " ) to "; 1035*cdf0e10cSrcweir aTraceStr += GetGroup(); 1036*cdf0e10cSrcweir aTraceStr += " in "; 1037*cdf0e10cSrcweir aTraceStr += ByteString( maFileName, RTL_TEXTENCODING_UTF8 ); 1038*cdf0e10cSrcweir DBG_TRACE( aTraceStr.GetBuffer() ); 1039*cdf0e10cSrcweir DBG_ASSERTWARNING( rStr != ReadKey( rKey ), "Config::WriteKey() with the same Value" ); 1040*cdf0e10cSrcweir #endif 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir // Config-Daten evt. updaten 1043*cdf0e10cSrcweir if ( !mnLockCount || !mpData->mbRead ) 1044*cdf0e10cSrcweir { 1045*cdf0e10cSrcweir ImplUpdateConfig(); 1046*cdf0e10cSrcweir mpData->mbRead = sal_True; 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir 1049*cdf0e10cSrcweir // Key suchen und Value setzen 1050*cdf0e10cSrcweir ImplGroupData* pGroup = ImplGetGroup(); 1051*cdf0e10cSrcweir if ( pGroup ) 1052*cdf0e10cSrcweir { 1053*cdf0e10cSrcweir ImplKeyData* pPrevKey = NULL; 1054*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 1055*cdf0e10cSrcweir while ( pKey ) 1056*cdf0e10cSrcweir { 1057*cdf0e10cSrcweir if ( !pKey->mbIsComment && pKey->maKey.EqualsIgnoreCaseAscii( rKey ) ) 1058*cdf0e10cSrcweir break; 1059*cdf0e10cSrcweir 1060*cdf0e10cSrcweir pPrevKey = pKey; 1061*cdf0e10cSrcweir pKey = pKey->mpNext; 1062*cdf0e10cSrcweir } 1063*cdf0e10cSrcweir 1064*cdf0e10cSrcweir sal_Bool bNewValue; 1065*cdf0e10cSrcweir if ( !pKey ) 1066*cdf0e10cSrcweir { 1067*cdf0e10cSrcweir pKey = new ImplKeyData; 1068*cdf0e10cSrcweir pKey->mpNext = NULL; 1069*cdf0e10cSrcweir pKey->maKey = rKey; 1070*cdf0e10cSrcweir pKey->mbIsComment = sal_False; 1071*cdf0e10cSrcweir if ( pPrevKey ) 1072*cdf0e10cSrcweir pPrevKey->mpNext = pKey; 1073*cdf0e10cSrcweir else 1074*cdf0e10cSrcweir pGroup->mpFirstKey = pKey; 1075*cdf0e10cSrcweir bNewValue = sal_True; 1076*cdf0e10cSrcweir } 1077*cdf0e10cSrcweir else 1078*cdf0e10cSrcweir bNewValue = pKey->maValue != rStr; 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir if ( bNewValue ) 1081*cdf0e10cSrcweir { 1082*cdf0e10cSrcweir pKey->maValue = rStr; 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir if ( !mnLockCount && mbPersistence ) 1085*cdf0e10cSrcweir ImplWriteConfig( mpData ); 1086*cdf0e10cSrcweir else 1087*cdf0e10cSrcweir { 1088*cdf0e10cSrcweir mpData->mbModified = sal_True; 1089*cdf0e10cSrcweir } 1090*cdf0e10cSrcweir } 1091*cdf0e10cSrcweir } 1092*cdf0e10cSrcweir } 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1095*cdf0e10cSrcweir 1096*cdf0e10cSrcweir void Config::WriteKey( const ByteString& rKey, const UniString& rValue, rtl_TextEncoding eEncoding ) 1097*cdf0e10cSrcweir { 1098*cdf0e10cSrcweir if ( mpData->mbIsUTF8BOM ) 1099*cdf0e10cSrcweir eEncoding = RTL_TEXTENCODING_UTF8; 1100*cdf0e10cSrcweir WriteKey( rKey, ByteString( rValue, eEncoding ) ); 1101*cdf0e10cSrcweir } 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1104*cdf0e10cSrcweir 1105*cdf0e10cSrcweir void Config::DeleteKey( const ByteString& rKey ) 1106*cdf0e10cSrcweir { 1107*cdf0e10cSrcweir // Config-Daten evt. updaten 1108*cdf0e10cSrcweir if ( !mnLockCount || !mpData->mbRead ) 1109*cdf0e10cSrcweir { 1110*cdf0e10cSrcweir ImplUpdateConfig(); 1111*cdf0e10cSrcweir mpData->mbRead = sal_True; 1112*cdf0e10cSrcweir } 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir // Key suchen und Value setzen 1115*cdf0e10cSrcweir ImplGroupData* pGroup = ImplGetGroup(); 1116*cdf0e10cSrcweir if ( pGroup ) 1117*cdf0e10cSrcweir { 1118*cdf0e10cSrcweir ImplKeyData* pPrevKey = NULL; 1119*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 1120*cdf0e10cSrcweir while ( pKey ) 1121*cdf0e10cSrcweir { 1122*cdf0e10cSrcweir if ( !pKey->mbIsComment && pKey->maKey.EqualsIgnoreCaseAscii( rKey ) ) 1123*cdf0e10cSrcweir break; 1124*cdf0e10cSrcweir 1125*cdf0e10cSrcweir pPrevKey = pKey; 1126*cdf0e10cSrcweir pKey = pKey->mpNext; 1127*cdf0e10cSrcweir } 1128*cdf0e10cSrcweir 1129*cdf0e10cSrcweir if ( pKey ) 1130*cdf0e10cSrcweir { 1131*cdf0e10cSrcweir // Gruppe weiterschalten und loeschen 1132*cdf0e10cSrcweir if ( pPrevKey ) 1133*cdf0e10cSrcweir pPrevKey->mpNext = pKey->mpNext; 1134*cdf0e10cSrcweir else 1135*cdf0e10cSrcweir pGroup->mpFirstKey = pKey->mpNext; 1136*cdf0e10cSrcweir delete pKey; 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir // Config-Datei neu schreiben 1139*cdf0e10cSrcweir if ( !mnLockCount && mbPersistence ) 1140*cdf0e10cSrcweir ImplWriteConfig( mpData ); 1141*cdf0e10cSrcweir else 1142*cdf0e10cSrcweir { 1143*cdf0e10cSrcweir mpData->mbModified = sal_True; 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir } 1146*cdf0e10cSrcweir } 1147*cdf0e10cSrcweir } 1148*cdf0e10cSrcweir 1149*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir sal_uInt16 Config::GetKeyCount() const 1152*cdf0e10cSrcweir { 1153*cdf0e10cSrcweir #ifdef DBG_UTIL 1154*cdf0e10cSrcweir ByteString aTraceStr( "Config::GetKeyCount()" ); 1155*cdf0e10cSrcweir aTraceStr += " from "; 1156*cdf0e10cSrcweir aTraceStr += GetGroup(); 1157*cdf0e10cSrcweir aTraceStr += " in "; 1158*cdf0e10cSrcweir aTraceStr += ByteString( maFileName, RTL_TEXTENCODING_UTF8 ); 1159*cdf0e10cSrcweir DBG_TRACE( aTraceStr.GetBuffer() ); 1160*cdf0e10cSrcweir #endif 1161*cdf0e10cSrcweir 1162*cdf0e10cSrcweir // Config-Daten evt. updaten 1163*cdf0e10cSrcweir if ( !mnLockCount ) 1164*cdf0e10cSrcweir ImplUpdateConfig(); 1165*cdf0e10cSrcweir 1166*cdf0e10cSrcweir // Key suchen und Value zurueckgeben 1167*cdf0e10cSrcweir sal_uInt16 nCount = 0; 1168*cdf0e10cSrcweir ImplGroupData* pGroup = ImplGetGroup(); 1169*cdf0e10cSrcweir if ( pGroup ) 1170*cdf0e10cSrcweir { 1171*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 1172*cdf0e10cSrcweir while ( pKey ) 1173*cdf0e10cSrcweir { 1174*cdf0e10cSrcweir if ( !pKey->mbIsComment ) 1175*cdf0e10cSrcweir nCount++; 1176*cdf0e10cSrcweir 1177*cdf0e10cSrcweir pKey = pKey->mpNext; 1178*cdf0e10cSrcweir } 1179*cdf0e10cSrcweir } 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir return nCount; 1182*cdf0e10cSrcweir } 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1185*cdf0e10cSrcweir 1186*cdf0e10cSrcweir ByteString Config::GetKeyName( sal_uInt16 nKey ) const 1187*cdf0e10cSrcweir { 1188*cdf0e10cSrcweir #ifdef DBG_UTIL 1189*cdf0e10cSrcweir ByteString aTraceStr( "Config::GetKeyName( " ); 1190*cdf0e10cSrcweir aTraceStr += ByteString::CreateFromInt32(nKey); 1191*cdf0e10cSrcweir aTraceStr += " ) from "; 1192*cdf0e10cSrcweir aTraceStr += GetGroup(); 1193*cdf0e10cSrcweir aTraceStr += " in "; 1194*cdf0e10cSrcweir aTraceStr += ByteString( maFileName, RTL_TEXTENCODING_UTF8 ); 1195*cdf0e10cSrcweir DBG_TRACE( aTraceStr.GetBuffer() ); 1196*cdf0e10cSrcweir #endif 1197*cdf0e10cSrcweir 1198*cdf0e10cSrcweir // Key suchen und Name zurueckgeben 1199*cdf0e10cSrcweir ImplGroupData* pGroup = ImplGetGroup(); 1200*cdf0e10cSrcweir if ( pGroup ) 1201*cdf0e10cSrcweir { 1202*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 1203*cdf0e10cSrcweir while ( pKey ) 1204*cdf0e10cSrcweir { 1205*cdf0e10cSrcweir if ( !pKey->mbIsComment ) 1206*cdf0e10cSrcweir { 1207*cdf0e10cSrcweir if ( !nKey ) 1208*cdf0e10cSrcweir return pKey->maKey; 1209*cdf0e10cSrcweir nKey--; 1210*cdf0e10cSrcweir } 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir pKey = pKey->mpNext; 1213*cdf0e10cSrcweir } 1214*cdf0e10cSrcweir } 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir return getEmptyByteString(); 1217*cdf0e10cSrcweir } 1218*cdf0e10cSrcweir 1219*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1220*cdf0e10cSrcweir 1221*cdf0e10cSrcweir ByteString Config::ReadKey( sal_uInt16 nKey ) const 1222*cdf0e10cSrcweir { 1223*cdf0e10cSrcweir #ifdef DBG_UTIL 1224*cdf0e10cSrcweir ByteString aTraceStr( "Config::ReadKey( " ); 1225*cdf0e10cSrcweir aTraceStr += ByteString::CreateFromInt32( nKey ); 1226*cdf0e10cSrcweir aTraceStr += " ) from "; 1227*cdf0e10cSrcweir aTraceStr += GetGroup(); 1228*cdf0e10cSrcweir aTraceStr += " in "; 1229*cdf0e10cSrcweir aTraceStr += ByteString( maFileName, RTL_TEXTENCODING_UTF8 ); 1230*cdf0e10cSrcweir DBG_TRACE( aTraceStr.GetBuffer() ); 1231*cdf0e10cSrcweir #endif 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir // Key suchen und Value zurueckgeben 1234*cdf0e10cSrcweir ImplGroupData* pGroup = ImplGetGroup(); 1235*cdf0e10cSrcweir if ( pGroup ) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir ImplKeyData* pKey = pGroup->mpFirstKey; 1238*cdf0e10cSrcweir while ( pKey ) 1239*cdf0e10cSrcweir { 1240*cdf0e10cSrcweir if ( !pKey->mbIsComment ) 1241*cdf0e10cSrcweir { 1242*cdf0e10cSrcweir if ( !nKey ) 1243*cdf0e10cSrcweir return pKey->maValue; 1244*cdf0e10cSrcweir nKey--; 1245*cdf0e10cSrcweir } 1246*cdf0e10cSrcweir 1247*cdf0e10cSrcweir pKey = pKey->mpNext; 1248*cdf0e10cSrcweir } 1249*cdf0e10cSrcweir } 1250*cdf0e10cSrcweir 1251*cdf0e10cSrcweir return getEmptyByteString(); 1252*cdf0e10cSrcweir } 1253*cdf0e10cSrcweir 1254*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1255*cdf0e10cSrcweir 1256*cdf0e10cSrcweir void Config::EnterLock() 1257*cdf0e10cSrcweir { 1258*cdf0e10cSrcweir // Config-Daten evt. updaten 1259*cdf0e10cSrcweir if ( !mnLockCount ) 1260*cdf0e10cSrcweir ImplUpdateConfig(); 1261*cdf0e10cSrcweir 1262*cdf0e10cSrcweir mnLockCount++; 1263*cdf0e10cSrcweir } 1264*cdf0e10cSrcweir 1265*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir void Config::LeaveLock() 1268*cdf0e10cSrcweir { 1269*cdf0e10cSrcweir DBG_ASSERT( mnLockCount, "Config::LeaveLook() without Config::EnterLook()" ); 1270*cdf0e10cSrcweir mnLockCount--; 1271*cdf0e10cSrcweir 1272*cdf0e10cSrcweir if ( (mnLockCount == 0) && mpData->mbModified && mbPersistence ) 1273*cdf0e10cSrcweir ImplWriteConfig( mpData ); 1274*cdf0e10cSrcweir } 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1277*cdf0e10cSrcweir 1278*cdf0e10cSrcweir sal_Bool Config::Update() 1279*cdf0e10cSrcweir { 1280*cdf0e10cSrcweir return ImplUpdateConfig(); 1281*cdf0e10cSrcweir } 1282*cdf0e10cSrcweir 1283*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1284*cdf0e10cSrcweir 1285*cdf0e10cSrcweir void Config::Flush() 1286*cdf0e10cSrcweir { 1287*cdf0e10cSrcweir if ( mpData->mbModified && mbPersistence ) 1288*cdf0e10cSrcweir ImplWriteConfig( mpData ); 1289*cdf0e10cSrcweir } 1290*cdf0e10cSrcweir 1291*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1292*cdf0e10cSrcweir 1293*cdf0e10cSrcweir void Config::SetLineEnd( LineEnd eLineEnd ) 1294*cdf0e10cSrcweir { 1295*cdf0e10cSrcweir mpData->meLineEnd = eLineEnd; 1296*cdf0e10cSrcweir } 1297*cdf0e10cSrcweir 1298*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1299*cdf0e10cSrcweir 1300*cdf0e10cSrcweir LineEnd Config::GetLineEnd() const 1301*cdf0e10cSrcweir { 1302*cdf0e10cSrcweir return mpData->meLineEnd; 1303*cdf0e10cSrcweir } 1304*cdf0e10cSrcweir 1305