+ wxLogWarning(_("can't open user configuration file '%s'."),
+ m_strLocalFile.c_str());
+ }
+}
+
+// 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)
+ : wxConfigBase(::GetAppName(appName), vendorName,
+ strLocal, strGlobal,
+ style),
+ m_strLocalFile(strLocal), m_strGlobalFile(strGlobal)
+{
+ // Make up names for files if empty
+ if ( m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) )
+ {
+ m_strLocalFile = GetLocalFileName(GetAppName());
+ }
+
+ if ( m_strGlobalFile.IsEmpty() && (style & wxCONFIG_USE_GLOBAL_FILE) )
+ {
+ m_strGlobalFile = GetGlobalFileName(GetAppName());
+ }
+
+ // Check if styles are not supplied, but filenames are, in which case
+ // add the correct styles.
+ if ( !m_strLocalFile.IsEmpty() )
+ SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
+
+ if ( !m_strGlobalFile.IsEmpty() )
+ SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE);
+
+ // if the path is not absolute, prepend the standard directory to it
+ // UNLESS wxCONFIG_USE_RELATIVE_PATH style is set
+ if ( !(style & wxCONFIG_USE_RELATIVE_PATH) )
+ {
+ if ( !m_strLocalFile.IsEmpty() && !wxIsAbsolutePath(m_strLocalFile) )
+ {
+ wxString strLocal = m_strLocalFile;
+ m_strLocalFile = GetLocalDir();
+ m_strLocalFile << strLocal;
+ }
+
+ if ( !m_strGlobalFile.IsEmpty() && !wxIsAbsolutePath(m_strGlobalFile) )
+ {
+ wxString strGlobal = m_strGlobalFile;
+ m_strGlobalFile = GetGlobalDir();
+ m_strGlobalFile << strGlobal;
+ }
+ }
+
+ SetUmask(-1);
+
+ Init();
+}
+
+#if wxUSE_STREAMS
+
+wxFileConfig::wxFileConfig(wxInputStream &inStream)
+{
+ // always local_file when this constructor is called (?)
+ SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
+
+ m_pCurrentGroup =
+ m_pRootGroup = new wxFileConfigGroup(NULL, "", this);
+
+ m_linesHead =
+ m_linesTail = NULL;
+
+ // translate everything to the current (platform-dependent) line
+ // termination character
+ wxString strTrans;
+ {
+ wxString strTmp;
+
+ char buf[1024];
+ while ( !inStream.Read(buf, WXSIZEOF(buf)).Eof() )
+ strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+
+ strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+
+ strTrans = wxTextBuffer::Translate(strTmp);
+ }
+
+ wxMemoryText memText;
+
+ // Now we can add the text to the memory text. To do this we extract line
+ // by line from the translated string, until we've reached the end.
+ //
+ // VZ: all this is horribly inefficient, we should do the translation on
+ // the fly in one pass saving both memory and time (TODO)
+
+ const wxChar *pEOL = wxTextBuffer::GetEOL(wxTextBuffer::typeDefault);
+ const size_t EOLLen = wxStrlen(pEOL);
+
+ int posLineStart = strTrans.Find(pEOL);
+ while ( posLineStart != -1 )
+ {
+ wxString line(strTrans.Left(posLineStart));
+
+ memText.AddLine(line);
+
+ strTrans = strTrans.Mid(posLineStart + EOLLen);
+
+ posLineStart = strTrans.Find(pEOL);
+ }
+
+ // also add whatever we have left in the translated string.
+ memText.AddLine(strTrans);
+
+ // Finally we can parse it all.
+ Parse(memText, TRUE /* local */);
+
+ SetRootPath();
+}
+
+#endif // wxUSE_STREAMS
+
+void wxFileConfig::CleanUp()
+{
+ delete m_pRootGroup;
+
+ wxFileConfigLineList *pCur = m_linesHead;
+ while ( pCur != NULL ) {
+ wxFileConfigLineList *pNext = pCur->Next();
+ delete pCur;
+ pCur = pNext;