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: reginfo.cxx,v $
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_svtools.hxx"
34 #include "reginfo.hxx"
35 #include <tools/debug.hxx>
36 #include <osl/thread.h>
38 #define MAXREGVALUE 200
40 // *****************************************************************************
41 #if defined(WIN) || defined(WNT)
43 #include <tools/svwin.h>
45 #define DBG_HDL DBG_ASSERT(pImp->bValidGroup, "Keine Gruppe gesetzt"); \
46 if( !pImp->bValidGroup ) return
56 pImp
=new RegInfo_Impl
;
57 pImp
->bValidGroup
= FALSE
;
63 RegCloseKey( pImp
->aGroupHdl
);
67 String
RegInfo::GetKeyName( USHORT nKey
) const
69 DBG_HDL
String::EmptyString();
70 char aBuffer
[MAXREGVALUE
];
71 RegEnumKey( pImp
->aGroupHdl
, nKey
, aBuffer
, MAXREGVALUE
);
72 return String( UniString::CreateFromAscii(aBuffer
) );
75 USHORT
RegInfo::GetKeyCount() const
80 DWORD Dum1
=10, Dum2
, Dum3
, Dum4
, Dum5
, Dum6
, Dum7
;
82 FILETIME aDumFileTime
;
83 RegQueryInfoKey( pImp
->aGroupHdl
, s
, &Dum1
, 0, &nKeys
, &Dum2
, &Dum3
,
84 &Dum4
, &Dum5
, &Dum6
, &Dum7
, &aDumFileTime
);
85 return (USHORT
) nKeys
;
87 char aBuffer
[MAXREGVALUE
];
90 pImp
->aGroupHdl
, n
, aBuffer
, MAXREGVALUE
) == ERROR_SUCCESS
)
96 inline String
MakeAppGroupString_Impl( const String
&rGroup
)
98 String
aGroup( UniString::CreateFromAscii("SvAppGroups\\") );
103 void RegInfo::SetAppGroup( const String
& rGroup
)
105 aCurrentGroup
= MakeAppGroupString_Impl(rGroup
);
106 if( pImp
->bValidGroup
)
108 RegCloseKey( pImp
->aGroupHdl
);
109 pImp
->bValidGroup
= FALSE
;
111 ByteString
aBStr( aCurrentGroup
, osl_getThreadTextEncoding() );
112 RegCreateKey( HKEY_CLASSES_ROOT
, aBStr
.GetBuffer(), &pImp
->aGroupHdl
);
113 pImp
->bValidGroup
= TRUE
;
116 void RegInfo::DeleteAppGroup( const String
&rGroup
)
118 String aOldGroup
= aCurrentGroup
;
119 SetAppGroup( rGroup
);
121 USHORT nMax
= GetKeyCount();
122 for( USHORT n
= nMax
; n
--; )
124 String
aKey( GetKeyName( n
));
127 RegCloseKey( pImp
->aGroupHdl
);
129 ByteString
aBStr( rGroup
, osl_getThreadTextEncoding() );
130 RegDeleteKey( HKEY_CLASSES_ROOT
, aBStr
.GetBuffer() );
131 pImp
->bValidGroup
= FALSE
;
132 if( rGroup
!= aOldGroup
)
133 SetAppGroup( aOldGroup
);
136 BOOL
ReadKey_Impl( const String
& rKey
,
137 HKEY aHdl
, String
& rResult
)
140 LONG aLen
=MAXREGVALUE
;
142 ByteString
aBStr( rKey
, osl_getThreadTextEncoding() );
143 LONG nRes
= RegQueryValue( aHdl
, aBStr
.GetBuffer(), s
, &aLen
);
144 if(nRes
== ERROR_SUCCESS
)
146 rResult
= UniString::CreateFromAscii(s
);
153 String
RegInfo::ReadKey( const String
& rKey
) const
155 DBG_HDL
String::EmptyString();
157 if(ReadKey_Impl( rKey
, pImp
->aGroupHdl
, aRes
))
160 return String::EmptyString();
163 String
RegInfo::ReadKey( const String
& rKey
, const String
&rDefault
) const
165 DBG_HDL
String::EmptyString();
167 if(ReadKey_Impl( rKey
, pImp
->aGroupHdl
, aRes
))
173 void RegInfo::WriteKey( const String
& rKey
, const String
& rValue
)
176 ByteString
aBStr( rKey
, osl_getThreadTextEncoding() );
177 ByteString
aBStr1( rValue
, osl_getThreadTextEncoding() );
178 RegSetValue( pImp
->aGroupHdl
, aBStr
.GetBuffer(), REG_SZ
, aBStr1
.GetBuffer(), 0);
182 void RegInfo::DeleteKey( const String
& rKey
)
185 ByteString
aBStr( rKey
, osl_getThreadTextEncoding() );
186 RegDeleteKey( pImp
->aGroupHdl
, aBStr
.GetBuffer() );
189 // *****************************************************************************
192 #define INCL_WINSHELLDATA
199 void BuildKeyList( const String
&rGroup
);
202 void RegInfo_Impl::BuildKeyList( const String
&rGroup
)
204 ByteString
aBStr( rGroup
, osl_getThreadTextEncoding() );
210 pKeyList
= new char[nLen
];
211 *(int *)pKeyList
= 0;
213 while( PrfQueryProfileString(
214 HINI_USERPROFILE
, (PCSZ
)aBStr
.GetBuffer(),
215 0, 0, pKeyList
, nLen
) == nLen
);
221 pImp
=new RegInfo_Impl
;
227 delete[] pImp
->pKeyList
;
231 inline String
MakeAppGroupString_Impl( const String
&rGroup
)
233 String
aGroup(UniString::CreateFromAscii("SvAppGroups:"));
238 String
RegInfo::GetKeyName( USHORT nKey
) const
240 if( !pImp
->pKeyList
)
241 pImp
->BuildKeyList(pImp
->aCurrentApp
);
243 const char *pc
=pImp
->pKeyList
;
244 for( USHORT n
=0; n
<nKey
; n
++ )
247 return String(UniString::CreateFromAscii(pc
));
250 USHORT
RegInfo::GetKeyCount() const
252 if( !pImp
->pKeyList
)
253 pImp
->BuildKeyList( pImp
->aCurrentApp
);
255 const char *pc
=pImp
->pKeyList
;
265 void RegInfo::SetAppGroup( const String
& rGroup
)
267 delete[] pImp
->pKeyList
;
269 aCurrentGroup
= rGroup
;
270 pImp
->aCurrentApp
= MakeAppGroupString_Impl( rGroup
);
273 void RegInfo::DeleteAppGroup( const String
&rGroup
)
275 ByteString
aBStr( MakeAppGroupString_Impl( rGroup
), osl_getThreadTextEncoding() );
276 PrfWriteProfileString(
277 HINI_USERPROFILE
, (PCSZ
)aBStr
.GetBuffer(), 0, 0);
281 String
RegInfo::ReadKey( const String
& rKey
) const
283 ULONG ulBufferMax
= MAXREGVALUE
;
284 char *pBuffer
= new char[MAXREGVALUE
];
285 ByteString
aBStr( pImp
->aCurrentApp
, osl_getThreadTextEncoding() );
286 ByteString
aBStr1( rKey
, osl_getThreadTextEncoding() );
289 HINI_USERPROFILE
, (PCSZ
)aBStr
.GetBuffer(), (PCSZ
)aBStr1
.GetBuffer(), pBuffer
, &ulBufferMax
);
290 String
aRet(UniString::CreateFromAscii(pBuffer
));
296 String
RegInfo::ReadKey( const String
& rKey
, const String
&rDefault
) const
298 String aResult
= ReadKey(rKey
);
306 void RegInfo::WriteKey( const String
& rKey
, const String
& rValue
)
308 ByteString
aBStr( pImp
->aCurrentApp
, osl_getThreadTextEncoding() );
309 ByteString
aBStr1( rKey
, osl_getThreadTextEncoding() );
311 HINI_USERPROFILE
, (PCSZ
)aBStr
.GetBuffer(), (PCSZ
)aBStr1
.GetBuffer(), (PVOID
)rValue
.GetBuffer(), rValue
.Len()*2);
314 void RegInfo::DeleteKey( const String
& rKey
)
316 ByteString
aBStr( pImp
->aCurrentApp
, osl_getThreadTextEncoding() );
317 ByteString
aBStr1( rKey
, osl_getThreadTextEncoding() );
318 PrfWriteProfileString(
319 HINI_USERPROFILE
, (PCSZ
)aBStr
.GetBuffer(), (PCSZ
)rKey
.GetBuffer(), 0);
322 // *****************************************************************************
335 String
RegInfo::GetKeyName( USHORT
) const
337 return String::EmptyString();
340 USHORT
RegInfo::GetKeyCount() const
345 void RegInfo::SetAppGroup( const String
& )
350 void RegInfo::DeleteAppGroup( const String
& )
355 String
RegInfo::ReadKey( const String
& ) const
357 return String::EmptyString();
360 String
RegInfo::ReadKey( const String
&, const String
& ) const
362 return String::EmptyString();
365 void RegInfo::WriteKey( const String
&, const String
& )
370 void RegInfo::DeleteKey( const String
& )