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
;
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
;
252 /** sets the data of the array.
254 @param registry specifies the registry files where the keys are located.
255 @param pKeyNames points to an array of key names.
256 @param length specifies the length of the array specified by pKeyNames.
258 inline void setKeyNames(Registry
const & registry
, rtl_uString
** pKeyNames
, sal_uInt32 length
);
260 /// stores the number of key names, the number of elements.
262 /// stores an array of key names.
263 rtl_uString
** m_pKeyNames
;
264 /// stores the handle to the registry file where the appropriate keys are located.
269 /** RegistryValueList represents a value list of the specified type.
271 RegistryValueList is a helper class to work with a list value.
273 template<class ValueType
>
274 class RegistryValueList final
277 /// Default constructor
280 , m_pValueList(nullptr)
281 , m_valueType(RegValueType::NOT_DEFINED
)
284 /// Destructor, the internal value list will be freed.
289 m_registry
.getApi()->freeValueList(m_valueType
, m_pValueList
, m_length
);
293 /// returns the value of the list specified by index.
294 ValueType
getElement(sal_uInt32 index
)
296 if (m_registry
.isValid() && index
< m_length
)
298 return m_pValueList
[index
];
305 /// returns the length of the list.
306 sal_uInt32
getLength()
311 friend class RegistryKey
;
314 /** sets the data of the value list.
316 @param registry specifies the registry files where the appropriate key is located.
317 @param valueType specifies the type of the list values.
318 @param pValueList points to a value list.
319 @param length specifies the length of the list.
321 void setValueList(const Registry
& registry
, RegValueType valueType
,
322 ValueType
* pValueList
, sal_uInt32 length
)
325 m_pValueList
= pValueList
;
326 m_valueType
= valueType
;
327 m_registry
= registry
;
330 /// stores the length of the list, the number of elements.
332 /// stores the value list.
333 ValueType
* m_pValueList
;
334 /// stores the type of the list elements
335 RegValueType m_valueType
;
336 /** stores the handle to the registry file where the appropriate key to this
343 /** RegistryKey reads or writes information of the underlying key in a registry.
345 Class is inline and use a load on call C-Api.
350 /// Default constructor
351 inline RegistryKey();
354 inline RegistryKey(const RegistryKey
& toCopy
);
356 /// Destructor, close the key if it references an open one.
357 inline ~RegistryKey();
360 inline RegistryKey
& operator = (const RegistryKey
& toAssign
);
362 /// checks if the key points to a valid registry key.
363 inline bool isValid() const;
365 /** returns the access mode of the key.
367 @return TRUE if access mode is read only else FALSE.
369 inline bool isReadOnly() const;
371 /// returns the full qualified name of the key beginning with the rootkey.
372 inline OUString
getName();
374 /** creates a new key or opens a key if the specified key already exists.
376 The specified keyname is relative to this key.
377 @param keyName specifies the name of the key which will be opened or created.
378 @param rNewKey references a RegistryKey which will be filled with the new or open key.
379 @return RegError::NO_ERROR if succeeds else an error code.
381 inline RegError
createKey(const OUString
& keyName
,
382 RegistryKey
& rNewKey
);
384 /** opens the specified key.
386 The specified keyname is relative to this key.
387 @param keyName specifies the name of the key which will be opened.
388 @param rOpenKey references a RegistryKey which will be filled with the open key.
389 @return RegError::NO_ERROR if succeeds else an error code.
391 inline RegError
openKey(const OUString
& keyName
,
392 RegistryKey
& rOpenKey
);
394 /** opens all subkeys of the specified key.
396 The specified keyname is relative to this key.
397 @param keyName specifies the name of the key which subkeys will be opened.
398 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys.
399 @return RegError::NO_ERROR if succeeds else an error code.
401 inline RegError
openSubKeys(const OUString
& keyName
,
402 RegistryKeyArray
& rSubKeys
);
404 /** returns an array with the names of all subkeys of the specified key.
406 The specified keyname is relative to this key.
407 @param keyName specifies the name of the key which subkey names will be returned.
408 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names.
409 @return RegError::NO_ERROR if succeeds else an error code.
411 inline RegError
getKeyNames(const OUString
& keyName
,
412 RegistryKeyNames
& rSubKeyNames
);
414 /** deletes the specified key.
416 @param keyName specifies the name of the key which will be deleted.
417 @return RegError::NO_ERROR if succeeds else an error code.
419 inline RegError
deleteKey(const OUString
& keyName
);
421 /// closes explicitly the current key
422 inline RegError
closeKey();
424 /// releases the current key
425 inline void releaseKey();
427 /** sets a value of a key.
429 @param keyName specifies the name of the key which value will be set.
430 If keyName is an empty string, the value will be set for the key
432 @param valueType specifies the type of the value.
433 @param pValue points to a memory block containing the data for the value.
434 @param valueSize specifies the size of pData in bytes
435 @return RegError::NO_ERROR if succeeds else an error code.
437 inline RegError
setValue(const OUString
& keyName
,
438 RegValueType valueType
,
440 sal_uInt32 valueSize
);
442 /** sets a long list value of a key.
444 @param keyName specifies the name of the key which value will be set.
445 If keyName is an empty string, the value will be set for the key
447 @param pValueList points to an array of longs containing the data for the value.
448 @param len specifies the length of the list (the array referenced by pValueList).
449 @return RegError::NO_ERROR if succeeds else an error code.
451 inline RegError
setLongListValue(const OUString
& keyName
,
452 sal_Int32
const * pValueList
,
455 /** sets an ascii list value of a key.
457 @param keyName specifies the name of the key which value will be set.
458 If keyName is an empty string, the value will be set for the key
460 @param pValueList points to an array of char* containing the data for the value.
461 @param len specifies the length of the list (the array referenced by pValueList).
462 @return RegError::NO_ERROR if succeeds else an error code.
464 inline RegError
setStringListValue(const OUString
& keyName
,
468 /** sets a unicode string list value of a key.
470 @param keyName specifies the name of the key which value will be set.
471 If keyName is an empty string, the value will be set for the key
473 @param pValueList points to an array of sal_Unicode* containing the data for the value.
474 @param len specifies the length of the list (the array referenced by pValueList).
475 @return RegError::NO_ERROR if succeeds else an error code.
477 inline RegError
setUnicodeListValue(const OUString
& keyName
,
478 sal_Unicode
** pValueList
,
481 /** gets info about type and size of a value.
483 @param keyName specifies the name of the key which value info will be returned.
484 If keyName is an empty string, the value info of the key
485 specified by hKey will be returned.
486 @param pValueType returns the type of the value.
487 @param pValueSize returns the size of the value in bytes or the length of a list value.
488 @return RegError::NO_ERROR if succeeds else an error code.
490 inline RegError
getValueInfo(const OUString
& keyName
,
491 RegValueType
* pValueType
,
492 sal_uInt32
* pValueSize
);
494 /** gets the value of a key.
496 @param keyName specifies the name of the key which value will be returned.
497 If keyName is an empty string, the value is get from the key
499 @param pValue points to an allocated memory block receiving the data of the value.
500 @return RegError::NO_ERROR if succeeds else an error code.
502 inline RegError
getValue(const OUString
& keyName
,
505 /** gets a long list value of a key.
507 @param keyName specifies the name of the key which value will be returned.
508 If keyName is an empty string, the value is get from the key
510 @param rValueList references a RegistryValueList which will be filled with the long values.
511 @return RegError::NO_ERROR if succeeds else an error code.
513 inline RegError
getLongListValue(const OUString
& keyName
,
514 RegistryValueList
<sal_Int32
>& rValueList
);
516 /** gets an ascii list value of a key.
518 @param keyName specifies the name of the key which value will be returned.
519 If keyName is an empty string, the value is get from the key
521 @param rValueList references a RegistryValueList which will be filled with the ascii values.
522 @return RegError::NO_ERROR if succeeds else an error code.
524 inline RegError
getStringListValue(const OUString
& keyName
,
525 RegistryValueList
<char*>& rValueList
);
527 /** gets a unicode value of a key.
529 @param keyName specifies the name of the key which value will be returned.
530 If keyName is an empty string, the value is get from the key
532 @param rValueList reference a RegistryValueList which will be filled with the unicode values.
533 @return RegError::NO_ERROR if succeeds else an error code.
535 inline RegError
getUnicodeListValue(const OUString
& keyName
,
536 RegistryValueList
<sal_Unicode
*>& rValueList
);
538 /** resolves a keyname.
540 @param[in] keyName specifies the name of the key which will be resolved relative to this key.
541 The resolved name will be prefixed with the name of this key.
542 @param[out] rResolvedName the resolved name.
543 @return RegError::NO_ERROR if succeeds else an error code.
545 inline RegError
getResolvedKeyName(const OUString
& keyName
,
546 OUString
& rResolvedName
) const;
548 /// returns the name of the registry in which the key is defined.
549 inline OUString
getRegistryName();
551 friend class Registry
;
555 /** Constructor, which initialize a RegistryKey with registry and a valid key handle.
557 This constructor is internal only.
559 inline RegistryKey(Registry
const & registry
,
563 /** sets the internal registry on which this key should work.
565 inline void setRegistry(Registry
const & registry
);
569 /// stores the registry on which this key works
571 /// stores the current key handle of this key
572 RegKeyHandle m_hImpl
;
576 inline RegistryKeyArray::RegistryKeyArray()
582 inline RegistryKeyArray::~RegistryKeyArray()
585 m_registry
.m_pApi
->closeSubKeys(m_phKeys
, m_length
);
588 inline RegistryKey
RegistryKeyArray::getElement(sal_uInt32 index
)
590 if (m_registry
.isValid() && index
< m_length
)
591 return RegistryKey(m_registry
, m_phKeys
[index
]);
593 return RegistryKey();
596 inline sal_uInt32
RegistryKeyArray::getLength() const
601 inline void RegistryKeyArray::setKeyHandles(Registry
const & registry
,
602 RegKeyHandle
* phKeys
,
607 m_registry
= registry
;
610 inline RegistryKeyNames::RegistryKeyNames()
612 , m_pKeyNames(nullptr)
616 inline RegistryKeyNames::~RegistryKeyNames()
619 m_registry
.m_pApi
->freeKeyNames(m_pKeyNames
, m_length
);
622 inline OUString
RegistryKeyNames::getElement(sal_uInt32 index
)
625 if (m_pKeyNames
&& index
< m_length
)
626 return m_pKeyNames
[index
];
631 inline sal_uInt32
RegistryKeyNames::getLength() const
636 inline void RegistryKeyNames::setKeyNames(Registry
const & registry
,
637 rtl_uString
** pKeyNames
,
640 m_pKeyNames
= pKeyNames
;
642 m_registry
= registry
;
645 inline RegistryKey::RegistryKey()
650 inline RegistryKey::RegistryKey(Registry
const & registry
, RegKeyHandle hKey
)
651 : m_registry(registry
)
655 m_registry
.m_pApi
->acquireKey(m_hImpl
);
659 inline RegistryKey::RegistryKey(const RegistryKey
& toCopy
)
660 : m_registry(toCopy
.m_registry
)
661 , m_hImpl(toCopy
.m_hImpl
)
664 m_registry
.m_pApi
->acquireKey(m_hImpl
);
668 inline void RegistryKey::setRegistry(Registry
const & registry
)
670 m_registry
= registry
;
674 inline RegistryKey::~RegistryKey()
677 m_registry
.m_pApi
->releaseKey(m_hImpl
);
680 inline RegistryKey
& RegistryKey::operator = (const RegistryKey
& toAssign
)
682 m_registry
= toAssign
.m_registry
;
684 if (toAssign
.m_hImpl
)
685 m_registry
.m_pApi
->acquireKey(toAssign
.m_hImpl
);
687 m_registry
.m_pApi
->releaseKey(m_hImpl
);
688 m_hImpl
= toAssign
.m_hImpl
;
693 inline bool RegistryKey::isValid() const
694 { return (m_hImpl
!= nullptr); }
696 inline bool RegistryKey::isReadOnly() const
698 if (m_registry
.isValid())
699 return m_registry
.m_pApi
->isKeyReadOnly(m_hImpl
);
704 inline OUString
RegistryKey::getName()
707 if (m_registry
.isValid())
708 m_registry
.m_pApi
->getKeyName(m_hImpl
, &sRet
.pData
);
712 inline RegError
RegistryKey::createKey(const OUString
& keyName
,
713 RegistryKey
& rNewKey
)
715 if (rNewKey
.isValid()) rNewKey
.closeKey();
716 if (m_registry
.isValid())
718 RegError ret
= m_registry
.m_pApi
->createKey(m_hImpl
, keyName
.pData
, &rNewKey
.m_hImpl
);
719 if (ret
== RegError::NO_ERROR
) rNewKey
.setRegistry(m_registry
);
722 return RegError::INVALID_KEY
;
725 inline RegError
RegistryKey::openKey(const OUString
& keyName
,
726 RegistryKey
& rOpenKey
)
728 if (rOpenKey
.isValid()) rOpenKey
.closeKey();
729 if (m_registry
.isValid())
731 RegError ret
= m_registry
.m_pApi
->openKey(m_hImpl
, keyName
.pData
,
733 if (ret
== RegError::NO_ERROR
) rOpenKey
.setRegistry(m_registry
);
736 return RegError::INVALID_KEY
;
739 inline RegError
RegistryKey::openSubKeys(const OUString
& keyName
,
740 RegistryKeyArray
& rSubKeys
)
742 if (m_registry
.isValid())
744 RegError ret
= RegError::NO_ERROR
;
745 RegKeyHandle
* pSubKeys
;
747 ret
= m_registry
.m_pApi
->openSubKeys(m_hImpl
, keyName
.pData
,
748 &pSubKeys
, &nSubKeys
);
749 if ( ret
!= RegError::NO_ERROR
)
754 rSubKeys
.setKeyHandles(m_registry
, pSubKeys
, nSubKeys
);
758 return RegError::INVALID_KEY
;
761 inline RegError
RegistryKey::getKeyNames(const OUString
& keyName
,
762 RegistryKeyNames
& rSubKeyNames
)
764 if (m_registry
.isValid())
766 RegError ret
= RegError::NO_ERROR
;
767 rtl_uString
** pSubKeyNames
;
769 ret
= m_registry
.m_pApi
->getKeyNames(m_hImpl
, keyName
.pData
,
770 &pSubKeyNames
, &nSubKeys
);
771 if ( ret
!= RegError::NO_ERROR
)
776 rSubKeyNames
.setKeyNames(m_registry
, pSubKeyNames
, nSubKeys
);
780 return RegError::INVALID_KEY
;
783 inline RegError
RegistryKey::deleteKey(const OUString
& keyName
)
785 if (m_registry
.isValid())
786 return m_registry
.m_pApi
->deleteKey(m_hImpl
, keyName
.pData
);
788 return RegError::INVALID_KEY
;
791 inline RegError
RegistryKey::closeKey()
793 if (m_registry
.isValid())
795 RegError ret
= m_registry
.m_pApi
->closeKey(m_hImpl
);
796 if (ret
== RegError::NO_ERROR
)
799 m_registry
= Registry();
803 return RegError::INVALID_KEY
;
806 inline void RegistryKey::releaseKey()
808 if (m_registry
.isValid() && (m_hImpl
!= nullptr))
810 m_registry
.m_pApi
->releaseKey(m_hImpl
);
815 inline RegError
RegistryKey::setValue(const OUString
& keyName
,
816 RegValueType valueType
,
818 sal_uInt32 valueSize
)
820 if (m_registry
.isValid())
821 return m_registry
.m_pApi
->setValue(m_hImpl
, keyName
.pData
, valueType
,
824 return RegError::INVALID_KEY
;
827 inline RegError
RegistryKey::setLongListValue(const OUString
& keyName
,
828 sal_Int32
const * pValueList
,
831 if (m_registry
.isValid())
832 return m_registry
.m_pApi
->setLongListValue(m_hImpl
, keyName
.pData
,
835 return RegError::INVALID_KEY
;
838 inline RegError
RegistryKey::setStringListValue(const OUString
& keyName
,
842 if (m_registry
.isValid())
843 return m_registry
.m_pApi
->setStringListValue(m_hImpl
, keyName
.pData
,
846 return RegError::INVALID_KEY
;
849 inline RegError
RegistryKey::setUnicodeListValue(const OUString
& keyName
,
850 sal_Unicode
** pValueList
,
853 if (m_registry
.isValid())
854 return m_registry
.m_pApi
->setUnicodeListValue(m_hImpl
, keyName
.pData
,
857 return RegError::INVALID_KEY
;
860 inline RegError
RegistryKey::getValueInfo(const OUString
& keyName
,
861 RegValueType
* pValueType
,
862 sal_uInt32
* pValueSize
)
864 if (m_registry
.isValid())
865 return m_registry
.m_pApi
->getValueInfo(m_hImpl
, keyName
.pData
, pValueType
, pValueSize
);
867 return RegError::INVALID_KEY
;
870 inline RegError
RegistryKey::getValue(const OUString
& keyName
,
873 if (m_registry
.isValid())
874 return m_registry
.m_pApi
->getValue(m_hImpl
, keyName
.pData
, pValue
);
876 return RegError::INVALID_KEY
;
879 inline RegError
RegistryKey::getLongListValue(const OUString
& keyName
,
880 RegistryValueList
<sal_Int32
>& rValueList
)
882 if (m_registry
.isValid())
884 RegError ret
= RegError::NO_ERROR
;
885 sal_Int32
* pValueList
;
887 ret
= m_registry
.m_pApi
->getLongListValue(m_hImpl
, keyName
.pData
,
888 &pValueList
, &length
);
889 if ( ret
!= RegError::NO_ERROR
)
894 rValueList
.setValueList(m_registry
, RegValueType::LONGLIST
,
899 return RegError::INVALID_KEY
;
902 inline RegError
RegistryKey::getStringListValue(const OUString
& keyName
,
903 RegistryValueList
<char*>& rValueList
)
905 if (m_registry
.isValid())
907 RegError ret
= RegError::NO_ERROR
;
910 ret
= m_registry
.m_pApi
->getStringListValue(m_hImpl
, keyName
.pData
,
911 &pValueList
, &length
);
912 if ( ret
!= RegError::NO_ERROR
)
917 rValueList
.setValueList(m_registry
, RegValueType::STRINGLIST
,
922 return RegError::INVALID_KEY
;
925 inline RegError
RegistryKey::getUnicodeListValue(const OUString
& keyName
,
926 RegistryValueList
<sal_Unicode
*>& rValueList
)
928 if (m_registry
.isValid())
930 RegError ret
= RegError::NO_ERROR
;
931 sal_Unicode
** pValueList
;
933 ret
= m_registry
.m_pApi
->getUnicodeListValue(m_hImpl
, keyName
.pData
,
934 &pValueList
, &length
);
935 if ( ret
!= RegError::NO_ERROR
)
940 rValueList
.setValueList(m_registry
, RegValueType::UNICODELIST
,
945 return RegError::INVALID_KEY
;
948 inline RegError
RegistryKey::getResolvedKeyName(const OUString
& keyName
,
949 OUString
& rResolvedName
) const
951 if (m_registry
.isValid())
952 return m_registry
.m_pApi
->getResolvedKeyName(m_hImpl
,
955 &rResolvedName
.pData
);
957 return RegError::INVALID_KEY
;
960 inline OUString
RegistryKey::getRegistryName()
962 if (m_registry
.isValid())
964 return m_registry
.getName();
970 inline Registry::Registry()
971 : m_pApi(initRegistry_Api())
975 inline Registry::Registry(const Registry
& toCopy
)
976 : m_pApi(toCopy
.m_pApi
)
977 , m_hImpl(toCopy
.m_hImpl
)
980 m_pApi
->acquire(m_hImpl
);
984 inline Registry::~Registry()
987 m_pApi
->release(m_hImpl
);
990 inline Registry
& Registry::operator = (const Registry
& toAssign
)
992 if (toAssign
.m_hImpl
)
993 toAssign
.m_pApi
->acquire(toAssign
.m_hImpl
);
995 m_pApi
->release(m_hImpl
);
997 m_pApi
= toAssign
.m_pApi
;
998 m_hImpl
= toAssign
.m_hImpl
;
1003 inline bool Registry::isValid() const
1004 { return ( m_hImpl
!= nullptr ); }
1006 inline bool Registry::isReadOnly() const
1007 { return m_pApi
->isReadOnly(m_hImpl
); }
1009 inline RegError
Registry::openRootKey(RegistryKey
& rRootKey
)
1011 rRootKey
.setRegistry(*this);
1012 return m_pApi
->openRootKey(m_hImpl
, &rRootKey
.m_hImpl
);
1015 inline OUString
Registry::getName()
1018 m_pApi
->getName(m_hImpl
, &sRet
.pData
);
1022 inline RegError
Registry::create(const OUString
& registryName
)
1025 m_pApi
->release(m_hImpl
);
1026 return m_pApi
->createRegistry(registryName
.pData
, &m_hImpl
);
1029 inline RegError
Registry::open(const OUString
& registryName
,
1030 RegAccessMode accessMode
)
1033 m_pApi
->release(m_hImpl
);
1034 return m_pApi
->openRegistry(registryName
.pData
, &m_hImpl
, accessMode
);
1037 inline RegError
Registry::close()
1039 RegError ret
= m_pApi
->closeRegistry(m_hImpl
);
1040 if (ret
== RegError::NO_ERROR
)
1045 inline RegError
Registry::destroy(const OUString
& registryName
)
1047 RegError ret
= m_pApi
->destroyRegistry(m_hImpl
, registryName
.pData
);
1048 if ( ret
== RegError::NO_ERROR
&& registryName
.isEmpty() )
1053 inline RegError
Registry::mergeKey(RegistryKey
& rKey
,
1054 const OUString
& keyName
,
1055 const OUString
& regFileName
,
1057 { return m_pApi
->mergeKey(m_hImpl
, rKey
.m_hImpl
, keyName
.pData
, regFileName
.pData
, false/*bWarnings*/, bReport
); }
1059 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */