commit 6c1beb460abc4664374bf7ec80757f64f1f106ab Author: Juergen Spitzmueller <sp...@lyx.org> Date: Wed Feb 12 13:24:26 2025 +0100
Improve error message with corrupted file if this underwent lyx2lyx (#13153) (cherry picked from commit e7171c951070b3e7cc66e645e59a1b31de20e67a) --- src/Buffer.cpp | 23 +++++++++++++++++------ src/Buffer.h | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index f9adc51ec7..9a22aa652d 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1231,7 +1231,8 @@ bool Buffer::readString(string const & s) } -Buffer::ReadStatus Buffer::readFile(FileName const & fn) +Buffer::ReadStatus Buffer::readFile(FileName const & fn, + string const ofn) { Lexer lex; if (!lex.setFile(fn)) { @@ -1251,7 +1252,7 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn) ReadStatus ret_clf = convertLyXFormat(fn, tmpFile, file_format); if (ret_clf != ReadSuccess) return ret_clf; - ret_clf = readFile(tmpFile); + ret_clf = readFile(tmpFile, fn.absFileName()); if (ret_clf == ReadSuccess) { d->file_format = file_format; d->need_format_backup = true; @@ -1264,10 +1265,20 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn) lyxvc().file_found_hook(d->filename); if (readDocument(lex)) { - Alert::error(_("Document format failure"), - bformat(_("%1$s ended unexpectedly, which means" - " that it is probably corrupted."), - from_utf8(fn.absFileName()))); + // if we have a lyx2lyx-converted document, tell user both + // the original file name and the converted's as the corruption + // might be in the latter only or in both (#13153). + docstring const msg = ofn.empty() + ? bformat(_("%1$s ended unexpectedly, which means" + " that it is probably corrupted."), + from_utf8(fn.absFileName())) + : bformat(_("The converted version of %1$s to current LyX format" + " ended unexpectedly, which means" + " that it is probably corrupted.\n" + "You can find the converted file at %2$s" + " while LyX is running."), + from_utf8(ofn), from_utf8(fn.absFileName())); + Alert::error(_("Document format failure"), msg); return ReadDocumentFailure; } diff --git a/src/Buffer.h b/src/Buffer.h index 824e10c890..dc2583629d 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -243,7 +243,8 @@ private: /// save checksum of the given file. void saveCheckSum() const; /// read a new file - ReadStatus readFile(support::FileName const & fn); + ReadStatus readFile(support::FileName const & fn, + std::string ofn = std::string()); /// Reads a file without header. /// \param par if != 0 insert the file. /// \return \c true if file is not completely read. -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs