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