X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/655719367ac5e131d9642e5783f3ecf64d1a3385..e822d1bd5fc4f3ac91fafd201d7519d091408dd2:/src/msw/dir.cpp?ds=sidebyside diff --git a/src/msw/dir.cpp b/src/msw/dir.cpp index fc9c933185..1bdeb321f7 100644 --- a/src/msw/dir.cpp +++ b/src/msw/dir.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "dir.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -34,9 +30,9 @@ #endif // PCH #include "wx/dir.h" -#include "wx/filefn.h" // for wxPathExists() +#include "wx/filefn.h" // for wxDirExists() -#ifdef __WXMSW__ +#ifdef __WINDOWS__ #include "wx/msw/private.h" #endif @@ -66,7 +62,7 @@ static inline void FreeFindData(FIND_DATA fd) static inline FIND_DATA FindFirst(const wxString& spec, FIND_STRUCT *finddata) { - return ::FindFirstFile(spec, finddata); + return ::FindFirstFile(spec.fn_str(), finddata); } static inline bool FindNext(FIND_DATA fd, FIND_STRUCT *finddata) @@ -175,7 +171,7 @@ void wxDirData::Rewind() bool wxDirData::Read(wxString *filename) { - bool first = FALSE; + bool first = false; WIN32_FIND_DATA finddata; #define PTR_TO_FINDDATA (&finddata) @@ -188,11 +184,14 @@ bool wxDirData::Read(wxString *filename) { filespec += _T('\\'); } - filespec += (!m_filespec ? _T("*.*") : m_filespec.c_str()); + if ( !m_filespec ) + filespec += _T("*.*"); + else + filespec += m_filespec; m_finddata = FindFirst(filespec, PTR_TO_FINDDATA); - first = TRUE; + first = true; } if ( !IsFindDataOk(m_finddata) ) @@ -200,7 +199,7 @@ bool wxDirData::Read(wxString *filename) #ifdef __WIN32__ DWORD err = ::GetLastError(); - if ( err != ERROR_FILE_NOT_FOUND ) + if ( err != ERROR_FILE_NOT_FOUND && err != ERROR_NO_MORE_FILES ) { wxLogSysError(err, _("Can not enumerate files in directory '%s'"), m_dirname.c_str()); @@ -208,7 +207,7 @@ bool wxDirData::Read(wxString *filename) #endif // __WIN32__ //else: not an error, just no (such) files - return FALSE; + return false; } const wxChar *name; @@ -218,7 +217,7 @@ bool wxDirData::Read(wxString *filename) { if ( first ) { - first = FALSE; + first = false; } else { @@ -234,7 +233,7 @@ bool wxDirData::Read(wxString *filename) #endif // __WIN32__ //else: not an error, just no more (such) files - return FALSE; + return false; } } @@ -277,7 +276,7 @@ bool wxDirData::Read(wxString *filename) break; } - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -287,7 +286,7 @@ bool wxDirData::Read(wxString *filename) /* static */ bool wxDir::Exists(const wxString& dir) { - return wxPathExists(dir); + return wxDirExists(dir); } // ---------------------------------------------------------------------------- @@ -304,9 +303,20 @@ wxDir::wxDir(const wxString& dirname) bool wxDir::Open(const wxString& dirname) { delete M_DIR; - m_data = new wxDirData(dirname); + + // The Unix code does a similar test + if (wxDirExists(dirname)) + { + m_data = new wxDirData(dirname); - return TRUE; + return true; + } + else + { + m_data = NULL; + + return false; + } } bool wxDir::IsOpened() const @@ -349,7 +359,7 @@ bool wxDir::GetFirst(wxString *filename, const wxString& filespec, int flags) const { - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + wxCHECK_MSG( IsOpened(), false, _T("must wxDir::Open() first") ); M_DIR->Rewind(); @@ -361,9 +371,9 @@ bool wxDir::GetFirst(wxString *filename, bool wxDir::GetNext(wxString *filename) const { - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + wxCHECK_MSG( IsOpened(), false, _T("must wxDir::Open() first") ); - wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") ); + wxCHECK_MSG( filename, false, _T("bad pointer in wxDir::GetNext()") ); return M_DIR->Read(filename); } @@ -378,15 +388,21 @@ extern bool wxGetDirectoryTimes(const wxString& dirname, FILETIME *ftAccess, FILETIME *ftCreate, FILETIME *ftMod) { +#ifdef __WXWINCE__ + // FindFirst() is going to fail + wxASSERT_MSG( !dirname.empty(), + _T("incorrect directory name format in wxGetDirectoryTimes") ); +#else // FindFirst() is going to fail wxASSERT_MSG( !dirname.empty() && dirname.Last() != _T('\\'), _T("incorrect directory name format in wxGetDirectoryTimes") ); +#endif FIND_STRUCT fs; FIND_DATA fd = FindFirst(dirname, &fs); if ( !IsFindDataOk(fd) ) { - return FALSE; + return false; } *ftAccess = fs.ftLastAccessTime; @@ -395,7 +411,7 @@ wxGetDirectoryTimes(const wxString& dirname, FindClose(fd); - return TRUE; + return true; } #endif // __WIN32__