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
This commit is contained in:
@@ -237,7 +237,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// Scans the resources list for unloaded files and loads them. Also reloads
|
// Scans the resources list for unloaded files and loads them. Also reloads
|
||||||
// files that have been modified since last loading.
|
// files that have been modified since last loading.
|
||||||
void UpdateResources();
|
bool UpdateResources();
|
||||||
|
|
||||||
// Finds a resource (calls UpdateResources) and returns a node containing it.
|
// Finds a resource (calls UpdateResources) and returns a node containing it.
|
||||||
wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE);
|
wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE);
|
||||||
|
@@ -142,7 +142,7 @@ bool wxXmlResource::Load(const wxString& filemask)
|
|||||||
}
|
}
|
||||||
# undef wxXmlFindFirst
|
# undef wxXmlFindFirst
|
||||||
# undef wxXmlFindNext
|
# 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;
|
bool modif;
|
||||||
# if wxUSE_FILESYSTEM
|
# if wxUSE_FILESYSTEM
|
||||||
wxFSFile *file = NULL;
|
wxFSFile *file = NULL;
|
||||||
@@ -350,7 +351,10 @@ void wxXmlResource::UpdateResources()
|
|||||||
file = fsys.OpenFile(m_data[i].File);
|
file = fsys.OpenFile(m_data[i].File);
|
||||||
modif = file && file->GetModificationTime() > m_data[i].Time;
|
modif = file && file->GetModificationTime() > m_data[i].Time;
|
||||||
if (!file)
|
if (!file)
|
||||||
|
{
|
||||||
wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str());
|
wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str());
|
||||||
|
rt = false;
|
||||||
|
}
|
||||||
wxDELETE(file);
|
wxDELETE(file);
|
||||||
# else
|
# else
|
||||||
modif = wxDateTime(wxFileModificationTime(m_data[i].File)) > m_data[i].Time;
|
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'."),
|
wxLogError(_("Cannot load resources from file '%s'."),
|
||||||
m_data[i].File.c_str());
|
m_data[i].File.c_str());
|
||||||
wxDELETE(m_data[i].Doc);
|
wxDELETE(m_data[i].Doc);
|
||||||
|
rt = false;
|
||||||
}
|
}
|
||||||
else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource"))
|
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());
|
wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str());
|
||||||
wxDELETE(m_data[i].Doc);
|
wxDELETE(m_data[i].Doc);
|
||||||
|
rt = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -399,7 +405,10 @@ void wxXmlResource::UpdateResources()
|
|||||||
if (m_version == -1)
|
if (m_version == -1)
|
||||||
m_version = version;
|
m_version = version;
|
||||||
if (m_version != version)
|
if (m_version != version)
|
||||||
|
{
|
||||||
wxLogError(_("Resource files must have same version number!"));
|
wxLogError(_("Resource files must have same version number!"));
|
||||||
|
rt = false;
|
||||||
|
}
|
||||||
|
|
||||||
ProcessPlatformProperty(m_data[i].Doc->GetRoot());
|
ProcessPlatformProperty(m_data[i].Doc->GetRoot());
|
||||||
m_data[i].Time = file->GetModificationTime();
|
m_data[i].Time = file->GetModificationTime();
|
||||||
@@ -412,6 +421,8 @@ void wxXmlResource::UpdateResources()
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -237,7 +237,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
// Scans the resources list for unloaded files and loads them. Also reloads
|
// Scans the resources list for unloaded files and loads them. Also reloads
|
||||||
// files that have been modified since last loading.
|
// files that have been modified since last loading.
|
||||||
void UpdateResources();
|
bool UpdateResources();
|
||||||
|
|
||||||
// Finds a resource (calls UpdateResources) and returns a node containing it.
|
// Finds a resource (calls UpdateResources) and returns a node containing it.
|
||||||
wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE);
|
wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE);
|
||||||
|
@@ -142,7 +142,7 @@ bool wxXmlResource::Load(const wxString& filemask)
|
|||||||
}
|
}
|
||||||
# undef wxXmlFindFirst
|
# undef wxXmlFindFirst
|
||||||
# undef wxXmlFindNext
|
# 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;
|
bool modif;
|
||||||
# if wxUSE_FILESYSTEM
|
# if wxUSE_FILESYSTEM
|
||||||
wxFSFile *file = NULL;
|
wxFSFile *file = NULL;
|
||||||
@@ -350,7 +351,10 @@ void wxXmlResource::UpdateResources()
|
|||||||
file = fsys.OpenFile(m_data[i].File);
|
file = fsys.OpenFile(m_data[i].File);
|
||||||
modif = file && file->GetModificationTime() > m_data[i].Time;
|
modif = file && file->GetModificationTime() > m_data[i].Time;
|
||||||
if (!file)
|
if (!file)
|
||||||
|
{
|
||||||
wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str());
|
wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str());
|
||||||
|
rt = false;
|
||||||
|
}
|
||||||
wxDELETE(file);
|
wxDELETE(file);
|
||||||
# else
|
# else
|
||||||
modif = wxDateTime(wxFileModificationTime(m_data[i].File)) > m_data[i].Time;
|
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'."),
|
wxLogError(_("Cannot load resources from file '%s'."),
|
||||||
m_data[i].File.c_str());
|
m_data[i].File.c_str());
|
||||||
wxDELETE(m_data[i].Doc);
|
wxDELETE(m_data[i].Doc);
|
||||||
|
rt = false;
|
||||||
}
|
}
|
||||||
else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource"))
|
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());
|
wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str());
|
||||||
wxDELETE(m_data[i].Doc);
|
wxDELETE(m_data[i].Doc);
|
||||||
|
rt = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -399,7 +405,10 @@ void wxXmlResource::UpdateResources()
|
|||||||
if (m_version == -1)
|
if (m_version == -1)
|
||||||
m_version = version;
|
m_version = version;
|
||||||
if (m_version != version)
|
if (m_version != version)
|
||||||
|
{
|
||||||
wxLogError(_("Resource files must have same version number!"));
|
wxLogError(_("Resource files must have same version number!"));
|
||||||
|
rt = false;
|
||||||
|
}
|
||||||
|
|
||||||
ProcessPlatformProperty(m_data[i].Doc->GetRoot());
|
ProcessPlatformProperty(m_data[i].Doc->GetRoot());
|
||||||
m_data[i].Time = file->GetModificationTime();
|
m_data[i].Time = file->GetModificationTime();
|
||||||
@@ -412,6 +421,8 @@ void wxXmlResource::UpdateResources()
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user