]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/dir.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()
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
54 #define MAX_PATH 260 // from VC++ headers
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 #define M_DIR ((wxDirData *)m_data)
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // this class stores everything we need to enumerate the files
71 wxDirData(const wxString
& dirname
);
74 void SetFileSpec(const wxString
& filespec
) { m_filespec
= filespec
; }
75 void SetFlags(int flags
) { m_flags
= flags
; }
77 bool Read(wxString
*filename
); // reads the next
93 // ============================================================================
95 // ============================================================================
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 wxDirData::wxDirData(const wxString
& dirname
)
104 // throw away the trailing slashes
105 size_t n
= m_dirname
.length();
106 wxCHECK_RET( n
, _T("empty dir name in wxDir") );
108 while ( n
> 0 && wxIsPathSeparator(m_dirname
[--n
]) )
111 m_dirname
.Truncate(n
+ 1);
115 wxUnixFilename2FSSpec( m_dirname
, &fsspec
) ;
116 m_CPB
.hFileInfo
.ioVRefNum
= fsspec
.vRefNum
;
117 m_CPB
.hFileInfo
.ioNamePtr
= m_name
;
120 FSpGetDirectoryID( &fsspec
, &m_dirId
, &m_isDir
) ;
123 wxDirData::~wxDirData()
127 void wxDirData::Rewind()
132 bool wxDirData::Read(wxString
*filename
)
141 while ( err
== noErr
)
144 m_CPB
.dirInfo
.ioFDirIndex
= m_index
;
145 m_CPB
.dirInfo
.ioDrDirID
= m_dirId
; /* we need to do this every time */
146 err
= PBGetCatInfoSync((CInfoPBPtr
)&m_CPB
);
151 if ( ( m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) != 0 && (m_flags
& wxDIR_DIRS
) ) // we have a directory
154 if ( ( m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) == 0 && !(m_flags
& wxDIR_FILES
) ) // its a file but we don't want it
157 if ( ( m_CPB
.hFileInfo
.ioFlFndrInfo
.fdFlags
& kIsInvisible
) && !(m_flags
& wxDIR_HIDDEN
) ) // its hidden but we don't want it
160 wxString
file( m_name
) ;
161 if ( m_filespec
.IsEmpty() || m_filespec
== "*.*" )
164 else if ( m_filespec
.Length() > 1 && m_filespec
.Left(1) =="*" )
166 if ( file
.Right( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Mid(1).Upper() )
171 else if ( m_filespec
.Length() > 1 && m_filespec
.Right(1) == "*" )
173 if ( file
.Left( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Left( m_filespec
.Length() - 1 ).Upper() )
178 else if ( file
.Upper() != m_filespec
.Upper() )
190 *filename
= (char*) m_name
;
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
200 bool wxDir::Exists(const wxString
& dir
)
202 return wxPathExists(dir
);
205 // ----------------------------------------------------------------------------
206 // wxDir construction/destruction
207 // ----------------------------------------------------------------------------
209 wxDir::wxDir(const wxString
& dirname
)
216 bool wxDir::Open(const wxString
& dirname
)
219 m_data
= new wxDirData(dirname
);
224 bool wxDir::IsOpened() const
226 return m_data
!= NULL
;
234 // ----------------------------------------------------------------------------
236 // ----------------------------------------------------------------------------
238 bool wxDir::GetFirst(wxString
*filename
,
239 const wxString
& filespec
,
242 wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") );
246 M_DIR
->SetFileSpec(filespec
);
247 M_DIR
->SetFlags(flags
);
249 return GetNext(filename
);
252 bool wxDir::GetNext(wxString
*filename
) const
254 wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") );
256 wxCHECK_MSG( filename
, FALSE
, _T("bad pointer in wxDir::GetNext()") );
258 return M_DIR
->Read(filename
);