Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / registry / source / regimpl.cxx
blob0bb4b2126ffa0acc9807cfc962512717c73cb7d2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "regimpl.hxx"
23 #include <memory>
24 #include <string.h>
25 #include <stdio.h>
27 #if defined(UNX)
28 #include <unistd.h>
29 #endif
31 #include "reflread.hxx"
33 #include "reflwrit.hxx"
35 #include <registry/reader.hxx>
36 #include <registry/refltype.hxx>
37 #include <registry/types.hxx>
38 #include <registry/version.h>
40 #include "reflcnst.hxx"
41 #include "keyimpl.hxx"
43 #include <osl/thread.h>
44 #include <rtl/alloc.h>
45 #include <rtl/ustring.hxx>
46 #include <rtl/ustrbuf.hxx>
47 #include <osl/file.hxx>
49 using namespace osl;
50 using namespace store;
53 namespace {
55 void printString(OUString const & s) {
56 printf("\"");
57 for (sal_Int32 i = 0; i < s.getLength(); ++i) {
58 sal_Unicode c = s[i];
59 if (c == '"' || c == '\\') {
60 printf("\\%c", static_cast< char >(c));
61 } else if (s[i] >= ' ' && s[i] <= '~') {
62 printf("%c", static_cast< char >(c));
63 } else {
64 printf("\\u%04X", static_cast< unsigned int >(c));
67 printf("\"");
70 void printFieldOrReferenceFlag(
71 RTFieldAccess * flags, RTFieldAccess flag, char const * name, bool * first)
73 if ((*flags & flag) != RTFieldAccess::NONE) {
74 if (!*first) {
75 printf("|");
77 *first = false;
78 printf("%s", name);
79 *flags &= ~flag;
83 void printFieldOrReferenceFlags(RTFieldAccess flags) {
84 if (flags == RTFieldAccess::NONE) {
85 printf("none");
86 } else {
87 bool first = true;
88 printFieldOrReferenceFlag(
89 &flags, RTFieldAccess::READONLY, "readonly", &first);
90 printFieldOrReferenceFlag(
91 &flags, RTFieldAccess::OPTIONAL, "optional", &first);
92 printFieldOrReferenceFlag(
93 &flags, RTFieldAccess::MAYBEVOID, "maybevoid", &first);
94 printFieldOrReferenceFlag(&flags, RTFieldAccess::BOUND, "bound", &first);
95 printFieldOrReferenceFlag(
96 &flags, RTFieldAccess::CONSTRAINED, "constrained", &first);
97 printFieldOrReferenceFlag(
98 &flags, RTFieldAccess::TRANSIENT, "transient", &first);
99 printFieldOrReferenceFlag(
100 &flags, RTFieldAccess::MAYBEAMBIGUOUS, "maybeambiguous", &first);
101 printFieldOrReferenceFlag(
102 &flags, RTFieldAccess::MAYBEDEFAULT, "maybedefault", &first);
103 printFieldOrReferenceFlag(
104 &flags, RTFieldAccess::REMOVABLE, "removable", &first);
105 printFieldOrReferenceFlag(
106 &flags, RTFieldAccess::ATTRIBUTE, "attribute", &first);
107 printFieldOrReferenceFlag(
108 &flags, RTFieldAccess::PROPERTY, "property", &first);
109 printFieldOrReferenceFlag(&flags, RTFieldAccess::CONST, "const", &first);
110 printFieldOrReferenceFlag(
111 &flags, RTFieldAccess::READWRITE, "readwrite", &first);
112 printFieldOrReferenceFlag(
113 &flags, RTFieldAccess::PARAMETERIZED_TYPE, "parameterized type", &first);
114 printFieldOrReferenceFlag(
115 &flags, RTFieldAccess::PUBLISHED, "published", &first);
116 if (flags != RTFieldAccess::NONE) {
117 if (!first) {
118 printf("|");
120 printf("<invalid (0x%04X)>", static_cast< unsigned int >(flags));
125 void dumpType(typereg::Reader const & reader, OString const & indent) {
126 if (reader.isValid()) {
127 printf("version: %ld\n", static_cast< long >(reader.getVersion()));
128 printf("%sdocumentation: ", indent.getStr());
129 printString(reader.getDocumentation());
130 printf("\n");
131 printf("%sfile name: ", indent.getStr());
132 printString(reader.getFileName());
133 printf("\n");
134 printf("%stype class: ", indent.getStr());
135 if (reader.isPublished()) {
136 printf("published ");
138 switch (reader.getTypeClass()) {
139 case RT_TYPE_INTERFACE:
140 printf("interface");
141 break;
143 case RT_TYPE_MODULE:
144 printf("module");
145 break;
147 case RT_TYPE_STRUCT:
148 printf("struct");
149 break;
151 case RT_TYPE_ENUM:
152 printf("enum");
153 break;
155 case RT_TYPE_EXCEPTION:
156 printf("exception");
157 break;
159 case RT_TYPE_TYPEDEF:
160 printf("typedef");
161 break;
163 case RT_TYPE_SERVICE:
164 printf("service");
165 break;
167 case RT_TYPE_SINGLETON:
168 printf("singleton");
169 break;
171 case RT_TYPE_CONSTANTS:
172 printf("constants");
173 break;
175 default:
176 printf(
177 "<invalid (%ld)>", static_cast< long >(reader.getTypeClass()));
178 break;
180 printf("\n");
181 printf("%stype name: ", indent.getStr());
182 printString(reader.getTypeName());
183 printf("\n");
184 printf(
185 "%ssuper type count: %u\n", indent.getStr(),
186 static_cast< unsigned int >(reader.getSuperTypeCount()));
187 for (sal_uInt16 i = 0; i < reader.getSuperTypeCount(); ++i) {
188 printf(
189 "%ssuper type name %u: ", indent.getStr(),
190 static_cast< unsigned int >(i));
191 printString(reader.getSuperTypeName(i));
192 printf("\n");
194 printf(
195 "%sfield count: %u\n", indent.getStr(),
196 static_cast< unsigned int >(reader.getFieldCount()));
197 for (sal_uInt16 i = 0; i < reader.getFieldCount(); ++i) {
198 printf(
199 "%sfield %u:\n", indent.getStr(),
200 static_cast< unsigned int >(i));
201 printf("%s documentation: ", indent.getStr());
202 printString(reader.getFieldDocumentation(i));
203 printf("\n");
204 printf("%s file name: ", indent.getStr());
205 printString(reader.getFieldFileName(i));
206 printf("\n");
207 printf("%s flags: ", indent.getStr());
208 printFieldOrReferenceFlags(reader.getFieldFlags(i));
209 printf("\n");
210 printf("%s name: ", indent.getStr());
211 printString(reader.getFieldName(i));
212 printf("\n");
213 printf("%s type name: ", indent.getStr());
214 printString(reader.getFieldTypeName(i));
215 printf("\n");
216 printf("%s value: ", indent.getStr());
217 RTConstValue value(reader.getFieldValue(i));
218 switch (value.m_type) {
219 case RT_TYPE_NONE:
220 printf("none");
221 break;
223 case RT_TYPE_BOOL:
224 printf("boolean %s", value.m_value.aBool ? "true" : "false");
225 break;
227 case RT_TYPE_BYTE:
228 printf("byte %d", static_cast< int >(value.m_value.aByte));
229 break;
231 case RT_TYPE_INT16:
232 printf("short %d", static_cast< int >(value.m_value.aShort));
233 break;
235 case RT_TYPE_UINT16:
236 printf(
237 "unsigned short %u",
238 static_cast< unsigned int >(value.m_value.aUShort));
239 break;
241 case RT_TYPE_INT32:
242 printf("long %ld", static_cast< long >(value.m_value.aLong));
243 break;
245 case RT_TYPE_UINT32:
246 printf(
247 "unsigned long %lu",
248 static_cast< unsigned long >(value.m_value.aULong));
249 break;
251 case RT_TYPE_INT64:
252 // TODO: no portable way to print hyper values
253 printf("hyper");
254 break;
256 case RT_TYPE_UINT64:
257 // TODO: no portable way to print unsigned hyper values
258 printf("unsigned hyper");
259 break;
261 case RT_TYPE_FLOAT:
262 // TODO: no portable way to print float values
263 printf("float");
264 break;
266 case RT_TYPE_DOUBLE:
267 // TODO: no portable way to print double values
268 printf("double");
269 break;
271 case RT_TYPE_STRING:
272 printf("string ");
273 printString(value.m_value.aString);
274 break;
276 default:
277 printf("<invalid (%ld)>", static_cast< long >(value.m_type));
278 break;
280 printf("\n");
282 printf(
283 "%smethod count: %u\n", indent.getStr(),
284 static_cast< unsigned int >(reader.getMethodCount()));
285 for (sal_uInt16 i = 0; i < reader.getMethodCount(); ++i) {
286 printf(
287 "%smethod %u:\n", indent.getStr(),
288 static_cast< unsigned int >(i));
289 printf("%s documentation: ", indent.getStr());
290 printString(reader.getMethodDocumentation(i));
291 printf("\n");
292 printf("%s flags: ", indent.getStr());
293 switch (reader.getMethodFlags(i)) {
294 case RTMethodMode::ONEWAY:
295 printf("oneway");
296 break;
298 case RTMethodMode::TWOWAY:
299 printf("synchronous");
300 break;
302 case RTMethodMode::ATTRIBUTE_GET:
303 printf("attribute get");
304 break;
306 case RTMethodMode::ATTRIBUTE_SET:
307 printf("attribute set");
308 break;
310 default:
311 printf(
312 "<invalid (%ld)>",
313 static_cast< long >(reader.getMethodFlags(i)));
314 break;
316 printf("\n");
317 printf("%s name: ", indent.getStr());
318 printString(reader.getMethodName(i));
319 printf("\n");
320 printf("%s return type name: ", indent.getStr());
321 printString(reader.getMethodReturnTypeName(i));
322 printf("\n");
323 printf(
324 "%s parameter count: %u\n", indent.getStr(),
325 static_cast< unsigned int >(reader.getMethodParameterCount(i)));
326 // coverity[tainted_data] cid#1215304 unhelpfully warns about an
327 // untrusted loop bound here:
328 for (sal_uInt16 j = 0; j < reader.getMethodParameterCount(i); ++j)
330 printf(
331 "%s parameter %u:\n", indent.getStr(),
332 static_cast< unsigned int >(j));
333 printf("%s flags: ", indent.getStr());
334 RTParamMode flags = reader.getMethodParameterFlags(i, j);
335 bool rest = (flags & RT_PARAM_REST) != 0;
336 switch (flags & ~RT_PARAM_REST) {
337 case RT_PARAM_IN:
338 printf("in");
339 break;
341 case RT_PARAM_OUT:
342 printf("out");
343 break;
345 case RT_PARAM_INOUT:
346 printf("inout");
347 break;
349 default:
350 printf("<invalid (%ld)>", static_cast< long >(flags));
351 rest = false;
352 break;
354 if (rest) {
355 printf("|rest");
357 printf("\n");
358 printf("%s name: ", indent.getStr());
359 printString(reader.getMethodParameterName(i, j));
360 printf("\n");
361 printf("%s type name: ", indent.getStr());
362 printString(reader.getMethodParameterTypeName(i, j));
363 printf("\n");
365 printf(
366 "%s exception count: %u\n", indent.getStr(),
367 static_cast< unsigned int >(reader.getMethodExceptionCount(i)));
368 // coverity[tainted_data] cid#1215304 unhelpfully warns about an
369 // untrusted loop bound here:
370 for (sal_uInt16 j = 0; j < reader.getMethodExceptionCount(i); ++j)
372 printf(
373 "%s exception type name %u: ", indent.getStr(),
374 static_cast< unsigned int >(j));
375 printString(reader.getMethodExceptionTypeName(i, j));
376 printf("\n");
379 printf(
380 "%sreference count: %u\n", indent.getStr(),
381 static_cast< unsigned int >(reader.getReferenceCount()));
382 for (sal_uInt16 i = 0; i < reader.getReferenceCount(); ++i) {
383 printf(
384 "%sreference %u:\n", indent.getStr(),
385 static_cast< unsigned int >(i));
386 printf("%s documentation: ", indent.getStr());
387 printString(reader.getReferenceDocumentation(i));
388 printf("\n");
389 printf("%s flags: ", indent.getStr());
390 printFieldOrReferenceFlags(reader.getReferenceFlags(i));
391 printf("\n");
392 printf("%s sort: ", indent.getStr());
393 switch (reader.getReferenceSort(i)) {
394 case RTReferenceType::SUPPORTS:
395 printf("supports");
396 break;
398 case RTReferenceType::EXPORTS:
399 printf("exports");
400 break;
402 case RTReferenceType::TYPE_PARAMETER:
403 printf("type parameter");
404 break;
406 default:
407 printf(
408 "<invalid (%ld)>",
409 static_cast< long >(reader.getReferenceSort(i)));
410 break;
412 printf("\n");
413 printf("%s type name: ", indent.getStr());
414 printString(reader.getReferenceTypeName(i));
415 printf("\n");
417 } else {
418 printf("<invalid>\n");
424 ORegistry::ORegistry()
425 : m_refCount(1)
426 , m_readOnly(false)
427 , m_isOpen(false)
428 , ROOT("/")
432 ORegistry::~ORegistry()
434 ORegKey* pRootKey = m_openKeyTable[ROOT];
435 if (pRootKey != nullptr)
436 (void) releaseKey(pRootKey);
438 if (m_file.isValid())
439 m_file.close();
442 RegError ORegistry::initRegistry(const OUString& regName, RegAccessMode accessMode, bool bCreate)
444 RegError eRet = RegError::INVALID_REGISTRY;
445 OStoreFile rRegFile;
446 storeAccessMode sAccessMode = storeAccessMode::ReadWrite;
447 storeError errCode;
449 if (bCreate)
451 sAccessMode = storeAccessMode::Create;
453 else if (accessMode & RegAccessMode::READONLY)
455 sAccessMode = storeAccessMode::ReadOnly;
456 m_readOnly = true;
459 if (regName.isEmpty() &&
460 storeAccessMode::Create == sAccessMode)
462 errCode = rRegFile.createInMemory();
464 else
466 errCode = rRegFile.create(regName, sAccessMode);
469 if (errCode)
471 switch (errCode)
473 case store_E_NotExists:
474 eRet = RegError::REGISTRY_NOT_EXISTS;
475 break;
476 case store_E_LockingViolation:
477 eRet = RegError::CANNOT_OPEN_FOR_READWRITE;
478 break;
479 default:
480 eRet = RegError::INVALID_REGISTRY;
481 break;
484 else
486 OStoreDirectory rStoreDir;
487 storeError _err = rStoreDir.create(rRegFile, OUString(), OUString(), sAccessMode);
489 if (_err == store_E_None)
491 m_file = rRegFile;
492 m_name = regName;
493 m_isOpen = true;
495 m_openKeyTable[ROOT] = new ORegKey(ROOT, this);
496 eRet = RegError::NO_ERROR;
498 else
499 eRet = RegError::INVALID_REGISTRY;
502 return eRet;
505 RegError ORegistry::closeRegistry()
507 REG_GUARD(m_mutex);
509 if (m_file.isValid())
511 (void) releaseKey(m_openKeyTable[ROOT]);
512 m_file.close();
513 m_isOpen = false;
514 return RegError::NO_ERROR;
515 } else
517 return RegError::REGISTRY_NOT_EXISTS;
521 RegError ORegistry::destroyRegistry(const OUString& regName)
523 REG_GUARD(m_mutex);
525 if (!regName.isEmpty())
527 std::unique_ptr<ORegistry> pReg(new ORegistry());
529 if (pReg->initRegistry(regName, RegAccessMode::READWRITE) == RegError::NO_ERROR)
531 pReg.reset();
533 OUString systemName;
534 if (FileBase::getSystemPathFromFileURL(regName, systemName) != FileBase::E_None)
535 systemName = regName;
537 OString name(OUStringToOString(systemName, osl_getThreadTextEncoding()));
538 if (unlink(name.getStr()) != 0)
540 return RegError::DESTROY_REGISTRY_FAILED;
542 } else
544 return RegError::DESTROY_REGISTRY_FAILED;
546 } else
548 if (m_refCount != 1 || isReadOnly())
550 return RegError::DESTROY_REGISTRY_FAILED;
553 if (m_file.isValid())
555 releaseKey(m_openKeyTable[ROOT]);
556 m_file.close();
557 m_isOpen = false;
559 if (!m_name.isEmpty())
561 OUString systemName;
562 if (FileBase::getSystemPathFromFileURL(m_name, systemName) != FileBase::E_None)
563 systemName = m_name;
565 OString name(OUStringToOString(systemName, osl_getThreadTextEncoding()));
566 if (unlink(name.getStr()) != 0)
568 return RegError::DESTROY_REGISTRY_FAILED;
571 } else
573 return RegError::REGISTRY_NOT_EXISTS;
577 return RegError::NO_ERROR;
580 RegError ORegistry::acquireKey (RegKeyHandle hKey)
582 ORegKey* pKey = static_cast< ORegKey* >(hKey);
583 if (!pKey)
584 return RegError::INVALID_KEY;
586 REG_GUARD(m_mutex);
587 pKey->acquire();
589 return RegError::NO_ERROR;
592 RegError ORegistry::releaseKey (RegKeyHandle hKey)
594 ORegKey* pKey = static_cast< ORegKey* >(hKey);
595 if (!pKey)
596 return RegError::INVALID_KEY;
598 REG_GUARD(m_mutex);
599 if (pKey->release() == 0)
601 m_openKeyTable.erase(pKey->getName());
602 delete pKey;
604 return RegError::NO_ERROR;
607 RegError ORegistry::createKey(RegKeyHandle hKey, const OUString& keyName,
608 RegKeyHandle* phNewKey)
610 ORegKey* pKey;
612 *phNewKey = nullptr;
614 if (keyName.isEmpty())
615 return RegError::INVALID_KEYNAME;
617 REG_GUARD(m_mutex);
619 if (hKey)
620 pKey = static_cast<ORegKey*>(hKey);
621 else
622 pKey = m_openKeyTable[ROOT];
624 OUString sFullKeyName = pKey->getFullPath(keyName);
626 if (m_openKeyTable.count(sFullKeyName) > 0)
628 *phNewKey = m_openKeyTable[sFullKeyName];
629 static_cast<ORegKey*>(*phNewKey)->acquire();
630 static_cast<ORegKey*>(*phNewKey)->setDeleted(false);
631 return RegError::NO_ERROR;
634 OStoreDirectory rStoreDir;
635 OUStringBuffer sFullPath(sFullKeyName.getLength());
636 OUString token;
638 sFullPath.append('/');
640 sal_Int32 nIndex = 0;
643 token = sFullKeyName.getToken(0, '/', nIndex);
644 if (!token.isEmpty())
646 if (rStoreDir.create(pKey->getStoreFile(), sFullPath.getStr(), token, storeAccessMode::Create))
648 return RegError::CREATE_KEY_FAILED;
651 sFullPath.append(token);
652 sFullPath.append('/');
654 } while(nIndex != -1);
657 pKey = new ORegKey(sFullKeyName, this);
658 *phNewKey = pKey;
659 m_openKeyTable[sFullKeyName] = pKey;
661 return RegError::NO_ERROR;
664 RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName,
665 RegKeyHandle* phOpenKey)
667 ORegKey* pKey;
669 *phOpenKey = nullptr;
671 if (keyName.isEmpty())
673 return RegError::INVALID_KEYNAME;
676 REG_GUARD(m_mutex);
678 if (hKey)
679 pKey = static_cast<ORegKey*>(hKey);
680 else
681 pKey = m_openKeyTable[ROOT];
683 OUString path(pKey->getFullPath(keyName));
684 KeyMap::iterator i(m_openKeyTable.find(path));
685 if (i == m_openKeyTable.end()) {
686 sal_Int32 n = path.lastIndexOf('/') + 1;
687 switch (OStoreDirectory().create(
688 pKey->getStoreFile(), path.copy(0, n), path.copy(n),
689 isReadOnly() ? storeAccessMode::ReadOnly : storeAccessMode::ReadWrite))
691 case store_E_NotExists:
692 return RegError::KEY_NOT_EXISTS;
693 case store_E_WrongFormat:
694 return RegError::INVALID_KEY;
695 default:
696 break;
699 std::unique_ptr< ORegKey > p(new ORegKey(path, this));
700 i = m_openKeyTable.insert(std::make_pair(path, p.get())).first;
701 p.release();
702 } else {
703 i->second->acquire();
705 *phOpenKey = i->second;
706 return RegError::NO_ERROR;
709 RegError ORegistry::closeKey(RegKeyHandle hKey)
711 ORegKey* pKey = static_cast< ORegKey* >(hKey);
713 REG_GUARD(m_mutex);
715 OUString const aKeyName (pKey->getName());
716 if (m_openKeyTable.count(aKeyName) <= 0)
717 return RegError::KEY_NOT_OPEN;
719 if (pKey->isModified())
721 ORegKey * pRootKey = getRootKey();
722 if (pKey != pRootKey)
724 // propagate "modified" state to RootKey.
725 pRootKey->setModified();
727 else
729 // closing modified RootKey, flush registry file.
730 (void) m_file.flush();
732 pKey->setModified(false);
733 (void) releaseKey(pRootKey);
736 return releaseKey(pKey);
739 RegError ORegistry::deleteKey(RegKeyHandle hKey, const OUString& keyName)
741 ORegKey* pKey = static_cast< ORegKey* >(hKey);
742 if (keyName.isEmpty())
743 return RegError::INVALID_KEYNAME;
745 REG_GUARD(m_mutex);
747 if (!pKey)
748 pKey = m_openKeyTable[ROOT];
750 OUString sFullKeyName(pKey->getFullPath(keyName));
751 return eraseKey(m_openKeyTable[ROOT], sFullKeyName);
754 RegError ORegistry::eraseKey(ORegKey* pKey, const OUString& keyName)
756 RegError _ret = RegError::NO_ERROR;
758 if (keyName.isEmpty())
760 return RegError::INVALID_KEYNAME;
763 OUString sFullKeyName(pKey->getName());
764 OUString sFullPath(sFullKeyName);
765 OUString sRelativKey;
766 sal_Int32 lastIndex = keyName.lastIndexOf('/');
768 if (lastIndex >= 0)
770 sRelativKey += keyName.copy(lastIndex + 1);
772 if (sFullKeyName.getLength() > 1)
773 sFullKeyName += keyName;
774 else
775 sFullKeyName += keyName.copy(1);
777 sFullPath = sFullKeyName.copy(0, keyName.lastIndexOf('/') + 1);
778 } else
780 if (sFullKeyName.getLength() > 1)
781 sFullKeyName += ROOT;
783 sRelativKey += keyName;
784 sFullKeyName += keyName;
786 if (sFullPath.getLength() > 1)
787 sFullPath += ROOT;
790 ORegKey* pOldKey = nullptr;
791 _ret = pKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pOldKey));
792 if (_ret != RegError::NO_ERROR)
793 return _ret;
795 _ret = deleteSubkeysAndValues(pOldKey);
796 if (_ret != RegError::NO_ERROR)
798 pKey->closeKey(pOldKey);
799 return _ret;
802 OUString tmpName(sRelativKey);
803 tmpName += ROOT;
805 OStoreFile sFile(pKey->getStoreFile());
806 if (sFile.isValid() && sFile.remove(sFullPath, tmpName))
808 return RegError::DELETE_KEY_FAILED;
810 pOldKey->setModified();
812 // set flag deleted !!!
813 pOldKey->setDeleted(true);
815 return pKey->closeKey(pOldKey);
818 RegError ORegistry::deleteSubkeysAndValues(ORegKey* pKey)
820 OStoreDirectory::iterator iter;
821 RegError _ret = RegError::NO_ERROR;
822 OStoreDirectory rStoreDir(pKey->getStoreDir());
823 storeError _err = rStoreDir.first(iter);
825 while (_err == store_E_None)
827 OUString const keyName = iter.m_pszName;
829 if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
831 _ret = eraseKey(pKey, keyName);
832 if (_ret != RegError::NO_ERROR)
833 return _ret;
835 else
837 OUString sFullPath(pKey->getName());
839 if (sFullPath.getLength() > 1)
840 sFullPath += ROOT;
842 if (const_cast<OStoreFile&>(pKey->getStoreFile()).remove(sFullPath, keyName))
844 return RegError::DELETE_VALUE_FAILED;
846 pKey->setModified();
849 _err = rStoreDir.next(iter);
852 return RegError::NO_ERROR;
855 RegError ORegistry::loadKey(RegKeyHandle hKey, const OUString& regFileName,
856 bool bWarnings, bool bReport)
858 ORegKey* pKey = static_cast< ORegKey* >(hKey);
860 std::unique_ptr< ORegistry > pReg (new ORegistry());
861 RegError _ret = pReg->initRegistry(regFileName, RegAccessMode::READONLY);
862 if (_ret != RegError::NO_ERROR)
863 return _ret;
864 ORegKey* pRootKey = pReg->getRootKey();
866 REG_GUARD(m_mutex);
868 OStoreDirectory::iterator iter;
869 OStoreDirectory rStoreDir(pRootKey->getStoreDir());
870 storeError _err = rStoreDir.first(iter);
872 while (_err == store_E_None)
874 OUString const keyName = iter.m_pszName;
876 if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
878 _ret = loadAndSaveKeys(pKey, pRootKey, keyName, 0, bWarnings, bReport);
880 else
882 _ret = loadAndSaveValue(pKey, pRootKey, keyName, 0, bWarnings, bReport);
885 if (_ret == RegError::MERGE_ERROR)
886 break;
887 if (_ret == RegError::MERGE_CONFLICT && bWarnings)
888 break;
890 _err = rStoreDir.next(iter);
893 rStoreDir = OStoreDirectory();
894 (void) pReg->releaseKey(pRootKey);
895 return _ret;
898 RegError ORegistry::loadAndSaveValue(ORegKey* pTargetKey,
899 ORegKey const * pSourceKey,
900 const OUString& valueName,
901 sal_uInt32 nCut,
902 bool bWarnings,
903 bool bReport)
905 OStoreStream rValue;
906 sal_uInt8* pBuffer;
907 RegValueType valueType;
908 sal_uInt32 valueSize;
909 sal_uInt32 nSize;
910 storeAccessMode sourceAccess = storeAccessMode::ReadWrite;
911 OUString sTargetPath(pTargetKey->getName());
912 OUString sSourcePath(pSourceKey->getName());
914 if (pSourceKey->isReadOnly())
916 sourceAccess = storeAccessMode::ReadOnly;
919 if (nCut)
921 sTargetPath = sSourcePath.copy(nCut);
922 } else
924 if (sTargetPath.getLength() > 1)
926 if (sSourcePath.getLength() > 1)
927 sTargetPath += sSourcePath;
928 } else
929 sTargetPath = sSourcePath;
932 if (sTargetPath.getLength() > 1) sTargetPath += ROOT;
933 if (sSourcePath.getLength() > 1) sSourcePath += ROOT;
935 if (rValue.create(pSourceKey->getStoreFile(), sSourcePath, valueName, sourceAccess))
937 return RegError::VALUE_NOT_EXISTS;
940 pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(VALUE_HEADERSIZE));
942 sal_uInt32 rwBytes;
943 if (rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes))
945 rtl_freeMemory(pBuffer);
946 return RegError::INVALID_VALUE;
948 if (rwBytes != VALUE_HEADERSIZE)
950 rtl_freeMemory(pBuffer);
951 return RegError::INVALID_VALUE;
954 RegError _ret = RegError::NO_ERROR;
955 sal_uInt8 type = *pBuffer;
956 valueType = static_cast<RegValueType>(type);
957 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
958 rtl_freeMemory(pBuffer);
960 nSize = VALUE_HEADERSIZE + valueSize;
961 pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(nSize));
963 if (rValue.readAt(0, pBuffer, nSize, rwBytes))
965 rtl_freeMemory(pBuffer);
966 return RegError::INVALID_VALUE;
968 if (rwBytes != nSize)
970 rtl_freeMemory(pBuffer);
971 return RegError::INVALID_VALUE;
974 OStoreFile rTargetFile(pTargetKey->getStoreFile());
976 if (!rValue.create(rTargetFile, sTargetPath, valueName, storeAccessMode::ReadWrite))
978 if (valueType == RegValueType::BINARY)
980 _ret = checkBlop(
981 rValue, sTargetPath, valueSize, pBuffer+VALUE_HEADEROFFSET,
982 bReport);
983 if (_ret != RegError::NO_ERROR)
985 if (_ret == RegError::MERGE_ERROR ||
986 (_ret == RegError::MERGE_CONFLICT && bWarnings))
988 rtl_freeMemory(pBuffer);
989 return _ret;
991 } else
993 rtl_freeMemory(pBuffer);
994 return _ret;
999 if (rValue.create(rTargetFile, sTargetPath, valueName, storeAccessMode::Create))
1001 rtl_freeMemory(pBuffer);
1002 return RegError::INVALID_VALUE;
1004 if (rValue.writeAt(0, pBuffer, nSize, rwBytes))
1006 rtl_freeMemory(pBuffer);
1007 return RegError::INVALID_VALUE;
1010 if (rwBytes != nSize)
1012 rtl_freeMemory(pBuffer);
1013 return RegError::INVALID_VALUE;
1015 pTargetKey->setModified();
1017 rtl_freeMemory(pBuffer);
1018 return _ret;
1021 RegError ORegistry::checkBlop(OStoreStream& rValue,
1022 const OUString& sTargetPath,
1023 sal_uInt32 srcValueSize,
1024 sal_uInt8 const * pSrcBuffer,
1025 bool bReport)
1027 RegistryTypeReader reader(pSrcBuffer, srcValueSize);
1029 if (reader.getTypeClass() == RT_TYPE_INVALID)
1031 return RegError::INVALID_VALUE;
1034 sal_uInt8* pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(VALUE_HEADERSIZE));
1035 RegValueType valueType;
1036 sal_uInt32 valueSize;
1037 sal_uInt32 rwBytes;
1038 OString targetPath(OUStringToOString(sTargetPath, RTL_TEXTENCODING_UTF8));
1040 if (!rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes) &&
1041 (rwBytes == VALUE_HEADERSIZE))
1043 sal_uInt8 type = *pBuffer;
1044 valueType = static_cast<RegValueType>(type);
1045 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
1046 rtl_freeMemory(pBuffer);
1048 if (valueType == RegValueType::BINARY)
1050 pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(valueSize));
1051 if (!rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, rwBytes) &&
1052 (rwBytes == valueSize))
1054 RegistryTypeReader reader2(pBuffer, valueSize);
1056 if ((reader.getTypeClass() != reader2.getTypeClass())
1057 || reader2.getTypeClass() == RT_TYPE_INVALID)
1059 rtl_freeMemory(pBuffer);
1061 if (bReport)
1063 fprintf(stdout, "ERROR: values of blop from key \"%s\" has different types.\n",
1064 targetPath.getStr());
1066 return RegError::MERGE_ERROR;
1069 if (reader.getTypeClass() == RT_TYPE_MODULE)
1071 if (reader.getFieldCount() > 0 &&
1072 reader2.getFieldCount() > 0)
1074 mergeModuleValue(rValue, reader, reader2);
1076 rtl_freeMemory(pBuffer);
1077 return RegError::NO_ERROR;
1078 } else
1079 if (reader2.getFieldCount() > 0)
1081 rtl_freeMemory(pBuffer);
1082 return RegError::NO_ERROR;
1083 } else
1085 rtl_freeMemory(pBuffer);
1086 return RegError::MERGE_CONFLICT;
1088 } else
1090 rtl_freeMemory(pBuffer);
1092 if (bReport)
1094 fprintf(stderr, "WARNING: value of key \"%s\" already exists.\n",
1095 targetPath.getStr());
1097 return RegError::MERGE_CONFLICT;
1099 } else
1101 rtl_freeMemory(pBuffer);
1102 if (bReport)
1104 fprintf(stderr, "ERROR: values of key \"%s\" contains bad data.\n",
1105 targetPath.getStr());
1107 return RegError::MERGE_ERROR;
1109 } else
1111 rtl_freeMemory(pBuffer);
1112 if (bReport)
1114 fprintf(stderr, "ERROR: values of key \"%s\" has different types.\n",
1115 targetPath.getStr());
1117 return RegError::MERGE_ERROR;
1119 } else
1121 rtl_freeMemory(pBuffer);
1122 return RegError::INVALID_VALUE;
1126 static sal_uInt32 checkTypeReaders(RegistryTypeReader const & reader1,
1127 RegistryTypeReader const & reader2,
1128 std::set< OUString >& nameSet)
1130 sal_uInt32 count=0;
1131 for (sal_uInt32 i=0 ; i < reader1.getFieldCount(); i++)
1133 nameSet.insert(reader1.getFieldName(i));
1134 count++;
1136 for (sal_uInt32 i=0 ; i < reader2.getFieldCount(); i++)
1138 if (nameSet.find(reader2.getFieldName(i)) == nameSet.end())
1140 nameSet.insert(reader2.getFieldName(i));
1141 count++;
1144 return count;
1147 RegError ORegistry::mergeModuleValue(OStoreStream& rTargetValue,
1148 RegistryTypeReader const & reader,
1149 RegistryTypeReader const & reader2)
1151 std::set< OUString > nameSet;
1152 sal_uInt32 count = checkTypeReaders(reader, reader2, nameSet);
1154 if (count != reader.getFieldCount())
1156 sal_uInt16 index = 0;
1158 RegistryTypeWriter writer(reader.getTypeClass(),
1159 reader.getTypeName(),
1160 reader.getSuperTypeName(),
1161 static_cast<sal_uInt16>(count));
1163 for (sal_uInt32 i=0 ; i < reader.getFieldCount(); i++)
1165 writer.setFieldData(index,
1166 reader.getFieldName(i),
1167 reader.getFieldType(i),
1168 reader.getFieldDoku(i),
1169 reader.getFieldFileName(i),
1170 reader.getFieldAccess(i),
1171 reader.getFieldConstValue(i));
1172 index++;
1174 for (sal_uInt32 i=0 ; i < reader2.getFieldCount(); i++)
1176 if (nameSet.find(reader2.getFieldName(i)) == nameSet.end())
1178 writer.setFieldData(index,
1179 reader2.getFieldName(i),
1180 reader2.getFieldType(i),
1181 reader2.getFieldDoku(i),
1182 reader2.getFieldFileName(i),
1183 reader2.getFieldAccess(i),
1184 reader2.getFieldConstValue(i));
1185 index++;
1189 const sal_uInt8* pBlop = writer.getBlop();
1190 sal_uInt32 aBlopSize = writer.getBlopSize();
1192 sal_uInt8 type = sal_uInt8(RegValueType::BINARY);
1193 sal_uInt8* pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(VALUE_HEADERSIZE + aBlopSize));
1195 memcpy(pBuffer, &type, 1);
1196 writeUINT32(pBuffer+VALUE_TYPEOFFSET, aBlopSize);
1197 memcpy(pBuffer+VALUE_HEADEROFFSET, pBlop, aBlopSize);
1199 sal_uInt32 rwBytes;
1200 if (rTargetValue.writeAt(0, pBuffer, VALUE_HEADERSIZE+aBlopSize, rwBytes))
1202 rtl_freeMemory(pBuffer);
1203 return RegError::INVALID_VALUE;
1206 if (rwBytes != VALUE_HEADERSIZE+aBlopSize)
1208 rtl_freeMemory(pBuffer);
1209 return RegError::INVALID_VALUE;
1212 rtl_freeMemory(pBuffer);
1214 return RegError::NO_ERROR;
1217 RegError ORegistry::loadAndSaveKeys(ORegKey* pTargetKey,
1218 ORegKey* pSourceKey,
1219 const OUString& keyName,
1220 sal_uInt32 nCut,
1221 bool bWarnings,
1222 bool bReport)
1224 RegError _ret = RegError::NO_ERROR;
1225 OUString sRelPath(pSourceKey->getName().copy(nCut));
1226 OUString sFullPath;
1228 if(pTargetKey->getName().getLength() > 1)
1229 sFullPath += pTargetKey->getName();
1230 sFullPath += sRelPath;
1231 if (sRelPath.getLength() > 1 || sFullPath.isEmpty())
1232 sFullPath += ROOT;
1234 OUString sFullKeyName = sFullPath;
1235 sFullKeyName += keyName;
1237 OStoreDirectory rStoreDir;
1238 if (rStoreDir.create(pTargetKey->getStoreFile(), sFullPath, keyName, storeAccessMode::Create))
1240 return RegError::CREATE_KEY_FAILED;
1243 if (m_openKeyTable.count(sFullKeyName) > 0)
1245 m_openKeyTable[sFullKeyName]->setDeleted(false);
1248 ORegKey* pTmpKey = nullptr;
1249 _ret = pSourceKey->openKey(keyName, reinterpret_cast<RegKeyHandle*>(&pTmpKey));
1250 if (_ret != RegError::NO_ERROR)
1251 return _ret;
1253 OStoreDirectory::iterator iter;
1254 OStoreDirectory rTmpStoreDir(pTmpKey->getStoreDir());
1255 storeError _err = rTmpStoreDir.first(iter);
1257 while (_err == store_E_None)
1259 OUString const sName = iter.m_pszName;
1261 if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1263 _ret = loadAndSaveKeys(pTargetKey, pTmpKey,
1264 sName, nCut, bWarnings, bReport);
1265 } else
1267 _ret = loadAndSaveValue(pTargetKey, pTmpKey,
1268 sName, nCut, bWarnings, bReport);
1271 if (_ret == RegError::MERGE_ERROR)
1272 break;
1273 if (_ret == RegError::MERGE_CONFLICT && bWarnings)
1274 break;
1276 _err = rTmpStoreDir.next(iter);
1279 pSourceKey->releaseKey(pTmpKey);
1280 return _ret;
1283 ORegKey* ORegistry::getRootKey()
1285 m_openKeyTable[ROOT]->acquire();
1286 return m_openKeyTable[ROOT];
1289 RegError ORegistry::dumpRegistry(RegKeyHandle hKey) const
1291 ORegKey *pKey = static_cast<ORegKey*>(hKey);
1292 OUString sName;
1293 RegError _ret = RegError::NO_ERROR;
1294 OStoreDirectory::iterator iter;
1295 OStoreDirectory rStoreDir(pKey->getStoreDir());
1296 storeError _err = rStoreDir.first(iter);
1298 OString regName(OUStringToOString(getName(), osl_getThreadTextEncoding()));
1299 OString keyName(OUStringToOString(pKey->getName(), RTL_TEXTENCODING_UTF8));
1300 fprintf(stdout, "Registry \"%s\":\n\n%s\n", regName.getStr(), keyName.getStr());
1302 while (_err == store_E_None)
1304 sName = iter.m_pszName;
1306 if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1308 _ret = dumpKey(pKey->getName(), sName, 1);
1309 } else
1311 _ret = dumpValue(pKey->getName(), sName, 1);
1314 if (_ret != RegError::NO_ERROR)
1316 return _ret;
1319 _err = rStoreDir.next(iter);
1322 return RegError::NO_ERROR;
1325 RegError ORegistry::dumpValue(const OUString& sPath, const OUString& sName, sal_Int16 nSpc) const
1327 OStoreStream rValue;
1328 sal_uInt8* pBuffer;
1329 sal_uInt32 valueSize;
1330 RegValueType valueType;
1331 OUString sFullPath(sPath);
1332 OString sIndent;
1333 storeAccessMode accessMode = storeAccessMode::ReadWrite;
1335 if (isReadOnly())
1337 accessMode = storeAccessMode::ReadOnly;
1340 for (int i= 0; i < nSpc; i++) sIndent += " ";
1342 if (sFullPath.getLength() > 1)
1344 sFullPath += ROOT;
1346 if (rValue.create(m_file, sFullPath, sName, accessMode))
1348 return RegError::VALUE_NOT_EXISTS;
1351 pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(VALUE_HEADERSIZE));
1353 sal_uInt32 rwBytes;
1354 if (rValue.readAt(0, pBuffer, VALUE_HEADERSIZE, rwBytes))
1356 rtl_freeMemory(pBuffer);
1357 return RegError::INVALID_VALUE;
1359 if (rwBytes != (VALUE_HEADERSIZE))
1361 rtl_freeMemory(pBuffer);
1362 return RegError::INVALID_VALUE;
1365 sal_uInt8 type = *pBuffer;
1366 valueType = static_cast<RegValueType>(type);
1367 readUINT32(pBuffer+VALUE_TYPEOFFSET, valueSize);
1369 pBuffer = static_cast<sal_uInt8*>(rtl_allocateMemory(valueSize));
1370 if (rValue.readAt(VALUE_HEADEROFFSET, pBuffer, valueSize, rwBytes))
1372 rtl_freeMemory(pBuffer);
1373 return RegError::INVALID_VALUE;
1375 if (rwBytes != valueSize)
1377 rtl_freeMemory(pBuffer);
1378 return RegError::INVALID_VALUE;
1381 const sal_Char* indent = sIndent.getStr();
1382 switch (valueType)
1384 case RegValueType::NOT_DEFINED:
1385 fprintf(stdout, "%sValue: Type = VALUETYPE_NOT_DEFINED\n", indent);
1386 break;
1387 case RegValueType::LONG:
1389 fprintf(stdout, "%sValue: Type = RegValueType::LONG\n", indent);
1390 fprintf(
1391 stdout, "%s Size = %lu\n", indent,
1392 sal::static_int_cast< unsigned long >(valueSize));
1393 fprintf(stdout, "%s Data = ", indent);
1395 sal_Int32 value;
1396 readINT32(pBuffer, value);
1397 fprintf(stdout, "%ld\n", sal::static_int_cast< long >(value));
1399 break;
1400 case RegValueType::STRING:
1402 sal_Char* value = static_cast<sal_Char*>(rtl_allocateMemory(valueSize));
1403 readUtf8(pBuffer, value, valueSize);
1404 fprintf(stdout, "%sValue: Type = RegValueType::STRING\n", indent);
1405 fprintf(
1406 stdout, "%s Size = %lu\n", indent,
1407 sal::static_int_cast< unsigned long >(valueSize));
1408 fprintf(stdout, "%s Data = \"%s\"\n", indent, value);
1409 rtl_freeMemory(value);
1411 break;
1412 case RegValueType::UNICODE:
1414 sal_uInt32 size = (valueSize / 2) * sizeof(sal_Unicode);
1415 fprintf(stdout, "%sValue: Type = RegValueType::UNICODE\n", indent);
1416 fprintf(
1417 stdout, "%s Size = %lu\n", indent,
1418 sal::static_int_cast< unsigned long >(valueSize));
1419 fprintf(stdout, "%s Data = ", indent);
1421 std::unique_ptr<sal_Unicode[]> value(new sal_Unicode[size]);
1422 readString(pBuffer, value.get(), size);
1424 OString uStr = OUStringToOString(value.get(), RTL_TEXTENCODING_UTF8);
1425 fprintf(stdout, "L\"%s\"\n", uStr.getStr());
1427 break;
1428 case RegValueType::BINARY:
1430 fprintf(stdout, "%sValue: Type = RegValueType::BINARY\n", indent);
1431 fprintf(
1432 stdout, "%s Size = %lu\n", indent,
1433 sal::static_int_cast< unsigned long >(valueSize));
1434 fprintf(stdout, "%s Data = ", indent);
1435 dumpType(
1436 typereg::Reader(pBuffer, valueSize),
1437 sIndent + " ");
1439 break;
1440 case RegValueType::LONGLIST:
1442 sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
1443 sal_uInt32 len = 0;
1445 readUINT32(pBuffer, len);
1447 fprintf(stdout, "%sValue: Type = RegValueType::LONGLIST\n", indent);
1448 fprintf(
1449 stdout, "%s Size = %lu\n", indent,
1450 sal::static_int_cast< unsigned long >(valueSize));
1451 fprintf(
1452 stdout, "%s Len = %lu\n", indent,
1453 sal::static_int_cast< unsigned long >(len));
1454 fprintf(stdout, "%s Data = ", indent);
1456 sal_Int32 longValue;
1457 for (sal_uInt32 i=0; i < len; i++)
1459 readINT32(pBuffer+offset, longValue);
1461 if (offset > 4)
1462 fprintf(stdout, "%s ", indent);
1464 fprintf(
1465 stdout, "%lu = %ld\n",
1466 sal::static_int_cast< unsigned long >(i),
1467 sal::static_int_cast< long >(longValue));
1468 offset += 4; // 4 Bytes for sal_Int32
1471 break;
1472 case RegValueType::STRINGLIST:
1474 sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
1475 sal_uInt32 sLen = 0;
1476 sal_uInt32 len = 0;
1478 readUINT32(pBuffer, len);
1480 fprintf(stdout, "%sValue: Type = RegValueType::STRINGLIST\n", indent);
1481 fprintf(
1482 stdout, "%s Size = %lu\n", indent,
1483 sal::static_int_cast< unsigned long >(valueSize));
1484 fprintf(
1485 stdout, "%s Len = %lu\n", indent,
1486 sal::static_int_cast< unsigned long >(len));
1487 fprintf(stdout, "%s Data = ", indent);
1489 for (sal_uInt32 i=0; i < len; i++)
1491 readUINT32(pBuffer+offset, sLen);
1493 offset += 4; // 4 bytes (sal_uInt32) for the string size
1495 sal_Char *pValue = static_cast<sal_Char*>(rtl_allocateMemory(sLen));
1496 readUtf8(pBuffer+offset, pValue, sLen);
1498 if (offset > 8)
1499 fprintf(stdout, "%s ", indent);
1501 fprintf(
1502 stdout, "%lu = \"%s\"\n",
1503 sal::static_int_cast< unsigned long >(i), pValue);
1504 rtl_freeMemory(pValue);
1505 offset += sLen;
1508 break;
1509 case RegValueType::UNICODELIST:
1511 sal_uInt32 offset = 4; // initial 4 bytes for the size of the array
1512 sal_uInt32 sLen = 0;
1513 sal_uInt32 len = 0;
1515 readUINT32(pBuffer, len);
1517 fprintf(stdout, "%sValue: Type = RegValueType::UNICODELIST\n", indent);
1518 fprintf(
1519 stdout, "%s Size = %lu\n", indent,
1520 sal::static_int_cast< unsigned long >(valueSize));
1521 fprintf(
1522 stdout, "%s Len = %lu\n", indent,
1523 sal::static_int_cast< unsigned long >(len));
1524 fprintf(stdout, "%s Data = ", indent);
1526 OString uStr;
1527 for (sal_uInt32 i=0; i < len; i++)
1529 readUINT32(pBuffer+offset, sLen);
1531 offset += 4; // 4 bytes (sal_uInt32) for the string size
1533 sal_Unicode *pValue = static_cast<sal_Unicode*>(rtl_allocateMemory((sLen / 2) * sizeof(sal_Unicode)));
1534 readString(pBuffer+offset, pValue, sLen);
1536 if (offset > 8)
1537 fprintf(stdout, "%s ", indent);
1539 uStr = OUStringToOString(pValue, RTL_TEXTENCODING_UTF8);
1540 fprintf(
1541 stdout, "%lu = L\"%s\"\n",
1542 sal::static_int_cast< unsigned long >(i),
1543 uStr.getStr());
1545 offset += sLen;
1547 rtl_freeMemory(pValue);
1550 break;
1553 fprintf(stdout, "\n");
1555 rtl_freeMemory(pBuffer);
1556 return RegError::NO_ERROR;
1559 RegError ORegistry::dumpKey(const OUString& sPath, const OUString& sName, sal_Int16 nSpace) const
1561 OStoreDirectory rStoreDir;
1562 OUString sFullPath(sPath);
1563 OString sIndent;
1564 storeAccessMode accessMode = storeAccessMode::ReadWrite;
1565 RegError _ret = RegError::NO_ERROR;
1567 if (isReadOnly())
1569 accessMode = storeAccessMode::ReadOnly;
1572 for (int i= 0; i < nSpace; i++) sIndent += " ";
1574 if (sFullPath.getLength() > 1)
1575 sFullPath += ROOT;
1577 storeError _err = rStoreDir.create(m_file, sFullPath, sName, accessMode);
1579 if (_err == store_E_NotExists)
1580 return RegError::KEY_NOT_EXISTS;
1581 else if (_err == store_E_WrongFormat)
1582 return RegError::INVALID_KEY;
1584 fprintf(stdout, "%s/ %s\n", sIndent.getStr(), OUStringToOString(sName, RTL_TEXTENCODING_UTF8).getStr());
1586 OUString sSubPath(sFullPath);
1587 OUString sSubName;
1588 sSubPath += sName;
1590 OStoreDirectory::iterator iter;
1592 _err = rStoreDir.first(iter);
1594 while (_err == store_E_None)
1596 sSubName = iter.m_pszName;
1598 if (iter.m_nAttrib & STORE_ATTRIB_ISDIR)
1600 _ret = dumpKey(sSubPath, sSubName, nSpace+2);
1601 } else
1603 _ret = dumpValue(sSubPath, sSubName, nSpace+2);
1606 if (_ret != RegError::NO_ERROR)
1608 return _ret;
1611 _err = rStoreDir.next(iter);
1614 return RegError::NO_ERROR;
1617 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */