]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/dir.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/dir.cpp
3 // Purpose: wxDir implementation for PalmOS
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
36 // ----------------------------------------------------------------------------
37 // define the types and functions used for file searching
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
45 #define MAX_PATH 260 // from VC++ headers
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 #define M_DIR ((wxDirData *)m_data)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // this class stores everything we need to enumerate the files
62 wxDirData(const wxString
& dirname
);
65 bool IsOk() const { return m_dir
!= NULL
; }
67 void SetFileSpec(const wxString
& filespec
) { m_filespec
= filespec
; }
68 void SetFlags(int flags
) { m_flags
= flags
; }
71 bool Read(wxString
*filename
);
73 const wxString
& GetName() const { return m_dirname
; }
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 wxDirData::wxDirData(const wxString
& dirname
)
97 // throw away the trailing slashes
98 size_t n
= m_dirname
.length();
99 wxCHECK_RET( n
, wxT("empty dir name in wxDir") );
101 while ( n
> 0 && m_dirname
[--n
] == '/' )
104 m_dirname
.Truncate(n
+ 1);
107 //m_dir = opendir(m_dirname.fn_str());
110 wxDirData::~wxDirData()
115 void wxDirData::Close()
119 if ( svfs_dir_endfind (m_dir
) != 0 )
121 wxLogLastError(wxT("svfs_dir_endfind"));
127 bool wxDirData::Read(wxString
*filename
)
129 //dirent *de = NULL; // just to silence compiler warnings
132 bool matches
= false;
135 // speed up string concatenation in the loop a bit
136 wxString path
= m_dirname
;
138 path
.reserve(path
.length() + 255);
141 de_d_name
.reserve(500);
143 if (wxDIR_DIRS
& m_flags
) {
144 flags_search
|= SDIR_DIRS
;
146 if (wxDIR_FILES
& m_flags
) {
147 flags_search
|= SDIR_FILES
;
151 // walk around the PalmOS pacc compiler bug
152 ret
= svfs_dir_findfirst (m_dirname
.fn_str().data(), &m_dir
, tmpbuf
, sizeof (tmpbuf
), flags_search
);
154 ret
= svfs_dir_findfirst (m_dirname
.fn_str(), &m_dir
, tmpbuf
, sizeof (tmpbuf
), flags_search
);
157 ret
= svfs_dir_findnext (m_dir
, tmpbuf
, sizeof (tmpbuf
));
162 de_d_name
= wxString(tmpbuf
, *wxConvFileName
);
167 // don't return "." and ".." unless asked for
168 if ( tmpbuf
[0] == '.' &&
169 ((tmpbuf
[1] == '.' && tmpbuf
[2] == '\0') ||
170 (tmpbuf
[1] == '\0')) )
172 if ( !(m_flags
& wxDIR_DOTDOT
) )
175 // we found a valid match
180 if ( m_filespec
.empty() )
182 matches
= m_flags
& wxDIR_HIDDEN
? true : tmpbuf
[0] != '.';
186 // test against the pattern
187 matches
= wxMatchWild(m_filespec
, de_d_name
,
188 !(m_flags
& wxDIR_HIDDEN
));
192 ret
= svfs_dir_findnext (m_dir
, tmpbuf
, sizeof (tmpbuf
));
195 *filename
= de_d_name
;
200 // ----------------------------------------------------------------------------
201 // wxDir construction/destruction
202 // ----------------------------------------------------------------------------
204 wxDir::wxDir(const wxString
& dirname
)
210 bool wxDir::Open(const wxString
& dirname
)
213 m_data
= new wxDirData(dirname
);
218 bool wxDir::IsOpened() const
220 return m_data
!= NULL
;
223 wxString
wxDir::GetName() const
228 name
= M_DIR
->GetName();
229 if ( !name
.empty() && (name
.Last() == wxT('/')) )
231 // chop off the last (back)slash
232 name
.Truncate(name
.length() - 1);
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 bool wxDir::GetFirst(wxString
*filename
,
249 const wxString
& filespec
,
252 wxCHECK_MSG( IsOpened(), false, wxT("must wxDir::Open() first") );
254 M_DIR
->SetFileSpec(filespec
);
255 M_DIR
->SetFlags(flags
);
256 return GetNext(filename
);
259 bool wxDir::GetNext(wxString
*filename
) const
261 wxCHECK_MSG( IsOpened(), false, wxT("must wxDir::Open() first") );
262 wxCHECK_MSG( filename
, false, wxT("bad pointer in wxDir::GetNext()") );
263 return M_DIR
->Read(filename
);