// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "fileconf.h"
#endif
wxString strTmp;
char buf[1024];
- while ( !inStream.Read(buf, WXSIZEOF(buf)).Eof() )
- strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+ do
+ {
+ inStream.Read(buf, WXSIZEOF(buf));
+
+ const wxStreamError err = inStream.GetLastError();
+
+ if ( err != wxSTREAM_NO_ERROR && err != wxSTREAM_EOF )
+ {
+ wxLogError(_("Error reading config options."));
+ break;
+ }
- strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+ strTmp.append(wxConvertMB2WX(buf), inStream.LastRead());
+ }
+ while ( !inStream.Eof() );
strTrans = wxTextBuffer::Translate(strTmp);
}
SetPath(strGroup);
if ( bLocal )
+ {
+ if ( m_pCurrentGroup->Parent() )
+ m_pCurrentGroup->Parent()->SetLastGroup(m_pCurrentGroup);
m_pCurrentGroup->SetLine(m_linesTail);
+ }
// check that there is nothing except comments left on this line
bool bCont = TRUE;
}
else { // a key
const wxChar *pEnd = pStart;
- while ( *pEnd && *pEnd != wxT('=') && !wxIsspace(*pEnd) ) {
+ while ( *pEnd && *pEnd != wxT('=') /* && !wxIsspace(*pEnd)*/ ) {
if ( *pEnd == wxT('\\') ) {
// next character may be space or not - still take it because it's
// quoted (unless there is nothing)
pEnd++;
}
- wxString strKey(FilterInEntryName(wxString(pStart, pEnd)));
+ wxString strKey(FilterInEntryName(wxString(pStart, pEnd).Trim()));
// skip whitespace
while ( wxIsspace(*pEnd) )
if ( pEntry == NULL ) {
// new entry
pEntry = m_pCurrentGroup->AddEntry(strKey, n);
-
- // <JACS>
- // Take the opportunity to set some pointers now
- // that we know there are items in this group.
- // Otherwise, items added to a newly read file
- // can be put in the wrong place.
- m_pCurrentGroup->SetLastEntry(pEntry);
- if (m_pCurrentGroup->Parent())
- m_pCurrentGroup->Parent()->SetLastGroup(m_pCurrentGroup);
- // </JACS>
-
- if ( bLocal )
- pEntry->SetLine(m_linesTail);
}
else {
if ( bLocal && pEntry->IsImmutable() ) {
wxLogWarning(_("file '%s', line %d: key '%s' was first found at line %d."),
buffer.GetName(), n + 1, strKey.c_str(), pEntry->Line());
- if ( bLocal )
- pEntry->SetLine(m_linesTail);
}
}
+ if ( bLocal )
+ pEntry->SetLine(m_linesTail);
+
// skip whitespace
while ( wxIsspace(*pEnd) )
pEnd++;
bool ret = file.Commit();
#if defined(__WXMAC__)
- if ( ret )
- {
- FSSpec spec ;
-
- wxMacFilename2FSSpec( m_strLocalFile , &spec ) ;
- FInfo finfo ;
- if ( FSpGetFInfo( &spec , &finfo ) == noErr )
- {
- finfo.fdType = 'TEXT' ;
- finfo.fdCreator = 'ttxt' ;
- FSpSetFInfo( &spec , &finfo ) ;
- }
- }
+ if ( ret )
+ {
+ FSRef fsRef ;
+ FSCatalogInfo catInfo;
+ FileInfo *finfo ;
+
+ if ( wxMacPathToFSRef( m_strLocalFile , &fsRef ) == noErr )
+ {
+ if ( FSGetCatalogInfo (&fsRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr )
+ {
+ finfo = (FileInfo*)&catInfo.finderInfo;
+ finfo->fileType = 'TEXT' ;
+ finfo->fileCreator = 'ttxt' ;
+ FSSetCatalogInfo( &fsRef, kFSCatInfoFinderInfo, &catInfo ) ;
+ }
+ }
+ }
#endif // __WXMAC__
#ifdef __UNIX__
{
CleanUp();
- if ( wxRemove(m_strLocalFile) == -1 )
- wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str());
+ if ( wxFile::Exists(m_strLocalFile) && wxRemove(m_strLocalFile) == -1 )
+ {
+ wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str());
+ return FALSE;
+ }
m_strLocalFile = m_strGlobalFile = wxT("");
Init();
else // this entry didn't exist in the local file
{
// add a new line to the file
- wxASSERT( m_nLine == wxNOT_FOUND ); // consistency check
-
wxFileConfigLineList *line = Group()->GetLastEntryLine();
m_pLine = Group()->Config()->LineListInsert(strLine, line);
strResult.Alloc(str.Len());
for ( const wxChar *pc = str.c_str(); *pc != wxT('\0'); pc++ ) {
- wxChar c = *pc;
+ const wxChar c = *pc;
// we explicitly allow some of "safe" chars and 8bit ASCII characters
- // which will probably never have special meaning
+ // which will probably never have special meaning and with which we can't
+ // use isalnum() anyhow (in ASCII built, in Unicode it's just fine)
+ //
// NB: note that wxCONFIG_IMMUTABLE_PREFIX and wxCONFIG_PATH_SEPARATOR
// should *not* be quoted
- if ( !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%"), c) && ((c & 0x80) == 0) )
+ if (
+#if !wxUSE_UNICODE
+ ((unsigned char)c < 127) &&
+#endif // ANSI
+ !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%"), c) )
+ {
strResult += wxT('\\');
+ }
strResult += c;
}