1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _REGISTRY_REGISTRY_HXX_ 29 #define _REGISTRY_REGISTRY_HXX_ 30 31 #include <registry/regtype.h> 32 #include <rtl/ustring.hxx> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** specifies a collection of function pointers which represents the complete registry C-API. 39 40 This funtions pointers are used by the C++ wrapper to call the C-API. 41 */ 42 struct Registry_Api 43 { 44 void (REGISTRY_CALLTYPE *acquire) (RegHandle); 45 void (REGISTRY_CALLTYPE *release) (RegHandle); 46 sal_Bool (REGISTRY_CALLTYPE *isReadOnly) (RegHandle); 47 RegError (REGISTRY_CALLTYPE *openRootKey) (RegHandle, RegKeyHandle*); 48 RegError (REGISTRY_CALLTYPE *getName) (RegHandle, rtl_uString**); 49 RegError (REGISTRY_CALLTYPE *createRegistry) (rtl_uString*, RegHandle*); 50 RegError (REGISTRY_CALLTYPE *openRegistry) (rtl_uString*, RegHandle*, RegAccessMode); 51 RegError (REGISTRY_CALLTYPE *closeRegistry) (RegHandle); 52 RegError (REGISTRY_CALLTYPE *destroyRegistry) (RegHandle, rtl_uString*); 53 RegError (REGISTRY_CALLTYPE *loadKey) (RegHandle, RegKeyHandle, rtl_uString*, rtl_uString*); 54 RegError (REGISTRY_CALLTYPE *saveKey) (RegHandle, RegKeyHandle, rtl_uString*, rtl_uString*); 55 RegError (REGISTRY_CALLTYPE *mergeKey) (RegHandle, RegKeyHandle, rtl_uString*, rtl_uString*, sal_Bool, sal_Bool); 56 RegError (REGISTRY_CALLTYPE *dumpRegistry) (RegHandle, RegKeyHandle); 57 void (REGISTRY_CALLTYPE *acquireKey) (RegKeyHandle); 58 void (REGISTRY_CALLTYPE *releaseKey) (RegKeyHandle); 59 sal_Bool (REGISTRY_CALLTYPE *isKeyReadOnly) (RegKeyHandle); 60 RegError (REGISTRY_CALLTYPE *getKeyName) (RegKeyHandle, rtl_uString**); 61 RegError (REGISTRY_CALLTYPE *createKey) (RegKeyHandle, rtl_uString*, RegKeyHandle*); 62 RegError (REGISTRY_CALLTYPE *openKey) (RegKeyHandle, rtl_uString*, RegKeyHandle*); 63 RegError (REGISTRY_CALLTYPE *openSubKeys) (RegKeyHandle, rtl_uString*, RegKeyHandle**, sal_uInt32*); 64 RegError (REGISTRY_CALLTYPE *closeSubKeys) (RegKeyHandle*, sal_uInt32); 65 RegError (REGISTRY_CALLTYPE *deleteKey) (RegKeyHandle, rtl_uString*); 66 RegError (REGISTRY_CALLTYPE *closeKey) (RegKeyHandle); 67 RegError (REGISTRY_CALLTYPE *setValue) (RegKeyHandle, rtl_uString*, RegValueType, RegValue, sal_uInt32); 68 RegError (REGISTRY_CALLTYPE *setLongListValue) (RegKeyHandle, rtl_uString*, sal_Int32*, sal_uInt32); 69 RegError (REGISTRY_CALLTYPE *setStringListValue) (RegKeyHandle, rtl_uString*, sal_Char**, sal_uInt32); 70 RegError (REGISTRY_CALLTYPE *setUnicodeListValue)(RegKeyHandle, rtl_uString*, sal_Unicode**, sal_uInt32); 71 RegError (REGISTRY_CALLTYPE *getValueInfo) (RegKeyHandle, rtl_uString*, RegValueType*, sal_uInt32*); 72 RegError (REGISTRY_CALLTYPE *getValue) (RegKeyHandle, rtl_uString*, RegValue); 73 RegError (REGISTRY_CALLTYPE *getLongListValue) (RegKeyHandle, rtl_uString*, sal_Int32**, sal_uInt32*); 74 RegError (REGISTRY_CALLTYPE *getStringListValue) (RegKeyHandle, rtl_uString*, sal_Char***, sal_uInt32*); 75 RegError (REGISTRY_CALLTYPE *getUnicodeListValue)(RegKeyHandle, rtl_uString*, sal_Unicode***, sal_uInt32*); 76 RegError (REGISTRY_CALLTYPE *freeValueList) (RegValueType, RegValue, sal_uInt32); 77 RegError (REGISTRY_CALLTYPE *createLink) (RegKeyHandle, rtl_uString*, rtl_uString*); 78 RegError (REGISTRY_CALLTYPE *deleteLink) (RegKeyHandle, rtl_uString*); 79 RegError (REGISTRY_CALLTYPE *getKeyType) (RegKeyHandle, rtl_uString*, RegKeyType*); 80 RegError (REGISTRY_CALLTYPE *getLinkTarget) (RegKeyHandle, rtl_uString*, rtl_uString**); 81 RegError (REGISTRY_CALLTYPE *getResolvedKeyName) (RegKeyHandle, rtl_uString*, sal_Bool, rtl_uString**); 82 RegError (REGISTRY_CALLTYPE *getKeyNames) (RegKeyHandle, rtl_uString*, rtl_uString***, sal_uInt32*); 83 RegError (REGISTRY_CALLTYPE *freeKeyNames) (rtl_uString**, sal_uInt32); 84 }; 85 86 /** the API initialization function. 87 */ 88 Registry_Api* REGISTRY_CALLTYPE initRegistry_Api(void); 89 90 #ifdef __cplusplus 91 } 92 #endif 93 94 95 class RegistryKey; 96 97 //----------------------------------------------------------------------------- 98 99 /** The Registry provides the functionality to read and write information in a registry file. 100 101 The class is implemented inline and use a C-Api. 102 */ 103 class Registry 104 { 105 public: 106 /** Default constructor. 107 */ 108 inline Registry(); 109 110 /// Copy constructcor 111 inline Registry(const Registry& toCopy); 112 113 /// Destructor. The Destructor close the registry if it is open. 114 inline ~Registry(); 115 116 /// Assign operator 117 inline Registry& operator = (const Registry& toAssign); 118 119 /// checks if the registry points to a valid registry data file. 120 inline sal_Bool isValid() const; 121 122 /** returns the access mode of the registry. 123 124 @return TRUE if the access mode is readonly else FALSE. 125 */ 126 inline sal_Bool isReadOnly() const; 127 128 /** opens the root key of the registry. 129 130 @param rRootKey reference to a RegistryKey which is filled with the rootkey. 131 @return REG_NO_ERROR if succeeds else an error code. 132 */ 133 inline RegError openRootKey(RegistryKey& rRootKey); 134 135 /// returns the name of the current registry data file. 136 inline ::rtl::OUString getName(); 137 138 /** creates a new registry with the specified name and creates a root key. 139 140 @param registryName specifies the name of the new registry. 141 @return REG_NO_ERROR if succeeds else an error code. 142 */ 143 inline RegError create(const ::rtl::OUString& registryName); 144 145 /** opens a registry with the specified name. 146 147 If the registry already points to a valid registry, the old registry will be closed. 148 @param registryName specifies a registry name. 149 @param accessMode specifies the access mode for the registry, REG_READONLY or REG_READWRITE. 150 @return REG_NO_ERROR if succeeds else an error code. 151 */ 152 inline RegError open(const ::rtl::OUString& registryName, 153 RegAccessMode accessMode); 154 155 /// closes explicitly the current registry data file. 156 inline RegError close(); 157 158 /** destroys a registry. 159 160 @param registryName specifies a registry name, if the name is an empty string the registry 161 itselfs will be destroyed. 162 @return REG_NO_ERROR if succeeds else an error code. 163 */ 164 inline RegError destroy(const ::rtl::OUString& registryName); 165 166 /** loads registry information from a specified file and save it under the 167 specified keyName. 168 169 @param rKey references a currently open key. The key which should store the registry information 170 is a subkey of this key. 171 @param keyName specifies the name of the key which stores the registry information. If keyName is 172 is an empty string the registry information will be saved under the key specified 173 by rKey. 174 @param regFileName specifies the file containing the registry information. 175 @return REG_NO_ERROR if succeeds else an error code. 176 */ 177 inline RegError loadKey(RegistryKey& rKey, 178 const ::rtl::OUString& keyName, 179 const ::rtl::OUString& regFileName); 180 181 /** saves the registry information of the specified key and all subkeys and save 182 it in the specified file. 183 184 @param rKey references a currently open key. The key which information is saved by this 185 function is a subkey of this key. 186 @param keyName specifies the name of the key which information should be stored. 187 If keyName is an empty string the registry information under the key specified 188 by rKey is saved in the specified file. 189 @param regFileName specifies the file containing the registry information. 190 @return REG_NO_ERROR if succeeds else an error code. 191 */ 192 inline RegError saveKey(RegistryKey& rKey, 193 const ::rtl::OUString& keyName, 194 const ::rtl::OUString& regFileName); 195 196 /** merges the registry information of the specified key with the registry 197 information of the specified file. 198 199 All existing keys will be extended and existing key values will be overwritten. 200 @param rKey references a currently open key. The key which information is merged by this 201 function is a subkey of this key 202 @param keyName specifies the name of the key which will be merged. 203 If keyName is an empty string the registry information under the key specified 204 by rKey is merged with the information from the specified file. 205 @param regFileName specifies the file containing the registry information. 206 @param bWarnings if TRUE the function returns an error if a key already exists. 207 @param bReport if TRUE the function reports warnings on stdout if a key already exists. 208 @return REG_NO_ERROR if succeeds else an error code. If it returns an error the registry will 209 restore the state before merging. 210 */ 211 inline RegError mergeKey(RegistryKey& rKey, 212 const ::rtl::OUString& keyName, 213 const ::rtl::OUString& regFileName, 214 sal_Bool bWarnings = sal_False, 215 sal_Bool bReport = sal_False); 216 217 /** This function reports the complete registry information of a key and all of its subkeys. 218 219 All information which are available (keynames, value types, values, ...) 220 will be printed to stdout for report issues only. 221 @param rKey references a currently open key which content will be reported. 222 @return REG_NO_ERROR if succeeds else an error code. 223 */ 224 inline RegError dumpRegistry(RegistryKey& rKey); 225 226 friend class RegistryKey; 227 friend class RegistryKeyArray; 228 friend class RegistryKeyNames; 229 230 /// returns the used registry Api. 231 const Registry_Api* getApi() { return m_pApi; } 232 protected: 233 234 /// stores the used and initialized registry Api. 235 const Registry_Api* m_pApi; 236 /// stores the handle of the underlying registry file on which most of the functions work. 237 RegHandle m_hImpl; 238 }; 239 240 241 //----------------------------------------------------------------------------- 242 243 /** RegistryKeyArray represents an array of open keys. 244 245 RegistryKeyArray is a helper class to work with an array of keys. 246 */ 247 class RegistryKeyArray 248 { 249 public: 250 /// Default constructor 251 inline RegistryKeyArray(); 252 253 /// Destructor, all subkeys will be closed. 254 inline ~RegistryKeyArray(); 255 256 /// returns the open key specified by index. 257 inline RegistryKey getElement(sal_uInt32 index); 258 259 /// returns the length of the array. 260 inline sal_uInt32 getLength(); 261 262 friend class RegistryKey; 263 protected: 264 /** sets the data of the key array. 265 266 @param registry specifies the registry files where the keys are located. 267 @param phKeys points to an array of open keys. 268 @param length specifies the length of the array specified by phKeys. 269 */ 270 inline void setKeyHandles(Registry& registry, RegKeyHandle* phKeys, sal_uInt32 length); 271 /// close all subkeys 272 inline RegError closeKeyHandles(); 273 274 /// stores the number of open subkeys, the number of elements. 275 sal_uInt32 m_length; 276 /// stores an array of open subkeys. 277 RegKeyHandle* m_phKeys; 278 /// stores the handle to the registry file where the appropriate keys are located. 279 Registry m_registry; 280 }; 281 282 283 /** RegistryKeyNames represents an array of key names. 284 285 RegistryKeyNames is a helper class to work with an array of key names. 286 */ 287 class RegistryKeyNames 288 { 289 public: 290 /// Default constructor 291 inline RegistryKeyNames(); 292 293 /// Destructor, the internal array with key names will be deleted. 294 inline ~RegistryKeyNames(); 295 296 /// returns the name of the key sepecified by index. 297 inline ::rtl::OUString getElement(sal_uInt32 index); 298 299 /// returns the length of the array. 300 inline sal_uInt32 getLength(); 301 302 friend class RegistryKey; 303 protected: 304 /** sets the data of the array. 305 306 @param registry specifies the registry files where the keys are located. 307 @param pKeyNames points to an array of key names. 308 @param length specifies the length of the array specified by pKeyNames. 309 */ 310 inline void setKeyNames(Registry& registry, rtl_uString** pKeyNames, sal_uInt32 length); 311 /// delete the array of key names. 312 inline RegError freeKeyNames(); 313 314 /// stores the number of key names, the number of elements. 315 sal_uInt32 m_length; 316 /// stores an array of key names. 317 rtl_uString** m_pKeyNames; 318 /// stores the handle to the registry file where the appropriate keys are located. 319 Registry m_registry; 320 }; 321 322 //----------------------------------------------------------------------------- 323 324 /** RegistryValueList represents a value list of the specified type. 325 326 RegistryValueList is a helper class to work with a list value. 327 */ 328 template<class ValueType> 329 class RegistryValueList 330 { 331 public: 332 /// Default constructor 333 RegistryValueList() 334 : m_length(0) 335 , m_pValueList(NULL) 336 , m_valueType(RG_VALUETYPE_NOT_DEFINED) 337 {} 338 339 /// Destructor, the internal value list will be freed. 340 ~RegistryValueList() 341 { 342 if (m_pValueList) 343 { 344 m_registry.getApi()->freeValueList(m_valueType, m_pValueList, m_length); 345 } 346 } 347 348 /// returns the value of the list specified by index. 349 ValueType getElement(sal_uInt32 index) 350 { 351 if (m_registry.isValid() && index < m_length) 352 { 353 return m_pValueList[index]; 354 } else 355 { 356 return 0; 357 } 358 } 359 360 /// returns the length of the list. 361 sal_uInt32 getLength() 362 { 363 return m_length; 364 } 365 366 friend class RegistryKey; 367 protected: 368 /** sets the data of the value list. 369 370 @param registry specifies the registry files where the appropriate key is located. 371 @param valueType specifies the type of the list values. 372 @param pValueList points to a value list. 373 @param length specifies the length of the list. 374 */ 375 void setValueList(Registry& registry, RegValueType valueType, 376 ValueType* pValueList, sal_uInt32 length) 377 { 378 m_length = length; 379 m_pValueList = pValueList; 380 m_valueType = valueType; 381 m_registry = registry; 382 } 383 384 /// stores the length of the list, the number of elements. 385 sal_uInt32 m_length; 386 /// stores the value list. 387 ValueType* m_pValueList; 388 /// stores the type of the list elements 389 RegValueType m_valueType; 390 /** stores the handle to the registry file where the appropriate key to this 391 value is located. 392 */ 393 Registry m_registry; 394 }; 395 396 //----------------------------------------------------------------------------- 397 398 /** RegistryKey reads or writes information of the underlying key in a registry. 399 400 Class is inline and use a load on call C-Api. 401 */ 402 class RegistryKey 403 { 404 public: 405 /// Default constructor 406 inline RegistryKey(); 407 408 /// Copy constructor 409 inline RegistryKey(const RegistryKey& toCopy); 410 411 /// Destructor, close the key if it references an open one. 412 inline ~RegistryKey(); 413 414 /// Assign operator 415 inline RegistryKey& operator = (const RegistryKey& toAssign); 416 417 /// checks if the key points to a valid registry key. 418 inline sal_Bool isValid() const; 419 420 /** returns the access mode of the key. 421 422 @return TRUE if access mode is read only else FALSE. 423 */ 424 inline sal_Bool isReadOnly() const; 425 426 /// returns the full qualified name of the key beginning with the rootkey. 427 inline ::rtl::OUString getName(); 428 429 /** creates a new key or opens a key if the specified key already exists. 430 431 The specified keyname is relativ to this key. 432 @param keyName specifies the name of the key which will be opened or created. 433 @param rNewKey references a RegistryKey which will be filled with the new or open key. 434 @return REG_NO_ERROR if succeeds else an error code. 435 */ 436 inline RegError createKey(const ::rtl::OUString& keyName, 437 RegistryKey& rNewKey); 438 439 /** opens the specified key. 440 441 The specified keyname is relativ to this key. 442 @param keyName specifies the name of the key which will be opened. 443 @param rOpenKey references a RegistryKey which will be filled with the open key. 444 @return REG_NO_ERROR if succeeds else an error code. 445 */ 446 inline RegError openKey(const ::rtl::OUString& keyName, 447 RegistryKey& rOpenKey); 448 449 /** opens all subkeys of the specified key. 450 451 The specified keyname is relativ to this key. 452 @param keyName specifies the name of the key which subkeys will be opened. 453 @param rSubKeys reference a RegistryKeyArray which will be filled with the open subkeys. 454 @return REG_NO_ERROR if succeeds else an error code. 455 */ 456 inline RegError openSubKeys(const ::rtl::OUString& keyName, 457 RegistryKeyArray& rSubKeys); 458 459 /** returns an array with the names of all subkeys of the specified key. 460 461 The specified keyname is relativ to this key. 462 @param keyName specifies the name of the key which subkey names will be returned. 463 @param rSubKeyNames reference a RegistryKeyNames array which will be filled with the subkey names. 464 @return REG_NO_ERROR if succeeds else an error code. 465 */ 466 inline RegError getKeyNames(const ::rtl::OUString& keyName, 467 RegistryKeyNames& rSubKeyNames); 468 469 /** closes all keys specified in the array. 470 471 @param rSubKeys reference a RegistryKeyArray which contains the open keys. 472 @return REG_NO_ERROR if succeeds else an error code. 473 */ 474 inline RegError closeSubKeys(RegistryKeyArray& rSubKeys); 475 476 /** deletes the specified key. 477 478 @param keyName specifies the name of the key which will be deleted. 479 @return REG_NO_ERROR if succeeds else an error code. 480 */ 481 inline RegError deleteKey(const ::rtl::OUString& keyName); 482 483 /// closes explicitly the current key 484 inline RegError closeKey(); 485 486 /// releases the current key 487 inline void releaseKey(); 488 489 /** sets a value of a key. 490 491 @param keyName specifies the name of the key which value will be set. 492 If keyName is an empty string, the value will be set for the key 493 specified by hKey. 494 @param valueType specifies the type of the value. 495 @param pData points to a memory block containing the data for the value. 496 @param valueSize specifies the size of pData in bytes 497 @return REG_NO_ERROR if succeeds else an error code. 498 */ 499 inline RegError setValue(const ::rtl::OUString& keyName, 500 RegValueType valueType, 501 RegValue pValue, 502 sal_uInt32 valueSize); 503 504 /** sets a long list value of a key. 505 506 @param keyName specifies the name of the key which value will be set. 507 If keyName is an empty string, the value will be set for the key 508 specified by hKey. 509 @param pValueList points to an array of longs containing the data for the value. 510 @param len specifies the length of the list (the array referenced by pValueList). 511 @return REG_NO_ERROR if succeeds else an error code. 512 */ 513 inline RegError setLongListValue(const ::rtl::OUString& keyName, 514 sal_Int32* pValueList, 515 sal_uInt32 len); 516 517 /** sets an ascii list value of a key. 518 519 @param keyName specifies the name of the key which value will be set. 520 If keyName is an empty string, the value will be set for the key 521 specified by hKey. 522 @param pValueList points to an array of sal_Char* containing the data for the value. 523 @param len specifies the length of the list (the array referenced by pValueList). 524 @return REG_NO_ERROR if succeeds else an error code. 525 */ 526 inline RegError setStringListValue(const ::rtl::OUString& keyName, 527 sal_Char** pValueList, 528 sal_uInt32 len); 529 530 /** sets an unicode string list value of a key. 531 532 @param keyName specifies the name of the key which value will be set. 533 If keyName is an empty string, the value will be set for the key 534 specified by hKey. 535 @param pValueList points to an array of sal_Unicode* containing the data for the value. 536 @param len specifies the length of the list (the array referenced by pValueList). 537 @return REG_NO_ERROR if succeeds else an error code. 538 */ 539 inline RegError setUnicodeListValue(const ::rtl::OUString& keyName, 540 sal_Unicode** pValueList, 541 sal_uInt32 len); 542 543 /** gets info about type and size of a value. 544 545 @param keyName specifies the name of the key which value info will be returned. 546 If keyName is an empty string, the value info of the key 547 specified by hKey will be returned. 548 @param pValueType returns the type of the value. 549 @param pValueSize returns the size of the value in bytes or the length of a list value. 550 @return REG_NO_ERROR if succeeds else an error code. 551 */ 552 inline RegError getValueInfo(const ::rtl::OUString& keyName, 553 RegValueType* pValueType, 554 sal_uInt32* pValueSize); 555 556 /** gets the value of a key. 557 558 @param keyName specifies the name of the key which value will be returned. 559 If keyName is an empty string, the value is get from the key 560 specified by hKey. 561 @param pValue points to an allocated memory block receiving the data of the value. 562 @return REG_NO_ERROR if succeeds else an error code. 563 */ 564 inline RegError getValue(const ::rtl::OUString& keyName, 565 RegValue pValue); 566 567 /** gets a long list value of a key. 568 569 @param keyName specifies the name of the key which value will be returned. 570 If keyName is an empty string, the value is get from the key 571 specified by hKey. 572 @param rValueList references a RegistryValueList which will be filled with the long values. 573 @return REG_NO_ERROR if succeeds else an error code. 574 */ 575 inline RegError getLongListValue(const ::rtl::OUString& keyName, 576 RegistryValueList<sal_Int32>& rValueList); 577 578 /** gets an ascii list value of a key. 579 580 @param keyName specifies the name of the key which value will be returned. 581 If keyName is an empty string, the value is get from the key 582 specified by hKey. 583 @param rValueList references a RegistryValueList which will be filled with the ascii values. 584 @return REG_NO_ERROR if succeeds else an error code. 585 */ 586 inline RegError getStringListValue(const ::rtl::OUString& keyName, 587 RegistryValueList<sal_Char*>& rValueList); 588 589 /** gets a unicode value of a key. 590 591 @param keyName specifies the name of the key which value will be returned. 592 If keyName is an empty string, the value is get from the key 593 specified by hKey. 594 @param rValueList reference a RegistryValueList which will be filled with the unicode values. 595 @return REG_NO_ERROR if succeeds else an error code. 596 */ 597 inline RegError getUnicodeListValue(const ::rtl::OUString& keyName, 598 RegistryValueList<sal_Unicode*>& rValueList); 599 600 /** used to create a link. 601 602 @obsolete Links are no longer supported. 603 604 @return REG_INVALID_LINK 605 */ 606 inline RegError createLink(const ::rtl::OUString& linkName, 607 const ::rtl::OUString& linkTarget); 608 609 /** used to delete a link. 610 611 @obsolete Links are no longer supported. 612 613 @return REG_INVALID_LINK 614 */ 615 inline RegError deleteLink(const ::rtl::OUString& linkName); 616 617 /** returns the type of the specified key. 618 619 @param name specifies the name of the key or link. 620 @param pKeyType returns the type of the key (always RG_KEYTYPE). 621 @return REG_NO_ERROR if succeeds else an error code. 622 */ 623 inline RegError getKeyType(const ::rtl::OUString& name, 624 RegKeyType* pKeyType) const; 625 626 /** used to return the target of a link. 627 628 @obsolete Links are no longer supported. 629 630 @return REG_INVALID_LINK 631 */ 632 inline RegError getLinkTarget(const ::rtl::OUString& linkName, 633 ::rtl::OUString& rLinkTarget) const; 634 635 /** resolves a keyname. 636 637 @param keyName specifies the name of the key which will be resolved relativ to this key. 638 The resolved name will be prefixed with the name of this key. 639 @param firstLinkOnly ignored 640 @return REG_NO_ERROR if succeeds else an error code. 641 */ 642 inline RegError getResolvedKeyName(const ::rtl::OUString& keyName, 643 sal_Bool firstLinkOnly, 644 ::rtl::OUString& rResolvedName) const; 645 646 /// returns the name of the registry in which the key is defined. 647 inline ::rtl::OUString getRegistryName(); 648 649 /// returns the registry in which the key is defined. 650 Registry getRegistry() const { return m_registry; } 651 652 friend class Registry; 653 public: 654 /** Constructor, which initialize a RegistryKey with registry and an valid key handle. 655 656 This constructor is internal only. 657 @internal 658 */ 659 inline RegistryKey(Registry& registry, 660 RegKeyHandle hKey); 661 662 /** returns the internal key handle. 663 664 @internal 665 */ 666 RegKeyHandle getKeyHandle() const { return m_hImpl; } 667 668 protected: 669 /** sets the internal registry on which this key should work. 670 671 @internal 672 */ 673 inline void setRegistry(Registry& registry); 674 675 /// stores the registry on which this key works 676 Registry m_registry; 677 /// stores the current key handle of this key 678 RegKeyHandle m_hImpl; 679 }; 680 681 682 //----------------------------------------------------------------------------- 683 684 inline RegistryKeyArray::RegistryKeyArray() 685 : m_length(0) 686 , m_phKeys(NULL) 687 { 688 } 689 690 inline RegistryKeyArray::~RegistryKeyArray() 691 { 692 if (m_phKeys) 693 m_registry.m_pApi->closeSubKeys(m_phKeys, m_length); 694 } 695 696 inline RegistryKey RegistryKeyArray::getElement(sal_uInt32 index) 697 { 698 if (m_registry.isValid() && index < m_length) 699 return RegistryKey(m_registry, m_phKeys[index]); 700 else 701 return RegistryKey(); 702 } 703 704 inline sal_uInt32 RegistryKeyArray::getLength() 705 { 706 return m_length; 707 } 708 709 inline void RegistryKeyArray::setKeyHandles(Registry& registry, 710 RegKeyHandle* phKeys, 711 sal_uInt32 length) 712 { 713 m_phKeys = phKeys; 714 m_length = length; 715 m_registry = registry; 716 } 717 718 inline RegError RegistryKeyArray::closeKeyHandles() 719 { 720 if (m_registry.isValid() && m_phKeys) 721 { 722 RegError ret; 723 ret = m_registry.m_pApi->closeSubKeys(m_phKeys, m_length); 724 m_registry = Registry(); 725 m_length = 0; 726 m_phKeys = NULL; 727 return ret; 728 } else 729 return(REG_INVALID_KEY); 730 } 731 732 //----------------------------------------------------------------------------- 733 734 inline RegistryKeyNames::RegistryKeyNames() 735 : m_length(0) 736 , m_pKeyNames(NULL) 737 { 738 } 739 740 inline RegistryKeyNames::~RegistryKeyNames() 741 { 742 if (m_pKeyNames) 743 m_registry.m_pApi->freeKeyNames(m_pKeyNames, m_length); 744 } 745 746 inline ::rtl::OUString RegistryKeyNames::getElement(sal_uInt32 index) 747 { 748 749 if (m_pKeyNames && index < m_length) 750 return m_pKeyNames[index]; 751 else 752 return ::rtl::OUString(); 753 } 754 755 inline sal_uInt32 RegistryKeyNames::getLength() 756 { 757 return m_length; 758 } 759 760 inline void RegistryKeyNames::setKeyNames(Registry& registry, 761 rtl_uString** pKeyNames, 762 sal_uInt32 length) 763 { 764 m_pKeyNames = pKeyNames; 765 m_length = length; 766 m_registry = registry; 767 } 768 769 inline RegError RegistryKeyNames::freeKeyNames() 770 { 771 if (m_registry.isValid() && m_pKeyNames) 772 { 773 RegError ret = REG_NO_ERROR; 774 ret = m_registry.m_pApi->freeKeyNames(m_pKeyNames, m_length); 775 m_registry = Registry(); 776 m_length = 0; 777 m_pKeyNames = NULL; 778 return ret; 779 } else 780 return REG_INVALID_KEY; 781 } 782 783 //----------------------------------------------------------------------------- 784 785 inline RegistryKey::RegistryKey() 786 : m_hImpl(NULL) 787 { } 788 789 inline RegistryKey::RegistryKey(Registry& registry, RegKeyHandle hKey) 790 : m_registry(registry) 791 , m_hImpl(hKey) 792 { 793 if (m_hImpl) 794 m_registry.m_pApi->acquireKey(m_hImpl); 795 } 796 797 inline RegistryKey::RegistryKey(const RegistryKey& toCopy) 798 : m_registry(toCopy.m_registry) 799 , m_hImpl(toCopy.m_hImpl) 800 { 801 if (m_hImpl) 802 m_registry.m_pApi->acquireKey(m_hImpl); 803 } 804 805 inline void RegistryKey::setRegistry(Registry& registry) 806 { 807 m_registry = registry; 808 } 809 810 inline RegistryKey::~RegistryKey() 811 { 812 if (m_hImpl) 813 m_registry.m_pApi->releaseKey(m_hImpl); 814 } 815 816 inline RegistryKey& RegistryKey::operator = (const RegistryKey& toAssign) 817 { 818 m_registry = toAssign.m_registry; 819 820 if (toAssign.m_hImpl) 821 m_registry.m_pApi->acquireKey(toAssign.m_hImpl); 822 if (m_hImpl) 823 m_registry.m_pApi->releaseKey(m_hImpl); 824 m_hImpl = toAssign.m_hImpl; 825 826 return *this; 827 } 828 829 inline sal_Bool RegistryKey::isValid() const 830 { return (m_hImpl != NULL); } 831 832 inline sal_Bool RegistryKey::isReadOnly() const 833 { 834 if (m_registry.isValid()) 835 return (m_registry.m_pApi)->isKeyReadOnly(m_hImpl); 836 else 837 return sal_False; 838 } 839 840 inline ::rtl::OUString RegistryKey::getName() 841 { 842 ::rtl::OUString sRet; 843 if (m_registry.isValid()) 844 m_registry.m_pApi->getKeyName(m_hImpl, &sRet.pData); 845 return sRet;; 846 } 847 848 inline RegError RegistryKey::createKey(const ::rtl::OUString& keyName, 849 RegistryKey& rNewKey) 850 { 851 if (rNewKey.isValid()) rNewKey.closeKey(); 852 if (m_registry.isValid()) 853 { 854 RegError ret = m_registry.m_pApi->createKey(m_hImpl, keyName.pData, &rNewKey.m_hImpl); 855 if (!ret) rNewKey.setRegistry(m_registry); 856 return ret; 857 } else 858 return REG_INVALID_KEY; 859 } 860 861 inline RegError RegistryKey::openKey(const ::rtl::OUString& keyName, 862 RegistryKey& rOpenKey) 863 { 864 if (rOpenKey.isValid()) rOpenKey.closeKey(); 865 if (m_registry.isValid()) 866 { 867 RegError ret = m_registry.m_pApi->openKey(m_hImpl, keyName.pData, 868 &rOpenKey.m_hImpl); 869 if (!ret) rOpenKey.setRegistry(m_registry); 870 return ret; 871 } else 872 return REG_INVALID_KEY; 873 } 874 875 inline RegError RegistryKey::openSubKeys(const ::rtl::OUString& keyName, 876 RegistryKeyArray& rSubKeys) 877 { 878 if (m_registry.isValid()) 879 { 880 RegError ret = REG_NO_ERROR; 881 RegKeyHandle* pSubKeys; 882 sal_uInt32 nSubKeys; 883 ret = m_registry.m_pApi->openSubKeys(m_hImpl, keyName.pData, 884 &pSubKeys, &nSubKeys); 885 if ( ret ) 886 { 887 return ret; 888 } else 889 { 890 rSubKeys.setKeyHandles(m_registry, pSubKeys, nSubKeys); 891 return ret; 892 } 893 } else 894 return REG_INVALID_KEY; 895 } 896 897 inline RegError RegistryKey::getKeyNames(const ::rtl::OUString& keyName, 898 RegistryKeyNames& rSubKeyNames) 899 { 900 if (m_registry.isValid()) 901 { 902 RegError ret = REG_NO_ERROR; 903 rtl_uString** pSubKeyNames; 904 sal_uInt32 nSubKeys; 905 ret = m_registry.m_pApi->getKeyNames(m_hImpl, keyName.pData, 906 &pSubKeyNames, &nSubKeys); 907 if ( ret ) 908 { 909 return ret; 910 } else 911 { 912 rSubKeyNames.setKeyNames(m_registry, pSubKeyNames, nSubKeys); 913 return ret; 914 } 915 } else 916 return REG_INVALID_KEY; 917 } 918 919 inline RegError RegistryKey::closeSubKeys(RegistryKeyArray& rSubKeys) 920 { 921 if (m_registry.isValid()) 922 return rSubKeys.closeKeyHandles(); 923 else 924 return REG_INVALID_KEY; 925 } 926 927 inline RegError RegistryKey::deleteKey(const ::rtl::OUString& keyName) 928 { 929 if (m_registry.isValid()) 930 return m_registry.m_pApi->deleteKey(m_hImpl, keyName.pData); 931 else 932 return REG_INVALID_KEY; 933 } 934 935 inline RegError RegistryKey::closeKey() 936 { 937 if (m_registry.isValid()) 938 { 939 RegError ret = m_registry.m_pApi->closeKey(m_hImpl); 940 if (!ret) 941 { 942 m_hImpl = NULL; 943 m_registry = Registry(); 944 } 945 return ret; 946 } else 947 return REG_INVALID_KEY; 948 } 949 950 inline void RegistryKey::releaseKey() 951 { 952 if (m_registry.isValid() && (m_hImpl != 0)) 953 { 954 m_registry.m_pApi->releaseKey(m_hImpl), m_hImpl = 0; 955 } 956 } 957 958 inline RegError RegistryKey::setValue(const ::rtl::OUString& keyName, 959 RegValueType valueType, 960 RegValue pValue, 961 sal_uInt32 valueSize) 962 { 963 if (m_registry.isValid()) 964 return m_registry.m_pApi->setValue(m_hImpl, keyName.pData, valueType, 965 pValue, valueSize); 966 else 967 return REG_INVALID_KEY; 968 } 969 970 inline RegError RegistryKey::setLongListValue(const ::rtl::OUString& keyName, 971 sal_Int32* pValueList, 972 sal_uInt32 len) 973 { 974 if (m_registry.isValid()) 975 return m_registry.m_pApi->setLongListValue(m_hImpl, keyName.pData, 976 pValueList, len); 977 else 978 return REG_INVALID_KEY; 979 } 980 981 inline RegError RegistryKey::setStringListValue(const ::rtl::OUString& keyName, 982 sal_Char** pValueList, 983 sal_uInt32 len) 984 { 985 if (m_registry.isValid()) 986 return m_registry.m_pApi->setStringListValue(m_hImpl, keyName.pData, 987 pValueList, len); 988 else 989 return REG_INVALID_KEY; 990 } 991 992 inline RegError RegistryKey::setUnicodeListValue(const ::rtl::OUString& keyName, 993 sal_Unicode** pValueList, 994 sal_uInt32 len) 995 { 996 if (m_registry.isValid()) 997 return m_registry.m_pApi->setUnicodeListValue(m_hImpl, keyName.pData, 998 pValueList, len); 999 else 1000 return REG_INVALID_KEY; 1001 } 1002 1003 inline RegError RegistryKey::getValueInfo(const ::rtl::OUString& keyName, 1004 RegValueType* pValueType, 1005 sal_uInt32* pValueSize) 1006 { 1007 if (m_registry.isValid()) 1008 return m_registry.m_pApi->getValueInfo(m_hImpl, keyName.pData, pValueType, pValueSize); 1009 else 1010 return REG_INVALID_KEY; 1011 } 1012 1013 inline RegError RegistryKey::getValue(const ::rtl::OUString& keyName, 1014 RegValue pValue) 1015 { 1016 if (m_registry.isValid()) 1017 return m_registry.m_pApi->getValue(m_hImpl, keyName.pData, pValue); 1018 else 1019 return REG_INVALID_KEY; 1020 } 1021 1022 inline RegError RegistryKey::getLongListValue(const ::rtl::OUString& keyName, 1023 RegistryValueList<sal_Int32>& rValueList) 1024 { 1025 if (m_registry.isValid()) 1026 { 1027 RegError ret = REG_NO_ERROR; 1028 sal_Int32* pValueList; 1029 sal_uInt32 length; 1030 ret = m_registry.m_pApi->getLongListValue(m_hImpl, keyName.pData, 1031 &pValueList, &length); 1032 if ( ret ) 1033 { 1034 return ret; 1035 } else 1036 { 1037 rValueList.setValueList(m_registry, RG_VALUETYPE_LONGLIST, 1038 pValueList, length); 1039 return ret; 1040 } 1041 } else 1042 return REG_INVALID_KEY; 1043 } 1044 1045 inline RegError RegistryKey::getStringListValue(const ::rtl::OUString& keyName, 1046 RegistryValueList<sal_Char*>& rValueList) 1047 { 1048 if (m_registry.isValid()) 1049 { 1050 RegError ret = REG_NO_ERROR; 1051 sal_Char** pValueList; 1052 sal_uInt32 length; 1053 ret = m_registry.m_pApi->getStringListValue(m_hImpl, keyName.pData, 1054 &pValueList, &length); 1055 if ( ret ) 1056 { 1057 return ret; 1058 } else 1059 { 1060 rValueList.setValueList(m_registry, RG_VALUETYPE_STRINGLIST, 1061 pValueList, length); 1062 return ret; 1063 } 1064 } else 1065 return REG_INVALID_KEY; 1066 } 1067 1068 inline RegError RegistryKey::getUnicodeListValue(const ::rtl::OUString& keyName, 1069 RegistryValueList<sal_Unicode*>& rValueList) 1070 { 1071 if (m_registry.isValid()) 1072 { 1073 RegError ret = REG_NO_ERROR; 1074 sal_Unicode** pValueList; 1075 sal_uInt32 length; 1076 ret = m_registry.m_pApi->getUnicodeListValue(m_hImpl, keyName.pData, 1077 &pValueList, &length); 1078 if ( ret ) 1079 { 1080 return ret; 1081 } else 1082 { 1083 rValueList.setValueList(m_registry, RG_VALUETYPE_UNICODELIST, 1084 pValueList, length); 1085 return ret; 1086 } 1087 } else 1088 return REG_INVALID_KEY; 1089 } 1090 1091 inline RegError RegistryKey::createLink(const ::rtl::OUString& linkName, 1092 const ::rtl::OUString& linkTarget) 1093 { 1094 if (m_registry.isValid()) 1095 return m_registry.m_pApi->createLink(m_hImpl, linkName.pData, linkTarget.pData); 1096 else 1097 return REG_INVALID_KEY; 1098 } 1099 1100 inline RegError RegistryKey::deleteLink(const ::rtl::OUString& linkName) 1101 { 1102 if (m_registry.isValid()) 1103 return m_registry.m_pApi->deleteLink(m_hImpl, linkName.pData); 1104 else 1105 return REG_INVALID_KEY; 1106 } 1107 1108 inline RegError RegistryKey::getKeyType(const ::rtl::OUString& keyName, 1109 RegKeyType* pKeyType) const 1110 { 1111 if (m_registry.isValid()) 1112 return m_registry.m_pApi->getKeyType(m_hImpl, keyName.pData, pKeyType); 1113 else 1114 return REG_INVALID_KEY; 1115 } 1116 1117 inline RegError RegistryKey::getLinkTarget(const ::rtl::OUString& linkName, 1118 ::rtl::OUString& rLinkTarget) const 1119 { 1120 if (m_registry.isValid()) 1121 { 1122 return m_registry.m_pApi->getLinkTarget(m_hImpl, 1123 linkName.pData, 1124 &rLinkTarget.pData); 1125 } else 1126 return REG_INVALID_KEY; 1127 } 1128 1129 1130 inline RegError RegistryKey::getResolvedKeyName(const ::rtl::OUString& keyName, 1131 sal_Bool firstLinkOnly, 1132 ::rtl::OUString& rResolvedName) const 1133 { 1134 if (m_registry.isValid()) 1135 return m_registry.m_pApi->getResolvedKeyName(m_hImpl, 1136 keyName.pData, 1137 firstLinkOnly, 1138 &rResolvedName.pData); 1139 else 1140 return REG_INVALID_KEY; 1141 } 1142 1143 inline ::rtl::OUString RegistryKey::getRegistryName() 1144 { 1145 if (m_registry.isValid()) 1146 { 1147 return m_registry.getName(); 1148 } else 1149 return ::rtl::OUString(); 1150 } 1151 1152 //----------------------------------------------------------------------------- 1153 1154 inline Registry::Registry() 1155 : m_pApi(initRegistry_Api()) 1156 , m_hImpl(NULL) 1157 { } 1158 1159 inline Registry::Registry(const Registry& toCopy) 1160 : m_pApi(toCopy.m_pApi) 1161 , m_hImpl(toCopy.m_hImpl) 1162 { 1163 if (m_hImpl) 1164 m_pApi->acquire(m_hImpl); 1165 } 1166 1167 1168 inline Registry::~Registry() 1169 { 1170 if (m_hImpl) 1171 m_pApi->release(m_hImpl); 1172 } 1173 1174 inline Registry& Registry::operator = (const Registry& toAssign) 1175 { 1176 if (toAssign.m_hImpl) 1177 toAssign.m_pApi->acquire(toAssign.m_hImpl); 1178 if (m_hImpl) 1179 m_pApi->release(m_hImpl); 1180 1181 m_pApi = toAssign.m_pApi; 1182 m_hImpl = toAssign.m_hImpl; 1183 1184 return *this; 1185 } 1186 1187 inline sal_Bool Registry::isValid() const 1188 { return ( m_hImpl != NULL ); } 1189 1190 inline sal_Bool Registry::isReadOnly() const 1191 { return m_pApi->isReadOnly(m_hImpl); } 1192 1193 inline RegError Registry::openRootKey(RegistryKey& rRootKey) 1194 { 1195 rRootKey.setRegistry(*this); 1196 return m_pApi->openRootKey(m_hImpl, &rRootKey.m_hImpl); 1197 } 1198 1199 inline ::rtl::OUString Registry::getName() 1200 { 1201 ::rtl::OUString sRet; 1202 m_pApi->getName(m_hImpl, &sRet.pData); 1203 return sRet; 1204 } 1205 1206 inline RegError Registry::create(const ::rtl::OUString& registryName) 1207 { 1208 if (m_hImpl) 1209 m_pApi->release(m_hImpl); 1210 return m_pApi->createRegistry(registryName.pData, &m_hImpl); 1211 } 1212 1213 inline RegError Registry::open(const ::rtl::OUString& registryName, 1214 RegAccessMode accessMode) 1215 { 1216 if (m_hImpl) 1217 m_pApi->release(m_hImpl); 1218 return m_pApi->openRegistry(registryName.pData, &m_hImpl, accessMode); 1219 } 1220 1221 inline RegError Registry::close() 1222 { 1223 RegError ret = m_pApi->closeRegistry(m_hImpl); 1224 if (!ret) 1225 m_hImpl = NULL; 1226 return ret; 1227 } 1228 1229 inline RegError Registry::destroy(const ::rtl::OUString& registryName) 1230 { 1231 RegError ret = m_pApi->destroyRegistry(m_hImpl, registryName.pData); 1232 if ( !ret && (registryName.getLength() == 0) ) 1233 m_hImpl = NULL; 1234 return ret; 1235 } 1236 1237 inline RegError Registry::loadKey(RegistryKey& rKey, 1238 const ::rtl::OUString& keyName, 1239 const ::rtl::OUString& regFileName) 1240 { return m_pApi->loadKey(m_hImpl, rKey.m_hImpl, keyName.pData, regFileName.pData); } 1241 1242 inline RegError Registry::saveKey(RegistryKey& rKey, 1243 const ::rtl::OUString& keyName, 1244 const ::rtl::OUString& regFileName) 1245 { return m_pApi->saveKey(m_hImpl, rKey.m_hImpl, keyName.pData, regFileName.pData); } 1246 1247 inline RegError Registry::mergeKey(RegistryKey& rKey, 1248 const ::rtl::OUString& keyName, 1249 const ::rtl::OUString& regFileName, 1250 sal_Bool bWarnings, 1251 sal_Bool bReport) 1252 { return m_pApi->mergeKey(m_hImpl, rKey.m_hImpl, keyName.pData, regFileName.pData, bWarnings, bReport); } 1253 1254 inline RegError Registry::dumpRegistry(RegistryKey& rKey) 1255 { return m_pApi->dumpRegistry(m_hImpl, rKey.m_hImpl); } 1256 1257 1258 #endif 1259