X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e90c1d2a19361551eb07778280f22be3e759cf64..6842d18650b487249b4ae29d0d7e17231b24cde8:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 1ae6beaa4d..80b528c70e 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -99,7 +99,7 @@ wxString wxFileConfig::GetGlobalDir() wxString strDir; #ifdef __UNIX__ - strDir = T("/etc/"); + strDir = wxT("/etc/"); #elif defined(__WXPM__) ULONG aulSysInfo[QSV_MAX] = {0}; UINT drive; @@ -192,15 +192,27 @@ wxString wxFileConfig::GetGlobalDir() } } #elif defined(__WXSTUBS__) - wxASSERT_MSG( FALSE, T("TODO") ) ; + wxASSERT_MSG( FALSE, wxT("TODO") ) ; #elif defined(__WXMAC__) - wxASSERT_MSG( FALSE, T("TODO") ) ; + { + short vRefNum ; + long dirID ; + + if ( FindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRefNum, &dirID) == noErr) + { + FSSpec file ; + if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr ) + { + strDir = wxMacFSSpec2UnixFilename( &file ) + "/" ; + } + } + } #else // Windows wxChar szWinDir[MAX_PATH]; ::GetWindowsDirectory(szWinDir, MAX_PATH); strDir = szWinDir; - strDir << T('\\'); + strDir << wxT('\\'); #endif // Unix/Windows return strDir; @@ -210,12 +222,17 @@ wxString wxFileConfig::GetLocalDir() { wxString strDir; +#ifndef __WXMAC__ wxGetHomeDir(&strDir); #ifdef __UNIX__ - if (strDir.Last() != T('/')) strDir << T('/'); + if (strDir.Last() != wxT('/')) strDir << wxT('/'); +#else + if (strDir.Last() != wxT('\\')) strDir << wxT('\\'); +#endif #else - if (strDir.Last() != T('\\')) strDir << T('\\'); + // no local dir concept on mac + return GetGlobalDir() ; #endif return strDir; @@ -226,11 +243,13 @@ wxString wxFileConfig::GetGlobalFileName(const wxChar *szFile) wxString str = GetGlobalDir(); str << szFile; - if ( wxStrchr(szFile, T('.')) == NULL ) + if ( wxStrchr(szFile, wxT('.')) == NULL ) #ifdef __UNIX__ - str << T(".conf"); + str << wxT(".conf"); + #elif defined( __WXMAC__ ) + str << " Preferences"; #else // Windows - str << T(".ini"); + str << wxT(".ini"); #endif // UNIX/Win return str; @@ -241,16 +260,20 @@ wxString wxFileConfig::GetLocalFileName(const wxChar *szFile) wxString str = GetLocalDir(); #ifdef __UNIX__ - str << T('.'); + str << wxT('.'); #endif str << szFile; #ifdef __WXMSW__ - if ( wxStrchr(szFile, T('.')) == NULL ) - str << T(".ini"); + if ( wxStrchr(szFile, wxT('.')) == NULL ) + str << wxT(".ini"); #endif + + #ifdef __WXMAC__ + str << " Preferences"; + #endif return str; } @@ -324,20 +347,21 @@ wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName, // 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; - } + 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; + } } Init(); @@ -385,18 +409,18 @@ void wxFileConfig::Parse(wxTextFile& file, bool bLocal) ; // skip blank/comment lines - if ( *pStart == T('\0')|| *pStart == T(';') || *pStart == T('#') ) + if ( *pStart == wxT('\0')|| *pStart == wxT(';') || *pStart == wxT('#') ) continue; - if ( *pStart == T('[') ) { // a new group + if ( *pStart == wxT('[') ) { // a new group pEnd = pStart; - while ( *++pEnd != T(']') ) { - if ( *pEnd == T('\n') || *pEnd == T('\0') ) + while ( *++pEnd != wxT(']') ) { + if ( *pEnd == wxT('\n') || *pEnd == wxT('\0') ) break; } - if ( *pEnd != T(']') ) { + if ( *pEnd != wxT(']') ) { wxLogError(_("file '%s': unexpected character %c at line %d."), file.GetName(), *pEnd, n + 1); continue; // skip this line @@ -416,15 +440,15 @@ void wxFileConfig::Parse(wxTextFile& file, bool bLocal) // check that there is nothing except comments left on this line bool bCont = TRUE; - while ( *++pEnd != T('\0') && bCont ) { + while ( *++pEnd != wxT('\0') && bCont ) { switch ( *pEnd ) { - case T('#'): - case T(';'): + case wxT('#'): + case wxT(';'): bCont = FALSE; break; - case T(' '): - case T('\t'): + case wxT(' '): + case wxT('\t'): // ignore whitespace ('\n' impossible here) break; @@ -438,8 +462,8 @@ void wxFileConfig::Parse(wxTextFile& file, bool bLocal) } else { // a key const wxChar *pEnd = pStart; - while ( *pEnd != T('=') && !wxIsspace(*pEnd) ) { - if ( *pEnd == T('\\') ) { + while ( *pEnd != wxT('=') && !wxIsspace(*pEnd) ) { + if ( *pEnd == wxT('\\') ) { // next character may be space or not - still take it because it's // quoted pEnd++; @@ -454,7 +478,7 @@ void wxFileConfig::Parse(wxTextFile& file, bool bLocal) while ( isspace(*pEnd) ) pEnd++; - if ( *pEnd++ != T('=') ) { + if ( *pEnd++ != wxT('=') ) { wxLogError(_("file '%s', line %d: '=' expected."), file.GetName(), n + 1); } @@ -692,7 +716,7 @@ bool wxFileConfig::Write(const wxString& key, const wxString& szValue) wxString strName = path.Name(); if ( strName.IsEmpty() ) { // setting the value of a group is an error - wxASSERT_MSG( wxIsEmpty(szValue), T("can't set value of a group!") ); + wxASSERT_MSG( wxIsEmpty(szValue), wxT("can't set value of a group!") ); // ... except if it's empty in which case it's a way to force it's creation m_pCurrentGroup->SetDirty(); @@ -724,7 +748,7 @@ bool wxFileConfig::Write(const wxString& key, long lValue) { // ltoa() is not ANSI :-( wxString buf; - buf.Printf(T("%ld"), lValue); + buf.Printf(wxT("%ld"), lValue); return Write(key, buf); } @@ -748,7 +772,25 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */) } } +#ifndef __WXMAC__ return file.Commit(); +#else + bool ret = file.Commit(); + if ( ret ) + { + FSSpec spec ; + + wxUnixFilename2FSSpec( m_strLocalFile , &spec ) ; + FInfo finfo ; + if ( FSpGetFInfo( &spec , &finfo ) == noErr ) + { + finfo.fdType = 'TEXT' ; + finfo.fdCreator = 'ttxt' ; + FSpSetFInfo( &spec , &finfo ) ; + } + } + return ret ; +#endif } // ---------------------------------------------------------------------------- @@ -809,7 +851,7 @@ bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso) if ( bGroupIfEmptyAlso && m_pCurrentGroup->IsEmpty() ) { if ( m_pCurrentGroup != m_pRootGroup ) { ConfigGroup *pGroup = m_pCurrentGroup; - SetPath(T("..")); // changes m_pCurrentGroup! + SetPath(wxT("..")); // changes m_pCurrentGroup! m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()); } //else: never delete the root group @@ -832,7 +874,7 @@ bool wxFileConfig::DeleteAll() if ( remove(m_strLocalFile.fn_str()) == -1 ) wxLogSysError(_("can't delete user configuration file '%s'"), m_strLocalFile.c_str()); - m_strLocalFile = m_strGlobalFile = T(""); + m_strLocalFile = m_strGlobalFile = wxT(""); Init(); return TRUE; @@ -1004,10 +1046,10 @@ LineList *ConfigGroup::GetGroupLine() // this group wasn't present in local config file, add it now if ( pParent != NULL ) { wxString strFullName; - strFullName << T("[") + strFullName << wxT("[") // +1: no '/' << FilterOutEntryName(GetFullName().c_str() + 1) - << T("]"); + << wxT("]"); m_pLine = m_pConfig->LineListInsert(strFullName, pParent->GetLastGroupLine()); pParent->SetLastGroup(this); // we're surely after all the others @@ -1065,7 +1107,7 @@ void ConfigGroup::Rename(const wxString& newName) LineList *line = GetGroupLine(); wxString strFullName; - strFullName << T("[") << (GetFullName().c_str() + 1) << T("]"); // +1: no '/' + strFullName << wxT("[") << (GetFullName().c_str() + 1) << wxT("]"); // +1: no '/' line->SetText(strFullName); SetDirty(); @@ -1076,7 +1118,7 @@ wxString ConfigGroup::GetFullName() const if ( Parent() ) return Parent()->GetFullName() + wxCONFIG_PATH_SEPARATOR + Name(); else - return T(""); + return wxT(""); } // ---------------------------------------------------------------------------- @@ -1374,7 +1416,7 @@ void ConfigEntry::SetValue(const wxString& strValue, bool bUser) if ( bUser ) { wxString strVal = FilterOutValue(strValue); wxString strLine; - strLine << FilterOutEntryName(m_strName) << T('=') << strVal; + strLine << FilterOutEntryName(m_strName) << wxT('=') << strVal; if ( m_pLine != NULL ) { // entry was read from the local config file, just modify the line @@ -1440,31 +1482,31 @@ static wxString FilterInValue(const wxString& str) bool bQuoted = !str.IsEmpty() && str[0] == '"'; for ( size_t n = bQuoted ? 1 : 0; n < str.Len(); n++ ) { - if ( str[n] == T('\\') ) { + if ( str[n] == wxT('\\') ) { switch ( str[++n] ) { - case T('n'): - strResult += T('\n'); + case wxT('n'): + strResult += wxT('\n'); break; - case T('r'): - strResult += T('\r'); + case wxT('r'): + strResult += wxT('\r'); break; - case T('t'): - strResult += T('\t'); + case wxT('t'): + strResult += wxT('\t'); break; - case T('\\'): - strResult += T('\\'); + case wxT('\\'): + strResult += wxT('\\'); break; - case T('"'): - strResult += T('"'); + case wxT('"'): + strResult += wxT('"'); break; } } else { - if ( str[n] != T('"') || !bQuoted ) + if ( str[n] != wxT('"') || !bQuoted ) strResult += str[n]; else if ( n != str.Len() - 1 ) { wxLogWarning(_("unexpected \" at position %d in '%s'."), @@ -1487,33 +1529,33 @@ static wxString FilterOutValue(const wxString& str) strResult.Alloc(str.Len()); // quoting is necessary to preserve spaces in the beginning of the string - bool bQuote = wxIsspace(str[0]) || str[0] == T('"'); + bool bQuote = wxIsspace(str[0]) || str[0] == wxT('"'); if ( bQuote ) - strResult += T('"'); + strResult += wxT('"'); wxChar c; for ( size_t n = 0; n < str.Len(); n++ ) { switch ( str[n] ) { - case T('\n'): - c = T('n'); + case wxT('\n'): + c = wxT('n'); break; - case T('\r'): - c = T('r'); + case wxT('\r'): + c = wxT('r'); break; - case T('\t'): - c = T('t'); + case wxT('\t'): + c = wxT('t'); break; - case T('\\'): - c = T('\\'); + case wxT('\\'): + c = wxT('\\'); break; - case T('"'): + case wxT('"'): if ( bQuote ) { - c = T('"'); + c = wxT('"'); break; } //else: fall through @@ -1524,11 +1566,11 @@ static wxString FilterOutValue(const wxString& str) } // we get here only for special characters - strResult << T('\\') << c; + strResult << wxT('\\') << c; } if ( bQuote ) - strResult += T('"'); + strResult += wxT('"'); return strResult; } @@ -1540,7 +1582,7 @@ static wxString FilterInEntryName(const wxString& str) strResult.Alloc(str.Len()); for ( const wxChar *pc = str.c_str(); *pc != '\0'; pc++ ) { - if ( *pc == T('\\') ) + if ( *pc == wxT('\\') ) pc++; strResult += *pc; @@ -1555,15 +1597,15 @@ static wxString FilterOutEntryName(const wxString& str) wxString strResult; strResult.Alloc(str.Len()); - for ( const wxChar *pc = str.c_str(); *pc != T('\0'); pc++ ) { + for ( const wxChar *pc = str.c_str(); *pc != wxT('\0'); pc++ ) { wxChar c = *pc; // we explicitly allow some of "safe" chars and 8bit ASCII characters // which will probably never have special meaning // NB: note that wxCONFIG_IMMUTABLE_PREFIX and wxCONFIG_PATH_SEPARATOR // should *not* be quoted - if ( !wxIsalnum(c) && !wxStrchr(T("@_/-!.*%"), c) && ((c & 0x80) == 0) ) - strResult += T('\\'); + if ( !wxIsalnum(c) && !wxStrchr(wxT("@_/-!.*%"), c) && ((c & 0x80) == 0) ) + strResult += wxT('\\'); strResult += c; }