1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registry.cxx,v $
10 * $Revision: 1.20.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_registry.hxx"
33 #include <registry/registry.h>
34 #include <registry/registry.hxx>
35 #include <osl/process.h>
36 #include "regimpl.hxx"
38 #include "keyimpl.hxx"
42 #if defined(WIN32) || defined(WNT) || defined(OS2)
52 #if defined ( GCC ) && ( defined ( SCO ) )
53 ORealDynamicLoader
* ODynamicLoader
<Registry_Api
>::m_pLoader
= NULL
;
58 //*********************************************************************
61 static void REGISTRY_CALLTYPE
acquire(RegHandle hReg
)
63 ORegistry
* pReg
= (ORegistry
*) hReg
;
70 //*********************************************************************
73 static void REGISTRY_CALLTYPE
release(RegHandle hReg
)
75 ORegistry
* pReg
= (ORegistry
*) hReg
;
79 if (pReg
->release() == 0)
88 //*********************************************************************
91 static RegError REGISTRY_CALLTYPE
getName(RegHandle hReg
, rtl_uString
** pName
)
97 pReg
= (ORegistry
*)hReg
;
100 rtl_uString_assign(pName
, pReg
->getName().pData
);
104 rtl_uString_new(pName
);
105 return REG_REGISTRY_NOT_OPEN
;
109 rtl_uString_new(pName
);
110 return REG_INVALID_REGISTRY
;
114 //*********************************************************************
117 static sal_Bool REGISTRY_CALLTYPE
isReadOnly(RegHandle hReg
)
120 return ((ORegistry
*)hReg
)->isReadOnly();
126 //*********************************************************************
129 static RegError REGISTRY_CALLTYPE
createRegistry(rtl_uString
* registryName
,
130 RegHandle
* phRegistry
)
134 ORegistry
* pReg
= new ORegistry();
135 if ((ret
= pReg
->initRegistry(registryName
, REG_CREATE
)))
146 //*********************************************************************
149 static RegError REGISTRY_CALLTYPE
openRootKey(RegHandle hReg
,
150 RegKeyHandle
* phRootKey
)
156 pReg
= (ORegistry
*)hReg
;
158 return REG_REGISTRY_NOT_OPEN
;
162 return REG_INVALID_REGISTRY
;
165 *phRootKey
= pReg
->getRootKey();
171 //*********************************************************************
174 static RegError REGISTRY_CALLTYPE
openRegistry(rtl_uString
* registryName
,
175 RegHandle
* phRegistry
,
176 RegAccessMode accessMode
)
180 ORegistry
* pReg
= new ORegistry();
181 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)))
194 //*********************************************************************
197 static RegError REGISTRY_CALLTYPE
closeRegistry(RegHandle hReg
)
203 pReg
= (ORegistry
*)hReg
;
205 return REG_REGISTRY_NOT_OPEN
;
207 RegError ret
= REG_NO_ERROR
;
208 if (pReg
->release() == 0)
214 ret
= pReg
->closeRegistry();
219 return REG_INVALID_REGISTRY
;
224 //*********************************************************************
227 static RegError REGISTRY_CALLTYPE
destroyRegistry(RegHandle hReg
,
228 rtl_uString
* registryName
)
234 pReg
= (ORegistry
*)hReg
;
236 return REG_INVALID_REGISTRY
;
238 RegError ret
= pReg
->destroyRegistry(registryName
);
241 if (!registryName
->length
)
250 return REG_INVALID_REGISTRY
;
255 //*********************************************************************
258 static RegError REGISTRY_CALLTYPE
loadKey(RegHandle hReg
,
260 rtl_uString
* keyName
,
261 rtl_uString
* regFileName
)
264 ORegKey
*pKey
, *pNewKey
;
269 pReg
= (ORegistry
*)hReg
;
271 return REG_REGISTRY_NOT_OPEN
;
274 return REG_INVALID_REGISTRY
;
279 pKey
= (ORegKey
*)hKey
;
281 if (pKey
->getRegistry() != pReg
|| pKey
->isDeleted())
282 return REG_INVALID_KEY
;
285 return REG_INVALID_KEY
;
288 if (pKey
->isReadOnly())
289 return REG_REGISTRY_READONLY
;
291 if (!pKey
->openKey(keyName
, (RegKeyHandle
*)&pNewKey
))
293 pKey
->closeKey(pNewKey
);
294 pKey
->deleteKey(keyName
);
297 if ((_ret
= pKey
->createKey(keyName
, (RegKeyHandle
*)&pNewKey
)))
300 if ((_ret
= pReg
->loadKey(pNewKey
, regFileName
)))
302 pKey
->closeKey(pNewKey
);
303 pKey
->deleteKey(keyName
);
307 return pKey
->closeKey(pNewKey
);
310 //*********************************************************************
313 static RegError REGISTRY_CALLTYPE
saveKey(RegHandle hReg
,
315 rtl_uString
* keyName
,
316 rtl_uString
* regFileName
)
319 ORegKey
*pKey
, *pNewKey
;
324 pReg
= (ORegistry
*)hReg
;
326 return REG_REGISTRY_NOT_OPEN
;
329 return REG_INVALID_REGISTRY
;
334 pKey
= (ORegKey
*)hKey
;
336 if (pKey
->getRegistry() != pReg
|| pKey
->isDeleted())
337 return REG_INVALID_KEY
;
340 return REG_INVALID_KEY
;
343 if ((_ret
= pKey
->openKey(keyName
, (RegKeyHandle
*)&pNewKey
)))
346 if ((_ret
= pReg
->saveKey(pNewKey
, regFileName
)))
348 pKey
->closeKey(pNewKey
);
352 return pKey
->closeKey(pNewKey
);
355 //*********************************************************************
358 static RegError REGISTRY_CALLTYPE
mergeKey(RegHandle hReg
,
360 rtl_uString
* keyName
,
361 rtl_uString
* regFileName
,
366 ORegKey
*pKey
, *pNewKey
;
371 pReg
= (ORegistry
*)hReg
;
373 return(REG_REGISTRY_NOT_OPEN
);
376 return REG_INVALID_REGISTRY
;
381 pKey
= (ORegKey
*)hKey
;
383 if (pKey
->getRegistry() != pReg
|| pKey
->isDeleted())
384 return REG_INVALID_KEY
;
387 return REG_INVALID_KEY
;
390 if (pKey
->isReadOnly())
391 return REG_REGISTRY_READONLY
;
395 if ((_ret
= pKey
->createKey(keyName
, (RegKeyHandle
*)&pNewKey
) ))
402 _ret
= pKey
->getRegistry()->loadKey(pNewKey
, regFileName
, bWarnings
, bReport
);
404 if (_ret
== REG_MERGE_ERROR
||
405 (_ret
== REG_MERGE_CONFLICT
&& bWarnings
))
407 pKey
->closeKey(pNewKey
);
414 if (_ret == REG_MERGE_ERROR ||
415 (_ret == REG_MERGE_CONFLICT && bWarnings))
417 pKey->closeKey(pNewKey);
418 pKey->deleteKey(keyName);
419 pKey->createKey(keyName, (RegKeyHandle*)&pNewKey);
420 pReg->loadKey(pNewKey, tmpName, sal_False, sal_False);
423 destroyRegistry(hReg, tmpName);
425 pKey->closeKey(pNewKey);
429 destroyRegistry(hReg, tmpName);
431 _ret
= pKey
->closeKey(pNewKey
);
437 //*********************************************************************
440 static RegError REGISTRY_CALLTYPE
dumpRegistry(RegHandle hReg
,
448 pReg
= (ORegistry
*)hReg
;
450 return REG_REGISTRY_NOT_OPEN
;
453 return REG_INVALID_REGISTRY
;
458 pKey
= (ORegKey
*)hKey
;
460 if (pKey
->getRegistry() != pReg
|| pKey
->isDeleted())
461 return REG_INVALID_KEY
;
464 return REG_INVALID_KEY
;
467 return pReg
->dumpRegistry(hKey
);
471 //*********************************************************************
474 Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api(void)
476 static Registry_Api aApi
= {&acquire
,
502 &setUnicodeListValue
,
507 &getUnicodeListValue
,
522 //*********************************************************************
525 RegError REGISTRY_CALLTYPE
reg_loadKey(RegKeyHandle hKey
,
526 rtl_uString
* keyName
,
527 rtl_uString
* regFileName
)
532 pKey
= (ORegKey
*)hKey
;
534 return REG_INVALID_KEY
;
536 return loadKey(pKey
->getRegistry(), hKey
, keyName
, regFileName
);
539 //*********************************************************************
542 RegError REGISTRY_CALLTYPE
reg_saveKey(RegKeyHandle hKey
,
543 rtl_uString
* keyName
,
544 rtl_uString
* regFileName
)
549 pKey
= (ORegKey
*)hKey
;
551 return REG_INVALID_KEY
;
553 return saveKey(pKey
->getRegistry(), hKey
, keyName
, regFileName
);
556 //*********************************************************************
559 RegError REGISTRY_CALLTYPE
reg_mergeKey(RegKeyHandle hKey
,
560 rtl_uString
* keyName
,
561 rtl_uString
* regFileName
,
568 pKey
= (ORegKey
*)hKey
;
570 return REG_INVALID_KEY
;
572 return mergeKey(pKey
->getRegistry(), hKey
, keyName
, regFileName
, bWarnings
, bReport
);
575 //*********************************************************************
576 // reg_createRegistry
578 RegError REGISTRY_CALLTYPE
reg_createRegistry(rtl_uString
* registryName
,
579 RegHandle
* phRegistry
)
583 ORegistry
* pReg
= new ORegistry();
584 if ((ret
= pReg
->initRegistry(registryName
, REG_CREATE
)))
595 //*********************************************************************
598 RegError REGISTRY_CALLTYPE
reg_openRootKey(RegHandle hRegistry
,
599 RegKeyHandle
* phRootKey
)
601 return openRootKey(hRegistry
, phRootKey
);
605 //*********************************************************************
608 RegError REGISTRY_CALLTYPE
reg_getName(RegHandle hRegistry
, rtl_uString
** pName
)
610 return getName(hRegistry
, pName
);
614 //*********************************************************************
617 sal_Bool REGISTRY_CALLTYPE
reg_isReadOnly(RegHandle hRegistry
)
619 return isReadOnly(hRegistry
);
623 //*********************************************************************
626 RegError REGISTRY_CALLTYPE
reg_openRegistry(rtl_uString
* registryName
,
627 RegHandle
* phRegistry
,
628 RegAccessMode accessMode
)
632 ORegistry
* pReg
= new ORegistry();
633 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)))
644 //*********************************************************************
647 RegError REGISTRY_CALLTYPE
reg_closeRegistry(RegHandle hRegistry
)
653 pReg
= (ORegistry
*)hRegistry
;
658 return REG_REGISTRY_NOT_OPEN
;
663 //*********************************************************************
664 // reg_destroyRegistry
666 RegError REGISTRY_CALLTYPE
reg_destroyRegistry(RegHandle hRegistry
,
667 rtl_uString
* registryName
)
669 return destroyRegistry(hRegistry
, registryName
);
673 //*********************************************************************
676 RegError REGISTRY_CALLTYPE
reg_dumpRegistry(RegKeyHandle hKey
)
681 pKey
= (ORegKey
*)hKey
;
683 return REG_INVALID_KEY
;
685 return dumpRegistry(pKey
->getRegistry(), hKey
);