X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..1a19e369fbce12ce4d8097fc08609a436748a6ed:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index c93a8f5d01..0ff30e5381 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -7,7 +7,7 @@ // RCS-ID: $Id$ // Copyright: (c) 1997 Karsten Ballüder & Vadim Zeitlin // Ballueder@usa.net -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -137,6 +137,8 @@ private: wxString m_strLine; // line contents wxFileConfigLineList *m_pNext, // next node *m_pPrev; // previous one + + DECLARE_NO_COPY_CLASS(wxFileConfigLineList) }; // ---------------------------------------------------------------------------- @@ -179,6 +181,8 @@ public: void SetValue(const wxString& strValue, bool bUser = TRUE); void SetDirty(); void SetLine(wxFileConfigLineList *pLine); + + DECLARE_NO_COPY_CLASS(wxFileConfigEntry) }; // ---------------------------------------------------------------------------- @@ -248,6 +252,8 @@ public: // called by entries/subgroups when they're created/deleted void SetLastEntry(wxFileConfigEntry *pEntry) { m_pLastEntry = pEntry; } void SetLastGroup(wxFileConfigGroup *pGroup) { m_pLastGroup = pGroup; } + + DECLARE_NO_COPY_CLASS(wxFileConfigGroup) }; // ============================================================================ @@ -337,7 +343,7 @@ wxString wxFileConfig::GetGlobalFileName(const wxChar *szFile) wxString wxFileConfig::GetLocalFileName(const wxChar *szFile) { -#ifdef __VMS__ +#ifdef __VMS__ // On VMS I saw the problem that the home directory was appended // twice for the configuration file. Does that also happen for // other platforms? @@ -383,11 +389,7 @@ void wxFileConfig::Init() { wxTextFile fileGlobal(m_strGlobalFile); -#if defined(__WXGTK20__) && wxUSE_UNICODE - if ( fileGlobal.Open( wxConvUTF8 ) ) -#else - if ( fileGlobal.Open() ) -#endif + if ( fileGlobal.Open(m_conv/*ignored in ANSI build*/) ) { Parse(fileGlobal, FALSE /* global */); SetRootPath(); @@ -402,11 +404,7 @@ void wxFileConfig::Init() if ( !m_strLocalFile.IsEmpty() && wxFile::Exists(m_strLocalFile) ) { wxTextFile fileLocal(m_strLocalFile); -#if defined(__WXGTK20__) && wxUSE_UNICODE - if ( fileLocal.Open( wxConvUTF8 ) ) -#else - if ( fileLocal.Open() ) -#endif + if ( fileLocal.Open(m_conv/*ignored in ANSI build*/) ) { Parse(fileLocal, TRUE /* local */); SetRootPath(); @@ -421,11 +419,12 @@ void wxFileConfig::Init() // constructor supports creation of wxFileConfig objects of any type wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName, const wxString& strLocal, const wxString& strGlobal, - long style) + long style, wxMBConv& conv) : wxConfigBase(::GetAppName(appName), vendorName, strLocal, strGlobal, style), - m_strLocalFile(strLocal), m_strGlobalFile(strGlobal) + m_strLocalFile(strLocal), m_strGlobalFile(strGlobal), + m_conv(conv) { // Make up names for files if empty if ( m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) ) @@ -462,13 +461,14 @@ wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName, } SetUmask(-1); - + Init(); } #if wxUSE_STREAMS -wxFileConfig::wxFileConfig(wxInputStream &inStream) +wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv) + : m_conv(conv) { // always local_file when this constructor is called (?) SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE); @@ -558,7 +558,7 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal) wxString strLine; size_t nLineCount = buffer.GetLineCount(); - + for ( size_t n = 0; n < nLineCount; n++ ) { strLine = buffer[n]; @@ -867,7 +867,7 @@ bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue) { wxConfigPathChanger path(this, key); wxString strName = path.Name(); - + wxLogTrace( _T("wxFileConfig"), _T(" Writing String '%s' = '%s' to Group '%s'"), strName.c_str(), @@ -955,12 +955,7 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */) { wxString line = p->Text(); line += wxTextFile::GetEOL(); -#if wxUSE_UNICODE - wxCharBuffer buf = wxConvLocal.cWX2MB( line ); - if ( !file.Write( (const char*)buf, strlen( (const char*) buf ) ) ) -#else - if ( !file.Write( line.c_str(), line.Len() ) ) -#endif + if ( !file.Write(line, m_conv) ) { wxLogError(_("can't write user configuration file.")); return FALSE; @@ -1512,13 +1507,17 @@ wxFileConfigGroup *wxFileConfigGroup::AddSubgroup(const wxString& strName) bool wxFileConfigGroup::DeleteSubgroupByName(const wxChar *szName) { - return DeleteSubgroup(FindSubgroup(szName)); + wxFileConfigGroup * const pGroup = FindSubgroup(szName); + + return pGroup ? DeleteSubgroup(pGroup) : FALSE; } // Delete the subgroup and remove all references to it from // other data structures. bool wxFileConfigGroup::DeleteSubgroup(wxFileConfigGroup *pGroup) { + wxCHECK_MSG( pGroup, FALSE, _T("deleting non existing group?") ); + wxLogTrace( _T("wxFileConfig"), _T("Deleting group '%s' from '%s'"), pGroup->Name().c_str(), @@ -1533,11 +1532,8 @@ bool wxFileConfigGroup::DeleteSubgroup(wxFileConfigGroup *pGroup) _T(" text: '%s'"), ((m_pLine) ? m_pLine->Text().c_str() : wxEmptyString) ); - wxCHECK_MSG( pGroup != 0, FALSE, _T("deleting non existing group?") ); - - // delete all entries - - size_t nCount = pGroup->m_aEntries.Count(); + // delete all entries + size_t nCount = pGroup->m_aEntries.Count(); wxLogTrace(_T("wxFileConfig"), _T("Removing %lu Entries"), @@ -1621,7 +1617,7 @@ bool wxFileConfigGroup::DeleteSubgroup(wxFileConfigGroup *pGroup) { wxLogTrace( _T("wxFileConfig"), _T(" ------- No previous group found -------") ); - + wxASSERT_MSG( !pNewLast || m_pLine == 0, _T("how comes it has the same line as we?") );