wxIniConfig::wxIniConfig(const wxString& strAppName, const wxString& strVendor, const wxString& localFilename, const wxString& globalFilename, long style) : wxConfigBase(!strAppName && wxTheApp ? wxTheApp->GetAppName() : strAppName, !strVendor ? (wxTheApp ? wxTheApp->GetVendorName() : strAppName) : strVendor, localFilename, globalFilename, style) { m_strLocalFilename = localFilename; if (m_strLocalFilename.empty()) { m_strLocalFilename = GetAppName() + wxT(".ini"); } // append the extension if none given and it's not an absolute file name // (otherwise we assume that they know what they're doing) if ( !wxIsPathSeparator(m_strLocalFilename[(size_t) 0]) && m_strLocalFilename.Find('.') == wxNOT_FOUND ) { m_strLocalFilename << wxT(".ini"); } // set root path SetPath(wxEmptyString); }
bool wxFileSystem::FindFileInPath(wxString *pStr, const wxString& path, const wxString& basename) { // we assume that it's not empty wxCHECK_MSG( !basename.empty(), false, wxT("empty file name in wxFileSystem::FindFileInPath")); wxString name; // skip path separator in the beginning of the file name if present if ( wxIsPathSeparator(basename[0u]) ) name = basename.substr(1); else name = basename; wxStringTokenizer tokenizer(path, wxPATH_SEP); while ( tokenizer.HasMoreTokens() ) { wxString strFile = tokenizer.GetNextToken(); if ( !wxEndsWithPathSeparator(strFile) ) strFile += wxFILE_SEP_PATH; strFile += name; wxFSFile *file = OpenFile(strFile); if ( file ) { delete file; *pStr = strFile; return true; } } return false; }
// find a file in a list of directories, returns false if not found bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile) { // we assume that it's not empty wxCHECK_MSG( !szFile.empty(), false, wxT("empty file name in wxFindFileInPath")); // skip path separator in the beginning of the file name if present wxString szFile2; if ( wxIsPathSeparator(szFile[0u]) ) szFile2 = szFile.Mid(1); else szFile2 = szFile; wxStringTokenizer tkn(szPath, wxPATH_SEP); while ( tkn.HasMoreTokens() ) { wxString strFile = tkn.GetNextToken(); if ( !wxEndsWithPathSeparator(strFile) ) strFile += wxFILE_SEP_PATH; strFile += szFile2; if ( wxFileExists(strFile) ) { *pStr = strFile; return true; } } return false; }
wxDirData::wxDirData(const wxString& dirname) : m_dirname(dirname) { // throw away the trailing slashes size_t n = m_dirname.length(); wxCHECK_RET( n, wxT("empty dir name in wxDir") ); while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) ) ; m_dirname.Truncate(n + 1); m_iterator = NULL ; }
wxDirData::wxDirData(const wxString& dirname) : m_dirname(dirname) { m_ok = false; OSErr err; // throw away the trailing slashes size_t n = m_dirname.length(); wxCHECK_RET( n, _T("empty dir name in wxDir") ); while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) ) ; m_dirname.Truncate(n + 1); #ifdef __DARWIN__ FSRef theRef; // get the FSRef associated with the POSIX path err = FSPathMakeRef((const UInt8 *) m_dirname.c_str(), &theRef, NULL); FSGetVRefNum(&theRef, &(m_CPB.hFileInfo.ioVRefNum)); err = FSGetNodeID( &theRef , &m_dirId , &m_isDir ) ; #else FSSpec fsspec ; wxMacFilename2FSSpec( m_dirname , &fsspec ) ; m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; #endif //wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; if ( (err == noErr) || (err == nsvErr)) m_ok = true; else wxLogError(wxString(wxT("Error accessing directory ")) + m_dirname); m_CPB.hFileInfo.ioNamePtr = m_name ; m_index = 0 ; }
bool wxEndsWithPathSeparator(const wxString& filename) { return !filename.empty() && wxIsPathSeparator(filename.Last()); }