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 .
22 #include <registry/regdllapi.h>
23 #include <registry/regtype.h>
24 #include <rtl/ustring.hxx>
28 /** specifies a collection of function pointers which represents the complete registry C-API.
30 These function pointers are used by the C++ wrapper to call the C-API.
34 void (REGISTRY_CALLTYPE
*acquire
) (RegHandle
);
35 void (REGISTRY_CALLTYPE
*release
) (RegHandle
);
36 sal_Bool (REGISTRY_CALLTYPE
*isReadOnly
) (RegHandle
);
37 RegError (REGISTRY_CALLTYPE
*openRootKey
) (RegHandle
, RegKeyHandle
*);
38 RegError (REGISTRY_CALLTYPE
*getName
) (RegHandle
, rtl_uString
**);
39 RegError (REGISTRY_CALLTYPE
*createRegistry
) (rtl_uString
*, RegHandle
*);
40 RegError (REGISTRY_CALLTYPE
*openRegistry
) (rtl_uString
*, RegHandle
*, RegAccessMode
);
41 RegError (REGISTRY_CALLTYPE
*closeRegistry
) (RegHandle
);
42 RegError (REGISTRY_CALLTYPE
*destroyRegistry
) (RegHandle
, rtl_uString
*);
43 RegError (REGISTRY_CALLTYPE
*mergeKey
) (RegHandle
, RegKeyHandle
, rtl_uString
*, rtl_uString
*, sal_Bool
, sal_Bool
);
44 void (REGISTRY_CALLTYPE
*acquireKey
) (RegKeyHandle
);
45 void (REGISTRY_CALLTYPE
*releaseKey
) (RegKeyHandle
);
46 sal_Bool (REGISTRY_CALLTYPE
*isKeyReadOnly
) (RegKeyHandle
);
47 RegError (REGISTRY_CALLTYPE
*getKeyName
) (RegKeyHandle
, rtl_uString
**);
48 RegError (REGISTRY_CALLTYPE
*createKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
49 RegError (REGISTRY_CALLTYPE
*openKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
50 RegError (REGISTRY_CALLTYPE
*openSubKeys
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
**, sal_uInt32
*);
51 RegError (REGISTRY_CALLTYPE
*closeSubKeys
) (RegKeyHandle
*, sal_uInt32
);
52 RegError (REGISTRY_CALLTYPE
*deleteKey
) (RegKeyHandle
, rtl_uString
*);
53 RegError (REGISTRY_CALLTYPE
*closeKey
) (RegKeyHandle
);
54 RegError (REGISTRY_CALLTYPE
*setValue
) (RegKeyHandle
, rtl_uString
*, RegValueType
, RegValue
, sal_uInt32
);
55 RegError (REGISTRY_CALLTYPE
*setLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
const *, sal_uInt32
);
56 RegError (REGISTRY_CALLTYPE
*setStringListValue
) (RegKeyHandle
, rtl_uString
*, char**, sal_uInt32
);
57 RegError (REGISTRY_CALLTYPE
*setUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
**, sal_uInt32
);
58 RegError (REGISTRY_CALLTYPE
*getValueInfo
) (RegKeyHandle
, rtl_uString
*, RegValueType
*, sal_uInt32
*);
59 RegError (REGISTRY_CALLTYPE
*getValue
) (RegKeyHandle
, rtl_uString
*, RegValue
);
60 RegError (REGISTRY_CALLTYPE
*getLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
**, sal_uInt32
*);
61 RegError (REGISTRY_CALLTYPE
*getStringListValue
) (RegKeyHandle
, rtl_uString
*, char***, sal_uInt32
*);
62 RegError (REGISTRY_CALLTYPE
*getUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
***, sal_uInt32
*);
63 RegError (REGISTRY_CALLTYPE
*freeValueList
) (RegValueType
, RegValue
, sal_uInt32
);
64 RegError (REGISTRY_CALLTYPE
*getResolvedKeyName
) (RegKeyHandle
, rtl_uString
*, sal_Bool
, rtl_uString
**);
65 RegError (REGISTRY_CALLTYPE
*getKeyNames
) (RegKeyHandle
, rtl_uString
*, rtl_uString
***, sal_uInt32
*);
66 RegError (REGISTRY_CALLTYPE
*freeKeyNames
) (rtl_uString
**, sal_uInt32
);
69 /** the API initialization function.
71 REG_DLLPUBLIC Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api();
78 /** The Registry provides the functionality to read and write information in a registry file.
80 The class is implemented inline and use a C-Api.
85 /** Default constructor.
90 inline Registry(const Registry
& toCopy
);
92 Registry(Registry
&& other
) noexcept
: m_pApi(other
.m_pApi
), m_hImpl(other
.m_hImpl
)
93 { other
.m_hImpl
= nullptr; }
95 /// Destructor. The Destructor close the registry if it is open.
99 inline Registry
& operator = (const Registry
& toAssign
);
101 Registry
& operator =(Registry
&& other
) {
102 if (m_hImpl
!= nullptr) {
103 m_pApi
->release(m_hImpl
);
105 m_hImpl
= other
.m_hImpl
;
106 other
.m_hImpl
= nullptr;
110 /// checks if the registry points to a valid registry data file.
111 inline bool isValid() const;
113 /** returns the access mode of the registry.
115 @return TRUE if the access mode is readonly else FALSE.
117 inline bool isReadOnly() const;
119 /** opens the root key of the registry.
121 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
122 @return RegError::NO_ERROR if succeeds else an error code.
124 inline RegError
openRootKey(RegistryKey
& rRootKey
);
126 /// returns the name of the current registry data file.
127 inline OUString
getName();
129 /** creates a new registry with the specified name and creates a root key.
131 @param registryName specifies the name of the new registry.
132 @return RegError::NO_ERROR if succeeds else an error code.
134 inline RegError
create(const OUString
& registryName
);
136 /** opens a registry with the specified name.
138 If the registry already points to a valid registry, the old registry will be closed.
139 @param registryName specifies a registry name.
140 @param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
141 @return RegError::NO_ERROR if succeeds else an error code.
143 inline RegError
open(const OUString
& registryName
,
144 RegAccessMode accessMode
);
146 /// closes explicitly the current registry data file.
147 inline RegError
close();
149 /** destroys a registry.
151 @param registryName specifies a registry name, if the name is an empty string the registry
152 itself will be destroyed.
153 @return RegError::NO_ERROR if succeeds else an error code.
155 inline RegError
destroy(const OUString
& registryName
);
157 /** merges the registry information of the specified key with the registry
158 information of the specified file.
160 All existing keys will be extended and existing key values will be overwritten.
161 @param rKey references a currently open key. The key which information is merged by this
162 function is a subkey of this key
163 @param keyName specifies the name of the key which will be merged.
164 If keyName is an empty string the registry information under the key specified
165 by rKey is merged with the information from the specified file.
166 @param regFileName specifies the file containing the registry information.
167 @param bReport if TRUE the function reports warnings on stdout if a key already exists.
168 @return RegError::NO_ERROR if succeeds else an error code. If it returns an error the registry will
169 restore the state before merging.
171 inline RegError
mergeKey(RegistryKey
& rKey
,
172 const OUString
& keyName
,
173 const OUString
& regFileName
,
176 friend class RegistryKey
;
177 friend class RegistryKeyArray
;
178 friend class RegistryKeyNames
;
180 /// returns the used registry Api.
181 const Registry_Api
* getApi() const { return m_pApi
; }
184 /// stores the used and initialized registry Api.
185 const Registry_Api
* m_pApi
;
186 /// stores the handle of the underlying registry file on which most of the functions work.
191 /** RegistryKeyArray represents an array of open keys.
193 RegistryKeyArray is a helper class to work with an array of keys.
195 class RegistryKeyArray
198 /// Default constructor
199 inline RegistryKeyArray();
201 /// Destructor, all subkeys will be closed.
202 inline ~RegistryKeyArray();
204 /// returns the open key specified by index.
205 inline RegistryKey
getElement(sal_uInt32 index
);
207 /// returns the length of the array.
208 inline sal_uInt32
getLength() const;
210 friend class RegistryKey
;
212 /** sets the data of the key array.
214 @param registry specifies the registry files where the keys are located.
215 @param phKeys points to an array of open keys.
216 @param length specifies the length of the array specified by phKeys.
218 inline void setKeyHandles(Registry
const & registry
, RegKeyHandle
* phKeys
, sal_uInt32 length
);
220 /// stores the number of open subkeys, the number of elements.
222 /// stores an array of open subkeys.
223 RegKeyHandle
* m_phKeys
;
224 /// stores the handle to the registry file where the appropriate keys are located.
229 /** RegistryKeyNames represents an array of key names.
231 RegistryKeyNames is a helper class to work with an array of key names.
233 class RegistryKeyNames
236 /// Default constructor
237 inline RegistryKeyNames();
239 /// Destructor, the internal array with key names will be deleted.
240 inline ~RegistryKeyNames();
242 /// returns the name of the key specified by index.
243 inline OUString
getElement(sal_uInt32 index
);
245 /// returns the length of the array.
246 inline sal_uInt32
getLength() const;
248 friend class RegistryKey
;
250 /** sets the data of the array.
252 @param registry specifies the registry files where the keys are located.
253 @param pKeyNames points to an array of key names.
254 @param length specifies the length of the array specified by pKeyNames.
256 inline void setKeyNames(Registry
const & registry
, rtl_uString
** pKeyNames
, sal_uInt32 length
);
258 /// stores the number of key names, the number of elements.
260 /// stores an array of key names.
261 rtl_uString
** m_pKeyNames
;
262 /// stores the handle to the registry file where the appropriate keys are located.
267 /** RegistryValueList represents a value list of the specified type.
269 RegistryValueList is a helper class to work with a list value.
271 template<class ValueType
>
272 class RegistryValueList final
275 /// Default constructor
278 , m_pValueList(nullptr)
279 , m_valueType(RegValueType::NOT_DEFINED
)
282 /// Destructor, the internal value list will be freed.
287 m_registry
.getApi()->freeValueList(m_valueType
, m_pValueList
, m_length
);
291 /// returns the value of the list specified by index.
292 ValueType
getElement(sal_uInt32 index
)
294 if (m_registry
.isValid() && index
< m_length
)
296 return m_pValueList
[index
];
303 /// returns the length of the list.
304 sal_uInt32
getLength()
309 friend class RegistryKey
;
312 /** sets the data of the value list.
314 @param registry specifies the registry files where the appropriate key is located.
315 @param valueType specifies the type of the list values.
316 @param pValueList points to a value list.
317 @param length specifies the length of the list.
319 void setValueList(const Registry
& registry
, RegValueType valueType
,
320 ValueType
* pValueList
, sal_uInt32 length
)
323 m_pValueList
= pValueList
;
324 m_valueType
= valueType
;
325 m_registry
= registry
;
328 /// stores the length of the list, the number of elements.
330 /// stores the value list.
331 ValueType
* m_pValueList
;
332 /// stores the type of the list elements
333 RegValueType m_valueType
;
334 /** stores the handle to the registry file where the appropriate key to this
341 /** RegistryKey reads or writes information of the underlying key in a registry.
343 Class is inline and use a load on call C-Api.
348 /// Default constructor
349 inline RegistryKey();
352 inline RegistryKey(const RegistryKey
& toCopy
);
354 /// Destructor, close the key if it references an open one.
355 inline ~RegistryKey();
358 inline RegistryKey
& operator = (const RegistryKey
& toAssign
);
360 /// checks if the key points to a valid registry key.
361 inline bool isValid() const;
363 /** returns the access mode of the key.
365 @return TRUE if access mode is read only else FALSE.
367 inline bool isReadOnly() const;
369 /// returns the full qualified name of the key beginning with the rootkey.
370 inline OUString
getName();
372 /** creates a new key or opens a key if the specified key already exists.
374 The specified keyname is relative to this key.
375 @param keyName specifies the name of the key which will be opened or created.
376 @param rNewKey references a RegistryKey which will be filled with the new or open key.
377 @return RegError::NO_ERROR if succeeds else an error code.
379 inline RegError
createKey(const OUString
& keyName
,
380 RegistryKey
& rNewKey
);
382 /** opens the specified key.
384 The specified keyname is relative to this key.
385 @param keyName specifies the name of the key which will be opened.
386 @param rOpenKey references a RegistryKey which will be filled with the open key.
387 @return RegError::NO_ERROR if succeeds else an error code.
389 inline RegError
openKey(const OUString
& keyName
,
390 RegistryKey
& rOpenKey
);
392 /** opens all subkeys of the specified key.
394 The specified keyname is relative to this key.
395 @param keyName specifies the name of the key which subkeys will be opened.
396 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
397 @return RegError::NO_ERROR if succeeds else an error code.
399 inline RegError
openSubKeys(const OUString
& keyName
,
400 RegistryKeyArray
& rSubKeys
);
402 /** returns an array with the names of all subkeys of the specified key.
404 The specified keyname is relative to this key.
405 @param keyName specifies the name of the key which subkey names will be returned.
406 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
407 @return RegError::NO_ERROR if succeeds else an error code.
409 inline RegError
getKeyNames(const OUString
& keyName
,
410 RegistryKeyNames
& rSubKeyNames
);
412 /** deletes the specified key.
414 @param keyName specifies the name of the key which will be deleted.
415 @return RegError::NO_ERROR if succeeds else an error code.
417 inline RegError
deleteKey(const OUString
& keyName
);
419 /// closes explicitly the current key
420 inline RegError
closeKey();
422 /// releases the current key
423 inline void releaseKey();
425 /** sets a value of a key.
427 @param keyName specifies the name of the key which value will be set.
428 If keyName is an empty string, the value will be set for the key
430 @param valueType specifies the type of the value.
431 @param pValue points to a memory block containing the data for the value.
432 @param valueSize specifies the size of pData in bytes
433 @return RegError::NO_ERROR if succeeds else an error code.
435 inline RegError
setValue(const OUString
& keyName
,
436 RegValueType valueType
,
438 sal_uInt32 valueSize
);
440 /** sets a long list value of a key.
442 @param keyName specifies the name of the key which value will be set.
443 If keyName is an empty string, the value will be set for the key
445 @param pValueList points to an array of longs containing the data for the value.
446 @param len specifies the length of the list (the array referenced by pValueList).
447 @return RegError::NO_ERROR if succeeds else an error code.
449 inline RegError
setLongListValue(const OUString
& keyName
,
450 sal_Int32
const * pValueList
,
453 /** sets an ascii list value of a key.
455 @param keyName specifies the name of the key which value will be set.
456 If keyName is an empty string, the value will be set for the key
458 @param pValueList points to an array of char* containing the data for the value.
459 @param len specifies the length of the list (the array referenced by pValueList).
460 @return RegError::NO_ERROR if succeeds else an error code.
462 inline RegError
setStringListValue(const OUString
& keyName
,
466 /** sets a unicode string list value of a key.
468 @param keyName specifies the name of the key which value will be set.
469 If keyName is an empty string, the value will be set for the key
471 @param pValueList points to an array of sal_Unicode* containing the data for the value.
472 @param len specifies the length of the list (the array referenced by pValueList).
473 @return RegError::NO_ERROR if succeeds else an error code.
475 inline RegError
setUnicodeListValue(const OUString
& keyName
,
476 sal_Unicode
** pValueList
,
479 /** gets info about type and size of a value.
481 @param keyName specifies the name of the key which value info will be returned.
482 If keyName is an empty string, the value info of the key
483 specified by hKey will be returned.
484 @param pValueType returns the type of the value.
485 @param pValueSize returns the size of the value in bytes or the length of a list value.
486 @return RegError::NO_ERROR if succeeds else an error code.
488 inline RegError
getValueInfo(const OUString
& keyName
,
489 RegValueType
* pValueType
,
490 sal_uInt32
* pValueSize
);
492 /** gets the value of a key.
494 @param keyName specifies the name of the key which value will be returned.
495 If keyName is an empty string, the value is get from the key
497 @param pValue points to an allocated memory block receiving the data of the value.
498 @return RegError::NO_ERROR if succeeds else an error code.
500 inline RegError
getValue(const OUString
& keyName
,
503 /** gets a long list value of a key.
505 @param keyName specifies the name of the key which value will be returned.
506 If keyName is an empty string, the value is get from the key
508 @param rValueList references a RegistryValueList which will be filled with the long values.
509 @return RegError::NO_ERROR if succeeds else an error code.
511 inline RegError
getLongListValue(const OUString
& keyName
,
512 RegistryValueList
<sal_Int32
>& rValueList
);
514 /** gets an ascii list value of a key.
516 @param keyName specifies the name of the key which value will be returned.
517 If keyName is an empty string, the value is get from the key
519 @param rValueList references a RegistryValueList which will be filled with the ascii values.
520 @return RegError::NO_ERROR if succeeds else an error code.
522 inline RegError
getStringListValue(const OUString
& keyName
,
523 RegistryValueList
<char*>& rValueList
);
525 /** gets a unicode value of a key.
527 @param keyName specifies the name of the key which value will be returned.
528 If keyName is an empty string, the value is get from the key
530 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
531 @return RegError::NO_ERROR if succeeds else an error code.
533 inline RegError
getUnicodeListValue(const OUString
& keyName
,
534 RegistryValueList
<sal_Unicode
*>& rValueList
);
536 /** resolves a keyname.
538 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
539 The resolved name will be prefixed with the name of this key.
540 @param[out] rResolvedName the resolved name.
541 @return RegError::NO_ERROR if succeeds else an error code.
543 inline RegError
getResolvedKeyName(const OUString
& keyName
,
544 OUString
& rResolvedName
) const;
546 /// returns the name of the registry in which the key is defined.
547 inline OUString
getRegistryName();
549 friend class Registry
;
553 /** Constructor, which initialize a RegistryKey with registry and a valid key handle.
555 This constructor is internal only.
557 inline RegistryKey(Registry
const & registry
,
561 /** sets the internal registry on which this key should work.
563 inline void setRegistry(Registry
const & registry
);
567 /// stores the registry on which this key works
569 /// stores the current key handle of this key
570 RegKeyHandle m_hImpl
;
574 inline RegistryKeyArray::RegistryKeyArray()
580 inline RegistryKeyArray::~RegistryKeyArray()
583 m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
586 inline RegistryKey
RegistryKeyArray::getElement(sal_uInt32 index
)
588 if (m_registry
.isValid() && index
< m_length
)
589 return RegistryKey(m_registry
, m_phKeys
[index
]);
591 return RegistryKey();
594 inline sal_uInt32
RegistryKeyArray::getLength() const
599 inline void RegistryKeyArray::setKeyHandles(Registry
const & registry
,
600 RegKeyHandle
* phKeys
,
605 m_registry
= registry
;
608 inline RegistryKeyNames::RegistryKeyNames()
610 , m_pKeyNames(nullptr)
614 inline RegistryKeyNames::~RegistryKeyNames()
617 m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
620 inline OUString
RegistryKeyNames::getElement(sal_uInt32 index
)
623 if (m_pKeyNames
&& index
< m_length
)
624 return m_pKeyNames
[index
];
629 inline sal_uInt32
RegistryKeyNames::getLength() const
634 inline void RegistryKeyNames::setKeyNames(Registry
const & registry
,
635 rtl_uString
** pKeyNames
,
638 m_pKeyNames
= pKeyNames
;
640 m_registry
= registry
;
643 inline RegistryKey::RegistryKey()
648 inline RegistryKey::RegistryKey(Registry
const & registry
, RegKeyHandle hKey
)
649 : m_registry(registry
)
653 m_registry
.m_pApi
->acquireKey(m_hImpl
);
657 inline RegistryKey::RegistryKey(const RegistryKey
& toCopy
)
658 : m_registry(toCopy
.m_registry
)
659 , m_hImpl(toCopy
.m_hImpl
)
662 m_registry
.m_pApi
->acquireKey(m_hImpl
);
666 inline void RegistryKey::setRegistry(Registry
const & registry
)
668 m_registry
= registry
;
672 inline RegistryKey::~RegistryKey()
675 m_registry
.m_pApi
->releaseKey(m_hImpl
);
678 inline RegistryKey
& RegistryKey::operator = (const RegistryKey
& toAssign
)
680 m_registry
= toAssign
.m_registry
;
682 if (toAssign
.m_hImpl
)
683 m_registry
.m_pApi
->acquireKey(toAssign
.m_hImpl
);
685 m_registry
.m_pApi
->releaseKey(m_hImpl
);
686 m_hImpl
= toAssign
.m_hImpl
;
691 inline bool RegistryKey::isValid() const
692 { return (m_hImpl
!= nullptr); }
694 inline bool RegistryKey::isReadOnly() const
696 if (m_registry
.isValid())
697 return m_registry
.m_pApi
->isKeyReadOnly(m_hImpl
);
702 inline OUString
RegistryKey::getName()
705 if (m_registry
.isValid())
706 m_registry
.m_pApi
->getKeyName(m_hImpl
, &sRet
.pData
);
710 inline RegError
RegistryKey::createKey(const OUString
& keyName
,
711 RegistryKey
& rNewKey
)
713 if (rNewKey
.isValid()) rNewKey
.closeKey();
714 if (m_registry
.isValid())
716 RegError ret
= m_registry
.m_pApi
->createKey(m_hImpl
, keyName
.pData
, &rNewKey
.m_hImpl
);
717 if (ret
== RegError::NO_ERROR
) rNewKey
.setRegistry(m_registry
);
720 return RegError::INVALID_KEY
;
723 inline RegError
RegistryKey::openKey(const OUString
& keyName
,
724 RegistryKey
& rOpenKey
)
726 if (rOpenKey
.isValid()) rOpenKey
.closeKey();
727 if (m_registry
.isValid())
729 RegError ret
= m_registry
.m_pApi
->openKey(m_hImpl
, keyName
.pData
,
731 if (ret
== RegError::NO_ERROR
) rOpenKey
.setRegistry(m_registry
);
734 return RegError::INVALID_KEY
;
737 inline RegError
RegistryKey::openSubKeys(const OUString
& keyName
,
738 RegistryKeyArray
& rSubKeys
)
740 if (m_registry
.isValid())
742 RegError ret
= RegError::NO_ERROR
;
743 RegKeyHandle
* pSubKeys
;
745 ret
= m_registry
.m_pApi
->openSubKeys(m_hImpl
, keyName
.pData
,
746 &pSubKeys
, &nSubKeys
);
747 if ( ret
!= RegError::NO_ERROR
)
752 rSubKeys
.setKeyHandles(m_registry
, pSubKeys
, nSubKeys
);
756 return RegError::INVALID_KEY
;
759 inline RegError
RegistryKey::getKeyNames(const OUString
& keyName
,
760 RegistryKeyNames
& rSubKeyNames
)
762 if (m_registry
.isValid())
764 RegError ret
= RegError::NO_ERROR
;
765 rtl_uString
** pSubKeyNames
;
767 ret
= m_registry
.m_pApi
->getKeyNames(m_hImpl
, keyName
.pData
,
768 &pSubKeyNames
, &nSubKeys
);
769 if ( ret
!= RegError::NO_ERROR
)
774 rSubKeyNames
.setKeyNames(m_registry
, pSubKeyNames
, nSubKeys
);
778 return RegError::INVALID_KEY
;
781 inline RegError
RegistryKey::deleteKey(const OUString
& keyName
)
783 if (m_registry
.isValid())
784 return m_registry
.m_pApi
->deleteKey(m_hImpl
, keyName
.pData
);
786 return RegError::INVALID_KEY
;
789 inline RegError
RegistryKey::closeKey()
791 if (m_registry
.isValid())
793 RegError ret
= m_registry
.m_pApi
->closeKey(m_hImpl
);
794 if (ret
== RegError::NO_ERROR
)
797 m_registry
= Registry();
801 return RegError::INVALID_KEY
;
804 inline void RegistryKey::releaseKey()
806 if (m_registry
.isValid() && (m_hImpl
!= nullptr))
808 m_registry
.m_pApi
->releaseKey(m_hImpl
);
813 inline RegError
RegistryKey::setValue(const OUString
& keyName
,
814 RegValueType valueType
,
816 sal_uInt32 valueSize
)
818 if (m_registry
.isValid())
819 return m_registry
.m_pApi
->setValue(m_hImpl
, keyName
.pData
, valueType
,
822 return RegError::INVALID_KEY
;
825 inline RegError
RegistryKey::setLongListValue(const OUString
& keyName
,
826 sal_Int32
const * pValueList
,
829 if (m_registry
.isValid())
830 return m_registry
.m_pApi
->setLongListValue(m_hImpl
, keyName
.pData
,
833 return RegError::INVALID_KEY
;
836 inline RegError
RegistryKey::setStringListValue(const OUString
& keyName
,
840 if (m_registry
.isValid())
841 return m_registry
.m_pApi
->setStringListValue(m_hImpl
, keyName
.pData
,
844 return RegError::INVALID_KEY
;
847 inline RegError
RegistryKey::setUnicodeListValue(const OUString
& keyName
,
848 sal_Unicode
** pValueList
,
851 if (m_registry
.isValid())
852 return m_registry
.m_pApi
->setUnicodeListValue(m_hImpl
, keyName
.pData
,
855 return RegError::INVALID_KEY
;
858 inline RegError
RegistryKey::getValueInfo(const OUString
& keyName
,
859 RegValueType
* pValueType
,
860 sal_uInt32
* pValueSize
)
862 if (m_registry
.isValid())
863 return m_registry
.m_pApi
->getValueInfo(m_hImpl
, keyName
.pData
, pValueType
, pValueSize
);
865 return RegError::INVALID_KEY
;
868 inline RegError
RegistryKey::getValue(const OUString
& keyName
,
871 if (m_registry
.isValid())
872 return m_registry
.m_pApi
->getValue(m_hImpl
, keyName
.pData
, pValue
);
874 return RegError::INVALID_KEY
;
877 inline RegError
RegistryKey::getLongListValue(const OUString
& keyName
,
878 RegistryValueList
<sal_Int32
>& rValueList
)
880 if (m_registry
.isValid())
882 RegError ret
= RegError::NO_ERROR
;
883 sal_Int32
* pValueList
;
885 ret
= m_registry
.m_pApi
->getLongListValue(m_hImpl
, keyName
.pData
,
886 &pValueList
, &length
);
887 if ( ret
!= RegError::NO_ERROR
)
892 rValueList
.setValueList(m_registry
, RegValueType::LONGLIST
,
897 return RegError::INVALID_KEY
;
900 inline RegError
RegistryKey::getStringListValue(const OUString
& keyName
,
901 RegistryValueList
<char*>& rValueList
)
903 if (m_registry
.isValid())
905 RegError ret
= RegError::NO_ERROR
;
908 ret
= m_registry
.m_pApi
->getStringListValue(m_hImpl
, keyName
.pData
,
909 &pValueList
, &length
);
910 if ( ret
!= RegError::NO_ERROR
)
915 rValueList
.setValueList(m_registry
, RegValueType::STRINGLIST
,
920 return RegError::INVALID_KEY
;
923 inline RegError
RegistryKey::getUnicodeListValue(const OUString
& keyName
,
924 RegistryValueList
<sal_Unicode
*>& rValueList
)
926 if (m_registry
.isValid())
928 RegError ret
= RegError::NO_ERROR
;
929 sal_Unicode
** pValueList
;
931 ret
= m_registry
.m_pApi
->getUnicodeListValue(m_hImpl
, keyName
.pData
,
932 &pValueList
, &length
);
933 if ( ret
!= RegError::NO_ERROR
)
938 rValueList
.setValueList(m_registry
, RegValueType::UNICODELIST
,
943 return RegError::INVALID_KEY
;
946 inline RegError
RegistryKey::getResolvedKeyName(const OUString
& keyName
,
947 OUString
& rResolvedName
) const
949 if (m_registry
.isValid())
950 return m_registry
.m_pApi
->getResolvedKeyName(m_hImpl
,
953 &rResolvedName
.pData
);
955 return RegError::INVALID_KEY
;
958 inline OUString
RegistryKey::getRegistryName()
960 if (m_registry
.isValid())
962 return m_registry
.getName();
968 inline Registry::Registry()
969 : m_pApi(initRegistry_Api())
973 inline Registry::Registry(const Registry
& toCopy
)
974 : m_pApi(toCopy
.m_pApi
)
975 , m_hImpl(toCopy
.m_hImpl
)
978 m_pApi
->acquire(m_hImpl
);
982 inline Registry::~Registry()
985 m_pApi
->release(m_hImpl
);
988 inline Registry
& Registry::operator = (const Registry
& toAssign
)
990 if (toAssign
.m_hImpl
)
991 toAssign
.m_pApi
->acquire(toAssign
.m_hImpl
);
993 m_pApi
->release(m_hImpl
);
995 m_pApi
= toAssign
.m_pApi
;
996 m_hImpl
= toAssign
.m_hImpl
;
1001 inline bool Registry::isValid() const
1002 { return ( m_hImpl
!= nullptr ); }
1004 inline bool Registry::isReadOnly() const
1005 { return m_pApi
->isReadOnly(m_hImpl
); }
1007 inline RegError
Registry::openRootKey(RegistryKey
& rRootKey
)
1009 rRootKey
.setRegistry(*this);
1010 return m_pApi
->openRootKey(m_hImpl
, &rRootKey
.m_hImpl
);
1013 inline OUString
Registry::getName()
1016 m_pApi
->getName(m_hImpl
, &sRet
.pData
);
1020 inline RegError
Registry::create(const OUString
& registryName
)
1023 m_pApi
->release(m_hImpl
);
1024 return m_pApi
->createRegistry(registryName
.pData
, &m_hImpl
);
1027 inline RegError
Registry::open(const OUString
& registryName
,
1028 RegAccessMode accessMode
)
1031 m_pApi
->release(m_hImpl
);
1032 return m_pApi
->openRegistry(registryName
.pData
, &m_hImpl
, accessMode
);
1035 inline RegError
Registry::close()
1037 RegError ret
= m_pApi
->closeRegistry(m_hImpl
);
1038 if (ret
== RegError::NO_ERROR
)
1043 inline RegError
Registry::destroy(const OUString
& registryName
)
1045 RegError ret
= m_pApi
->destroyRegistry(m_hImpl
, registryName
.pData
);
1046 if ( ret
== RegError::NO_ERROR
&& registryName
.isEmpty() )
1051 inline RegError
Registry::mergeKey(RegistryKey
& rKey
,
1052 const OUString
& keyName
,
1053 const OUString
& regFileName
,
1055 { return m_pApi
->mergeKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
, false/*bWarnings*/, bReport
); }
1057 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */