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 INCLUDED_REGISTRY_REGISTRY_HXX
21 #define INCLUDED_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 These function 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
*mergeKey
) (RegHandle
, RegKeyHandle
, rtl_uString
*, rtl_uString
*, sal_Bool
, sal_Bool
);
47 void (REGISTRY_CALLTYPE
*acquireKey
) (RegKeyHandle
);
48 void (REGISTRY_CALLTYPE
*releaseKey
) (RegKeyHandle
);
49 sal_Bool (REGISTRY_CALLTYPE
*isKeyReadOnly
) (RegKeyHandle
);
50 RegError (REGISTRY_CALLTYPE
*getKeyName
) (RegKeyHandle
, rtl_uString
**);
51 RegError (REGISTRY_CALLTYPE
*createKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
52 RegError (REGISTRY_CALLTYPE
*openKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
53 RegError (REGISTRY_CALLTYPE
*openSubKeys
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
**, sal_uInt32
*);
54 RegError (REGISTRY_CALLTYPE
*closeSubKeys
) (RegKeyHandle
*, sal_uInt32
);
55 RegError (REGISTRY_CALLTYPE
*deleteKey
) (RegKeyHandle
, rtl_uString
*);
56 RegError (REGISTRY_CALLTYPE
*closeKey
) (RegKeyHandle
);
57 RegError (REGISTRY_CALLTYPE
*setValue
) (RegKeyHandle
, rtl_uString
*, RegValueType
, RegValue
, sal_uInt32
);
58 RegError (REGISTRY_CALLTYPE
*setLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
*, sal_uInt32
);
59 RegError (REGISTRY_CALLTYPE
*setStringListValue
) (RegKeyHandle
, rtl_uString
*, sal_Char
**, sal_uInt32
);
60 RegError (REGISTRY_CALLTYPE
*setUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
**, sal_uInt32
);
61 RegError (REGISTRY_CALLTYPE
*getValueInfo
) (RegKeyHandle
, rtl_uString
*, RegValueType
*, sal_uInt32
*);
62 RegError (REGISTRY_CALLTYPE
*getValue
) (RegKeyHandle
, rtl_uString
*, RegValue
);
63 RegError (REGISTRY_CALLTYPE
*getLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
**, sal_uInt32
*);
64 RegError (REGISTRY_CALLTYPE
*getStringListValue
) (RegKeyHandle
, rtl_uString
*, sal_Char
***, sal_uInt32
*);
65 RegError (REGISTRY_CALLTYPE
*getUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
***, sal_uInt32
*);
66 RegError (REGISTRY_CALLTYPE
*freeValueList
) (RegValueType
, RegValue
, sal_uInt32
);
67 RegError (REGISTRY_CALLTYPE
*getResolvedKeyName
) (RegKeyHandle
, rtl_uString
*, sal_Bool
, rtl_uString
**);
68 RegError (REGISTRY_CALLTYPE
*getKeyNames
) (RegKeyHandle
, rtl_uString
*, rtl_uString
***, sal_uInt32
*);
69 RegError (REGISTRY_CALLTYPE
*freeKeyNames
) (rtl_uString
**, sal_uInt32
);
72 /** the API initialization function.
74 REG_DLLPUBLIC Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api();
84 /** The Registry provides the functionality to read and write information in a registry file.
86 The class is implemented inline and use a C-Api.
91 /** Default constructor.
96 inline Registry(const Registry
& toCopy
);
98 /// Destructor. The Destructor close the registry if it is open.
102 inline Registry
& operator = (const Registry
& toAssign
);
104 /// checks if the registry points to a valid registry data file.
105 inline bool isValid() const;
107 /** returns the access mode of the registry.
109 @return TRUE if the access mode is readonly else FALSE.
111 inline bool isReadOnly() const;
113 /** opens the root key of the registry.
115 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
116 @return RegError::NO_ERROR if succeeds else an error code.
118 inline RegError
openRootKey(RegistryKey
& rRootKey
);
120 /// returns the name of the current registry data file.
121 inline rtl::OUString
getName();
123 /** creates a new registry with the specified name and creates a root key.
125 @param registryName specifies the name of the new registry.
126 @return RegError::NO_ERROR if succeeds else an error code.
128 inline RegError
create(const rtl::OUString
& registryName
);
130 /** opens a registry with the specified name.
132 If the registry already points to a valid registry, the old registry will be closed.
133 @param registryName specifies a registry name.
134 @param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
135 @return RegError::NO_ERROR if succeeds else an error code.
137 inline RegError
open(const rtl::OUString
& registryName
,
138 RegAccessMode accessMode
);
140 /// closes explicitly the current registry data file.
141 inline RegError
close();
143 /** destroys a registry.
145 @param registryName specifies a registry name, if the name is an empty string the registry
146 itself will be destroyed.
147 @return RegError::NO_ERROR if succeeds else an error code.
149 inline RegError
destroy(const rtl::OUString
& registryName
);
151 /** merges the registry information of the specified key with the registry
152 information of the specified file.
154 All existing keys will be extended and existing key values will be overwritten.
155 @param rKey references a currently open key. The key which information is merged by this
156 function is a subkey of this key
157 @param keyName specifies the name of the key which will be merged.
158 If keyName is an empty string the registry information under the key specified
159 by rKey is merged with the information from the specified file.
160 @param regFileName specifies the file containing the registry information.
161 @param bWarnings if TRUE the function returns an error if a key already exists.
162 @param bReport if TRUE the function reports warnings on stdout if a key already exists.
163 @return RegError::NO_ERROR if succeeds else an error code. If it returns an error the registry will
164 restore the state before merging.
166 inline RegError
mergeKey(RegistryKey
& rKey
,
167 const rtl::OUString
& keyName
,
168 const rtl::OUString
& regFileName
,
169 bool bWarnings
= false,
170 bool bReport
= false);
172 friend class RegistryKey
;
173 friend class RegistryKeyArray
;
174 friend class RegistryKeyNames
;
176 /// returns the used registry Api.
177 const Registry_Api
* getApi() { return m_pApi
; }
180 /// stores the used and initialized registry Api.
181 const Registry_Api
* m_pApi
;
182 /// stores the handle of the underlying registry file on which most of the functions work.
187 /** RegistryKeyArray represents an array of open keys.
189 RegistryKeyArray is a helper class to work with an array of keys.
191 class RegistryKeyArray
194 /// Default constructor
195 inline RegistryKeyArray();
197 /// Destructor, all subkeys will be closed.
198 inline ~RegistryKeyArray();
200 /// returns the open key specified by index.
201 inline RegistryKey
getElement(sal_uInt32 index
);
203 /// returns the length of the array.
204 inline sal_uInt32
getLength();
206 friend class RegistryKey
;
208 /** sets the data of the key array.
210 @param registry specifies the registry files where the keys are located.
211 @param phKeys points to an array of open keys.
212 @param length specifies the length of the array specified by phKeys.
214 inline void setKeyHandles(Registry
& registry
, RegKeyHandle
* phKeys
, sal_uInt32 length
);
216 /// stores the number of open subkeys, the number of elements.
218 /// stores an array of open subkeys.
219 RegKeyHandle
* m_phKeys
;
220 /// stores the handle to the registry file where the appropriate keys are located.
225 /** RegistryKeyNames represents an array of key names.
227 RegistryKeyNames is a helper class to work with an array of key names.
229 class RegistryKeyNames
232 /// Default constructor
233 inline RegistryKeyNames();
235 /// Destructor, the internal array with key names will be deleted.
236 inline ~RegistryKeyNames();
238 /// returns the name of the key sepecified by index.
239 inline rtl::OUString
getElement(sal_uInt32 index
);
241 /// returns the length of the array.
242 inline sal_uInt32
getLength();
244 friend class RegistryKey
;
246 /** sets the data of the array.
248 @param registry specifies the registry files where the keys are located.
249 @param pKeyNames points to an array of key names.
250 @param length specifies the length of the array specified by pKeyNames.
252 inline void setKeyNames(Registry
& registry
, rtl_uString
** pKeyNames
, sal_uInt32 length
);
254 /// stores the number of key names, the number of elements.
256 /// stores an array of key names.
257 rtl_uString
** m_pKeyNames
;
258 /// stores the handle to the registry file where the appropriate keys are located.
263 /** RegistryValueList represents a value list of the specified type.
265 RegistryValueList is a helper class to work with a list value.
267 template<class ValueType
>
268 class RegistryValueList
271 /// Default constructor
274 , m_pValueList(nullptr)
275 , m_valueType(RegValueType::NOT_DEFINED
)
278 /// Destructor, the internal value list will be freed.
283 m_registry
.getApi()->freeValueList(m_valueType
, m_pValueList
, m_length
);
287 /// returns the value of the list specified by index.
288 ValueType
getElement(sal_uInt32 index
)
290 if (m_registry
.isValid() && index
< m_length
)
292 return m_pValueList
[index
];
299 /// returns the length of the list.
300 sal_uInt32
getLength()
305 friend class RegistryKey
;
307 /** sets the data of the value list.
309 @param registry specifies the registry files where the appropriate key is located.
310 @param valueType specifies the type of the list values.
311 @param pValueList points to a value list.
312 @param length specifies the length of the list.
314 void setValueList(Registry
& registry
, RegValueType valueType
,
315 ValueType
* pValueList
, sal_uInt32 length
)
318 m_pValueList
= pValueList
;
319 m_valueType
= valueType
;
320 m_registry
= registry
;
323 /// stores the length of the list, the number of elements.
325 /// stores the value list.
326 ValueType
* m_pValueList
;
327 /// stores the type of the list elements
328 RegValueType m_valueType
;
329 /** stores the handle to the registry file where the appropriate key to this
336 /** RegistryKey reads or writes information of the underlying key in a registry.
338 Class is inline and use a load on call C-Api.
343 /// Default constructor
344 inline RegistryKey();
347 inline RegistryKey(const RegistryKey
& toCopy
);
349 /// Destructor, close the key if it references an open one.
350 inline ~RegistryKey();
353 inline RegistryKey
& operator = (const RegistryKey
& toAssign
);
355 /// checks if the key points to a valid registry key.
356 inline bool isValid() const;
358 /** returns the access mode of the key.
360 @return TRUE if access mode is read only else FALSE.
362 inline bool isReadOnly() const;
364 /// returns the full qualified name of the key beginning with the rootkey.
365 inline rtl::OUString
getName();
367 /** creates a new key or opens a key if the specified key already exists.
369 The specified keyname is relativ to this key.
370 @param keyName specifies the name of the key which will be opened or created.
371 @param rNewKey references a RegistryKey which will be filled with the new or open key.
372 @return RegError::NO_ERROR if succeeds else an error code.
374 inline RegError
createKey(const rtl::OUString
& keyName
,
375 RegistryKey
& rNewKey
);
377 /** opens the specified key.
379 The specified keyname is relativ to this key.
380 @param keyName specifies the name of the key which will be opened.
381 @param rOpenKey references a RegistryKey which will be filled with the open key.
382 @return RegError::NO_ERROR if succeeds else an error code.
384 inline RegError
openKey(const rtl::OUString
& keyName
,
385 RegistryKey
& rOpenKey
);
387 /** opens all subkeys of the specified key.
389 The specified keyname is relativ to this key.
390 @param keyName specifies the name of the key which subkeys will be opened.
391 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
392 @return RegError::NO_ERROR if succeeds else an error code.
394 inline RegError
openSubKeys(const rtl::OUString
& keyName
,
395 RegistryKeyArray
& rSubKeys
);
397 /** returns an array with the names of all subkeys of the specified key.
399 The specified keyname is relativ to this key.
400 @param keyName specifies the name of the key which subkey names will be returned.
401 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
402 @return RegError::NO_ERROR if succeeds else an error code.
404 inline RegError
getKeyNames(const rtl::OUString
& keyName
,
405 RegistryKeyNames
& rSubKeyNames
);
407 /** deletes the specified key.
409 @param keyName specifies the name of the key which will be deleted.
410 @return RegError::NO_ERROR if succeeds else an error code.
412 inline RegError
deleteKey(const rtl::OUString
& keyName
);
414 /// closes explicitly the current key
415 inline RegError
closeKey();
417 /// releases the current key
418 inline void releaseKey();
420 /** sets a value of a key.
422 @param keyName specifies the name of the key which value will be set.
423 If keyName is an empty string, the value will be set for the key
425 @param valueType specifies the type of the value.
426 @param pValue points to a memory block containing the data for the value.
427 @param valueSize specifies the size of pData in bytes
428 @return RegError::NO_ERROR if succeeds else an error code.
430 inline RegError
setValue(const rtl::OUString
& keyName
,
431 RegValueType valueType
,
433 sal_uInt32 valueSize
);
435 /** sets a long list value of a key.
437 @param keyName specifies the name of the key which value will be set.
438 If keyName is an empty string, the value will be set for the key
440 @param pValueList points to an array of longs containing the data for the value.
441 @param len specifies the length of the list (the array referenced by pValueList).
442 @return RegError::NO_ERROR if succeeds else an error code.
444 inline RegError
setLongListValue(const rtl::OUString
& keyName
,
445 sal_Int32
* pValueList
,
448 /** sets an ascii list value of a key.
450 @param keyName specifies the name of the key which value will be set.
451 If keyName is an empty string, the value will be set for the key
453 @param pValueList points to an array of sal_Char* containing the data for the value.
454 @param len specifies the length of the list (the array referenced by pValueList).
455 @return RegError::NO_ERROR if succeeds else an error code.
457 inline RegError
setStringListValue(const rtl::OUString
& keyName
,
458 sal_Char
** pValueList
,
461 /** sets an unicode string list value of a key.
463 @param keyName specifies the name of the key which value will be set.
464 If keyName is an empty string, the value will be set for the key
466 @param pValueList points to an array of sal_Unicode* containing the data for the value.
467 @param len specifies the length of the list (the array referenced by pValueList).
468 @return RegError::NO_ERROR if succeeds else an error code.
470 inline RegError
setUnicodeListValue(const rtl::OUString
& keyName
,
471 sal_Unicode
** pValueList
,
474 /** gets info about type and size of a value.
476 @param keyName specifies the name of the key which value info will be returned.
477 If keyName is an empty string, the value info of the key
478 specified by hKey will be returned.
479 @param pValueType returns the type of the value.
480 @param pValueSize returns the size of the value in bytes or the length of a list value.
481 @return RegError::NO_ERROR if succeeds else an error code.
483 inline RegError
getValueInfo(const rtl::OUString
& keyName
,
484 RegValueType
* pValueType
,
485 sal_uInt32
* pValueSize
);
487 /** gets the value of a key.
489 @param keyName specifies the name of the key which value will be returned.
490 If keyName is an empty string, the value is get from the key
492 @param pValue points to an allocated memory block receiving the data of the value.
493 @return RegError::NO_ERROR if succeeds else an error code.
495 inline RegError
getValue(const rtl::OUString
& keyName
,
498 /** gets a long list value of a key.
500 @param keyName specifies the name of the key which value will be returned.
501 If keyName is an empty string, the value is get from the key
503 @param rValueList references a RegistryValueList which will be filled with the long values.
504 @return RegError::NO_ERROR if succeeds else an error code.
506 inline RegError
getLongListValue(const rtl::OUString
& keyName
,
507 RegistryValueList
<sal_Int32
>& rValueList
);
509 /** gets an ascii list value of a key.
511 @param keyName specifies the name of the key which value will be returned.
512 If keyName is an empty string, the value is get from the key
514 @param rValueList references a RegistryValueList which will be filled with the ascii values.
515 @return RegError::NO_ERROR if succeeds else an error code.
517 inline RegError
getStringListValue(const rtl::OUString
& keyName
,
518 RegistryValueList
<sal_Char
*>& rValueList
);
520 /** gets a unicode value of a key.
522 @param keyName specifies the name of the key which value will be returned.
523 If keyName is an empty string, the value is get from the key
525 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
526 @return RegError::NO_ERROR if succeeds else an error code.
528 inline RegError
getUnicodeListValue(const rtl::OUString
& keyName
,
529 RegistryValueList
<sal_Unicode
*>& rValueList
);
531 /** used to create a link.
533 @deprecated Links are no longer supported.
535 @return RegError::INVALID_LINK
537 inline RegError
createLink(const rtl::OUString
& linkName
,
538 const rtl::OUString
& linkTarget
);
540 /** used to delete a link.
542 @deprecated Links are no longer supported.
544 @return RegError::INVALID_LINK
546 inline RegError
deleteLink(const rtl::OUString
& linkName
);
548 /** used to return the target of a link.
550 @deprecated Links are no longer supported.
552 @return RegError::INVALID_LINK
554 inline RegError
getLinkTarget(const rtl::OUString
& linkName
,
555 rtl::OUString
& rLinkTarget
) const;
557 /** resolves a keyname.
559 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
560 The resolved name will be prefixed with the name of this key.
561 @param[out] rResolvedName the resolved name.
562 @return RegError::NO_ERROR if succeeds else an error code.
564 inline RegError
getResolvedKeyName(const rtl::OUString
& keyName
,
565 rtl::OUString
& rResolvedName
) const;
567 /// returns the name of the registry in which the key is defined.
568 inline rtl::OUString
getRegistryName();
570 friend class Registry
;
574 /** Constructor, which initialize a RegistryKey with registry and an valid key handle.
576 This constructor is internal only.
578 inline RegistryKey(Registry
& registry
,
582 /** sets the internal registry on which this key should work.
584 inline void setRegistry(Registry
& registry
);
588 /// stores the registry on which this key works
590 /// stores the current key handle of this key
591 RegKeyHandle m_hImpl
;
595 inline RegistryKeyArray::RegistryKeyArray()
601 inline RegistryKeyArray::~RegistryKeyArray()
604 m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
607 inline RegistryKey
RegistryKeyArray::getElement(sal_uInt32 index
)
609 if (m_registry
.isValid() && index
< m_length
)
610 return RegistryKey(m_registry
, m_phKeys
[index
]);
612 return RegistryKey();
615 inline sal_uInt32
RegistryKeyArray::getLength()
620 inline void RegistryKeyArray::setKeyHandles(Registry
& registry
,
621 RegKeyHandle
* phKeys
,
626 m_registry
= registry
;
629 inline RegistryKeyNames::RegistryKeyNames()
631 , m_pKeyNames(nullptr)
635 inline RegistryKeyNames::~RegistryKeyNames()
638 m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
641 inline rtl::OUString
RegistryKeyNames::getElement(sal_uInt32 index
)
644 if (m_pKeyNames
&& index
< m_length
)
645 return m_pKeyNames
[index
];
647 return rtl::OUString();
650 inline sal_uInt32
RegistryKeyNames::getLength()
655 inline void RegistryKeyNames::setKeyNames(Registry
& registry
,
656 rtl_uString
** pKeyNames
,
659 m_pKeyNames
= pKeyNames
;
661 m_registry
= registry
;
664 inline RegistryKey::RegistryKey()
669 inline RegistryKey::RegistryKey(Registry
& registry
, RegKeyHandle hKey
)
670 : m_registry(registry
)
674 m_registry
.m_pApi
->acquireKey(m_hImpl
);
678 inline RegistryKey::RegistryKey(const RegistryKey
& toCopy
)
679 : m_registry(toCopy
.m_registry
)
680 , m_hImpl(toCopy
.m_hImpl
)
683 m_registry
.m_pApi
->acquireKey(m_hImpl
);
687 inline void RegistryKey::setRegistry(Registry
& registry
)
689 m_registry
= registry
;
693 inline RegistryKey::~RegistryKey()
696 m_registry
.m_pApi
->releaseKey(m_hImpl
);
699 inline RegistryKey
& RegistryKey::operator = (const RegistryKey
& toAssign
)
701 m_registry
= toAssign
.m_registry
;
703 if (toAssign
.m_hImpl
)
704 m_registry
.m_pApi
->acquireKey(toAssign
.m_hImpl
);
706 m_registry
.m_pApi
->releaseKey(m_hImpl
);
707 m_hImpl
= toAssign
.m_hImpl
;
712 inline bool RegistryKey::isValid() const
713 { return (m_hImpl
!= nullptr); }
715 inline bool RegistryKey::isReadOnly() const
717 if (m_registry
.isValid())
718 return (m_registry
.m_pApi
)->isKeyReadOnly(m_hImpl
);
723 inline rtl::OUString
RegistryKey::getName()
726 if (m_registry
.isValid())
727 m_registry
.m_pApi
->getKeyName(m_hImpl
, &sRet
.pData
);
731 inline RegError
RegistryKey::createKey(const rtl::OUString
& keyName
,
732 RegistryKey
& rNewKey
)
734 if (rNewKey
.isValid()) rNewKey
.closeKey();
735 if (m_registry
.isValid())
737 RegError ret
= m_registry
.m_pApi
->createKey(m_hImpl
, keyName
.pData
, &rNewKey
.m_hImpl
);
738 if (ret
== RegError::NO_ERROR
) rNewKey
.setRegistry(m_registry
);
741 return RegError::INVALID_KEY
;
744 inline RegError
RegistryKey::openKey(const rtl::OUString
& keyName
,
745 RegistryKey
& rOpenKey
)
747 if (rOpenKey
.isValid()) rOpenKey
.closeKey();
748 if (m_registry
.isValid())
750 RegError ret
= m_registry
.m_pApi
->openKey(m_hImpl
, keyName
.pData
,
752 if (ret
== RegError::NO_ERROR
) rOpenKey
.setRegistry(m_registry
);
755 return RegError::INVALID_KEY
;
758 inline RegError
RegistryKey::openSubKeys(const rtl::OUString
& keyName
,
759 RegistryKeyArray
& rSubKeys
)
761 if (m_registry
.isValid())
763 RegError ret
= RegError::NO_ERROR
;
764 RegKeyHandle
* pSubKeys
;
766 ret
= m_registry
.m_pApi
->openSubKeys(m_hImpl
, keyName
.pData
,
767 &pSubKeys
, &nSubKeys
);
768 if ( ret
!= RegError::NO_ERROR
)
773 rSubKeys
.setKeyHandles(m_registry
, pSubKeys
, nSubKeys
);
777 return RegError::INVALID_KEY
;
780 inline RegError
RegistryKey::getKeyNames(const rtl::OUString
& keyName
,
781 RegistryKeyNames
& rSubKeyNames
)
783 if (m_registry
.isValid())
785 RegError ret
= RegError::NO_ERROR
;
786 rtl_uString
** pSubKeyNames
;
788 ret
= m_registry
.m_pApi
->getKeyNames(m_hImpl
, keyName
.pData
,
789 &pSubKeyNames
, &nSubKeys
);
790 if ( ret
!= RegError::NO_ERROR
)
795 rSubKeyNames
.setKeyNames(m_registry
, pSubKeyNames
, nSubKeys
);
799 return RegError::INVALID_KEY
;
802 inline RegError
RegistryKey::deleteKey(const rtl::OUString
& keyName
)
804 if (m_registry
.isValid())
805 return m_registry
.m_pApi
->deleteKey(m_hImpl
, keyName
.pData
);
807 return RegError::INVALID_KEY
;
810 inline RegError
RegistryKey::closeKey()
812 if (m_registry
.isValid())
814 RegError ret
= m_registry
.m_pApi
->closeKey(m_hImpl
);
815 if (ret
== RegError::NO_ERROR
)
818 m_registry
= Registry();
822 return RegError::INVALID_KEY
;
825 inline void RegistryKey::releaseKey()
827 if (m_registry
.isValid() && (m_hImpl
!= nullptr))
829 m_registry
.m_pApi
->releaseKey(m_hImpl
);
834 inline RegError
RegistryKey::setValue(const rtl::OUString
& keyName
,
835 RegValueType valueType
,
837 sal_uInt32 valueSize
)
839 if (m_registry
.isValid())
840 return m_registry
.m_pApi
->setValue(m_hImpl
, keyName
.pData
, valueType
,
843 return RegError::INVALID_KEY
;
846 inline RegError
RegistryKey::setLongListValue(const rtl::OUString
& keyName
,
847 sal_Int32
* pValueList
,
850 if (m_registry
.isValid())
851 return m_registry
.m_pApi
->setLongListValue(m_hImpl
, keyName
.pData
,
854 return RegError::INVALID_KEY
;
857 inline RegError
RegistryKey::setStringListValue(const rtl::OUString
& keyName
,
858 sal_Char
** pValueList
,
861 if (m_registry
.isValid())
862 return m_registry
.m_pApi
->setStringListValue(m_hImpl
, keyName
.pData
,
865 return RegError::INVALID_KEY
;
868 inline RegError
RegistryKey::setUnicodeListValue(const rtl::OUString
& keyName
,
869 sal_Unicode
** pValueList
,
872 if (m_registry
.isValid())
873 return m_registry
.m_pApi
->setUnicodeListValue(m_hImpl
, keyName
.pData
,
876 return RegError::INVALID_KEY
;
879 inline RegError
RegistryKey::getValueInfo(const rtl::OUString
& keyName
,
880 RegValueType
* pValueType
,
881 sal_uInt32
* pValueSize
)
883 if (m_registry
.isValid())
884 return m_registry
.m_pApi
->getValueInfo(m_hImpl
, keyName
.pData
, pValueType
, pValueSize
);
886 return RegError::INVALID_KEY
;
889 inline RegError
RegistryKey::getValue(const rtl::OUString
& keyName
,
892 if (m_registry
.isValid())
893 return m_registry
.m_pApi
->getValue(m_hImpl
, keyName
.pData
, pValue
);
895 return RegError::INVALID_KEY
;
898 inline RegError
RegistryKey::getLongListValue(const rtl::OUString
& keyName
,
899 RegistryValueList
<sal_Int32
>& rValueList
)
901 if (m_registry
.isValid())
903 RegError ret
= RegError::NO_ERROR
;
904 sal_Int32
* pValueList
;
906 ret
= m_registry
.m_pApi
->getLongListValue(m_hImpl
, keyName
.pData
,
907 &pValueList
, &length
);
908 if ( ret
!= RegError::NO_ERROR
)
913 rValueList
.setValueList(m_registry
, RegValueType::LONGLIST
,
918 return RegError::INVALID_KEY
;
921 inline RegError
RegistryKey::getStringListValue(const rtl::OUString
& keyName
,
922 RegistryValueList
<sal_Char
*>& rValueList
)
924 if (m_registry
.isValid())
926 RegError ret
= RegError::NO_ERROR
;
927 sal_Char
** pValueList
;
929 ret
= m_registry
.m_pApi
->getStringListValue(m_hImpl
, keyName
.pData
,
930 &pValueList
, &length
);
931 if ( ret
!= RegError::NO_ERROR
)
936 rValueList
.setValueList(m_registry
, RegValueType::STRINGLIST
,
941 return RegError::INVALID_KEY
;
944 inline RegError
RegistryKey::getUnicodeListValue(const rtl::OUString
& keyName
,
945 RegistryValueList
<sal_Unicode
*>& rValueList
)
947 if (m_registry
.isValid())
949 RegError ret
= RegError::NO_ERROR
;
950 sal_Unicode
** pValueList
;
952 ret
= m_registry
.m_pApi
->getUnicodeListValue(m_hImpl
, keyName
.pData
,
953 &pValueList
, &length
);
954 if ( ret
!= RegError::NO_ERROR
)
959 rValueList
.setValueList(m_registry
, RegValueType::UNICODELIST
,
964 return RegError::INVALID_KEY
;
967 inline RegError
RegistryKey::createLink(const rtl::OUString
& ,
968 const rtl::OUString
& )
970 if (m_registry
.isValid())
971 return RegError::INVALID_LINK
; // links are no longer supported
973 return RegError::INVALID_KEY
;
976 inline RegError
RegistryKey::deleteLink(const rtl::OUString
& )
978 if (m_registry
.isValid())
979 return RegError::INVALID_LINK
; // links are no longer supported
981 return RegError::INVALID_KEY
;
984 inline RegError
RegistryKey::getLinkTarget(const rtl::OUString
& ,
985 rtl::OUString
& ) const
987 if (m_registry
.isValid())
988 return RegError::INVALID_LINK
; // links are no longer supported
990 return RegError::INVALID_KEY
;
994 inline RegError
RegistryKey::getResolvedKeyName(const rtl::OUString
& keyName
,
995 rtl::OUString
& rResolvedName
) const
997 if (m_registry
.isValid())
998 return m_registry
.m_pApi
->getResolvedKeyName(m_hImpl
,
1001 &rResolvedName
.pData
);
1003 return RegError::INVALID_KEY
;
1006 inline rtl::OUString
RegistryKey::getRegistryName()
1008 if (m_registry
.isValid())
1010 return m_registry
.getName();
1012 return rtl::OUString();
1016 inline Registry::Registry()
1017 : m_pApi(initRegistry_Api())
1021 inline Registry::Registry(const Registry
& toCopy
)
1022 : m_pApi(toCopy
.m_pApi
)
1023 , m_hImpl(toCopy
.m_hImpl
)
1026 m_pApi
->acquire(m_hImpl
);
1030 inline Registry::~Registry()
1033 m_pApi
->release(m_hImpl
);
1036 inline Registry
& Registry::operator = (const Registry
& toAssign
)
1038 if (toAssign
.m_hImpl
)
1039 toAssign
.m_pApi
->acquire(toAssign
.m_hImpl
);
1041 m_pApi
->release(m_hImpl
);
1043 m_pApi
= toAssign
.m_pApi
;
1044 m_hImpl
= toAssign
.m_hImpl
;
1049 inline bool Registry::isValid() const
1050 { return ( m_hImpl
!= nullptr ); }
1052 inline bool Registry::isReadOnly() const
1053 { return m_pApi
->isReadOnly(m_hImpl
); }
1055 inline RegError
Registry::openRootKey(RegistryKey
& rRootKey
)
1057 rRootKey
.setRegistry(*this);
1058 return m_pApi
->openRootKey(m_hImpl
, &rRootKey
.m_hImpl
);
1061 inline rtl::OUString
Registry::getName()
1064 m_pApi
->getName(m_hImpl
, &sRet
.pData
);
1068 inline RegError
Registry::create(const rtl::OUString
& registryName
)
1071 m_pApi
->release(m_hImpl
);
1072 return m_pApi
->createRegistry(registryName
.pData
, &m_hImpl
);
1075 inline RegError
Registry::open(const rtl::OUString
& registryName
,
1076 RegAccessMode accessMode
)
1079 m_pApi
->release(m_hImpl
);
1080 return m_pApi
->openRegistry(registryName
.pData
, &m_hImpl
, accessMode
);
1083 inline RegError
Registry::close()
1085 RegError ret
= m_pApi
->closeRegistry(m_hImpl
);
1086 if (ret
== RegError::NO_ERROR
)
1091 inline RegError
Registry::destroy(const rtl::OUString
& registryName
)
1093 RegError ret
= m_pApi
->destroyRegistry(m_hImpl
, registryName
.pData
);
1094 if ( ret
== RegError::NO_ERROR
&& registryName
.isEmpty() )
1099 inline RegError
Registry::mergeKey(RegistryKey
& rKey
,
1100 const rtl::OUString
& keyName
,
1101 const rtl::OUString
& regFileName
,
1104 { return m_pApi
->mergeKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
, bWarnings
, bReport
); }
1109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */