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>
29 /** specifies a collection of function pointers which represents the complete registry C-API.
31 These function pointers are used by the C++ wrapper to call the C-API.
35 void (REGISTRY_CALLTYPE
*acquire
) (RegHandle
);
36 void (REGISTRY_CALLTYPE
*release
) (RegHandle
);
37 sal_Bool (REGISTRY_CALLTYPE
*isReadOnly
) (RegHandle
);
38 RegError (REGISTRY_CALLTYPE
*openRootKey
) (RegHandle
, RegKeyHandle
*);
39 RegError (REGISTRY_CALLTYPE
*getName
) (RegHandle
, rtl_uString
**);
40 RegError (REGISTRY_CALLTYPE
*createRegistry
) (rtl_uString
*, RegHandle
*);
41 RegError (REGISTRY_CALLTYPE
*openRegistry
) (rtl_uString
*, RegHandle
*, RegAccessMode
);
42 RegError (REGISTRY_CALLTYPE
*closeRegistry
) (RegHandle
);
43 RegError (REGISTRY_CALLTYPE
*destroyRegistry
) (RegHandle
, rtl_uString
*);
44 RegError (REGISTRY_CALLTYPE
*mergeKey
) (RegHandle
, RegKeyHandle
, rtl_uString
*, rtl_uString
*, sal_Bool
, sal_Bool
);
45 void (REGISTRY_CALLTYPE
*acquireKey
) (RegKeyHandle
);
46 void (REGISTRY_CALLTYPE
*releaseKey
) (RegKeyHandle
);
47 sal_Bool (REGISTRY_CALLTYPE
*isKeyReadOnly
) (RegKeyHandle
);
48 RegError (REGISTRY_CALLTYPE
*getKeyName
) (RegKeyHandle
, rtl_uString
**);
49 RegError (REGISTRY_CALLTYPE
*createKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
50 RegError (REGISTRY_CALLTYPE
*openKey
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
*);
51 RegError (REGISTRY_CALLTYPE
*openSubKeys
) (RegKeyHandle
, rtl_uString
*, RegKeyHandle
**, sal_uInt32
*);
52 RegError (REGISTRY_CALLTYPE
*closeSubKeys
) (RegKeyHandle
*, sal_uInt32
);
53 RegError (REGISTRY_CALLTYPE
*deleteKey
) (RegKeyHandle
, rtl_uString
*);
54 RegError (REGISTRY_CALLTYPE
*closeKey
) (RegKeyHandle
);
55 RegError (REGISTRY_CALLTYPE
*setValue
) (RegKeyHandle
, rtl_uString
*, RegValueType
, RegValue
, sal_uInt32
);
56 RegError (REGISTRY_CALLTYPE
*setLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
const *, sal_uInt32
);
57 RegError (REGISTRY_CALLTYPE
*setStringListValue
) (RegKeyHandle
, rtl_uString
*, sal_Char
**, sal_uInt32
);
58 RegError (REGISTRY_CALLTYPE
*setUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
**, sal_uInt32
);
59 RegError (REGISTRY_CALLTYPE
*getValueInfo
) (RegKeyHandle
, rtl_uString
*, RegValueType
*, sal_uInt32
*);
60 RegError (REGISTRY_CALLTYPE
*getValue
) (RegKeyHandle
, rtl_uString
*, RegValue
);
61 RegError (REGISTRY_CALLTYPE
*getLongListValue
) (RegKeyHandle
, rtl_uString
*, sal_Int32
**, sal_uInt32
*);
62 RegError (REGISTRY_CALLTYPE
*getStringListValue
) (RegKeyHandle
, rtl_uString
*, sal_Char
***, sal_uInt32
*);
63 RegError (REGISTRY_CALLTYPE
*getUnicodeListValue
)(RegKeyHandle
, rtl_uString
*, sal_Unicode
***, sal_uInt32
*);
64 RegError (REGISTRY_CALLTYPE
*freeValueList
) (RegValueType
, RegValue
, sal_uInt32
);
65 RegError (REGISTRY_CALLTYPE
*getResolvedKeyName
) (RegKeyHandle
, rtl_uString
*, sal_Bool
, rtl_uString
**);
66 RegError (REGISTRY_CALLTYPE
*getKeyNames
) (RegKeyHandle
, rtl_uString
*, rtl_uString
***, sal_uInt32
*);
67 RegError (REGISTRY_CALLTYPE
*freeKeyNames
) (rtl_uString
**, sal_uInt32
);
70 /** the API initialization function.
72 REG_DLLPUBLIC Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api();
79 /** The Registry provides the functionality to read and write information in a registry file.
81 The class is implemented inline and use a C-Api.
86 /** Default constructor.
91 inline Registry(const Registry
& toCopy
);
93 Registry(Registry
&& other
) noexcept
: m_pApi(other
.m_pApi
), m_hImpl(other
.m_hImpl
)
94 { other
.m_hImpl
= nullptr; }
96 /// Destructor. The Destructor close the registry if it is open.
100 inline Registry
& operator = (const Registry
& toAssign
);
102 Registry
& operator =(Registry
&& other
) {
103 if (m_hImpl
!= nullptr) {
104 m_pApi
->release(m_hImpl
);
106 m_hImpl
= other
.m_hImpl
;
107 other
.m_hImpl
= nullptr;
111 /// checks if the registry points to a valid registry data file.
112 inline bool isValid() const;
114 /** returns the access mode of the registry.
116 @return TRUE if the access mode is readonly else FALSE.
118 inline bool isReadOnly() const;
120 /** opens the root key of the registry.
122 @param rRootKey reference to a RegistryKey which is filled with the rootkey.
123 @return RegError::NO_ERROR if succeeds else an error code.
125 inline RegError
openRootKey(RegistryKey
& rRootKey
);
127 /// returns the name of the current registry data file.
128 inline OUString
getName();
130 /** creates a new registry with the specified name and creates a root key.
132 @param registryName specifies the name of the new registry.
133 @return RegError::NO_ERROR if succeeds else an error code.
135 inline RegError
create(const OUString
& registryName
);
137 /** opens a registry with the specified name.
139 If the registry already points to a valid registry, the old registry will be closed.
140 @param registryName specifies a registry name.
141 @param accessMode specifies the access mode for the registry, RegAccessMode::READONLY or RegAccessMode::READWRITE.
142 @return RegError::NO_ERROR if succeeds else an error code.
144 inline RegError
open(const OUString
& registryName
,
145 RegAccessMode accessMode
);
147 /// closes explicitly the current registry data file.
148 inline RegError
close();
150 /** destroys a registry.
152 @param registryName specifies a registry name, if the name is an empty string the registry
153 itself will be destroyed.
154 @return RegError::NO_ERROR if succeeds else an error code.
156 inline RegError
destroy(const OUString
& registryName
);
158 /** merges the registry information of the specified key with the registry
159 information of the specified file.
161 All existing keys will be extended and existing key values will be overwritten.
162 @param rKey references a currently open key. The key which information is merged by this
163 function is a subkey of this key
164 @param keyName specifies the name of the key which will be merged.
165 If keyName is an empty string the registry information under the key specified
166 by rKey is merged with the information from the specified file.
167 @param regFileName specifies the file containing the registry information.
168 @param bReport if TRUE the function reports warnings on stdout if a key already exists.
169 @return RegError::NO_ERROR if succeeds else an error code. If it returns an error the registry will
170 restore the state before merging.
172 inline RegError
mergeKey(RegistryKey
& rKey
,
173 const OUString
& keyName
,
174 const OUString
& regFileName
,
177 friend class RegistryKey
;
178 friend class RegistryKeyArray
;
179 friend class RegistryKeyNames
;
181 /// returns the used registry Api.
182 const Registry_Api
* getApi() const { return m_pApi
; }
185 /// stores the used and initialized registry Api.
186 const Registry_Api
* m_pApi
;
187 /// stores the handle of the underlying registry file on which most of the functions work.
192 /** RegistryKeyArray represents an array of open keys.
194 RegistryKeyArray is a helper class to work with an array of keys.
196 class RegistryKeyArray
199 /// Default constructor
200 inline RegistryKeyArray();
202 /// Destructor, all subkeys will be closed.
203 inline ~RegistryKeyArray();
205 /// returns the open key specified by index.
206 inline RegistryKey
getElement(sal_uInt32 index
);
208 /// returns the length of the array.
209 inline sal_uInt32
getLength() const;
211 friend class RegistryKey
;
213 /** sets the data of the key array.
215 @param registry specifies the registry files where the keys are located.
216 @param phKeys points to an array of open keys.
217 @param length specifies the length of the array specified by phKeys.
219 inline void setKeyHandles(Registry
const & registry
, RegKeyHandle
* phKeys
, sal_uInt32 length
);
221 /// stores the number of open subkeys, the number of elements.
223 /// stores an array of open subkeys.
224 RegKeyHandle
* m_phKeys
;
225 /// stores the handle to the registry file where the appropriate keys are located.
230 /** RegistryKeyNames represents an array of key names.
232 RegistryKeyNames is a helper class to work with an array of key names.
234 class RegistryKeyNames
237 /// Default constructor
238 inline RegistryKeyNames();
240 /// Destructor, the internal array with key names will be deleted.
241 inline ~RegistryKeyNames();
243 /// returns the name of the key specified by index.
244 inline OUString
getElement(sal_uInt32 index
);
246 /// returns the length of the array.
247 inline sal_uInt32
getLength() const;
249 friend class RegistryKey
;
251 /** sets the data of the array.
253 @param registry specifies the registry files where the keys are located.
254 @param pKeyNames points to an array of key names.
255 @param length specifies the length of the array specified by pKeyNames.
257 inline void setKeyNames(Registry
const & registry
, rtl_uString
** pKeyNames
, sal_uInt32 length
);
259 /// stores the number of key names, the number of elements.
261 /// stores an array of key names.
262 rtl_uString
** m_pKeyNames
;
263 /// stores the handle to the registry file where the appropriate keys are located.
268 /** RegistryValueList represents a value list of the specified type.
270 RegistryValueList is a helper class to work with a list value.
272 template<class ValueType
>
273 class RegistryValueList final
276 /// Default constructor
279 , m_pValueList(nullptr)
280 , m_valueType(RegValueType::NOT_DEFINED
)
283 /// Destructor, the internal value list will be freed.
288 m_registry
.getApi()->freeValueList(m_valueType
, m_pValueList
, m_length
);
292 /// returns the value of the list specified by index.
293 ValueType
getElement(sal_uInt32 index
)
295 if (m_registry
.isValid() && index
< m_length
)
297 return m_pValueList
[index
];
304 /// returns the length of the list.
305 sal_uInt32
getLength()
310 friend class RegistryKey
;
313 /** sets the data of the value list.
315 @param registry specifies the registry files where the appropriate key is located.
316 @param valueType specifies the type of the list values.
317 @param pValueList points to a value list.
318 @param length specifies the length of the list.
320 void setValueList(Registry
& registry
, RegValueType valueType
,
321 ValueType
* pValueList
, sal_uInt32 length
)
324 m_pValueList
= pValueList
;
325 m_valueType
= valueType
;
326 m_registry
= registry
;
329 /// stores the length of the list, the number of elements.
331 /// stores the value list.
332 ValueType
* m_pValueList
;
333 /// stores the type of the list elements
334 RegValueType m_valueType
;
335 /** stores the handle to the registry file where the appropriate key to this
342 /** RegistryKey reads or writes information of the underlying key in a registry.
344 Class is inline and use a load on call C-Api.
349 /// Default constructor
350 inline RegistryKey();
353 inline RegistryKey(const RegistryKey
& toCopy
);
355 /// Destructor, close the key if it references an open one.
356 inline ~RegistryKey();
359 inline RegistryKey
& operator = (const RegistryKey
& toAssign
);
361 /// checks if the key points to a valid registry key.
362 inline bool isValid() const;
364 /** returns the access mode of the key.
366 @return TRUE if access mode is read only else FALSE.
368 inline bool isReadOnly() const;
370 /// returns the full qualified name of the key beginning with the rootkey.
371 inline OUString
getName();
373 /** creates a new key or opens a key if the specified key already exists.
375 The specified keyname is relative to this key.
376 @param keyName specifies the name of the key which will be opened or created.
377 @param rNewKey references a RegistryKey which will be filled with the new or open key.
378 @return RegError::NO_ERROR if succeeds else an error code.
380 inline RegError
createKey(const OUString
& keyName
,
381 RegistryKey
& rNewKey
);
383 /** opens the specified key.
385 The specified keyname is relative to this key.
386 @param keyName specifies the name of the key which will be opened.
387 @param rOpenKey references a RegistryKey which will be filled with the open key.
388 @return RegError::NO_ERROR if succeeds else an error code.
390 inline RegError
openKey(const OUString
& keyName
,
391 RegistryKey
& rOpenKey
);
393 /** opens all subkeys of the specified key.
395 The specified keyname is relative to this key.
396 @param keyName specifies the name of the key which subkeys will be opened.
397 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
398 @return RegError::NO_ERROR if succeeds else an error code.
400 inline RegError
openSubKeys(const OUString
& keyName
,
401 RegistryKeyArray
& rSubKeys
);
403 /** returns an array with the names of all subkeys of the specified key.
405 The specified keyname is relative to this key.
406 @param keyName specifies the name of the key which subkey names will be returned.
407 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
408 @return RegError::NO_ERROR if succeeds else an error code.
410 inline RegError
getKeyNames(const OUString
& keyName
,
411 RegistryKeyNames
& rSubKeyNames
);
413 /** deletes the specified key.
415 @param keyName specifies the name of the key which will be deleted.
416 @return RegError::NO_ERROR if succeeds else an error code.
418 inline RegError
deleteKey(const OUString
& keyName
);
420 /// closes explicitly the current key
421 inline RegError
closeKey();
423 /// releases the current key
424 inline void releaseKey();
426 /** sets a value of a key.
428 @param keyName specifies the name of the key which value will be set.
429 If keyName is an empty string, the value will be set for the key
431 @param valueType specifies the type of the value.
432 @param pValue points to a memory block containing the data for the value.
433 @param valueSize specifies the size of pData in bytes
434 @return RegError::NO_ERROR if succeeds else an error code.
436 inline RegError
setValue(const OUString
& keyName
,
437 RegValueType valueType
,
439 sal_uInt32 valueSize
);
441 /** sets a long list value of a key.
443 @param keyName specifies the name of the key which value will be set.
444 If keyName is an empty string, the value will be set for the key
446 @param pValueList points to an array of longs containing the data for the value.
447 @param len specifies the length of the list (the array referenced by pValueList).
448 @return RegError::NO_ERROR if succeeds else an error code.
450 inline RegError
setLongListValue(const OUString
& keyName
,
451 sal_Int32
const * pValueList
,
454 /** sets an ascii list value of a key.
456 @param keyName specifies the name of the key which value will be set.
457 If keyName is an empty string, the value will be set for the key
459 @param pValueList points to an array of sal_Char* containing the data for the value.
460 @param len specifies the length of the list (the array referenced by pValueList).
461 @return RegError::NO_ERROR if succeeds else an error code.
463 inline RegError
setStringListValue(const OUString
& keyName
,
464 sal_Char
** pValueList
,
467 /** sets a unicode string list value of a key.
469 @param keyName specifies the name of the key which value will be set.
470 If keyName is an empty string, the value will be set for the key
472 @param pValueList points to an array of sal_Unicode* containing the data for the value.
473 @param len specifies the length of the list (the array referenced by pValueList).
474 @return RegError::NO_ERROR if succeeds else an error code.
476 inline RegError
setUnicodeListValue(const OUString
& keyName
,
477 sal_Unicode
** pValueList
,
480 /** gets info about type and size of a value.
482 @param keyName specifies the name of the key which value info will be returned.
483 If keyName is an empty string, the value info of the key
484 specified by hKey will be returned.
485 @param pValueType returns the type of the value.
486 @param pValueSize returns the size of the value in bytes or the length of a list value.
487 @return RegError::NO_ERROR if succeeds else an error code.
489 inline RegError
getValueInfo(const OUString
& keyName
,
490 RegValueType
* pValueType
,
491 sal_uInt32
* pValueSize
);
493 /** gets the value of a key.
495 @param keyName specifies the name of the key which value will be returned.
496 If keyName is an empty string, the value is get from the key
498 @param pValue points to an allocated memory block receiving the data of the value.
499 @return RegError::NO_ERROR if succeeds else an error code.
501 inline RegError
getValue(const OUString
& keyName
,
504 /** gets a long list value of a key.
506 @param keyName specifies the name of the key which value will be returned.
507 If keyName is an empty string, the value is get from the key
509 @param rValueList references a RegistryValueList which will be filled with the long values.
510 @return RegError::NO_ERROR if succeeds else an error code.
512 inline RegError
getLongListValue(const OUString
& keyName
,
513 RegistryValueList
<sal_Int32
>& rValueList
);
515 /** gets an ascii list value of a key.
517 @param keyName specifies the name of the key which value will be returned.
518 If keyName is an empty string, the value is get from the key
520 @param rValueList references a RegistryValueList which will be filled with the ascii values.
521 @return RegError::NO_ERROR if succeeds else an error code.
523 inline RegError
getStringListValue(const OUString
& keyName
,
524 RegistryValueList
<sal_Char
*>& rValueList
);
526 /** gets a unicode value of a key.
528 @param keyName specifies the name of the key which value will be returned.
529 If keyName is an empty string, the value is get from the key
531 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
532 @return RegError::NO_ERROR if succeeds else an error code.
534 inline RegError
getUnicodeListValue(const OUString
& keyName
,
535 RegistryValueList
<sal_Unicode
*>& rValueList
);
537 /** resolves a keyname.
539 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
540 The resolved name will be prefixed with the name of this key.
541 @param[out] rResolvedName the resolved name.
542 @return RegError::NO_ERROR if succeeds else an error code.
544 inline RegError
getResolvedKeyName(const OUString
& keyName
,
545 OUString
& rResolvedName
) const;
547 /// returns the name of the registry in which the key is defined.
548 inline OUString
getRegistryName();
550 friend class Registry
;
554 /** Constructor, which initialize a RegistryKey with registry and a valid key handle.
556 This constructor is internal only.
558 inline RegistryKey(Registry
const & registry
,
562 /** sets the internal registry on which this key should work.
564 inline void setRegistry(Registry
const & registry
);
568 /// stores the registry on which this key works
570 /// stores the current key handle of this key
571 RegKeyHandle m_hImpl
;
575 inline RegistryKeyArray::RegistryKeyArray()
581 inline RegistryKeyArray::~RegistryKeyArray()
584 m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
587 inline RegistryKey
RegistryKeyArray::getElement(sal_uInt32 index
)
589 if (m_registry
.isValid() && index
< m_length
)
590 return RegistryKey(m_registry
, m_phKeys
[index
]);
592 return RegistryKey();
595 inline sal_uInt32
RegistryKeyArray::getLength() const
600 inline void RegistryKeyArray::setKeyHandles(Registry
const & registry
,
601 RegKeyHandle
* phKeys
,
606 m_registry
= registry
;
609 inline RegistryKeyNames::RegistryKeyNames()
611 , m_pKeyNames(nullptr)
615 inline RegistryKeyNames::~RegistryKeyNames()
618 m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
621 inline OUString
RegistryKeyNames::getElement(sal_uInt32 index
)
624 if (m_pKeyNames
&& index
< m_length
)
625 return m_pKeyNames
[index
];
630 inline sal_uInt32
RegistryKeyNames::getLength() const
635 inline void RegistryKeyNames::setKeyNames(Registry
const & registry
,
636 rtl_uString
** pKeyNames
,
639 m_pKeyNames
= pKeyNames
;
641 m_registry
= registry
;
644 inline RegistryKey::RegistryKey()
649 inline RegistryKey::RegistryKey(Registry
const & registry
, RegKeyHandle hKey
)
650 : m_registry(registry
)
654 m_registry
.m_pApi
->acquireKey(m_hImpl
);
658 inline RegistryKey::RegistryKey(const RegistryKey
& toCopy
)
659 : m_registry(toCopy
.m_registry
)
660 , m_hImpl(toCopy
.m_hImpl
)
663 m_registry
.m_pApi
->acquireKey(m_hImpl
);
667 inline void RegistryKey::setRegistry(Registry
const & registry
)
669 m_registry
= registry
;
673 inline RegistryKey::~RegistryKey()
676 m_registry
.m_pApi
->releaseKey(m_hImpl
);
679 inline RegistryKey
& RegistryKey::operator = (const RegistryKey
& toAssign
)
681 m_registry
= toAssign
.m_registry
;
683 if (toAssign
.m_hImpl
)
684 m_registry
.m_pApi
->acquireKey(toAssign
.m_hImpl
);
686 m_registry
.m_pApi
->releaseKey(m_hImpl
);
687 m_hImpl
= toAssign
.m_hImpl
;
692 inline bool RegistryKey::isValid() const
693 { return (m_hImpl
!= nullptr); }
695 inline bool RegistryKey::isReadOnly() const
697 if (m_registry
.isValid())
698 return m_registry
.m_pApi
->isKeyReadOnly(m_hImpl
);
703 inline OUString
RegistryKey::getName()
706 if (m_registry
.isValid())
707 m_registry
.m_pApi
->getKeyName(m_hImpl
, &sRet
.pData
);
711 inline RegError
RegistryKey::createKey(const OUString
& keyName
,
712 RegistryKey
& rNewKey
)
714 if (rNewKey
.isValid()) rNewKey
.closeKey();
715 if (m_registry
.isValid())
717 RegError ret
= m_registry
.m_pApi
->createKey(m_hImpl
, keyName
.pData
, &rNewKey
.m_hImpl
);
718 if (ret
== RegError::NO_ERROR
) rNewKey
.setRegistry(m_registry
);
721 return RegError::INVALID_KEY
;
724 inline RegError
RegistryKey::openKey(const OUString
& keyName
,
725 RegistryKey
& rOpenKey
)
727 if (rOpenKey
.isValid()) rOpenKey
.closeKey();
728 if (m_registry
.isValid())
730 RegError ret
= m_registry
.m_pApi
->openKey(m_hImpl
, keyName
.pData
,
732 if (ret
== RegError::NO_ERROR
) rOpenKey
.setRegistry(m_registry
);
735 return RegError::INVALID_KEY
;
738 inline RegError
RegistryKey::openSubKeys(const OUString
& keyName
,
739 RegistryKeyArray
& rSubKeys
)
741 if (m_registry
.isValid())
743 RegError ret
= RegError::NO_ERROR
;
744 RegKeyHandle
* pSubKeys
;
746 ret
= m_registry
.m_pApi
->openSubKeys(m_hImpl
, keyName
.pData
,
747 &pSubKeys
, &nSubKeys
);
748 if ( ret
!= RegError::NO_ERROR
)
753 rSubKeys
.setKeyHandles(m_registry
, pSubKeys
, nSubKeys
);
757 return RegError::INVALID_KEY
;
760 inline RegError
RegistryKey::getKeyNames(const OUString
& keyName
,
761 RegistryKeyNames
& rSubKeyNames
)
763 if (m_registry
.isValid())
765 RegError ret
= RegError::NO_ERROR
;
766 rtl_uString
** pSubKeyNames
;
768 ret
= m_registry
.m_pApi
->getKeyNames(m_hImpl
, keyName
.pData
,
769 &pSubKeyNames
, &nSubKeys
);
770 if ( ret
!= RegError::NO_ERROR
)
775 rSubKeyNames
.setKeyNames(m_registry
, pSubKeyNames
, nSubKeys
);
779 return RegError::INVALID_KEY
;
782 inline RegError
RegistryKey::deleteKey(const OUString
& keyName
)
784 if (m_registry
.isValid())
785 return m_registry
.m_pApi
->deleteKey(m_hImpl
, keyName
.pData
);
787 return RegError::INVALID_KEY
;
790 inline RegError
RegistryKey::closeKey()
792 if (m_registry
.isValid())
794 RegError ret
= m_registry
.m_pApi
->closeKey(m_hImpl
);
795 if (ret
== RegError::NO_ERROR
)
798 m_registry
= Registry();
802 return RegError::INVALID_KEY
;
805 inline void RegistryKey::releaseKey()
807 if (m_registry
.isValid() && (m_hImpl
!= nullptr))
809 m_registry
.m_pApi
->releaseKey(m_hImpl
);
814 inline RegError
RegistryKey::setValue(const OUString
& keyName
,
815 RegValueType valueType
,
817 sal_uInt32 valueSize
)
819 if (m_registry
.isValid())
820 return m_registry
.m_pApi
->setValue(m_hImpl
, keyName
.pData
, valueType
,
823 return RegError::INVALID_KEY
;
826 inline RegError
RegistryKey::setLongListValue(const OUString
& keyName
,
827 sal_Int32
const * pValueList
,
830 if (m_registry
.isValid())
831 return m_registry
.m_pApi
->setLongListValue(m_hImpl
, keyName
.pData
,
834 return RegError::INVALID_KEY
;
837 inline RegError
RegistryKey::setStringListValue(const OUString
& keyName
,
838 sal_Char
** pValueList
,
841 if (m_registry
.isValid())
842 return m_registry
.m_pApi
->setStringListValue(m_hImpl
, keyName
.pData
,
845 return RegError::INVALID_KEY
;
848 inline RegError
RegistryKey::setUnicodeListValue(const OUString
& keyName
,
849 sal_Unicode
** pValueList
,
852 if (m_registry
.isValid())
853 return m_registry
.m_pApi
->setUnicodeListValue(m_hImpl
, keyName
.pData
,
856 return RegError::INVALID_KEY
;
859 inline RegError
RegistryKey::getValueInfo(const OUString
& keyName
,
860 RegValueType
* pValueType
,
861 sal_uInt32
* pValueSize
)
863 if (m_registry
.isValid())
864 return m_registry
.m_pApi
->getValueInfo(m_hImpl
, keyName
.pData
, pValueType
, pValueSize
);
866 return RegError::INVALID_KEY
;
869 inline RegError
RegistryKey::getValue(const OUString
& keyName
,
872 if (m_registry
.isValid())
873 return m_registry
.m_pApi
->getValue(m_hImpl
, keyName
.pData
, pValue
);
875 return RegError::INVALID_KEY
;
878 inline RegError
RegistryKey::getLongListValue(const OUString
& keyName
,
879 RegistryValueList
<sal_Int32
>& rValueList
)
881 if (m_registry
.isValid())
883 RegError ret
= RegError::NO_ERROR
;
884 sal_Int32
* pValueList
;
886 ret
= m_registry
.m_pApi
->getLongListValue(m_hImpl
, keyName
.pData
,
887 &pValueList
, &length
);
888 if ( ret
!= RegError::NO_ERROR
)
893 rValueList
.setValueList(m_registry
, RegValueType::LONGLIST
,
898 return RegError::INVALID_KEY
;
901 inline RegError
RegistryKey::getStringListValue(const OUString
& keyName
,
902 RegistryValueList
<sal_Char
*>& rValueList
)
904 if (m_registry
.isValid())
906 RegError ret
= RegError::NO_ERROR
;
907 sal_Char
** pValueList
;
909 ret
= m_registry
.m_pApi
->getStringListValue(m_hImpl
, keyName
.pData
,
910 &pValueList
, &length
);
911 if ( ret
!= RegError::NO_ERROR
)
916 rValueList
.setValueList(m_registry
, RegValueType::STRINGLIST
,
921 return RegError::INVALID_KEY
;
924 inline RegError
RegistryKey::getUnicodeListValue(const OUString
& keyName
,
925 RegistryValueList
<sal_Unicode
*>& rValueList
)
927 if (m_registry
.isValid())
929 RegError ret
= RegError::NO_ERROR
;
930 sal_Unicode
** pValueList
;
932 ret
= m_registry
.m_pApi
->getUnicodeListValue(m_hImpl
, keyName
.pData
,
933 &pValueList
, &length
);
934 if ( ret
!= RegError::NO_ERROR
)
939 rValueList
.setValueList(m_registry
, RegValueType::UNICODELIST
,
944 return RegError::INVALID_KEY
;
947 inline RegError
RegistryKey::getResolvedKeyName(const OUString
& keyName
,
948 OUString
& rResolvedName
) const
950 if (m_registry
.isValid())
951 return m_registry
.m_pApi
->getResolvedKeyName(m_hImpl
,
954 &rResolvedName
.pData
);
956 return RegError::INVALID_KEY
;
959 inline OUString
RegistryKey::getRegistryName()
961 if (m_registry
.isValid())
963 return m_registry
.getName();
969 inline Registry::Registry()
970 : m_pApi(initRegistry_Api())
974 inline Registry::Registry(const Registry
& toCopy
)
975 : m_pApi(toCopy
.m_pApi
)
976 , m_hImpl(toCopy
.m_hImpl
)
979 m_pApi
->acquire(m_hImpl
);
983 inline Registry::~Registry()
986 m_pApi
->release(m_hImpl
);
989 inline Registry
& Registry::operator = (const Registry
& toAssign
)
991 if (toAssign
.m_hImpl
)
992 toAssign
.m_pApi
->acquire(toAssign
.m_hImpl
);
994 m_pApi
->release(m_hImpl
);
996 m_pApi
= toAssign
.m_pApi
;
997 m_hImpl
= toAssign
.m_hImpl
;
1002 inline bool Registry::isValid() const
1003 { return ( m_hImpl
!= nullptr ); }
1005 inline bool Registry::isReadOnly() const
1006 { return m_pApi
->isReadOnly(m_hImpl
); }
1008 inline RegError
Registry::openRootKey(RegistryKey
& rRootKey
)
1010 rRootKey
.setRegistry(*this);
1011 return m_pApi
->openRootKey(m_hImpl
, &rRootKey
.m_hImpl
);
1014 inline OUString
Registry::getName()
1017 m_pApi
->getName(m_hImpl
, &sRet
.pData
);
1021 inline RegError
Registry::create(const OUString
& registryName
)
1024 m_pApi
->release(m_hImpl
);
1025 return m_pApi
->createRegistry(registryName
.pData
, &m_hImpl
);
1028 inline RegError
Registry::open(const OUString
& registryName
,
1029 RegAccessMode accessMode
)
1032 m_pApi
->release(m_hImpl
);
1033 return m_pApi
->openRegistry(registryName
.pData
, &m_hImpl
, accessMode
);
1036 inline RegError
Registry::close()
1038 RegError ret
= m_pApi
->closeRegistry(m_hImpl
);
1039 if (ret
== RegError::NO_ERROR
)
1044 inline RegError
Registry::destroy(const OUString
& registryName
)
1046 RegError ret
= m_pApi
->destroyRegistry(m_hImpl
, registryName
.pData
);
1047 if ( ret
== RegError::NO_ERROR
&& registryName
.isEmpty() )
1052 inline RegError
Registry::mergeKey(RegistryKey
& rKey
,
1053 const OUString
& keyName
,
1054 const OUString
& regFileName
,
1056 { return m_pApi
->mergeKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
, false/*bWarnings*/, bReport
); }
1061 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */