1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _REGISTRY_REGISTRY_HXX_
21 #define _REGISTRY_REGISTRY_HXX_
23 #include <registry/regdllapi.h>
24 #include <registry/regtype.h>
25 #include <rtl/ustring.hxx>
31 /** specifies a collection of function pointers which represents the complete registry C-API.
33 This funtions pointers are used by the C++ wrapper to call the C-API.
37 void (REGISTRY_CALLTYPE
*acquire
) (RegHandle
);
38 void (REGISTRY_CALLTYPE
*release
) (RegHandle
);
39 sal_Bool (REGISTRY_CALLTYPE
*isReadOnly
) (RegHandle
);
40 RegError (REGISTRY_CALLTYPE
*openRootKey
) (RegHandle
, RegKeyHandle
*);
41 RegError (REGISTRY_CALLTYPE
*getName
) (RegHandle
, rtl_uString
**);
42 RegError (REGISTRY_CALLTYPE
*createRegistry
) (rtl_uString
*, RegHandle
*);
43 RegError (REGISTRY_CALLTYPE
*openRegistry
) (rtl_uString
*, RegHandle
*, RegAccessMode
);
44 RegError (REGISTRY_CALLTYPE
*closeRegistry
) (RegHandle
);
45 RegError (REGISTRY_CALLTYPE
*destroyRegistry
) (RegHandle
, rtl_uString
*);
46 RegError (REGISTRY_CALLTYPE
*loadKey
) (RegHandle
, RegKeyHandle
, rtl_uString
*, rtl_uString
*);
47 RegError (REGISTRY_CALLTYPE
*saveKey
) (RegHandle
, RegKeyHandle
, rtl_uString
*, rtl_uString
*);
48 RegError (REGISTRY_CALLTYPE
*mergeKey
) (RegHandle
, RegKeyHandle
, rtl_uString
*, rtl_uString
*, sal_Bool
, sal_Bool
);
49 RegError (REGISTRY_CALLTYPE
*dumpRegistry
) (RegHandle
, RegKeyHandle
);
50 void (REGISTRY_CALLTYPE
*acquireKey
) (RegKeyHandle
);
51 void (REGISTRY_CALLTYPE
*releaseKey
) (RegKeyHandle
);
52 sal_Bool (REGISTRY_CALLTYPE
*isKeyReadOnly
) (RegKeyHandle
);
53 RegError (REGISTRY_CALLTYPE
*getKeyName
) (RegKeyHandle
, rtl_uString
**);
54 RegError (REGISTRY_CALLTYPE
*createKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
55 RegError (REGISTRY_CALLTYPE
*openKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
56 RegError (REGISTRY_CALLTYPE
*openSubKeys
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
**, sal_uInt32
*);
57 RegError (REGISTRY_CALLTYPE
*closeSubKeys
) (RegKeyHandle
*, sal_uInt32
);
58 RegError (REGISTRY_CALLTYPE
*deleteKey
) (RegKeyHandle
, rtl_uString
*);
59 RegError (REGISTRY_CALLTYPE
*closeKey
) (RegKeyHandle
);
60 RegError (REGISTRY_CALLTYPE
*setValue
) (RegKeyHandle
, rtl_uString
*, RegValueType
, RegValue
, sal_uInt32
);
61 RegError (REGISTRY_CALLTYPE
*setLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
*, sal_uInt32
);
62 RegError (REGISTRY_CALLTYPE
*setStringListValue
) (RegKeyHandle
, rtl_uString
*, sal_Char
**, sal_uInt32
);
63 RegError (REGISTRY_CALLTYPE
*setUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
**, sal_uInt32
);
64 RegError (REGISTRY_CALLTYPE
*getValueInfo
) (RegKeyHandle
, rtl_uString
*, RegValueType
*, sal_uInt32
*);
65 RegError (REGISTRY_CALLTYPE
*getValue
) (RegKeyHandle
, rtl_uString
*, RegValue
);
66 RegError (REGISTRY_CALLTYPE
*getLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
**, sal_uInt32
*);
67 RegError (REGISTRY_CALLTYPE
*getStringListValue
) (RegKeyHandle
, rtl_uString
*, sal_Char
***, sal_uInt32
*);
68 RegError (REGISTRY_CALLTYPE
*getUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
***, sal_uInt32
*);
69 RegError (REGISTRY_CALLTYPE
*freeValueList
) (RegValueType
, RegValue
, sal_uInt32
);
70 RegError (REGISTRY_CALLTYPE
*createLink
) (RegKeyHandle
, rtl_uString
*, rtl_uString
*);
71 RegError (REGISTRY_CALLTYPE
*deleteLink
) (RegKeyHandle
, rtl_uString
*);
72 RegError (REGISTRY_CALLTYPE
*getKeyType
) (RegKeyHandle
, rtl_uString
*, RegKeyType
*);
73 RegError (REGISTRY_CALLTYPE
*getLinkTarget
) (RegKeyHandle
, rtl_uString
*, rtl_uString
**);
74 RegError (REGISTRY_CALLTYPE
*getResolvedKeyName
) (RegKeyHandle
, rtl_uString
*, sal_Bool
, rtl_uString
**);
75 RegError (REGISTRY_CALLTYPE
*getKeyNames
) (RegKeyHandle
, rtl_uString
*, rtl_uString
***, sal_uInt32
*);
76 RegError (REGISTRY_CALLTYPE
*freeKeyNames
) (rtl_uString
**, sal_uInt32
);
79 /** the API initialization function.
81 REG_DLLPUBLIC Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api(void);
90 //-----------------------------------------------------------------------------
92 /** The Registry provides the functionality to read and write information in a registry file.
94 The class is implemented inline and use a C-Api.
99 /** Default constructor.
103 /// Copy constructcor
104 inline Registry(const Registry
& toCopy
);
106 /// Destructor. The Destructor close the registry if it is open.
110 inline Registry
& operator = (const Registry
& toAssign
);
112 /// checks if the registry points to a valid registry data file.
113 inline sal_Bool
isValid() const;
115 /** returns the access mode of the registry.
117 @return TRUE if the access mode is readonly else FALSE.
119 inline sal_Bool
isReadOnly() const;
121 /** opens the root key of the registry.
123 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
124 @return REG_NO_ERROR if succeeds else an error code.
126 inline RegError
openRootKey(RegistryKey
& rRootKey
);
128 /// returns the name of the current registry data file.
129 inline OUString
getName();
131 /** creates a new registry with the specified name and creates a root key.
133 @param registryName specifies the name of the new registry.
134 @return REG_NO_ERROR if succeeds else an error code.
136 inline RegError
create(const OUString
& registryName
);
138 /** opens a registry with the specified name.
140 If the registry already points to a valid registry, the old registry will be closed.
141 @param registryName specifies a registry name.
142 @param accessMode specifies the access mode for the registry, REG_READONLY or REG_READWRITE.
143 @return REG_NO_ERROR if succeeds else an error code.
145 inline RegError
open(const OUString
& registryName
,
146 RegAccessMode accessMode
);
148 /// closes explicitly the current registry data file.
149 inline RegError
close();
151 /** destroys a registry.
153 @param registryName specifies a registry name, if the name is an empty string the registry
154 itselfs will be destroyed.
155 @return REG_NO_ERROR if succeeds else an error code.
157 inline RegError
destroy(const OUString
& registryName
);
159 /** loads registry information from a specified file and save it under the
162 @param rKey references a currently open key. The key which should store the registry information
163 is a subkey of this key.
164 @param keyName specifies the name of the key which stores the registry information. If keyName is
165 is an empty string the registry information will be saved under the key specified
167 @param regFileName specifies the file containing the registry information.
168 @return REG_NO_ERROR if succeeds else an error code.
170 inline RegError
loadKey(RegistryKey
& rKey
,
171 const OUString
& keyName
,
172 const OUString
& regFileName
);
174 /** saves the registry information of the specified key and all subkeys and save
175 it in the specified file.
177 @param rKey references a currently open key. The key which information is saved by this
178 function is a subkey of this key.
179 @param keyName specifies the name of the key which information should be stored.
180 If keyName is an empty string the registry information under the key specified
181 by rKey is saved in the specified file.
182 @param regFileName specifies the file containing the registry information.
183 @return REG_NO_ERROR if succeeds else an error code.
185 inline RegError
saveKey(RegistryKey
& rKey
,
186 const OUString
& keyName
,
187 const OUString
& regFileName
);
189 /** merges the registry information of the specified key with the registry
190 information of the specified file.
192 All existing keys will be extended and existing key values will be overwritten.
193 @param rKey references a currently open key. The key which information is merged by this
194 function is a subkey of this key
195 @param keyName specifies the name of the key which will be merged.
196 If keyName is an empty string the registry information under the key specified
197 by rKey is merged with the information from the specified file.
198 @param regFileName specifies the file containing the registry information.
199 @param bWarnings if TRUE the function returns an error if a key already exists.
200 @param bReport if TRUE the function reports warnings on stdout if a key already exists.
201 @return REG_NO_ERROR if succeeds else an error code. If it returns an error the registry will
202 restore the state before merging.
204 inline RegError
mergeKey(RegistryKey
& rKey
,
205 const OUString
& keyName
,
206 const OUString
& regFileName
,
207 sal_Bool bWarnings
= sal_False
,
208 sal_Bool bReport
= sal_False
);
210 /** This function reports the complete registry information of a key and all of its subkeys.
212 All information which are available (keynames, value types, values, ...)
213 will be printed to stdout for report issues only.
214 @param rKey references a currently open key which content will be reported.
215 @return REG_NO_ERROR if succeeds else an error code.
217 inline RegError
dumpRegistry(RegistryKey
& rKey
);
219 friend class RegistryKey
;
220 friend class RegistryKeyArray
;
221 friend class RegistryKeyNames
;
223 /// returns the used registry Api.
224 const Registry_Api
* getApi() { return m_pApi
; }
227 /// stores the used and initialized registry Api.
228 const Registry_Api
* m_pApi
;
229 /// stores the handle of the underlying registry file on which most of the functions work.
234 //-----------------------------------------------------------------------------
236 /** RegistryKeyArray represents an array of open keys.
238 RegistryKeyArray is a helper class to work with an array of keys.
240 class RegistryKeyArray
243 /// Default constructor
244 inline RegistryKeyArray();
246 /// Destructor, all subkeys will be closed.
247 inline ~RegistryKeyArray();
249 /// returns the open key specified by index.
250 inline RegistryKey
getElement(sal_uInt32 index
);
252 /// returns the length of the array.
253 inline sal_uInt32
getLength();
255 friend class RegistryKey
;
257 /** sets the data of the key array.
259 @param registry specifies the registry files where the keys are located.
260 @param phKeys points to an array of open keys.
261 @param length specifies the length of the array specified by phKeys.
263 inline void setKeyHandles(Registry
& registry
, RegKeyHandle
* phKeys
, sal_uInt32 length
);
264 /// close all subkeys
265 inline RegError
closeKeyHandles();
267 /// stores the number of open subkeys, the number of elements.
269 /// stores an array of open subkeys.
270 RegKeyHandle
* m_phKeys
;
271 /// stores the handle to the registry file where the appropriate keys are located.
276 /** RegistryKeyNames represents an array of key names.
278 RegistryKeyNames is a helper class to work with an array of key names.
280 class RegistryKeyNames
283 /// Default constructor
284 inline RegistryKeyNames();
286 /// Destructor, the internal array with key names will be deleted.
287 inline ~RegistryKeyNames();
289 /// returns the name of the key sepecified by index.
290 inline OUString
getElement(sal_uInt32 index
);
292 /// returns the length of the array.
293 inline sal_uInt32
getLength();
295 friend class RegistryKey
;
297 /** sets the data of the array.
299 @param registry specifies the registry files where the keys are located.
300 @param pKeyNames points to an array of key names.
301 @param length specifies the length of the array specified by pKeyNames.
303 inline void setKeyNames(Registry
& registry
, rtl_uString
** pKeyNames
, sal_uInt32 length
);
304 /// delete the array of key names.
305 inline RegError
freeKeyNames();
307 /// stores the number of key names, the number of elements.
309 /// stores an array of key names.
310 rtl_uString
** m_pKeyNames
;
311 /// stores the handle to the registry file where the appropriate keys are located.
315 //-----------------------------------------------------------------------------
317 /** RegistryValueList represents a value list of the specified type.
319 RegistryValueList is a helper class to work with a list value.
321 template<class ValueType
>
322 class RegistryValueList
325 /// Default constructor
329 , m_valueType(RG_VALUETYPE_NOT_DEFINED
)
332 /// Destructor, the internal value list will be freed.
337 m_registry
.getApi()->freeValueList(m_valueType
, m_pValueList
, m_length
);
341 /// returns the value of the list specified by index.
342 ValueType
getElement(sal_uInt32 index
)
344 if (m_registry
.isValid() && index
< m_length
)
346 return m_pValueList
[index
];
353 /// returns the length of the list.
354 sal_uInt32
getLength()
359 friend class RegistryKey
;
361 /** sets the data of the value list.
363 @param registry specifies the registry files where the appropriate key is located.
364 @param valueType specifies the type of the list values.
365 @param pValueList points to a value list.
366 @param length specifies the length of the list.
368 void setValueList(Registry
& registry
, RegValueType valueType
,
369 ValueType
* pValueList
, sal_uInt32 length
)
372 m_pValueList
= pValueList
;
373 m_valueType
= valueType
;
374 m_registry
= registry
;
377 /// stores the length of the list, the number of elements.
379 /// stores the value list.
380 ValueType
* m_pValueList
;
381 /// stores the type of the list elements
382 RegValueType m_valueType
;
383 /** stores the handle to the registry file where the appropriate key to this
389 //-----------------------------------------------------------------------------
391 /** RegistryKey reads or writes information of the underlying key in a registry.
393 Class is inline and use a load on call C-Api.
398 /// Default constructor
399 inline RegistryKey();
402 inline RegistryKey(const RegistryKey
& toCopy
);
404 /// Destructor, close the key if it references an open one.
405 inline ~RegistryKey();
408 inline RegistryKey
& operator = (const RegistryKey
& toAssign
);
410 /// checks if the key points to a valid registry key.
411 inline sal_Bool
isValid() const;
413 /** returns the access mode of the key.
415 @return TRUE if access mode is read only else FALSE.
417 inline sal_Bool
isReadOnly() const;
419 /// returns the full qualified name of the key beginning with the rootkey.
420 inline OUString
getName();
422 /** creates a new key or opens a key if the specified key already exists.
424 The specified keyname is relativ to this key.
425 @param keyName specifies the name of the key which will be opened or created.
426 @param rNewKey references a RegistryKey which will be filled with the new or open key.
427 @return REG_NO_ERROR if succeeds else an error code.
429 inline RegError
createKey(const OUString
& keyName
,
430 RegistryKey
& rNewKey
);
432 /** opens the specified key.
434 The specified keyname is relativ to this key.
435 @param keyName specifies the name of the key which will be opened.
436 @param rOpenKey references a RegistryKey which will be filled with the open key.
437 @return REG_NO_ERROR if succeeds else an error code.
439 inline RegError
openKey(const OUString
& keyName
,
440 RegistryKey
& rOpenKey
);
442 /** opens all subkeys of the specified key.
444 The specified keyname is relativ to this key.
445 @param keyName specifies the name of the key which subkeys will be opened.
446 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
447 @return REG_NO_ERROR if succeeds else an error code.
449 inline RegError
openSubKeys(const OUString
& keyName
,
450 RegistryKeyArray
& rSubKeys
);
452 /** returns an array with the names of all subkeys of the specified key.
454 The specified keyname is relativ to this key.
455 @param keyName specifies the name of the key which subkey names will be returned.
456 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
457 @return REG_NO_ERROR if succeeds else an error code.
459 inline RegError
getKeyNames(const OUString
& keyName
,
460 RegistryKeyNames
& rSubKeyNames
);
462 /** closes all keys specified in the array.
464 @param rSubKeys reference a RegistryKeyArray which contains the open keys.
465 @return REG_NO_ERROR if succeeds else an error code.
467 inline RegError
closeSubKeys(RegistryKeyArray
& rSubKeys
);
469 /** deletes the specified key.
471 @param keyName specifies the name of the key which will be deleted.
472 @return REG_NO_ERROR if succeeds else an error code.
474 inline RegError
deleteKey(const OUString
& keyName
);
476 /// closes explicitly the current key
477 inline RegError
closeKey();
479 /// releases the current key
480 inline void releaseKey();
482 /** sets a value of a key.
484 @param keyName specifies the name of the key which value will be set.
485 If keyName is an empty string, the value will be set for the key
487 @param valueType specifies the type of the value.
488 @param pValue points to a memory block containing the data for the value.
489 @param valueSize specifies the size of pData in bytes
490 @return REG_NO_ERROR if succeeds else an error code.
492 inline RegError
setValue(const OUString
& keyName
,
493 RegValueType valueType
,
495 sal_uInt32 valueSize
);
497 /** sets a long list value of a key.
499 @param keyName specifies the name of the key which value will be set.
500 If keyName is an empty string, the value will be set for the key
502 @param pValueList points to an array of longs containing the data for the value.
503 @param len specifies the length of the list (the array referenced by pValueList).
504 @return REG_NO_ERROR if succeeds else an error code.
506 inline RegError
setLongListValue(const OUString
& keyName
,
507 sal_Int32
* pValueList
,
510 /** sets an ascii list value of a key.
512 @param keyName specifies the name of the key which value will be set.
513 If keyName is an empty string, the value will be set for the key
515 @param pValueList points to an array of sal_Char* containing the data for the value.
516 @param len specifies the length of the list (the array referenced by pValueList).
517 @return REG_NO_ERROR if succeeds else an error code.
519 inline RegError
setStringListValue(const OUString
& keyName
,
520 sal_Char
** pValueList
,
523 /** sets an unicode string list value of a key.
525 @param keyName specifies the name of the key which value will be set.
526 If keyName is an empty string, the value will be set for the key
528 @param pValueList points to an array of sal_Unicode* containing the data for the value.
529 @param len specifies the length of the list (the array referenced by pValueList).
530 @return REG_NO_ERROR if succeeds else an error code.
532 inline RegError
setUnicodeListValue(const OUString
& keyName
,
533 sal_Unicode
** pValueList
,
536 /** gets info about type and size of a value.
538 @param keyName specifies the name of the key which value info will be returned.
539 If keyName is an empty string, the value info of the key
540 specified by hKey will be returned.
541 @param pValueType returns the type of the value.
542 @param pValueSize returns the size of the value in bytes or the length of a list value.
543 @return REG_NO_ERROR if succeeds else an error code.
545 inline RegError
getValueInfo(const OUString
& keyName
,
546 RegValueType
* pValueType
,
547 sal_uInt32
* pValueSize
);
549 /** gets the value of a key.
551 @param keyName specifies the name of the key which value will be returned.
552 If keyName is an empty string, the value is get from the key
554 @param pValue points to an allocated memory block receiving the data of the value.
555 @return REG_NO_ERROR if succeeds else an error code.
557 inline RegError
getValue(const OUString
& keyName
,
560 /** gets a long list value of a key.
562 @param keyName specifies the name of the key which value will be returned.
563 If keyName is an empty string, the value is get from the key
565 @param rValueList references a RegistryValueList which will be filled with the long values.
566 @return REG_NO_ERROR if succeeds else an error code.
568 inline RegError
getLongListValue(const OUString
& keyName
,
569 RegistryValueList
<sal_Int32
>& rValueList
);
571 /** gets an ascii list value of a key.
573 @param keyName specifies the name of the key which value will be returned.
574 If keyName is an empty string, the value is get from the key
576 @param rValueList references a RegistryValueList which will be filled with the ascii values.
577 @return REG_NO_ERROR if succeeds else an error code.
579 inline RegError
getStringListValue(const OUString
& keyName
,
580 RegistryValueList
<sal_Char
*>& rValueList
);
582 /** gets a unicode value of a key.
584 @param keyName specifies the name of the key which value will be returned.
585 If keyName is an empty string, the value is get from the key
587 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
588 @return REG_NO_ERROR if succeeds else an error code.
590 inline RegError
getUnicodeListValue(const OUString
& keyName
,
591 RegistryValueList
<sal_Unicode
*>& rValueList
);
593 /** used to create a link.
595 @deprecated Links are no longer supported.
597 @return REG_INVALID_LINK
599 inline RegError
createLink(const OUString
& linkName
,
600 const OUString
& linkTarget
);
602 /** used to delete a link.
604 @deprecated Links are no longer supported.
606 @return REG_INVALID_LINK
608 inline RegError
deleteLink(const OUString
& linkName
);
610 /** returns the type of the specified key.
612 @param name specifies the name of the key or link.
613 @param pKeyType returns the type of the key (always RG_KEYTYPE).
614 @return REG_NO_ERROR if succeeds else an error code.
616 inline RegError
getKeyType(const OUString
& name
,
617 RegKeyType
* pKeyType
) const;
619 /** used to return the target of a link.
621 @deprecated Links are no longer supported.
623 @return REG_INVALID_LINK
625 inline RegError
getLinkTarget(const OUString
& linkName
,
626 OUString
& rLinkTarget
) const;
628 /** resolves a keyname.
630 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
631 The resolved name will be prefixed with the name of this key.
632 @param[in] firstLinkOnly ignored
633 @param[out] rResolvedName the resolved name.
634 @return REG_NO_ERROR if succeeds else an error code.
636 inline RegError
getResolvedKeyName(const OUString
& keyName
,
637 sal_Bool firstLinkOnly
,
638 OUString
& rResolvedName
) const;
640 /// returns the name of the registry in which the key is defined.
641 inline OUString
getRegistryName();
643 /// returns the registry in which the key is defined.
644 Registry
getRegistry() const { return m_registry
; }
646 friend class Registry
;
650 /** Constructor, which initialize a RegistryKey with registry and an valid key handle.
652 This constructor is internal only.
654 inline RegistryKey(Registry
& registry
,
657 /** returns the internal key handle.
659 RegKeyHandle
getKeyHandle() const { return m_hImpl
; }
662 /** sets the internal registry on which this key should work.
664 inline void setRegistry(Registry
& registry
);
668 /// stores the registry on which this key works
670 /// stores the current key handle of this key
671 RegKeyHandle m_hImpl
;
675 //-----------------------------------------------------------------------------
677 inline RegistryKeyArray::RegistryKeyArray()
683 inline RegistryKeyArray::~RegistryKeyArray()
686 m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
689 inline RegistryKey
RegistryKeyArray::getElement(sal_uInt32 index
)
691 if (m_registry
.isValid() && index
< m_length
)
692 return RegistryKey(m_registry
, m_phKeys
[index
]);
694 return RegistryKey();
697 inline sal_uInt32
RegistryKeyArray::getLength()
702 inline void RegistryKeyArray::setKeyHandles(Registry
& registry
,
703 RegKeyHandle
* phKeys
,
708 m_registry
= registry
;
711 inline RegError
RegistryKeyArray::closeKeyHandles()
713 if (m_registry
.isValid() && m_phKeys
)
716 ret
= m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
717 m_registry
= Registry();
722 return(REG_INVALID_KEY
);
725 //-----------------------------------------------------------------------------
727 inline RegistryKeyNames::RegistryKeyNames()
733 inline RegistryKeyNames::~RegistryKeyNames()
736 m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
739 inline OUString
RegistryKeyNames::getElement(sal_uInt32 index
)
742 if (m_pKeyNames
&& index
< m_length
)
743 return m_pKeyNames
[index
];
748 inline sal_uInt32
RegistryKeyNames::getLength()
753 inline void RegistryKeyNames::setKeyNames(Registry
& registry
,
754 rtl_uString
** pKeyNames
,
757 m_pKeyNames
= pKeyNames
;
759 m_registry
= registry
;
762 inline RegError
RegistryKeyNames::freeKeyNames()
764 if (m_registry
.isValid() && m_pKeyNames
)
766 RegError ret
= REG_NO_ERROR
;
767 ret
= m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
768 m_registry
= Registry();
773 return REG_INVALID_KEY
;
776 //-----------------------------------------------------------------------------
778 inline RegistryKey::RegistryKey()
783 inline RegistryKey::RegistryKey(Registry
& registry
, RegKeyHandle hKey
)
784 : m_registry(registry
)
788 m_registry
.m_pApi
->acquireKey(m_hImpl
);
792 inline RegistryKey::RegistryKey(const RegistryKey
& toCopy
)
793 : m_registry(toCopy
.m_registry
)
794 , m_hImpl(toCopy
.m_hImpl
)
797 m_registry
.m_pApi
->acquireKey(m_hImpl
);
801 inline void RegistryKey::setRegistry(Registry
& registry
)
803 m_registry
= registry
;
807 inline RegistryKey::~RegistryKey()
810 m_registry
.m_pApi
->releaseKey(m_hImpl
);
813 inline RegistryKey
& RegistryKey::operator = (const RegistryKey
& toAssign
)
815 m_registry
= toAssign
.m_registry
;
817 if (toAssign
.m_hImpl
)
818 m_registry
.m_pApi
->acquireKey(toAssign
.m_hImpl
);
820 m_registry
.m_pApi
->releaseKey(m_hImpl
);
821 m_hImpl
= toAssign
.m_hImpl
;
826 inline sal_Bool
RegistryKey::isValid() const
827 { return (m_hImpl
!= NULL
); }
829 inline sal_Bool
RegistryKey::isReadOnly() const
831 if (m_registry
.isValid())
832 return (m_registry
.m_pApi
)->isKeyReadOnly(m_hImpl
);
837 inline OUString
RegistryKey::getName()
840 if (m_registry
.isValid())
841 m_registry
.m_pApi
->getKeyName(m_hImpl
, &sRet
.pData
);
845 inline RegError
RegistryKey::createKey(const OUString
& keyName
,
846 RegistryKey
& rNewKey
)
848 if (rNewKey
.isValid()) rNewKey
.closeKey();
849 if (m_registry
.isValid())
851 RegError ret
= m_registry
.m_pApi
->createKey(m_hImpl
, keyName
.pData
, &rNewKey
.m_hImpl
);
852 if (!ret
) rNewKey
.setRegistry(m_registry
);
855 return REG_INVALID_KEY
;
858 inline RegError
RegistryKey::openKey(const OUString
& keyName
,
859 RegistryKey
& rOpenKey
)
861 if (rOpenKey
.isValid()) rOpenKey
.closeKey();
862 if (m_registry
.isValid())
864 RegError ret
= m_registry
.m_pApi
->openKey(m_hImpl
, keyName
.pData
,
866 if (!ret
) rOpenKey
.setRegistry(m_registry
);
869 return REG_INVALID_KEY
;
872 inline RegError
RegistryKey::openSubKeys(const OUString
& keyName
,
873 RegistryKeyArray
& rSubKeys
)
875 if (m_registry
.isValid())
877 RegError ret
= REG_NO_ERROR
;
878 RegKeyHandle
* pSubKeys
;
880 ret
= m_registry
.m_pApi
->openSubKeys(m_hImpl
, keyName
.pData
,
881 &pSubKeys
, &nSubKeys
);
887 rSubKeys
.setKeyHandles(m_registry
, pSubKeys
, nSubKeys
);
891 return REG_INVALID_KEY
;
894 inline RegError
RegistryKey::getKeyNames(const OUString
& keyName
,
895 RegistryKeyNames
& rSubKeyNames
)
897 if (m_registry
.isValid())
899 RegError ret
= REG_NO_ERROR
;
900 rtl_uString
** pSubKeyNames
;
902 ret
= m_registry
.m_pApi
->getKeyNames(m_hImpl
, keyName
.pData
,
903 &pSubKeyNames
, &nSubKeys
);
909 rSubKeyNames
.setKeyNames(m_registry
, pSubKeyNames
, nSubKeys
);
913 return REG_INVALID_KEY
;
916 inline RegError
RegistryKey::closeSubKeys(RegistryKeyArray
& rSubKeys
)
918 if (m_registry
.isValid())
919 return rSubKeys
.closeKeyHandles();
921 return REG_INVALID_KEY
;
924 inline RegError
RegistryKey::deleteKey(const OUString
& keyName
)
926 if (m_registry
.isValid())
927 return m_registry
.m_pApi
->deleteKey(m_hImpl
, keyName
.pData
);
929 return REG_INVALID_KEY
;
932 inline RegError
RegistryKey::closeKey()
934 if (m_registry
.isValid())
936 RegError ret
= m_registry
.m_pApi
->closeKey(m_hImpl
);
940 m_registry
= Registry();
944 return REG_INVALID_KEY
;
947 inline void RegistryKey::releaseKey()
949 if (m_registry
.isValid() && (m_hImpl
!= 0))
951 m_registry
.m_pApi
->releaseKey(m_hImpl
), m_hImpl
= 0;
955 inline RegError
RegistryKey::setValue(const OUString
& keyName
,
956 RegValueType valueType
,
958 sal_uInt32 valueSize
)
960 if (m_registry
.isValid())
961 return m_registry
.m_pApi
->setValue(m_hImpl
, keyName
.pData
, valueType
,
964 return REG_INVALID_KEY
;
967 inline RegError
RegistryKey::setLongListValue(const OUString
& keyName
,
968 sal_Int32
* pValueList
,
971 if (m_registry
.isValid())
972 return m_registry
.m_pApi
->setLongListValue(m_hImpl
, keyName
.pData
,
975 return REG_INVALID_KEY
;
978 inline RegError
RegistryKey::setStringListValue(const OUString
& keyName
,
979 sal_Char
** pValueList
,
982 if (m_registry
.isValid())
983 return m_registry
.m_pApi
->setStringListValue(m_hImpl
, keyName
.pData
,
986 return REG_INVALID_KEY
;
989 inline RegError
RegistryKey::setUnicodeListValue(const OUString
& keyName
,
990 sal_Unicode
** pValueList
,
993 if (m_registry
.isValid())
994 return m_registry
.m_pApi
->setUnicodeListValue(m_hImpl
, keyName
.pData
,
997 return REG_INVALID_KEY
;
1000 inline RegError
RegistryKey::getValueInfo(const OUString
& keyName
,
1001 RegValueType
* pValueType
,
1002 sal_uInt32
* pValueSize
)
1004 if (m_registry
.isValid())
1005 return m_registry
.m_pApi
->getValueInfo(m_hImpl
, keyName
.pData
, pValueType
, pValueSize
);
1007 return REG_INVALID_KEY
;
1010 inline RegError
RegistryKey::getValue(const OUString
& keyName
,
1013 if (m_registry
.isValid())
1014 return m_registry
.m_pApi
->getValue(m_hImpl
, keyName
.pData
, pValue
);
1016 return REG_INVALID_KEY
;
1019 inline RegError
RegistryKey::getLongListValue(const OUString
& keyName
,
1020 RegistryValueList
<sal_Int32
>& rValueList
)
1022 if (m_registry
.isValid())
1024 RegError ret
= REG_NO_ERROR
;
1025 sal_Int32
* pValueList
;
1027 ret
= m_registry
.m_pApi
->getLongListValue(m_hImpl
, keyName
.pData
,
1028 &pValueList
, &length
);
1034 rValueList
.setValueList(m_registry
, RG_VALUETYPE_LONGLIST
,
1035 pValueList
, length
);
1039 return REG_INVALID_KEY
;
1042 inline RegError
RegistryKey::getStringListValue(const OUString
& keyName
,
1043 RegistryValueList
<sal_Char
*>& rValueList
)
1045 if (m_registry
.isValid())
1047 RegError ret
= REG_NO_ERROR
;
1048 sal_Char
** pValueList
;
1050 ret
= m_registry
.m_pApi
->getStringListValue(m_hImpl
, keyName
.pData
,
1051 &pValueList
, &length
);
1057 rValueList
.setValueList(m_registry
, RG_VALUETYPE_STRINGLIST
,
1058 pValueList
, length
);
1062 return REG_INVALID_KEY
;
1065 inline RegError
RegistryKey::getUnicodeListValue(const OUString
& keyName
,
1066 RegistryValueList
<sal_Unicode
*>& rValueList
)
1068 if (m_registry
.isValid())
1070 RegError ret
= REG_NO_ERROR
;
1071 sal_Unicode
** pValueList
;
1073 ret
= m_registry
.m_pApi
->getUnicodeListValue(m_hImpl
, keyName
.pData
,
1074 &pValueList
, &length
);
1080 rValueList
.setValueList(m_registry
, RG_VALUETYPE_UNICODELIST
,
1081 pValueList
, length
);
1085 return REG_INVALID_KEY
;
1088 inline RegError
RegistryKey::createLink(const OUString
& linkName
,
1089 const OUString
& linkTarget
)
1091 if (m_registry
.isValid())
1092 return m_registry
.m_pApi
->createLink(m_hImpl
, linkName
.pData
, linkTarget
.pData
);
1094 return REG_INVALID_KEY
;
1097 inline RegError
RegistryKey::deleteLink(const OUString
& linkName
)
1099 if (m_registry
.isValid())
1100 return m_registry
.m_pApi
->deleteLink(m_hImpl
, linkName
.pData
);
1102 return REG_INVALID_KEY
;
1105 inline RegError
RegistryKey::getKeyType(const OUString
& keyName
,
1106 RegKeyType
* pKeyType
) const
1108 if (m_registry
.isValid())
1109 return m_registry
.m_pApi
->getKeyType(m_hImpl
, keyName
.pData
, pKeyType
);
1111 return REG_INVALID_KEY
;
1114 inline RegError
RegistryKey::getLinkTarget(const OUString
& linkName
,
1115 OUString
& rLinkTarget
) const
1117 if (m_registry
.isValid())
1119 return m_registry
.m_pApi
->getLinkTarget(m_hImpl
,
1121 &rLinkTarget
.pData
);
1123 return REG_INVALID_KEY
;
1127 inline RegError
RegistryKey::getResolvedKeyName(const OUString
& keyName
,
1128 sal_Bool firstLinkOnly
,
1129 OUString
& rResolvedName
) const
1131 if (m_registry
.isValid())
1132 return m_registry
.m_pApi
->getResolvedKeyName(m_hImpl
,
1135 &rResolvedName
.pData
);
1137 return REG_INVALID_KEY
;
1140 inline OUString
RegistryKey::getRegistryName()
1142 if (m_registry
.isValid())
1144 return m_registry
.getName();
1149 //-----------------------------------------------------------------------------
1151 inline Registry::Registry()
1152 : m_pApi(initRegistry_Api())
1156 inline Registry::Registry(const Registry
& toCopy
)
1157 : m_pApi(toCopy
.m_pApi
)
1158 , m_hImpl(toCopy
.m_hImpl
)
1161 m_pApi
->acquire(m_hImpl
);
1165 inline Registry::~Registry()
1168 m_pApi
->release(m_hImpl
);
1171 inline Registry
& Registry::operator = (const Registry
& toAssign
)
1173 if (toAssign
.m_hImpl
)
1174 toAssign
.m_pApi
->acquire(toAssign
.m_hImpl
);
1176 m_pApi
->release(m_hImpl
);
1178 m_pApi
= toAssign
.m_pApi
;
1179 m_hImpl
= toAssign
.m_hImpl
;
1184 inline sal_Bool
Registry::isValid() const
1185 { return ( m_hImpl
!= NULL
); }
1187 inline sal_Bool
Registry::isReadOnly() const
1188 { return m_pApi
->isReadOnly(m_hImpl
); }
1190 inline RegError
Registry::openRootKey(RegistryKey
& rRootKey
)
1192 rRootKey
.setRegistry(*this);
1193 return m_pApi
->openRootKey(m_hImpl
, &rRootKey
.m_hImpl
);
1196 inline OUString
Registry::getName()
1199 m_pApi
->getName(m_hImpl
, &sRet
.pData
);
1203 inline RegError
Registry::create(const OUString
& registryName
)
1206 m_pApi
->release(m_hImpl
);
1207 return m_pApi
->createRegistry(registryName
.pData
, &m_hImpl
);
1210 inline RegError
Registry::open(const OUString
& registryName
,
1211 RegAccessMode accessMode
)
1214 m_pApi
->release(m_hImpl
);
1215 return m_pApi
->openRegistry(registryName
.pData
, &m_hImpl
, accessMode
);
1218 inline RegError
Registry::close()
1220 RegError ret
= m_pApi
->closeRegistry(m_hImpl
);
1226 inline RegError
Registry::destroy(const OUString
& registryName
)
1228 RegError ret
= m_pApi
->destroyRegistry(m_hImpl
, registryName
.pData
);
1229 if ( !ret
&& registryName
.isEmpty() )
1234 inline RegError
Registry::loadKey(RegistryKey
& rKey
,
1235 const OUString
& keyName
,
1236 const OUString
& regFileName
)
1237 { return m_pApi
->loadKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
); }
1239 inline RegError
Registry::saveKey(RegistryKey
& rKey
,
1240 const OUString
& keyName
,
1241 const OUString
& regFileName
)
1242 { return m_pApi
->saveKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
); }
1244 inline RegError
Registry::mergeKey(RegistryKey
& rKey
,
1245 const OUString
& keyName
,
1246 const OUString
& regFileName
,
1249 { return m_pApi
->mergeKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
, bWarnings
, bReport
); }
1251 inline RegError
Registry::dumpRegistry(RegistryKey
& rKey
)
1252 { return m_pApi
->dumpRegistry(m_hImpl
, rKey
.m_hImpl
); }
1257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */