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