]> git.saurik.com Git - wxWidgets.git/blame - src/msw/regconf.cpp
allow compilation with wxUSE_CHOICEDLG set to 0
[wxWidgets.git] / src / msw / regconf.cpp
CommitLineData
19454fa0
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/regconf.cpp
6d833566 3// Purpose:
19454fa0 4// Author: Vadim Zeitlin
6d833566 5// Modified by:
19454fa0
VZ
6// Created: 27.04.98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
19454fa0
VZ
10///////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
cfe780fb
JS
13#pragma implementation "regconf.h"
14#endif
15
a3b46648
UU
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
19454fa0 18
a3b46648
UU
19#ifdef __BORLANDC__
20#pragma hdrstop
82cf4761
VZ
21#endif
22
82cf4761 23#ifndef WX_PRECOMP
61ba49f2 24 #include "wx/string.h"
1f3943e0 25 #include "wx/intl.h"
82cf4761
VZ
26#endif //WX_PRECOMP
27
61ba49f2
VZ
28#include "wx/event.h"
29#include "wx/app.h"
30#include "wx/log.h"
f6bcfd97
BP
31
32#if wxUSE_CONFIG
33
61ba49f2 34#include "wx/config.h"
3d05544e 35
61ba49f2
VZ
36#include "wx/msw/registry.h"
37#include "wx/msw/regconf.h"
19454fa0
VZ
38
39// ----------------------------------------------------------------------------
40// constants
41// ----------------------------------------------------------------------------
42
43// we put our data in HKLM\SOFTWARE_KEY\appname
2b5f62a0 44#define SOFTWARE_KEY wxString(wxT("Software\\"))
19454fa0
VZ
45
46// ----------------------------------------------------------------------------
47// global functions
48// ----------------------------------------------------------------------------
49
50// get the value if the key is opened and it exists
51bool TryGetValue(const wxRegKey& key, const wxString& str, wxString& strVal)
52{
53 return key.IsOpened() && key.HasValue(str) && key.QueryValue(str, strVal);
54}
55
56bool TryGetValue(const wxRegKey& key, const wxString& str, long *plVal)
57{
58 return key.IsOpened() && key.HasValue(str) && key.QueryValue(str, plVal);
59}
60
61// ============================================================================
62// implementation
63// ============================================================================
64
65// ----------------------------------------------------------------------------
66// ctor/dtor
67// ----------------------------------------------------------------------------
18244936 68
040f0110
VZ
69// create the config object which stores its data under HKCU\vendor\app and, if
70// style & wxCONFIG_USE_GLOBAL_FILE, under HKLM\vendor\app
71wxRegConfig::wxRegConfig(const wxString& appName, const wxString& vendorName,
72 const wxString& strLocal, const wxString& strGlobal,
73 long style)
74 : wxConfigBase(appName, vendorName, strLocal, strGlobal, style)
19454fa0 75{
040f0110 76 wxString strRoot;
19454fa0 77
040f0110 78 bool bDoUseGlobal = (style & wxCONFIG_USE_GLOBAL_FILE) != 0;
41286812 79
040f0110
VZ
80 // the convention is to put the programs keys under <vendor>\<appname>
81 // (but it can be overriden by specifying the pathes explicitly in strLocal
82 // and/or strGlobal)
83 if ( strLocal.IsEmpty() || (strGlobal.IsEmpty() && bDoUseGlobal) )
84 {
85 if ( vendorName.IsEmpty() )
86 {
87 if ( wxTheApp )
88 strRoot = wxTheApp->GetVendorName();
89 }
90 else
91 {
92 strRoot = vendorName;
93 }
18244936 94
040f0110
VZ
95 // no '\\' needed if no vendor name
96 if ( !strRoot.IsEmpty() )
18244936 97 {
040f0110 98 strRoot += '\\';
18244936 99 }
18244936 100
040f0110
VZ
101 if ( appName.IsEmpty() )
102 {
223d09f6 103 wxCHECK_RET( wxTheApp, wxT("No application name in wxRegConfig ctor!") );
040f0110
VZ
104 strRoot << wxTheApp->GetAppName();
105 }
106 else
18244936 107 {
040f0110 108 strRoot << appName;
18244936 109 }
040f0110
VZ
110 }
111 //else: we don't need to do all the complicated stuff above
18244936 112
040f0110 113 wxString str = strLocal.IsEmpty() ? strRoot : strLocal;
807a903e
VZ
114
115 // as we're going to change the name of these keys fairly often and as
116 // there are only few of wxRegConfig objects (usually 1), we can allow
117 // ourselves to be generous and spend some memory to significantly improve
118 // performance of SetPath()
119 static const size_t MEMORY_PREALLOC = 512;
120
121 m_keyLocalRoot.ReserveMemoryForName(MEMORY_PREALLOC);
122 m_keyLocal.ReserveMemoryForName(MEMORY_PREALLOC);
123
040f0110 124 m_keyLocalRoot.SetName(wxRegKey::HKCU, SOFTWARE_KEY + str);
fda7962d 125 m_keyLocal.SetName(m_keyLocalRoot, wxEmptyString);
18244936 126
040f0110
VZ
127 if ( bDoUseGlobal )
128 {
129 str = strGlobal.IsEmpty() ? strRoot : strGlobal;
807a903e
VZ
130
131 m_keyGlobalRoot.ReserveMemoryForName(MEMORY_PREALLOC);
132 m_keyGlobal.ReserveMemoryForName(MEMORY_PREALLOC);
133
040f0110 134 m_keyGlobalRoot.SetName(wxRegKey::HKLM, SOFTWARE_KEY + str);
fda7962d 135 m_keyGlobal.SetName(m_keyGlobalRoot, wxEmptyString);
040f0110 136 }
18244936
JS
137
138 // Create() will Open() if key already exists
139 m_keyLocalRoot.Create();
140
141 // as it's the same key, Open() shouldn't fail (i.e. no need for Create())
142 m_keyLocal.Open();
143
040f0110
VZ
144 // OTOH, this key may perfectly not exist, so suppress error messages the call
145 // to Open() might generate
146 if ( bDoUseGlobal )
147 {
148 wxLogNull nolog;
9a85c87d
VZ
149 m_keyGlobalRoot.Open(wxRegKey::Read);
150 m_keyGlobal.Open(wxRegKey::Read);
040f0110 151 }
18244936 152}
19454fa0
VZ
153
154wxRegConfig::~wxRegConfig()
155{
156 // nothing to do - key will be closed in their dtors
157}
158
159// ----------------------------------------------------------------------------
160// path management
161// ----------------------------------------------------------------------------
807a903e
VZ
162
163// this function is called a *lot* of times (as I learned after seeing from
164// profiler output that it is called ~12000 times from Mahogany start up code!)
165// so it is important to optimize it - in particular, avoid using generic
166// string functions here and do everything manually because it is faster
167//
168// I still kept the old version to be able to check that the optimized code has
169// the same output as the non optimized version.
19454fa0
VZ
170void wxRegConfig::SetPath(const wxString& strPath)
171{
807a903e
VZ
172 // remember the old path
173 wxString strOldPath = m_strPath;
19454fa0 174
807a903e
VZ
175#ifdef WX_DEBUG_SET_PATH // non optimized version kept here for testing
176 wxString m_strPathAlt;
19454fa0 177
807a903e
VZ
178 {
179 wxArrayString aParts;
180
181 // because GetPath() returns "" when we're at root, we must understand
182 // empty string as "/"
183 if ( strPath.IsEmpty() || (strPath[0] == wxCONFIG_PATH_SEPARATOR) ) {
184 // absolute path
185 wxSplitPath(aParts, strPath);
186 }
187 else {
188 // relative path, combine with current one
189 wxString strFullPath = GetPath();
190 strFullPath << wxCONFIG_PATH_SEPARATOR << strPath;
191 wxSplitPath(aParts, strFullPath);
192 }
193
194 // recombine path parts in one variable
195 wxString strRegPath;
196 m_strPathAlt.Empty();
197 for ( size_t n = 0; n < aParts.Count(); n++ ) {
198 strRegPath << '\\' << aParts[n];
199 m_strPathAlt << wxCONFIG_PATH_SEPARATOR << aParts[n];
200 }
201 }
202#endif // 0
19454fa0 203
807a903e
VZ
204 // check for the most common case first
205 if ( strPath.empty() )
206 {
207 m_strPath = wxCONFIG_PATH_SEPARATOR;
208 }
209 else // not root
210 {
211 // construct the full path
212 wxString strFullPath;
213 if ( strPath[0u] == wxCONFIG_PATH_SEPARATOR )
214 {
215 // absolute path
216 strFullPath = strPath;
217 }
218 else // relative path
219 {
220 strFullPath.reserve(2*m_strPath.length());
221
e9c4c02c
VS
222 strFullPath << m_strPath;
223 if ( strFullPath.Len() == 0 ||
224 strFullPath.Last() != wxCONFIG_PATH_SEPARATOR )
225 strFullPath << wxCONFIG_PATH_SEPARATOR;
226 strFullPath << strPath;
807a903e
VZ
227 }
228
229 // simplify it: we need to handle ".." here
230
231 // count the total number of slashes we have to know if we can go upper
232 size_t totalSlashes = 0;
233
234 // position of the last slash to be able to backtrack to it quickly if
235 // needed, but we set it to -1 if we don't have a valid position
236 //
237 // we only remember the last position which means that we handle ".."
238 // quite efficiently but not "../.." - however the latter should be
239 // much more rare, so it is probably ok
240 int posLastSlash = -1;
241
242 const wxChar *src = strFullPath.c_str();
243 size_t len = strFullPath.length();
244 const wxChar *end = src + len;
245
de564874
MB
246 wxStringBufferLength buf(m_strPath, len);
247 wxChar *dst = buf;
807a903e
VZ
248 wxChar *start = dst;
249
250 for ( ; src < end; src++, dst++ )
251 {
252 if ( *src == wxCONFIG_PATH_SEPARATOR )
253 {
254 // check for "/.."
255
256 // note that we don't have to check for src < end here as
257 // *end == 0 so can't be '.'
258 if ( src[1] == _T('.') && src[2] == _T('.') &&
259 (src + 3 == end || src[3] == wxCONFIG_PATH_SEPARATOR) )
260 {
261 if ( !totalSlashes )
262 {
263 wxLogWarning(_("'%s' has extra '..', ignored."),
264 strFullPath.c_str());
265 }
266 else // return to the previous path component
267 {
268 // do we already have its position?
269 if ( posLastSlash == -1 )
270 {
271 // no, find it: note that we are sure to have one
272 // because totalSlashes > 0 so we don't have to
273 // check the boundary condition below
274
275 // this is more efficient than strrchr()
79c3b7b2 276 dst--;
807a903e
VZ
277 while ( *dst != wxCONFIG_PATH_SEPARATOR )
278 {
279 dst--;
280 }
281 }
282 else // the position of last slash was stored
283 {
284 // go directly there
285 dst = start + posLastSlash;
286
287 // invalidate posLastSlash
288 posLastSlash = -1;
289 }
290
79c3b7b2 291 // we must have found a slash one way or another!
807a903e
VZ
292 wxASSERT_MSG( *dst == wxCONFIG_PATH_SEPARATOR,
293 _T("error in wxRegConfig::SetPath") );
294
79c3b7b2
VZ
295 // stay at the same position
296 dst--;
297
807a903e
VZ
298 // we killed one
299 totalSlashes--;
300 }
301
302 // skip both dots
303 src += 2;
304 }
305 else // not "/.."
306 {
307 if ( (dst == start) || (dst[-1] != wxCONFIG_PATH_SEPARATOR) )
308 {
309 *dst = wxCONFIG_PATH_SEPARATOR;
310
311 posLastSlash = dst - start;
312
313 totalSlashes++;
314 }
eaac8805
VZ
315 else // previous char was a slash too
316 {
317 // squeeze several subsequent slashes into one: i.e.
318 // just ignore this one
319 dst--;
320 }
807a903e
VZ
321 }
322 }
323 else // normal character
324 {
325 // just copy
326 *dst = *src;
327 }
328 }
329
330 // NUL terminate the string
331 if ( dst[-1] == wxCONFIG_PATH_SEPARATOR && (dst != start + 1) )
332 {
333 // if it has a trailing slash we remove it unless it is the only
334 // string character
335 dst--;
336 }
337
338 *dst = _T('\0');
de564874 339 buf.SetLength(dst - start);
807a903e 340 }
b568d04f 341
807a903e
VZ
342#ifdef WX_DEBUG_SET_PATH
343 wxASSERT( m_strPath == m_strPathAlt );
344#endif
345
346 if ( m_strPath == strOldPath )
347 return;
348
349 // registry APIs want backslashes instead of slashes
350 wxString strRegPath;
275dea46
VZ
351 if ( !m_strPath.empty() )
352 {
353 size_t len = m_strPath.length();
b568d04f 354
275dea46 355 const wxChar *src = m_strPath.c_str();
de564874
MB
356 wxStringBufferLength buf(strRegPath, len);
357 wxChar *dst = buf;
807a903e 358
275dea46
VZ
359 const wxChar *end = src + len;
360 for ( ; src < end; src++, dst++ )
361 {
362 if ( *src == wxCONFIG_PATH_SEPARATOR )
363 *dst = _T('\\');
364 else
365 *dst = *src;
366 }
807a903e 367
de564874 368 buf.SetLength(len);
275dea46 369 }
807a903e
VZ
370
371 // this is not needed any longer as we don't create keys unnecessarily any
372 // more (now it is done on demand, i.e. only when they're going to contain
373 // something)
374#if 0
375 // as we create the registry key when SetPath(key) is done, we can be left
376 // with plenty of empty keys if this was only done to try to read some
377 // value which, in fact, doesn't exist - to prevent this from happening we
378 // automatically delete the old key if it was empty
379 if ( m_keyLocal.Exists() && LocalKey().IsEmpty() )
380 {
381 m_keyLocal.DeleteSelf();
382 }
383#endif // 0
19454fa0 384
807a903e
VZ
385 // change current key(s)
386 m_keyLocal.SetName(m_keyLocalRoot, strRegPath);
807a903e 387
72957aa3
VZ
388 if ( GetStyle() & wxCONFIG_USE_GLOBAL_FILE )
389 {
390 m_keyGlobal.SetName(m_keyGlobalRoot, strRegPath);
807a903e 391
72957aa3 392 wxLogNull nolog;
9a85c87d 393 m_keyGlobal.Open(wxRegKey::Read);
72957aa3 394 }
19454fa0
VZ
395}
396
397// ----------------------------------------------------------------------------
398// enumeration (works only with current group)
399// ----------------------------------------------------------------------------
400
401/*
6d833566 402 We want to enumerate all local keys/values after the global ones, but, of
19454fa0
VZ
403 course, we don't want to repeat a key which appears locally as well as
404 globally twice.
405
406 We use the 15th bit of lIndex for distinction between global and local.
407 */
408
409#define LOCAL_MASK 0x8000
410#define IS_LOCAL_INDEX(l) (((l) & LOCAL_MASK) != 0)
411
02569ba8 412bool wxRegConfig::GetFirstGroup(wxString& str, long& lIndex) const
19454fa0
VZ
413{
414 lIndex = 0;
415 return GetNextGroup(str, lIndex);
416}
417
02569ba8 418bool wxRegConfig::GetNextGroup(wxString& str, long& lIndex) const
19454fa0
VZ
419{
420 // are we already enumerating local entries?
421 if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) {
422 // try to find a global entry which doesn't appear locally
09f50eb3 423 while ( m_keyGlobal.GetNextKey(str, lIndex) ) {
807a903e 424 if ( !m_keyLocal.Exists() || !LocalKey().HasSubKey(str) ) {
09f50eb3
VZ
425 // ok, found one - return it
426 return TRUE;
19454fa0 427 }
09f50eb3
VZ
428 }
429
430 // no more global entries
431 lIndex |= LOCAL_MASK;
19454fa0
VZ
432 }
433
807a903e
VZ
434 // if we don't have the key at all, don't try to enumerate anything under it
435 if ( !m_keyLocal.Exists() )
436 return FALSE;
437
19454fa0
VZ
438 // much easier with local entries: get the next one we find
439 // (don't forget to clear our flag bit and set it again later)
440 lIndex &= ~LOCAL_MASK;
807a903e 441 bool bOk = LocalKey().GetNextKey(str, lIndex);
19454fa0
VZ
442 lIndex |= LOCAL_MASK;
443
444 return bOk;
445}
446
02569ba8 447bool wxRegConfig::GetFirstEntry(wxString& str, long& lIndex) const
19454fa0
VZ
448{
449 lIndex = 0;
82cf4761 450 return GetNextEntry(str, lIndex);
19454fa0
VZ
451}
452
02569ba8 453bool wxRegConfig::GetNextEntry(wxString& str, long& lIndex) const
19454fa0
VZ
454{
455 // are we already enumerating local entries?
456 if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) {
457 // try to find a global entry which doesn't appear locally
50f7d0a3 458 while ( m_keyGlobal.GetNextValue(str, lIndex) ) {
807a903e 459 if ( !m_keyLocal.Exists() || !LocalKey().HasValue(str) ) {
50f7d0a3
VZ
460 // ok, found one - return it
461 return TRUE;
19454fa0 462 }
50f7d0a3
VZ
463 }
464
465 // no more global entries
466 lIndex |= LOCAL_MASK;
19454fa0
VZ
467 }
468
807a903e
VZ
469 // if we don't have the key at all, don't try to enumerate anything under it
470 if ( !m_keyLocal.Exists() )
471 return FALSE;
472
19454fa0
VZ
473 // much easier with local entries: get the next one we find
474 // (don't forget to clear our flag bit and set it again later)
475 lIndex &= ~LOCAL_MASK;
807a903e 476 bool bOk = LocalKey().GetNextValue(str, lIndex);
19454fa0
VZ
477 lIndex |= LOCAL_MASK;
478
479 return bOk;
480}
481
33ac7e6f 482size_t wxRegConfig::GetNumberOfEntries(bool WXUNUSED(bRecursive)) const
82cf4761 483{
c86f1403 484 size_t nEntries = 0;
82cf4761
VZ
485
486 // dummy vars
487 wxString str;
488 long l;
6a23cbce 489 bool bCont = ((wxRegConfig*)this)->GetFirstEntry(str, l);
82cf4761
VZ
490 while ( bCont ) {
491 nEntries++;
492
6a23cbce 493 bCont = ((wxRegConfig*)this)->GetNextEntry(str, l);
82cf4761
VZ
494 }
495
496 return nEntries;
497}
498
33ac7e6f 499size_t wxRegConfig::GetNumberOfGroups(bool WXUNUSED(bRecursive)) const
82cf4761 500{
c86f1403 501 size_t nGroups = 0;
82cf4761
VZ
502
503 // dummy vars
504 wxString str;
505 long l;
6a23cbce 506 bool bCont = ((wxRegConfig*)this)->GetFirstGroup(str, l);
82cf4761
VZ
507 while ( bCont ) {
508 nGroups++;
509
6a23cbce 510 bCont = ((wxRegConfig*)this)->GetNextGroup(str, l);
82cf4761
VZ
511 }
512
513 return nGroups;
514}
515
6d833566
VZ
516// ----------------------------------------------------------------------------
517// tests for existence
518// ----------------------------------------------------------------------------
519
61ba49f2 520bool wxRegConfig::HasGroup(const wxString& key) const
6d833566 521{
61ba49f2
VZ
522 wxConfigPathChanger path(this, key);
523
524 wxString strName(path.Name());
525
807a903e
VZ
526 return (m_keyLocal.Exists() && LocalKey().HasSubKey(strName)) ||
527 m_keyGlobal.HasSubKey(strName);
6d833566
VZ
528}
529
61ba49f2 530bool wxRegConfig::HasEntry(const wxString& key) const
6d833566 531{
61ba49f2
VZ
532 wxConfigPathChanger path(this, key);
533
534 wxString strName(path.Name());
535
807a903e
VZ
536 return (m_keyLocal.Exists() && LocalKey().HasValue(strName)) ||
537 m_keyGlobal.HasValue(strName);
61ba49f2
VZ
538}
539
540wxConfigBase::EntryType wxRegConfig::GetEntryType(const wxString& key) const
541{
542 wxConfigPathChanger path(this, key);
543
544 wxString strName(path.Name());
545
546 bool isNumeric;
807a903e 547 if ( m_keyLocal.Exists() && LocalKey().HasValue(strName) )
61ba49f2
VZ
548 isNumeric = m_keyLocal.IsNumericValue(strName);
549 else if ( m_keyGlobal.HasValue(strName) )
550 isNumeric = m_keyGlobal.IsNumericValue(strName);
551 else
552 return wxConfigBase::Type_Unknown;
553
554 return isNumeric ? wxConfigBase::Type_Integer : wxConfigBase::Type_String;
6d833566
VZ
555}
556
19454fa0
VZ
557// ----------------------------------------------------------------------------
558// reading/writing
559// ----------------------------------------------------------------------------
560
2ba41305 561bool wxRegConfig::DoReadString(const wxString& key, wxString *pStr) const
19454fa0 562{
2ba41305 563 wxCHECK_MSG( pStr, FALSE, _T("wxRegConfig::Read(): NULL param") );
19454fa0 564
18244936
JS
565 wxConfigPathChanger path(this, key);
566
567 bool bQueryGlobal = TRUE;
568
569 // if immutable key exists in global key we must check that it's not
570 // overriden by the local key with the same name
571 if ( IsImmutable(path.Name()) ) {
572 if ( TryGetValue(m_keyGlobal, path.Name(), *pStr) ) {
807a903e 573 if ( m_keyLocal.Exists() && LocalKey().HasValue(path.Name()) ) {
223d09f6 574 wxLogWarning(wxT("User value for immutable key '%s' ignored."),
18244936
JS
575 path.Name().c_str());
576 }
577
578 return TRUE;
579 }
580 else {
581 // don't waste time - it's not there anyhow
582 bQueryGlobal = FALSE;
583 }
584 }
585
586 // first try local key
807a903e 587 if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), *pStr)) ||
18244936 588 (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), *pStr)) ) {
18244936 589 return TRUE;
41286812 590 }
baeed289 591
cf447356 592 return FALSE;
19454fa0
VZ
593}
594
2ba41305
VZ
595// this exactly reproduces the string version above except for ExpandEnvVars(),
596// we really should avoid this code duplication somehow...
597
598bool wxRegConfig::DoReadLong(const wxString& key, long *plResult) const
19454fa0 599{
2ba41305
VZ
600 wxCHECK_MSG( plResult, FALSE, _T("wxRegConfig::Read(): NULL param") );
601
18244936 602 wxConfigPathChanger path(this, key);
19454fa0 603
cf447356 604 bool bQueryGlobal = TRUE;
19454fa0
VZ
605
606 // if immutable key exists in global key we must check that it's not
607 // overriden by the local key with the same name
608 if ( IsImmutable(path.Name()) ) {
02569ba8 609 if ( TryGetValue(m_keyGlobal, path.Name(), plResult) ) {
807a903e 610 if ( m_keyLocal.Exists() && LocalKey().HasValue(path.Name()) ) {
223d09f6 611 wxLogWarning(wxT("User value for immutable key '%s' ignored."),
19454fa0
VZ
612 path.Name().c_str());
613 }
614
cf447356 615 return TRUE;
19454fa0
VZ
616 }
617 else {
618 // don't waste time - it's not there anyhow
cf447356 619 bQueryGlobal = FALSE;
19454fa0
VZ
620 }
621 }
622
623 // first try local key
807a903e 624 if ( (m_keyLocal.Exists() && TryGetValue(LocalKey(), path.Name(), plResult)) ||
02569ba8 625 (bQueryGlobal && TryGetValue(m_keyGlobal, path.Name(), plResult)) ) {
cf447356 626 return TRUE;
19454fa0 627 }
2ba41305 628
cf447356 629 return FALSE;
19454fa0
VZ
630}
631
2ba41305 632bool wxRegConfig::DoWriteString(const wxString& key, const wxString& szValue)
19454fa0 633{
18244936 634 wxConfigPathChanger path(this, key);
19454fa0
VZ
635
636 if ( IsImmutable(path.Name()) ) {
223d09f6 637 wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str());
cf447356 638 return FALSE;
19454fa0
VZ
639 }
640
807a903e 641 return LocalKey().SetValue(path.Name(), szValue);
19454fa0
VZ
642}
643
2ba41305 644bool wxRegConfig::DoWriteLong(const wxString& key, long lValue)
19454fa0 645{
18244936 646 wxConfigPathChanger path(this, key);
19454fa0
VZ
647
648 if ( IsImmutable(path.Name()) ) {
223d09f6 649 wxLogError(wxT("Can't change immutable entry '%s'."), path.Name().c_str());
cf447356 650 return FALSE;
19454fa0
VZ
651 }
652
807a903e 653 return LocalKey().SetValue(path.Name(), lValue);
19454fa0
VZ
654}
655
656// ----------------------------------------------------------------------------
89077ebc
VZ
657// renaming
658// ----------------------------------------------------------------------------
659
660bool wxRegConfig::RenameEntry(const wxString& oldName, const wxString& newName)
661{
662 // check that the old entry exists...
663 if ( !HasEntry(oldName) )
664 return FALSE;
665
666 // and that the new one doesn't
667 if ( HasEntry(newName) )
668 return FALSE;
669
442d08ce 670 return m_keyLocal.RenameValue(oldName, newName);
89077ebc
VZ
671}
672
673bool wxRegConfig::RenameGroup(const wxString& oldName, const wxString& newName)
674{
675 // check that the old group exists...
676 if ( !HasGroup(oldName) )
677 return FALSE;
678
679 // and that the new one doesn't
680 if ( HasGroup(newName) )
681 return FALSE;
682
442d08ce 683 return wxRegKey(m_keyLocal, oldName).Rename(newName);
89077ebc
VZ
684}
685
686// ----------------------------------------------------------------------------
19454fa0
VZ
687// deleting
688// ----------------------------------------------------------------------------
1ad6d522
VZ
689
690bool wxRegConfig::DeleteEntry(const wxString& value, bool bGroupIfEmptyAlso)
19454fa0 691{
18244936 692 wxConfigPathChanger path(this, value);
19454fa0 693
807a903e
VZ
694 if ( m_keyLocal.Exists() ) {
695 if ( !m_keyLocal.DeleteValue(path.Name()) )
696 return FALSE;
19454fa0 697
1ad6d522 698 if ( bGroupIfEmptyAlso && m_keyLocal.IsEmpty() ) {
807a903e 699 wxString strKey = GetPath().AfterLast(wxCONFIG_PATH_SEPARATOR);
2b5f62a0 700 SetPath(_T("..")); // changes m_keyLocal
807a903e
VZ
701 return LocalKey().DeleteKey(strKey);
702 }
19454fa0
VZ
703 }
704
cf447356 705 return TRUE;
19454fa0
VZ
706}
707
18244936 708bool wxRegConfig::DeleteGroup(const wxString& key)
19454fa0 709{
18244936 710 wxConfigPathChanger path(this, key);
19454fa0 711
807a903e 712 return m_keyLocal.Exists() ? LocalKey().DeleteKey(path.Name()) : TRUE;
19454fa0
VZ
713}
714
715bool wxRegConfig::DeleteAll()
716{
19454fa0
VZ
717 m_keyLocal.Close();
718 m_keyGlobal.Close();
90186e52 719
19454fa0 720 bool bOk = m_keyLocalRoot.DeleteSelf();
90186e52
VZ
721
722 // make sure that we opened m_keyGlobalRoot and so it has a reasonable name:
723 // otherwise we will delete HKEY_CLASSES_ROOT recursively
724 if ( bOk && m_keyGlobalRoot.IsOpened() )
19454fa0
VZ
725 bOk = m_keyGlobalRoot.DeleteSelf();
726
727 return bOk;
728}
3d05544e 729
f6bcfd97
BP
730#endif
731 // wxUSE_CONFIG