From d614f51b31930df5c41c03624b9579fded66656e Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 10 Oct 2003 09:48:52 +0000 Subject: [PATCH 1/1] return false from wxXmlResource::Load if the resource is corrupted git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24151 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/xrc/xmlres.h | 2 +- contrib/src/xrc/xmlres.cpp | 15 +++++++++++++-- include/wx/xrc/xmlres.h | 2 +- src/xrc/xmlres.cpp | 15 +++++++++++++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/contrib/include/wx/xrc/xmlres.h b/contrib/include/wx/xrc/xmlres.h index 607ed3f8d2..bf3f3c9d76 100644 --- a/contrib/include/wx/xrc/xmlres.h +++ b/contrib/include/wx/xrc/xmlres.h @@ -237,7 +237,7 @@ public: protected: // Scans the resources list for unloaded files and loads them. Also reloads // files that have been modified since last loading. - void UpdateResources(); + bool UpdateResources(); // Finds a resource (calls UpdateResources) and returns a node containing it. wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE); diff --git a/contrib/src/xrc/xmlres.cpp b/contrib/src/xrc/xmlres.cpp index 36d3989fc2..cd440746ff 100644 --- a/contrib/src/xrc/xmlres.cpp +++ b/contrib/src/xrc/xmlres.cpp @@ -142,7 +142,7 @@ bool wxXmlResource::Load(const wxString& filemask) } # undef wxXmlFindFirst # undef wxXmlFindNext - return rt; + return rt && UpdateResources(); } @@ -321,8 +321,9 @@ static void ProcessPlatformProperty(wxXmlNode *node) -void wxXmlResource::UpdateResources() +bool wxXmlResource::UpdateResources() { + bool rt = true; bool modif; # if wxUSE_FILESYSTEM wxFSFile *file = NULL; @@ -350,7 +351,10 @@ void wxXmlResource::UpdateResources() file = fsys.OpenFile(m_data[i].File); modif = file && file->GetModificationTime() > m_data[i].Time; if (!file) + { wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str()); + rt = false; + } wxDELETE(file); # else modif = wxDateTime(wxFileModificationTime(m_data[i].File)) > m_data[i].Time; @@ -379,11 +383,13 @@ void wxXmlResource::UpdateResources() wxLogError(_("Cannot load resources from file '%s'."), m_data[i].File.c_str()); wxDELETE(m_data[i].Doc); + rt = false; } else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource")) { wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str()); wxDELETE(m_data[i].Doc); + rt = false; } else { @@ -399,7 +405,10 @@ void wxXmlResource::UpdateResources() if (m_version == -1) m_version = version; if (m_version != version) + { wxLogError(_("Resource files must have same version number!")); + rt = false; + } ProcessPlatformProperty(m_data[i].Doc->GetRoot()); m_data[i].Time = file->GetModificationTime(); @@ -412,6 +421,8 @@ void wxXmlResource::UpdateResources() # endif } } + + return rt; } diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 607ed3f8d2..bf3f3c9d76 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -237,7 +237,7 @@ public: protected: // Scans the resources list for unloaded files and loads them. Also reloads // files that have been modified since last loading. - void UpdateResources(); + bool UpdateResources(); // Finds a resource (calls UpdateResources) and returns a node containing it. wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE); diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 36d3989fc2..cd440746ff 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -142,7 +142,7 @@ bool wxXmlResource::Load(const wxString& filemask) } # undef wxXmlFindFirst # undef wxXmlFindNext - return rt; + return rt && UpdateResources(); } @@ -321,8 +321,9 @@ static void ProcessPlatformProperty(wxXmlNode *node) -void wxXmlResource::UpdateResources() +bool wxXmlResource::UpdateResources() { + bool rt = true; bool modif; # if wxUSE_FILESYSTEM wxFSFile *file = NULL; @@ -350,7 +351,10 @@ void wxXmlResource::UpdateResources() file = fsys.OpenFile(m_data[i].File); modif = file && file->GetModificationTime() > m_data[i].Time; if (!file) + { wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str()); + rt = false; + } wxDELETE(file); # else modif = wxDateTime(wxFileModificationTime(m_data[i].File)) > m_data[i].Time; @@ -379,11 +383,13 @@ void wxXmlResource::UpdateResources() wxLogError(_("Cannot load resources from file '%s'."), m_data[i].File.c_str()); wxDELETE(m_data[i].Doc); + rt = false; } else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource")) { wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str()); wxDELETE(m_data[i].Doc); + rt = false; } else { @@ -399,7 +405,10 @@ void wxXmlResource::UpdateResources() if (m_version == -1) m_version = version; if (m_version != version) + { wxLogError(_("Resource files must have same version number!")); + rt = false; + } ProcessPlatformProperty(m_data[i].Doc->GetRoot()); m_data[i].Time = file->GetModificationTime(); @@ -412,6 +421,8 @@ void wxXmlResource::UpdateResources() # endif } } + + return rt; } -- 2.45.2