Add support for multi-resolution bitmaps to wxrc

Handle multiple semicolon-separated paths in <bitmap> elements which are
used to provide several versions of the same bitmap in different
resolutions.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin 2023-08-23 18:03:03 +02:00
parent 13d8adb4e1
commit ab88fecdc5

View file

@ -523,46 +523,58 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt
(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(wxT("adding %s...\n"), fullname);
wxFileInputStream sin(fullname);
if (!sin)
// At least <bitmap> content can include several semi-colon
// separated paths corresponding to the different resolutions of
// the bitmap, so check for this.
wxArrayString internalNames;
const wxArrayString paths = wxSplit(n->GetContent(), ';', '\0');
for (size_t i = 0; i < paths.size(); ++i)
{
// Note that the full name was already given in the error
// message logged by wxFileInputStream itself, so don't repeat
// it here.
wxLogError("Failed to read file referenced by \"%s\" at %d",
node->GetName(), node->GetLineNumber());
retCode = 1;
}
else
{
wxString filename = GetInternalFileName(n->GetContent(), flist);
const wxString& path = paths[i];
// Copy the entire stream to the output file.
wxFileOutputStream sout(parOutputPath + wxFILE_SEP_PATH + filename);
if ( sin.Read(sout).GetLastError() != wxSTREAM_EOF || !sout )
wxString fullname;
if (wxIsAbsolutePath(path) || inputPath.empty())
fullname = path;
else
fullname = inputPath + wxFILE_SEP_PATH + path;
if (flagVerbose)
wxPrintf(wxT("adding %s...\n"), fullname);
wxFileInputStream sin(fullname);
if (!sin)
{
wxLogError("Failed to save \"%s\" referenced by \"%s\" at %d"
" to a temporary file",
fullname, node->GetName(), node->GetLineNumber());
// Note that the full name was already given in the error
// message logged by wxFileInputStream itself, so don't repeat
// it here.
wxLogError("Failed to read file referenced by \"%s\" at %d",
node->GetName(), node->GetLineNumber());
retCode = 1;
}
else
{
n->SetContent(filename);
wxString filename = GetInternalFileName(path, flist);
if (flist.Index(filename) == wxNOT_FOUND)
flist.Add(filename);
// Copy the entire stream to the output file.
wxFileOutputStream sout(parOutputPath + wxFILE_SEP_PATH + filename);
if ( sin.Read(sout).GetLastError() != wxSTREAM_EOF || !sout )
{
wxLogError("Failed to save \"%s\" referenced by \"%s\" at %d"
" to a temporary file",
fullname, node->GetName(), node->GetLineNumber());
retCode = 1;
}
else
{
internalNames.push_back(filename);
if (flist.Index(filename) == wxNOT_FOUND)
flist.Add(filename);
}
}
}
n->SetContent(wxJoin(internalNames, ';', '\0'));
}
// subnodes: