From 13d8adb4e14c38dd7e8531f263d778dfbb0a0630 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 Aug 2023 17:45:13 +0200 Subject: [PATCH] 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. --- utils/wxrc/wxrc.cpp | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/utils/wxrc/wxrc.cpp b/utils/wxrc/wxrc.cpp index 795b59e753..c984a469b0 100644 --- a/utils/wxrc/wxrc.cpp +++ b/utils/wxrc/wxrc.cpp @@ -532,15 +532,37 @@ void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxSt if (flagVerbose) wxPrintf(wxT("adding %s...\n"), fullname); - 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 + 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); + } + } } // subnodes: