]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/dirmac.cpp
e37f079382775a1b9c33eec893a53c7b5efd6290
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 #if defined(__WXMAC__) && !defined(__UNIX__)
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
55 #define MAX_PATH 260 // from VC++ headers
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 #define M_DIR ((wxDirData *)m_data)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 // this class stores everything we need to enumerate the files
72 wxDirData(const wxString
& dirname
);
75 void SetFileSpec(const wxString
& filespec
) { m_filespec
= filespec
; }
76 void SetFlags(int flags
) { m_flags
= flags
; }
78 bool Read(wxString
*filename
); // reads the next
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 wxUnixFilename2FSSpec( m_dirname
, &fsspec
) ;
117 m_CPB
.hFileInfo
.ioVRefNum
= fsspec
.vRefNum
;
118 m_CPB
.hFileInfo
.ioNamePtr
= m_name
;
122 // TODO: what are we supposed to do for Mac OS X
124 FSpGetDirectoryID( &fsspec
, &m_dirId
, &m_isDir
) ;
128 wxDirData::~wxDirData()
132 void wxDirData::Rewind()
137 bool wxDirData::Read(wxString
*filename
)
149 while ( err
== noErr
)
152 m_CPB
.dirInfo
.ioFDirIndex
= m_index
;
153 m_CPB
.dirInfo
.ioDrDirID
= m_dirId
; /* we need to do this every time */
154 err
= PBGetCatInfoSync((CInfoPBPtr
)&m_CPB
);
159 p2cstrcpy( c_name
, m_name
) ;
160 strcpy( (char *)m_name
, c_name
);
164 if ( ( m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) != 0 && (m_flags
& wxDIR_DIRS
) ) // we have a directory
167 if ( ( m_CPB
.dirInfo
.ioFlAttrib
& ioDirMask
) == 0 && !(m_flags
& wxDIR_FILES
) ) // its a file but we don't want it
170 if ( ( m_CPB
.hFileInfo
.ioFlFndrInfo
.fdFlags
& kIsInvisible
) && !(m_flags
& wxDIR_HIDDEN
) ) // its hidden but we don't want it
173 wxString
file( m_name
) ;
174 if ( m_filespec
.IsEmpty() || m_filespec
== "*.*" )
177 else if ( m_filespec
.Length() > 1 && m_filespec
.Left(1) =="*" )
179 if ( file
.Right( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Mid(1).Upper() )
184 else if ( m_filespec
.Length() > 1 && m_filespec
.Right(1) == "*" )
186 if ( file
.Left( m_filespec
.Length() - 1 ).Upper() != m_filespec
.Left( m_filespec
.Length() - 1 ).Upper() )
191 else if ( file
.Upper() != m_filespec
.Upper() )
203 *filename
= (char*) m_name
;
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
213 bool wxDir::Exists(const wxString
& dir
)
215 return wxPathExists(dir
);
218 // ----------------------------------------------------------------------------
219 // wxDir construction/destruction
220 // ----------------------------------------------------------------------------
222 wxDir::wxDir(const wxString
& dirname
)
229 bool wxDir::Open(const wxString
& dirname
)
232 m_data
= new wxDirData(dirname
);
237 bool wxDir::IsOpened() const
239 return m_data
!= NULL
;
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
251 bool wxDir::GetFirst(wxString
*filename
,
252 const wxString
& filespec
,
255 wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") );
259 M_DIR
->SetFileSpec(filespec
);
260 M_DIR
->SetFlags(flags
);
262 return GetNext(filename
);
265 bool wxDir::GetNext(wxString
*filename
) const
267 wxCHECK_MSG( IsOpened(), FALSE
, _T("must wxDir::Open() first") );
269 wxCHECK_MSG( filename
, FALSE
, _T("bad pointer in wxDir::GetNext()") );
271 return M_DIR
->Read(filename
);