From ab88fecdc568857e1ca0f00529dcd92dc71a164c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 Aug 2023 18:03:03 +0200 Subject: [PATCH] Add support for multi-resolution bitmaps to wxrc Handle multiple semicolon-separated paths in elements which are used to provide several versions of the same bitmap in different resolutions. This commit is best viewed ignoring whitespace-only changes. --- utils/wxrc/wxrc.cpp | 72 ++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/utils/wxrc/wxrc.cpp b/utils/wxrc/wxrc.cpp index c984a469b0..8e716505e7 100644 --- a/utils/wxrc/wxrc.cpp +++ b/utils/wxrc/wxrc.cpp @@ -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 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: