// Author: David Webster
// Modified by:
// Created: 10/09/99
+// RCS-ID: $Id$
// Copyright: David Webster
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
+#if wxUSE_CONFIG
+
#ifndef WX_PRECOMP
- #include <wx/string.h>
- #include <wx/intl.h>
- #include <wx/event.h>
- #include <wx/app.h>
- #include <wx/utils.h>
+ #include "wx/dynarray.h"
+ #include "wx/string.h"
+ #include "wx/intl.h"
+ #include "wx/event.h"
+ #include "wx/app.h"
+ #include "wx/utils.h"
+ #include "wx/log.h"
#endif //WX_PRECOMP
-#include <wx/dynarray.h>
-#include <wx/log.h>
-
-#include <wx/config.h>
-#if wxUSE_CONFIG
+#include "wx/config.h"
-#include <wx/os2/iniconf.h>
+#include "wx/os2/iniconf.h"
#define INCL_PM
#include <os2.h>
}
// set root path
- SetPath(wxT(""));
+ SetPath(wxEmptyString);
}
wxIniConfig::~wxIniConfig()
// GetPrivateProfileString(m_strGroup, NULL, "",
// szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
- if ( !::IsEmpty(szBuf) )
+ if ( !::wxIsEmpty(szBuf) )
return false;
// GetProfileString(m_strGroup, NULL, "", szBuf, WXSIZEOF(szBuf));
-// if ( !::IsEmpty(szBuf) )
+// if ( !::wxIsEmpty(szBuf) )
// return false;
return true;
// NB: the lpDefault param to GetPrivateProfileString can't be NULL
// GetPrivateProfileString(m_strGroup, strKey, "",
// szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
- if ( ::IsEmpty((PSZ)szBuf) )
+ if ( ::wxIsEmpty((PSZ)szBuf) )
{
// now look in win.ini
wxString strKey = GetKeyName(path.Name());
// GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
}
- if ( ::IsEmpty((PSZ)szBuf) )
+ if ( ::wxIsEmpty((PSZ)szBuf) )
{
return false;
}
bool wxIniConfig::Read(const wxString& szKey, wxString *pstr,
const wxString& szDefault) const
{
- wxConfigPathChanger path(this, szKey);
- wxString strKey = GetPrivateKeyName(path.Name());
+ wxConfigPathChanger path(this, szKey);
+ wxString strKey = GetPrivateKeyName(path.Name());
- wxChar szBuf[1024]; // @@ should dynamically allocate memory...
+ wxChar szBuf[1024]; // @@ should dynamically allocate memory...
- // first look in the private INI file
+ // first look in the private INI file
- // NB: the lpDefault param to GetPrivateProfileString can't be NULL
-// GetPrivateProfileString(m_strGroup, strKey, "",
-// szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
- if ( ::IsEmpty((PSZ)szBuf) ) {
- // now look in win.ini
- wxString strKey = GetKeyName(path.Name());
-// GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
- }
-
- if ( ::IsEmpty((PSZ)szBuf) ) {
- *pstr = szDefault;
- return FALSE;
- }
- else {
- *pstr = szBuf ;
- return TRUE;
- }
+ // NB: the lpDefault param to GetPrivateProfileString can't be NULL
+ // GetPrivateProfileString(m_strGroup, strKey, "",
+ // szBuf, WXSIZEOF(szBuf), m_strLocalFilename);
+ if ( ::wxIsEmpty((PSZ)szBuf) )
+ {
+ // now look in win.ini
+ wxString strKey = GetKeyName(path.Name());
+ // GetProfileString(m_strGroup, strKey, "", szBuf, WXSIZEOF(szBuf));
+ }
+
+ if ( ::wxIsEmpty((PSZ)szBuf) )
+ {
+ *pstr = szDefault;
+ return false;
+ }
+ else
+ {
+ *pstr = szBuf ;
+ return true;
+ }
}
bool wxIniConfig::Read(const wxString& szKey, long *pl) const
{
- wxConfigPathChanger path(this, szKey);
- wxString strKey = GetPrivateKeyName(path.Name());
-
- // hack: we have no mean to know if it really found the default value or
- // didn't find anything, so we call it twice
-
- static const int nMagic = 17; // 17 is some "rare" number
- static const int nMagic2 = 28; // arbitrary number != nMagic
- long lVal = 0; // = GetPrivateProfileInt(m_strGroup, strKey, nMagic, m_strLocalFilename);
- if ( lVal != nMagic ) {
- // the value was read from the file
- *pl = lVal;
- return TRUE;
- }
-
- // is it really nMagic?
-// lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic2, m_strLocalFilename);
- if ( lVal == nMagic2 ) {
- // the nMagic it returned was indeed read from the file
- *pl = lVal;
- return TRUE;
- }
-
- // no, it was just returning the default value, so now look in win.ini
-// *pl = GetProfileInt(GetVendorName(), GetKeyName(szKey), *pl);
-
- return TRUE;
+ wxConfigPathChanger path(this, szKey);
+ wxString strKey = GetPrivateKeyName(path.Name());
+
+ // hack: we have no mean to know if it really found the default value or
+ // didn't find anything, so we call it twice
+
+ static const int nMagic = 17; // 17 is some "rare" number
+ static const int nMagic2 = 28; // arbitrary number != nMagic
+ long lVal = 0; // = GetPrivateProfileInt(m_strGroup, strKey, nMagic, m_strLocalFilename);
+
+ if ( lVal != nMagic )
+ {
+ // the value was read from the file
+ *pl = lVal;
+ return true;
+ }
+
+ // is it really nMagic?
+ // lVal = GetPrivateProfileInt(m_strGroup, strKey, nMagic2, m_strLocalFilename);
+ if ( lVal == nMagic2 )
+ {
+ // the nMagic it returned was indeed read from the file
+ *pl = lVal;
+ return true;
+ }
+
+ // no, it was just returning the default value, so now look in win.ini
+ // *pl = GetProfileInt(GetVendorName(), GetKeyName(szKey), *pl);
+
+ return true;
}
bool wxIniConfig::Write(const wxString& szKey, const wxString& WXUNUSED(szValue))
bool wxIniConfig::Flush(bool /* bCurrentOnly */)
{
- // this is just the way it works
-// return WritePrivateProfileString(NULL, NULL, NULL, m_strLocalFilename) != 0;
- return FALSE;
+ // this is just the way it works
+ // return WritePrivateProfileString(NULL, NULL, NULL, m_strLocalFilename) != 0;
+ return false;
}
// ----------------------------------------------------------------------------
bool wxIniConfig::DeleteEntry(const wxString& szKey, bool bGroupIfEmptyAlso)
{
- // passing NULL as value to WritePrivateProfileString deletes the key
-// if ( !Write(szKey, (const char *)NULL) )
-// return FALSE;
- wxConfigPathChanger path(this, szKey);
- wxString strKey = GetPrivateKeyName(path.Name());
+ // passing NULL as value to WritePrivateProfileString deletes the key
+ // if ( !Write(szKey, (const char *)NULL) )
+ // return false;
+ wxConfigPathChanger path(this, szKey);
+ wxString strKey = GetPrivateKeyName(path.Name());
-// if (WritePrivateProfileString(m_strGroup, szKey,
-// (const char*) NULL, m_strLocalFilename) == 0)
-// return FALSE;
+ // if (WritePrivateProfileString(m_strGroup, szKey,
+ // (const char*) NULL, m_strLocalFilename) == 0)
+ // return false;
- if ( !bGroupIfEmptyAlso || !IsEmpty() )
- return TRUE;
+ if ( !bGroupIfEmptyAlso || !IsEmpty() )
+ return true;
- // delete the current group too
- bool bOk = FALSE; // = WritePrivateProfileString(m_strGroup, NULL,
-// NULL, m_strLocalFilename) != 0;
+ // delete the current group too
+ bool bOk = false; // = WritePrivateProfileString(m_strGroup, NULL,
+ // NULL, m_strLocalFilename) != 0;
- if ( !bOk )
- wxLogLastError(wxT("WritePrivateProfileString"));
+ if ( !bOk )
+ wxLogLastError(wxT("WritePrivateProfileString"));
- return bOk;
+ return bOk;
}
bool wxIniConfig::DeleteGroup(const wxString& szKey)
// passing NULL as section name to WritePrivateProfileString deletes the
// whole section according to the docs
- bool bOk = FALSE; // = WritePrivateProfileString(path.Name(), NULL,
- // NULL, m_strLocalFilename) != 0;
+ bool bOk = false; // = WritePrivateProfileString(path.Name(), NULL,
+ // NULL, m_strLocalFilename) != 0;
if ( !bOk )
wxLogLastError(wxT("WritePrivateProfileString"));
bool wxIniConfig::DeleteAll()
{
- // first delete our group in win.ini
-// WriteProfileString(GetVendorName(), NULL, NULL);
-
- // then delete our own ini file
- wxChar szBuf[MAX_PATH];
- size_t nRc = 0; // = GetWindowsDirectory(szBuf, WXSIZEOF(szBuf));
- if ( nRc == 0 )
- {
- wxLogLastError(wxT("GetWindowsDirectory"));
- }
- else if ( nRc > WXSIZEOF(szBuf) )
- {
- wxFAIL_MSG(_("buffer is too small for Windows directory."));
- }
-
- wxString strFile = szBuf;
- strFile << wxT('\\') << m_strLocalFilename;
-
- if ( !wxRemoveFile(strFile) ) {
- wxLogSysError(_("Can't delete the INI file '%s'"), strFile.c_str());
- return FALSE;
- }
-
- return TRUE;
+ // first delete our group in win.ini
+ // WriteProfileString(GetVendorName(), NULL, NULL);
+
+ // then delete our own ini file
+ wxChar szBuf[MAX_PATH];
+ size_t nRc = 0; // = GetWindowsDirectory(szBuf, WXSIZEOF(szBuf));
+ if ( nRc == 0 )
+ {
+ wxLogLastError(wxT("GetWindowsDirectory"));
+ }
+ else if ( nRc > WXSIZEOF(szBuf) )
+ {
+ wxFAIL_MSG(_("buffer is too small for Windows directory."));
+ }
+
+ wxString strFile = szBuf;
+ strFile << wxT('\\') << m_strLocalFilename;
+
+ if ( !wxRemoveFile(strFile) )
+ {
+ wxLogSysError(_("Can't delete the INI file '%s'"), strFile.c_str());
+ return false;
+ }
+
+ return true;
}
bool wxIniConfig::RenameEntry(const wxString& WXUNUSED(oldName), const wxString& WXUNUSED(newName))