X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6dc863c78f4a4949579efa184d847f0fe41095c8..b9efe021b554fa3967d1442cf758435c5cd5ae8f:/src/mac/carbon/dirmac.cpp diff --git a/src/mac/carbon/dirmac.cpp b/src/mac/carbon/dirmac.cpp index 0afc3b5cb3..7c3651fd63 100644 --- a/src/mac/carbon/dirmac.cpp +++ b/src/mac/carbon/dirmac.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "dir.h" #endif @@ -34,20 +34,16 @@ #endif // PCH #include "wx/dir.h" -#include "wx/filefn.h" // for wxPathExists() +#include "wx/filefn.h" // for wxDirExists() #ifndef __DARWIN__ #include #endif +#include "wx/filename.h" #include "wx/mac/private.h" -#ifdef __DARWIN__ -# include "MoreFilesX.h" -#else -# include "MoreFiles.h" -# include "MoreFilesExtras.h" -#endif +#include "MoreFilesX.h" // ---------------------------------------------------------------------------- // constants @@ -74,27 +70,22 @@ public: wxDirData(const wxString& dirname); ~wxDirData(); + void Close() ; void SetFileSpec(const wxString& filespec) { m_filespec = filespec; } void SetFlags(int flags) { m_flags = flags; } - bool Read(wxString *filename); // reads the next + bool Read(wxString *filename); // reads the next void Rewind() ; const wxString& GetName() const { return m_dirname; } - bool Ok() const { return m_ok; } private: - CInfoPBRec m_CPB ; - wxInt16 m_index ; - long m_dirId ; - Str255 m_name ; - Boolean m_isDir ; + FSIterator m_iterator ; wxString m_dirname; wxString m_filespec; int m_flags; - bool m_ok; }; // ============================================================================ @@ -108,10 +99,6 @@ private: 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") ); @@ -120,114 +107,101 @@ wxDirData::wxDirData(const wxString& dirname) ; 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 ; + m_iterator = NULL ; } wxDirData::~wxDirData() { + Close() ; } -void wxDirData::Rewind() +void wxDirData::Close() { - m_index = 0 ; + if ( m_iterator ) + { + FSCloseIterator( m_iterator ) ; + m_iterator = NULL ; + } +} + +void wxDirData::Rewind() +{ + Close() ; } bool wxDirData::Read(wxString *filename) { - if ( !m_isDir ) - return FALSE ; - wxString result; + OSStatus err = noErr ; + if ( NULL == m_iterator ) + { + FSRef dirRef; + err = wxMacPathToFSRef( m_dirname , &dirRef ) ; + if ( err == noErr ) + { + err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator); + } + if ( err ) + { + Close() ; + return false ; + } + } + + wxString name ; - short err = noErr ; - - while ( err == noErr ) + while( noErr == err ) { - m_index++ ; - m_CPB.dirInfo.ioFDirIndex = m_index; - m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */ - err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB); - if ( err != noErr ) + HFSUniStr255 uniname ; + FSRef fileRef; + FSCatalogInfo catalogInfo; + UInt32 fetched = 0; + + err = FSGetCatalogInfoBulk( m_iterator, 1, &fetched, NULL, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo , &catalogInfo , &fileRef, NULL, &uniname ); + if ( errFSNoMoreItems == err ) + return false ; + + wxASSERT( noErr == err ) ; + + if ( noErr != err ) break ; - - // its hidden but we don't want it - if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) - continue ; -#ifdef __DARWIN__ - // under X, names that start with '.' are hidden - if ( ( m_name[1] == '.' ) && !(m_flags & wxDIR_HIDDEN) ) + + name = wxMacHFSUniStrToString( &uniname ) ; + + if ( ( name == wxT(".") || name == wxT("..") ) && !(m_flags & wxDIR_DOTDOT) ) continue; -#endif -#if TARGET_CARBON - // under X thats the way the mounting points look like - if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & wxDIR_DIRS) ) - break ; -#endif - // we have a directory - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) - break ; - + + if ( ( name[0U] == '.' ) && !(m_flags & wxDIR_HIDDEN ) ) + continue ; + + if ( (((FileInfo*)&catalogInfo.finderInfo)->finderFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN ) ) + continue ; + + // its a dir and we don't want it + if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) && !(m_flags & wxDIR_DIRS) ) + continue ; + // its a file but we don't want it - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) + if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0 && !(m_flags & wxDIR_FILES ) ) continue ; - - wxString file = wxMacMakeStringFromPascal( m_name ) ; - if ( m_filespec.IsEmpty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") ) - { - } - else if ( m_filespec.Length() > 1 && m_filespec.Left(1) == wxT("*") ) - { - if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) - { - continue ; - } - } - else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == wxT("*") ) + + if ( m_filespec.empty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") ) { - if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) - { - continue ; - } } - else if ( file.Upper() != m_filespec.Upper() ) + else if ( !wxMatchWild(m_filespec, name , false) ) { continue ; } - + break ; } if ( err != noErr ) { - return FALSE ; + return false ; } - - *filename = wxMacMakeStringFromPascal( m_name ) ; - return TRUE; + *filename = name ; + return true; } // ---------------------------------------------------------------------------- @@ -237,7 +211,7 @@ bool wxDirData::Read(wxString *filename) /* static */ bool wxDir::Exists(const wxString& dir) { - return wxPathExists(dir); + return wxDirExists(dir); } // ---------------------------------------------------------------------------- @@ -255,14 +229,8 @@ bool wxDir::Open(const wxString& dirname) { delete M_DIR; m_data = new wxDirData(dirname); - if (m_data->Ok()) - return TRUE; - else - { - delete m_data; - m_data = NULL; - return FALSE; - } + + return true; } bool wxDir::IsOpened() const @@ -302,7 +270,7 @@ bool wxDir::GetFirst(wxString *filename, const wxString& filespec, int flags) const { - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + wxCHECK_MSG( IsOpened(), false, _T("must wxDir::Open() first") ); M_DIR->Rewind(); @@ -314,9 +282,9 @@ bool wxDir::GetFirst(wxString *filename, bool wxDir::GetNext(wxString *filename) const { - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + wxCHECK_MSG( IsOpened(), false, _T("must wxDir::Open() first") ); - wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") ); + wxCHECK_MSG( filename, false, _T("bad pointer in wxDir::GetNext()") ); return M_DIR->Read(filename); }