Improve error reporting for IO errors in wxrc

Notably, give a clear error if an input file is not found and also check
that the temporary output file could have been written successfully.

Still continue handling the other files even if some of them couldn't be
found in order to give all errors at once if there is more than one
missing file.

(cherry picked from commit 13d8adb4e14c38dd7e8531f263d778dfbb0a0630)
This commit is contained in:
Vadim Zeitlin 2023-08-23 17:45:13 +02:00
parent afbf986bfc
commit dc7b887404

View File

@ -531,15 +531,37 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt
if (flagVerbose)
wxPrintf(wxT("adding ") + fullname + wxT("...\n"));
wxFileInputStream sin(fullname);
if (!sin)
{
// 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);
// 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
{
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: