X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3d1a4878f36ba4b5f66c2ccfd2cb27a9dc528b6f..3d7a1b394baa3255d084c877b5caae4b29720a12:/src/mac/carbon/dirmac.cpp diff --git a/src/mac/carbon/dirmac.cpp b/src/mac/carbon/dirmac.cpp index e9df6eedac..979f68a40e 100644 --- a/src/mac/carbon/dirmac.cpp +++ b/src/mac/carbon/dirmac.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: msw/dir.cpp +// Name: mac/dirmac.cpp // Purpose: wxDir implementation for Mac // Author: Stefan Csomor // Modified by: @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "dir.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -28,37 +24,17 @@ #pragma hdrstop #endif +#include "wx/dir.h" + #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" #endif // PCH -#include "wx/dir.h" -#include "wx/filefn.h" // for wxPathExists() - -#ifndef __DARWIN__ - #include -#endif - +#include "wx/filefn.h" // for wxDirExists() #include "wx/filename.h" #include "wx/mac/private.h" -#include "MoreFilesX.h" - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -#ifndef MAX_PATH - #define MAX_PATH 260 // from VC++ headers -#endif - -// ---------------------------------------------------------------------------- -// macros -// ---------------------------------------------------------------------------- - -#define M_DIR ((wxDirData *)m_data) - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -69,12 +45,12 @@ class wxDirData 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; } @@ -116,7 +92,7 @@ wxDirData::~wxDirData() } void wxDirData::Close() -{ +{ if ( m_iterator ) { FSCloseIterator( m_iterator ) ; @@ -124,13 +100,13 @@ void wxDirData::Close() } } -void wxDirData::Rewind() +void wxDirData::Rewind() { Close() ; } bool wxDirData::Read(wxString *filename) -{ +{ wxString result; OSStatus err = noErr ; if ( NULL == m_iterator ) @@ -139,33 +115,36 @@ bool wxDirData::Read(wxString *filename) err = wxMacPathToFSRef( m_dirname , &dirRef ) ; if ( err == noErr ) { - err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator); - } - if ( err ) - { - Close() ; - return FALSE ; - } + err = FSOpenIterator(&dirRef, kFSIterateFlat, &m_iterator); + } + if ( err ) + { + Close() ; + return false ; + } } - + wxString name ; - + while( noErr == err ) { HFSUniStr255 uniname ; FSRef fileRef; FSCatalogInfo catalogInfo; - UInt32 fetched = 0; + ItemCount fetched = 0; err = FSGetCatalogInfoBulk( m_iterator, 1, &fetched, NULL, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo , &catalogInfo , &fileRef, NULL, &uniname ); + + // expected error codes + if ( errFSNoMoreItems == err ) return false ; - - wxASSERT( noErr == err ) ; - + if ( afpAccessDenied == err ) + return false ; + if ( noErr != err ) break ; - + name = wxMacHFSUniStrToString( &uniname ) ; if ( ( name == wxT(".") || name == wxT("..") ) && !(m_flags & wxDIR_DOTDOT) ) @@ -176,7 +155,7 @@ bool wxDirData::Read(wxString *filename) 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 ; @@ -184,24 +163,24 @@ bool wxDirData::Read(wxString *filename) // its a file but we don't want it if ( (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0 && !(m_flags & wxDIR_FILES ) ) continue ; - - if ( m_filespec.IsEmpty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") ) + + if ( m_filespec.empty() || m_filespec == wxT("*.*") || m_filespec == wxT("*") ) { } - else if ( !wxMatchWild(m_filespec, name , FALSE) ) + else if ( !wxMatchWild(m_filespec, name , false) ) { continue ; } - + break ; } if ( err != noErr ) { - return FALSE ; + return false ; } - + *filename = name ; - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -211,7 +190,7 @@ bool wxDirData::Read(wxString *filename) /* static */ bool wxDir::Exists(const wxString& dir) { - return wxPathExists(dir); + return wxDirExists(dir); } // ---------------------------------------------------------------------------- @@ -227,10 +206,10 @@ wxDir::wxDir(const wxString& dirname) bool wxDir::Open(const wxString& dirname) { - delete M_DIR; + delete m_data; m_data = new wxDirData(dirname); - return TRUE; + return true; } bool wxDir::IsOpened() const @@ -243,12 +222,12 @@ wxString wxDir::GetName() const wxString name; if ( m_data ) { - name = M_DIR->GetName(); - if ( !name.empty() && (name.Last() == _T('/')) ) - { - // chop off the last (back)slash - name.Truncate(name.length() - 1); - } + name = m_data->GetName(); + if ( !name.empty() && (name.Last() == _T('/')) ) + { + // chop off the last (back)slash + name.Truncate(name.length() - 1); + } } return name; @@ -256,10 +235,8 @@ wxString wxDir::GetName() const wxDir::~wxDir() { - if (M_DIR != NULL) { - delete M_DIR; - m_data = NULL; - } + delete m_data; + m_data = NULL; } // ---------------------------------------------------------------------------- @@ -270,21 +247,21 @@ 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(); + m_data->Rewind(); - M_DIR->SetFileSpec(filespec); - M_DIR->SetFlags(flags); + m_data->SetFileSpec(filespec); + m_data->SetFlags(flags); return GetNext(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); + return m_data->Read(filename); }