+// Does 'node' contain filename information at all?
+static bool NodeContainsFilename(wxXmlNode *node)
+{
+ // Any bitmaps:
+ if (node->GetName() == _T("bitmap"))
+ return TRUE;
+
+ // URLs in wxHtmlWindow:
+ if (node->GetName() == _T("url"))
+ return TRUE;
+
+ // wxBitmapButton:
+ wxXmlNode *parent = node->GetParent();
+ if (parent != NULL &&
+ parent->GetPropVal(_T("class"), _T("")) == _T("wxBitmapButton") &&
+ (node->GetName() == _T("focus") ||
+ node->GetName() == _T("disabled") ||
+ node->GetName() == _T("selected")))
+ return TRUE;
+
+ // wxBitmap or wxIcon toplevel resources:
+ if (node->GetName() == _T("object"))
+ {
+ wxString klass = node->GetPropVal(_T("class"), wxEmptyString);
+ if (klass == _T("wxBitmap") || klass == _T("wxIcon"))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+// find all files mentioned in structure, e.g. <bitmap>filename</bitmap>
+void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath)
+{
+ // Is 'node' XML node element?
+ if (node == NULL) return;
+ if (node->GetType() != wxXML_ELEMENT_NODE) return;
+
+ bool containsFilename = NodeContainsFilename(node);
+
+ wxXmlNode *n = node->GetChildren();
+ while (n)
+ {
+ if (containsFilename &&
+ (n->GetType() == wxXML_TEXT_NODE ||
+ n->GetType() == wxXML_CDATA_SECTION_NODE))
+ {
+ wxString fullname;
+ if (wxIsAbsolutePath(n->GetContent()) || inputPath.empty())
+ fullname = n->GetContent();
+ else
+ fullname = inputPath + wxFILE_SEP_PATH + n->GetContent();
+
+ if (flagVerbose)
+ wxPrintf(_T("adding ") + fullname + _T("...\n"));
+
+ wxString filename = GetInternalFileName(n->GetContent(), flist);
+ n->SetContent(filename);
+
+ if (flist.Index(filename) == wxNOT_FOUND)
+ flist.Add(filename);
+
+ wxFileInputStream sin(fullname);
+ wxFileOutputStream sout(parOutputPath + wxFILE_SEP_PATH + filename);
+ sin.Read(sout); // copy the stream
+ }
+
+ // subnodes:
+ if (n->GetType() == wxXML_ELEMENT_NODE)
+ FindFilesInXML(n, flist, inputPath);
+
+ n = n->GetNext();
+ }
+}
+
+