small bug fixes + a couple of new functions added
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@303 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,10 +20,25 @@
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// headers
|
// headers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
#include <wx/wx.h>
|
|
||||||
|
#ifdef __GNUG__
|
||||||
|
#pragma implementation "regconf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma hdrstop
|
||||||
|
#endif //__BORLANDC__
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include <wx/string.h>
|
||||||
|
#endif //WX_PRECOMP
|
||||||
|
|
||||||
|
#include <wx/log.h>
|
||||||
#include <wx/config.h>
|
#include <wx/config.h>
|
||||||
#include <wx/regconf.h>
|
|
||||||
#include <wx/msw/registry.h>
|
#include <wx/msw/registry.h>
|
||||||
|
#include <wx/msw/regconf.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
@@ -77,20 +92,20 @@ wxRegConfig::~wxRegConfig()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void wxRegConfig::SetPath(const wxString& strPath)
|
void wxRegConfig::SetPath(const wxString& strPath)
|
||||||
{
|
{
|
||||||
ArrayString aParts;
|
wxArrayString aParts;
|
||||||
|
|
||||||
if ( strPath.IsEmpty() )
|
if ( strPath.IsEmpty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( strPath[0] == APPCONF_PATH_SEPARATOR ) {
|
if ( strPath[0] == APPCONF_PATH_SEPARATOR ) {
|
||||||
// absolute path
|
// absolute path
|
||||||
SplitPath(aParts, strPath);
|
wxSplitPath(aParts, strPath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// relative path, combine with current one
|
// relative path, combine with current one
|
||||||
wxString strFullPath = GetPath();
|
wxString strFullPath = GetPath();
|
||||||
strFullPath << APPCONF_PATH_SEPARATOR << strPath;
|
strFullPath << APPCONF_PATH_SEPARATOR << strPath;
|
||||||
SplitPath(aParts, strFullPath);
|
wxSplitPath(aParts, strFullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recombine path parts in one variable
|
// recombine path parts in one variable
|
||||||
@@ -125,13 +140,13 @@ void wxRegConfig::SetPath(const wxString& strPath)
|
|||||||
#define LOCAL_MASK 0x8000
|
#define LOCAL_MASK 0x8000
|
||||||
#define IS_LOCAL_INDEX(l) (((l) & LOCAL_MASK) != 0)
|
#define IS_LOCAL_INDEX(l) (((l) & LOCAL_MASK) != 0)
|
||||||
|
|
||||||
bool wxRegConfig::GetFirstGroup(wxString& str, long& lIndex)
|
bool wxRegConfig::GetFirstGroup(wxString& str, long& lIndex) const
|
||||||
{
|
{
|
||||||
lIndex = 0;
|
lIndex = 0;
|
||||||
return GetNextGroup(str, lIndex);
|
return GetNextGroup(str, lIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRegConfig::GetNextGroup (wxString& str, long& lIndex)
|
bool wxRegConfig::GetNextGroup(wxString& str, long& lIndex) const
|
||||||
{
|
{
|
||||||
// are we already enumerating local entries?
|
// are we already enumerating local entries?
|
||||||
if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) {
|
if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) {
|
||||||
@@ -154,35 +169,69 @@ bool wxRegConfig::GetNextGroup (wxString& str, long& lIndex)
|
|||||||
return bOk;
|
return bOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRegConfig::GetFirstEntry(wxString& str, long& lIndex)
|
bool wxRegConfig::GetFirstEntry(wxString& str, long& lIndex) const
|
||||||
{
|
{
|
||||||
lIndex = 0;
|
lIndex = 0;
|
||||||
return GetNextGroup(str, lIndex);
|
return GetNextEntry(str, lIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRegConfig::GetNextEntry (wxString& str, long& lIndex)
|
bool wxRegConfig::GetNextEntry(wxString& str, long& lIndex) const
|
||||||
{
|
{
|
||||||
// are we already enumerating local entries?
|
// are we already enumerating local entries?
|
||||||
if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) {
|
if ( m_keyGlobal.IsOpened() && !IS_LOCAL_INDEX(lIndex) ) {
|
||||||
// try to find a global entry which doesn't appear locally
|
// try to find a global entry which doesn't appear locally
|
||||||
do {
|
do {
|
||||||
if ( !m_keyGlobal.GetNextKey(str, lIndex) ) {
|
if ( !m_keyGlobal.GetNextValue(str, lIndex) ) {
|
||||||
// no more global entries
|
// no more global entries
|
||||||
lIndex |= LOCAL_MASK;
|
lIndex |= LOCAL_MASK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while( m_keyLocal.HasSubKey(str) );
|
} while( m_keyLocal.HasValue(str) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// much easier with local entries: get the next one we find
|
// much easier with local entries: get the next one we find
|
||||||
// (don't forget to clear our flag bit and set it again later)
|
// (don't forget to clear our flag bit and set it again later)
|
||||||
lIndex &= ~LOCAL_MASK;
|
lIndex &= ~LOCAL_MASK;
|
||||||
bool bOk = m_keyLocal.GetNextKey(str, lIndex);
|
bool bOk = m_keyLocal.GetNextValue(str, lIndex);
|
||||||
lIndex |= LOCAL_MASK;
|
lIndex |= LOCAL_MASK;
|
||||||
|
|
||||||
return bOk;
|
return bOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint wxRegConfig::GetNumberOfEntries() const
|
||||||
|
{
|
||||||
|
uint nEntries = 0;
|
||||||
|
|
||||||
|
// dummy vars
|
||||||
|
wxString str;
|
||||||
|
long l;
|
||||||
|
bool bCont = GetFirstEntry(str, l);
|
||||||
|
while ( bCont ) {
|
||||||
|
nEntries++;
|
||||||
|
|
||||||
|
bCont = GetNextEntry(str, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint wxRegConfig::GetNumberOfGroups() const
|
||||||
|
{
|
||||||
|
uint nGroups = 0;
|
||||||
|
|
||||||
|
// dummy vars
|
||||||
|
wxString str;
|
||||||
|
long l;
|
||||||
|
bool bCont = GetFirstGroup(str, l);
|
||||||
|
while ( bCont ) {
|
||||||
|
nGroups++;
|
||||||
|
|
||||||
|
bCont = GetNextGroup(str, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nGroups;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// tests for existence
|
// tests for existence
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -305,7 +354,7 @@ bool wxRegConfig::DeleteEntry(const char *szValue, bool bGroupIfEmptyAlso)
|
|||||||
if ( !m_keyLocal.DeleteValue(path.Name()) )
|
if ( !m_keyLocal.DeleteValue(path.Name()) )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if ( m_keyLocal.IsEmpty() ) {
|
if ( !m_keyLocal.HasSubkeys() ) {
|
||||||
wxString strKey = GetPath().Right(APPCONF_PATH_SEPARATOR);
|
wxString strKey = GetPath().Right(APPCONF_PATH_SEPARATOR);
|
||||||
SetPath(".."); // changes m_keyLocal
|
SetPath(".."); // changes m_keyLocal
|
||||||
return m_keyLocal.DeleteKey(strKey);
|
return m_keyLocal.DeleteKey(strKey);
|
||||||
@@ -323,9 +372,6 @@ bool wxRegConfig::DeleteGroup(const char *szKey)
|
|||||||
|
|
||||||
bool wxRegConfig::DeleteAll()
|
bool wxRegConfig::DeleteAll()
|
||||||
{
|
{
|
||||||
// first of all, prevent the creation of new registry entries
|
|
||||||
Config::EnableAutosave(FALSE);
|
|
||||||
|
|
||||||
m_keyLocal.Close();
|
m_keyLocal.Close();
|
||||||
m_keyGlobal.Close();
|
m_keyGlobal.Close();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user