X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5fde6fcc9b551340a194ae4c726db5ab64b5c594..bde4baaced626df90e0312a3d94d024e41d7ab80:/src/mac/dirmac.cpp diff --git a/src/mac/dirmac.cpp b/src/mac/dirmac.cpp index e37f079382..ff168bafdc 100644 --- a/src/mac/dirmac.cpp +++ b/src/mac/dirmac.cpp @@ -6,7 +6,7 @@ // Created: 08.12.99 // RCS-ID: $Id$ // Copyright: (c) 1999 Stefan Csomor -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -36,15 +36,17 @@ #include "wx/dir.h" #include "wx/filefn.h" // for wxPathExists() -#ifndef __WXMAC_X__ +#ifndef __DARWIN__ #include #endif -#if defined(__WXMAC__) && !defined(__UNIX__) - #include "morefile.h" - #include "moreextr.h" - #include "fullpath.h" - #include "fspcompa.h" +#include "wx/mac/private.h" + +#ifdef __DARWIN__ +# include "MoreFilesX.h" +#else +# include "MoreFiles.h" +# include "MoreFilesExtras.h" #endif // ---------------------------------------------------------------------------- @@ -78,12 +80,14 @@ public: bool Read(wxString *filename); // reads the next void Rewind() ; + const wxString& GetName() const { return m_dirname; } + private: - CInfoPBRec m_CPB ; - wxInt16 m_index ; - long m_dirId ; - Str255 m_name ; - Boolean m_isDir ; + CInfoPBRec m_CPB ; + wxInt16 m_index ; + long m_dirId ; + Str255 m_name ; + Boolean m_isDir ; wxString m_dirname; wxString m_filespec; @@ -102,6 +106,8 @@ private: wxDirData::wxDirData(const wxString& dirname) : m_dirname(dirname) { + OSErr err; + // throw away the trailing slashes size_t n = m_dirname.length(); wxCHECK_RET( n, _T("empty dir name in wxDir") ); @@ -110,19 +116,27 @@ 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 ; - FSSpec fsspec ; - - wxUnixFilename2FSSpec( m_dirname , &fsspec ) ; - m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; - m_CPB.hFileInfo.ioNamePtr = m_name ; - m_index = 0 ; + wxMacFilename2FSSpec( m_dirname , &fsspec ) ; + m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; -#ifdef __WXMAC_X__ - // TODO: what are we supposed to do for Mac OS X -#else - FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; + err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; #endif + wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; + + m_CPB.hFileInfo.ioNamePtr = m_name ; + m_index = 0 ; } wxDirData::~wxDirData() @@ -131,76 +145,79 @@ wxDirData::~wxDirData() void wxDirData::Rewind() { - m_index = 0 ; + m_index = 0 ; } bool wxDirData::Read(wxString *filename) { if ( !m_isDir ) return FALSE ; - -#if TARGET_CARBON - char c_name[256] ; -#endif + wxString result; - short err = noErr ; - - while ( err == noErr ) - { - 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 ) - break ; - + short err = noErr ; + + while ( err == noErr ) + { + 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 ) + 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) ) + continue; +#endif #if TARGET_CARBON - p2cstrcpy( c_name, m_name ) ; - strcpy( (char *)m_name, c_name); -#else - p2cstr( m_name ) ; + // under X thats the way the mounting points look like + if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & wxDIR_DIRS) ) + break ; #endif - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory - break ; - - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) // its a file but we don't want it - continue ; - - if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it - continue ; - - wxString file( m_name ) ; - if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) - { - } - else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) - { - if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) - { - continue ; - } - } - else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) - { - if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) - { - continue ; - } - } - else if ( file.Upper() != m_filespec.Upper() ) - { - continue ; - } - - break ; - } - if ( err != noErr ) - { - return FALSE ; - } - - *filename = (char*) m_name ; + // we have a directory + if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) + break ; + + // its a file but we don't want it + if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 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 ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) + { + continue ; + } + } + else if ( file.Upper() != m_filespec.Upper() ) + { + continue ; + } + + break ; + } + if ( err != noErr ) + { + return FALSE ; + } + + *filename = wxMacMakeStringFromPascal( m_name ) ; return TRUE; } @@ -239,9 +256,28 @@ bool wxDir::IsOpened() const return m_data != NULL; } +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); + } + } + + return name; +} + wxDir::~wxDir() { - delete M_DIR; + if (M_DIR != NULL) { + delete M_DIR; + m_data = NULL; + } } // ----------------------------------------------------------------------------