]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/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 "wx/mac/private.h"
45 #include "MoreFiles.h"
46 #include "MoreFilesExtras.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
53 #define MAX_PATH 260 // from VC++ headers
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 #define M_DIR ((wxDirData *)m_data)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // this class stores everything we need to enumerate the files
70 wxDirData(const wxString
& dirname
);
73 void SetFileSpec(const wxString
& filespec
) { m_filespec
= filespec
; }
74 void SetFlags(int flags
) { m_flags
= flags
; }
76 bool Read(wxString
*filename
); // reads the next
79 const wxString
& GetName() const { return m_dirname
; }
94 // ============================================================================
96 // ============================================================================
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 wxDirData::wxDirData(const wxString
& dirname
)
105 // throw away the trailing slashes
106 size_t n
= m_dirname
.length();
107 wxCHECK_RET( n
, _T("empty dir name in wxDir") );
109 while ( n
> 0 && wxIsPathSeparator(m_dirname
[--n
]) )
112 m_dirname
.Truncate(n
+ 1);
116 wxMacFilename2FSSpec( m_dirname
, &fsspec
) ;
117 m_CPB
.hFileInfo
.ioVRefNum
= fsspec
.vRefNum
;
118 m_CPB
.hFileInfo
.ioNamePtr
= m_name
;
121 OSErr err
= FSpGetDirectoryID( &fsspec
, &m_dirId
, &m_isDir
) ;
122 wxASSERT_MSG( err
== noErr
, "Error accessing directory") ;
125 wxDirData::~wxDirData()
129 void wxDirData::Rewind()
134 bool wxDirData::Read(wxString
*filename
)
146 while ( err
== noErr
)
149 m_CPB
.dirInfo
.ioFDirIndex
= m_index
;
150 m_CPB
.dirInfo
.ioDrDirID
= m_dirId
; /* we need to do this every time */
151 err
= PBGetCatInfoSync((CInfoPBPtr
)&m_CPB
);
156 p2cstrcpy( c_name
, m_name
) ;
157 strcpy( (char *)m_name
, c_name
);
162 // under X thats the way the mounting points look like
163 if ( ( m_CPB
.dirInfo
.ioDrDirID
== 0 ) && ( m_flags
& wxDIR_DIRS
) )
166 if ( ( m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) != 0 && (m_flags
& wxDIR_DIRS
) ) // we have a directory
169 if ( ( m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) == 0 && !(m_flags
& wxDIR_FILES
) ) // its a file but we don't want it
172 if ( ( m_CPB
.hFileInfo
.ioFlFndrInfo
.fdFlags
& kIsInvisible
) && !(m_flags
& wxDIR_HIDDEN
) ) // its hidden but we don't want it
175 wxString
file( m_name
) ;
176 if ( m_filespec
.IsEmpty() || m_filespec
== "*.*" || m_filespec
== "*" )
179 else if ( m_filespec
.Length() > 1 && m_filespec
.Left(1) =="*" )
181 if ( file
.Right( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Mid(1).Upper() )
186 else if ( m_filespec
.Length() > 1 && m_filespec
.Right(1) == "*" )
188 if ( file
.Left( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Left( m_filespec
.Length() - 1 ).Upper() )
193 else if ( file
.Upper() != m_filespec
.Upper() )
205 *filename
= (char*) m_name
;
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
215 bool wxDir::Exists(const wxString
& dir
)
217 return wxPathExists(dir
);
220 // ----------------------------------------------------------------------------
221 // wxDir construction/destruction
222 // ----------------------------------------------------------------------------
224 wxDir::wxDir(const wxString
& dirname
)
231 bool wxDir::Open(const wxString
& dirname
)
234 m_data
= new wxDirData(dirname
);
239 bool wxDir::IsOpened() const
241 return m_data
!= NULL
;
244 wxString
wxDir::GetName() const
249 name
= M_DIR
->GetName();
250 if ( !name
.empty() && (name
.Last() == _T('/')) )
252 // chop off the last (back)slash
253 name
.Truncate(name
.length() - 1);
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 bool wxDir::GetFirst(wxString
*filename
,
273 const wxString
& filespec
,
276 wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") );
280 M_DIR
->SetFileSpec(filespec
);
281 M_DIR
->SetFlags(flags
);
283 return GetNext(filename
);
286 bool wxDir::GetNext(wxString
*filename
) const
288 wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") );
290 wxCHECK_MSG( filename
, FALSE
, _T("bad pointer in wxDir::GetNext()") );
292 return M_DIR
->Read(filename
);