]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dirmac.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxDir implementation for Mac 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) 1999 Stefan Csomor <csomor@advanced.ch> 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  21     #pragma implementation "dir.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  37 #include "wx/filefn.h"          // for wxPathExists() 
  43 #include "MoreFiles.h" 
  44 #include "MoreFilesExtras.h" 
  46 // ---------------------------------------------------------------------------- 
  48 // ---------------------------------------------------------------------------- 
  51     #define MAX_PATH 260        // from VC++ headers 
  54 // ---------------------------------------------------------------------------- 
  56 // ---------------------------------------------------------------------------- 
  58 #define M_DIR       ((wxDirData *)m_data) 
  60 // ---------------------------------------------------------------------------- 
  62 // ---------------------------------------------------------------------------- 
  64 // this class stores everything we need to enumerate the files 
  68     wxDirData(const wxString
& dirname
); 
  71     void SetFileSpec(const wxString
& filespec
) { m_filespec 
= filespec
; } 
  72     void SetFlags(int flags
) { m_flags 
= flags
; } 
  74     bool Read(wxString 
*filename
); // reads the next  
  77     const wxString
& GetName() const { return m_dirname
; } 
  92 // ============================================================================ 
  94 // ============================================================================ 
  96 // ---------------------------------------------------------------------------- 
  98 // ---------------------------------------------------------------------------- 
 100 wxDirData::wxDirData(const wxString
& dirname
) 
 103     // throw away the trailing slashes 
 104     size_t n 
= m_dirname
.length(); 
 105     wxCHECK_RET( n
, _T("empty dir name in wxDir") ); 
 107     while ( n 
> 0 && wxIsPathSeparator(m_dirname
[--n
]) ) 
 110     m_dirname
.Truncate(n 
+ 1); 
 114         wxMacFilename2FSSpec( m_dirname 
, &fsspec 
) ; 
 115         m_CPB
.hFileInfo
.ioVRefNum 
= fsspec
.vRefNum 
; 
 116         m_CPB
.hFileInfo
.ioNamePtr 
= m_name 
; 
 119         FSpGetDirectoryID( &fsspec 
, &m_dirId 
, &m_isDir 
) ; 
 122 wxDirData::~wxDirData() 
 126 void wxDirData::Rewind()  
 131 bool wxDirData::Read(wxString 
*filename
) 
 143         while ( err 
== noErr 
) 
 146                 m_CPB
.dirInfo
.ioFDirIndex 
= m_index
; 
 147                 m_CPB
.dirInfo
.ioDrDirID 
= m_dirId
;      /* we need to do this every time */ 
 148                 err 
= PBGetCatInfoSync((CInfoPBPtr
)&m_CPB
); 
 153                 p2cstrcpy( c_name
, m_name 
) ; 
 154                 strcpy( (char *)m_name
, c_name
); 
 158                 if ( ( m_CPB
.dirInfo
.ioFlAttrib 
& ioDirMask
) != 0 && (m_flags 
& wxDIR_DIRS
) ) //  we have a directory 
 161                 if ( ( m_CPB
.dirInfo
.ioFlAttrib 
& ioDirMask
) == 0 && !(m_flags 
& wxDIR_FILES 
) ) // its a file but we don't want it 
 164         if ( ( m_CPB
.hFileInfo
.ioFlFndrInfo
.fdFlags 
& kIsInvisible 
) && !(m_flags 
& wxDIR_HIDDEN
) ) // its hidden but we don't want it 
 167                 wxString 
file( m_name 
) ; 
 168                 if ( m_filespec
.IsEmpty() || m_filespec 
== "*.*" ) 
 171                 else if ( m_filespec
.Length() > 1 && m_filespec
.Left(1) =="*" ) 
 173                         if ( file
.Right( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Mid(1).Upper() ) 
 178                 else if ( m_filespec
.Length() > 1 && m_filespec
.Right(1) == "*" ) 
 180                         if ( file
.Left( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Left( m_filespec
.Length() - 1 ).Upper() ) 
 185                 else if ( file
.Upper() != m_filespec
.Upper() ) 
 197         *filename 
= (char*) m_name 
; 
 202 // ---------------------------------------------------------------------------- 
 204 // ---------------------------------------------------------------------------- 
 207 bool wxDir::Exists(const wxString
& dir
) 
 209     return wxPathExists(dir
); 
 212 // ---------------------------------------------------------------------------- 
 213 // wxDir construction/destruction 
 214 // ---------------------------------------------------------------------------- 
 216 wxDir::wxDir(const wxString
& dirname
) 
 223 bool wxDir::Open(const wxString
& dirname
) 
 226     m_data 
= new wxDirData(dirname
); 
 231 bool wxDir::IsOpened() const 
 233     return m_data 
!= NULL
; 
 236 wxString 
wxDir::GetName() const 
 241         name 
= M_DIR
->GetName(); 
 242         if ( !name
.empty() && (name
.Last() == _T('/')) ) 
 244             // chop off the last (back)slash 
 245             name
.Truncate(name
.length() - 1); 
 257 // ---------------------------------------------------------------------------- 
 259 // ---------------------------------------------------------------------------- 
 261 bool wxDir::GetFirst(wxString 
*filename
, 
 262                      const wxString
& filespec
, 
 265     wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") ); 
 269     M_DIR
->SetFileSpec(filespec
); 
 270     M_DIR
->SetFlags(flags
); 
 272     return GetNext(filename
); 
 275 bool wxDir::GetNext(wxString 
*filename
) const 
 277     wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") ); 
 279     wxCHECK_MSG( filename
, FALSE
, _T("bad pointer in wxDir::GetNext()") ); 
 281     return M_DIR
->Read(filename
);