From 6dc863c78f4a4949579efa184d847f0fe41095c8 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Fri, 19 Mar 2004 10:34:15 +0000 Subject: [PATCH] When a directory can't accessed, don't assert, return false from wxDir and give a suppressable error message. This fixes problems reading e.g. .vol directories. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26271 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/dirmac.cpp | 20 +++++++++++++++++--- src/mac/dirmac.cpp | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/mac/carbon/dirmac.cpp b/src/mac/carbon/dirmac.cpp index ff168bafdc..0afc3b5cb3 100644 --- a/src/mac/carbon/dirmac.cpp +++ b/src/mac/carbon/dirmac.cpp @@ -81,6 +81,7 @@ public: void Rewind() ; const wxString& GetName() const { return m_dirname; } + bool Ok() const { return m_ok; } private: CInfoPBRec m_CPB ; @@ -93,6 +94,7 @@ private: wxString m_filespec; int m_flags; + bool m_ok; }; // ============================================================================ @@ -106,6 +108,8 @@ private: wxDirData::wxDirData(const wxString& dirname) : m_dirname(dirname) { + m_ok = false; + OSErr err; // throw away the trailing slashes @@ -133,7 +137,11 @@ wxDirData::wxDirData(const wxString& dirname) err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; #endif - wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; + //wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; + if ( (err == noErr) || (err == nsvErr)) + m_ok = true; + else + wxLogError(wxString(wxT("Error accessing directory ")) + m_dirname); m_CPB.hFileInfo.ioNamePtr = m_name ; m_index = 0 ; @@ -247,8 +255,14 @@ bool wxDir::Open(const wxString& dirname) { delete M_DIR; m_data = new wxDirData(dirname); - - return TRUE; + if (m_data->Ok()) + return TRUE; + else + { + delete m_data; + m_data = NULL; + return FALSE; + } } bool wxDir::IsOpened() const diff --git a/src/mac/dirmac.cpp b/src/mac/dirmac.cpp index ff168bafdc..0afc3b5cb3 100644 --- a/src/mac/dirmac.cpp +++ b/src/mac/dirmac.cpp @@ -81,6 +81,7 @@ public: void Rewind() ; const wxString& GetName() const { return m_dirname; } + bool Ok() const { return m_ok; } private: CInfoPBRec m_CPB ; @@ -93,6 +94,7 @@ private: wxString m_filespec; int m_flags; + bool m_ok; }; // ============================================================================ @@ -106,6 +108,8 @@ private: wxDirData::wxDirData(const wxString& dirname) : m_dirname(dirname) { + m_ok = false; + OSErr err; // throw away the trailing slashes @@ -133,7 +137,11 @@ wxDirData::wxDirData(const wxString& dirname) err = FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; #endif - wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; + //wxASSERT_MSG( (err == noErr) || (err == nsvErr) , wxT("Error accessing directory " + m_dirname)) ; + if ( (err == noErr) || (err == nsvErr)) + m_ok = true; + else + wxLogError(wxString(wxT("Error accessing directory ")) + m_dirname); m_CPB.hFileInfo.ioNamePtr = m_name ; m_index = 0 ; @@ -247,8 +255,14 @@ bool wxDir::Open(const wxString& dirname) { delete M_DIR; m_data = new wxDirData(dirname); - - return TRUE; + if (m_data->Ok()) + return TRUE; + else + { + delete m_data; + m_data = NULL; + return FALSE; + } } bool wxDir::IsOpened() const -- 2.45.2