removed debug message ; improved resource loading logic

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7966 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2000-08-06 16:51:54 +00:00
parent 2ada7c652c
commit 0ceae93229
3 changed files with 30 additions and 32 deletions

View File

@@ -32,13 +32,6 @@ class WXDLLEXPORT wxXmlResourceHandler;
#include "wx/xml/xml.h" #include "wx/xml/xml.h"
enum
{
wxXML_BINARY,
wxXML_ARCHIVE
};
class WXDLLEXPORT wxXmlResourceDataRecord class WXDLLEXPORT wxXmlResourceDataRecord
{ {
@@ -61,20 +54,12 @@ class WXDLLEXPORT wxXmlResource : public wxObject
{ {
public: public:
wxXmlResource(); wxXmlResource();
wxXmlResource(const wxString& filemask, int type); wxXmlResource(const wxString& filemask);
~wxXmlResource(); ~wxXmlResource();
// Loads resources from XML files that match given filemask. // Loads resources from XML files that match given filemask.
// This method understands VFS (see filesys.h). Type is one of // This method understands VFS (see filesys.h).
// wxXML_TEXT, wxXML_BINARY, wxXML_ARCHIVE and specifies type of bool Load(const wxString& filemask);
// data to be expected:
// wxXML_BINARY - binary version of .xml file, as produced
// by wxXmlDocument::SaveBinary
// wxXML_ARCHIVE - ZIP archive that contains arbitrary number
// of files with .xmb extension
// (this kind of ZIP archive is produced by
// XML resources compiler that ships with wxWin)
bool Load(const wxString& filemask, int type = wxXML_ARCHIVE);
// Initialize handlers for all supported controls/windows. This will // Initialize handlers for all supported controls/windows. This will
// make the executable quite big because it forces linking against // make the executable quite big because it forces linking against

View File

@@ -77,7 +77,6 @@ static void ReleaseLibxml()
{ {
if (gs_libxmlLoaded) if (gs_libxmlLoaded)
{ {
wxLogDebug("Releasing libxml.so.2");
wxDllLoader::UnloadLibrary(gs_libxmlDLL.Handle); wxDllLoader::UnloadLibrary(gs_libxmlDLL.Handle);
} }
gs_libxmlLoaded = FALSE; gs_libxmlLoaded = FALSE;
@@ -91,7 +90,6 @@ static bool LoadLibxml()
if (gs_libxmlLoadFailed) return FALSE; if (gs_libxmlLoadFailed) return FALSE;
gs_libxmlLoadFailed = TRUE; gs_libxmlLoadFailed = TRUE;
wxLogDebug("Loading libxml.so.2...");
{ {
wxLogNull lg; wxLogNull lg;
#ifdef __UNIX__ #ifdef __UNIX__
@@ -145,7 +143,6 @@ static bool LoadLibxml()
gs_libxmlLoadFailed = FALSE; gs_libxmlLoadFailed = FALSE;
wxLogDebug("...succeed");
return TRUE; return TRUE;
} }

View File

@@ -40,10 +40,10 @@ wxXmlResource::wxXmlResource()
m_Handlers.DeleteContents(TRUE); m_Handlers.DeleteContents(TRUE);
} }
wxXmlResource::wxXmlResource(const wxString& filemask, int type) wxXmlResource::wxXmlResource(const wxString& filemask)
{ {
m_Handlers.DeleteContents(TRUE); m_Handlers.DeleteContents(TRUE);
Load(filemask, type); Load(filemask);
} }
wxXmlResource::~wxXmlResource() wxXmlResource::~wxXmlResource()
@@ -52,10 +52,11 @@ wxXmlResource::~wxXmlResource()
} }
bool wxXmlResource::Load(const wxString& filemask, int type) bool wxXmlResource::Load(const wxString& filemask)
{ {
wxString fnd; wxString fnd;
wxXmlResourceDataRecord *drec; wxXmlResourceDataRecord *drec;
bool iswild = wxIsWild(filemask);
#if wxUSE_FILESYSTEM #if wxUSE_FILESYSTEM
wxFileSystem fsys; wxFileSystem fsys;
@@ -64,13 +65,16 @@ bool wxXmlResource::Load(const wxString& filemask, int type)
#else #else
# define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE) # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
# define wxXmlFindNext wxFindNextFile() # define wxXmlFindNext wxFindNextFile()
wxASSERT_MSG(type != wxXML_ARCHIVE, wxT("ZIP archive XML resources supported only with wxUSE_FILESYSTEM set to 1!"));
#endif #endif
fnd = wxXmlFindFirst; if (iswild)
fnd = wxXmlFindFirst;
else
fnd = filemask;
while (!!fnd) while (!!fnd)
{ {
#if wxUSE_FILESYSTEM #if wxUSE_FILESYSTEM
if (type == wxXML_ARCHIVE) if (filemask.Lower().Matches("*.zip") ||
filemask.Lower().Matches("*.rsc"))
{ {
wxFileSystem fs2; wxFileSystem fs2;
wxString fnd2; wxString fnd2;
@@ -91,7 +95,11 @@ bool wxXmlResource::Load(const wxString& filemask, int type)
drec->File = fnd; drec->File = fnd;
m_Data.Add(drec); m_Data.Add(drec);
} }
fnd = wxXmlFindNext;
if (iswild)
fnd = wxXmlFindNext;
else
fnd = wxEmptyString;
} }
# undef wxXmlFindFirst # undef wxXmlFindFirst
# undef wxXmlFindNext # undef wxXmlFindNext
@@ -249,12 +257,19 @@ void wxXmlResource::UpdateResources()
m_Data[i].Doc = new wxXmlDocument; m_Data[i].Doc = new wxXmlDocument;
} }
if (!stream || !m_Data[i].Doc->Load(*stream)) if (!stream || !m_Data[i].Doc->Load(*stream))
{
wxLogError(_("Cannot load resources from file '%s'."), m_Data[i].File.c_str()); wxLogError(_("Cannot load resources from file '%s'."), m_Data[i].File.c_str());
delete m_Data[i].Doc;
if (m_Data[i].Doc->GetRoot()->GetName() != _T("resource")) m_Data[i].Doc = NULL;
}
else if (m_Data[i].Doc->GetRoot()->GetName() != _T("resource"))
{
wxLogError(_("Invalid XML resource '%s': doesn't have root node 'resource'."), m_Data[i].File.c_str()); wxLogError(_("Invalid XML resource '%s': doesn't have root node 'resource'."), m_Data[i].File.c_str());
delete m_Data[i].Doc;
ProcessPlatformProperty(m_Data[i].Doc->GetRoot()); m_Data[i].Doc = NULL;
}
else
ProcessPlatformProperty(m_Data[i].Doc->GetRoot());
# if wxUSE_FILESYSTEM # if wxUSE_FILESYSTEM
delete file; delete file;
@@ -274,6 +289,7 @@ wxXmlNode *wxXmlResource::FindResource(const wxString& name, const wxString& typ
wxString dummy; wxString dummy;
for (size_t f = 0; f < m_Data.GetCount(); f++) for (size_t f = 0; f < m_Data.GetCount(); f++)
{ {
if (m_Data[f].Doc == NULL || m_Data[f].Doc->GetRoot() == NULL) continue;
for (wxXmlNode *node = m_Data[f].Doc->GetRoot()->GetChildren(); for (wxXmlNode *node = m_Data[f].Doc->GetRoot()->GetChildren();
node; node = node->GetNext()) node; node = node->GetNext())
if ( node->GetType() == wxXML_ELEMENT_NODE && if ( node->GetType() == wxXML_ELEMENT_NODE &&