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