From f07fd5d8bc8d5e0bb3e518237735a2b18563c54d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 6 Dec 2020 14:20:02 -0500 Subject: [PATCH] Export failure messages name the file, exactly as with FileException --- src/FileException.cpp | 16 ++++++++++------ src/FileException.h | 1 + src/export/Export.cpp | 7 ++----- src/export/Export.h | 2 +- src/export/ExportFFmpeg.cpp | 4 ++-- src/export/ExportFLAC.cpp | 2 +- src/export/ExportMP2.cpp | 2 +- src/export/ExportMP3.cpp | 2 +- src/export/ExportOGG.cpp | 2 +- 9 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/FileException.cpp b/src/FileException.cpp index 9fe108b5e..2ca091889 100644 --- a/src/FileException.cpp +++ b/src/FileException.cpp @@ -27,12 +27,7 @@ TranslatableString FileException::ErrorMessage() const format = XO("Audacity failed to read from a file in %s."); break; case Cause::Write: - format = - XO("Audacity failed to write to a file.\n" - "Perhaps %s is not writable or the disk is full.\n" - "For tips on freeing up space, click the help button." - ); - break; + return WriteFailureMessage(fileName); case Cause::Rename: format = XO("Audacity successfully wrote a file in %s but failed to rename it as %s."); @@ -82,3 +77,12 @@ wxString FileException::AbbreviatePath( const wxFileName &fileName ) #endif return target; } + +TranslatableString +FileException::WriteFailureMessage(const wxFileName &fileName) +{ + return XO("Audacity failed to write to a file.\n" + "Perhaps %s is not writable or the disk is full.\n" + "For tips on freeing up space, click the help button." + ).Format(AbbreviatePath(fileName)); +} diff --git a/src/FileException.h b/src/FileException.h index 388763724..3bd1d1979 100644 --- a/src/FileException.h +++ b/src/FileException.h @@ -47,6 +47,7 @@ public: ~FileException() override; static wxString AbbreviatePath(const wxFileName &fileName); + static TranslatableString WriteFailureMessage(const wxFileName &fileName); protected: //! %Format an error message appropriate for the @ref Cause. diff --git a/src/export/Export.cpp b/src/export/Export.cpp index ae977a722..9fb7e1655 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -1526,14 +1526,11 @@ void ShowExportErrorDialog(wxString ErrorCode, ); } -void ShowDiskFullExportErrorDialog() +void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName) { ShowErrorDialog(nullptr, XO("Warning"), - XO("Audacity failed to write to a file.\n" - "Perhaps the file is not writable or the disk is full.\n" - "For tips on freeing up space, click the help button." - ), + FileException::WriteFailureMessage(fileName), "Error:_Disk_full_or_not_writable" ); } diff --git a/src/export/Export.h b/src/export/Export.h index c5199e4bf..7aa2acd9c 100644 --- a/src/export/Export.h +++ b/src/export/Export.h @@ -332,6 +332,6 @@ void ShowExportErrorDialog(wxString ErrorCode, TranslatableString message = AudacityExportMessageStr(), const TranslatableString& caption = AudacityExportCaptionStr()); -void ShowDiskFullExportErrorDialog(); +void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName); #endif diff --git a/src/export/ExportFFmpeg.cpp b/src/export/ExportFFmpeg.cpp index 283fabfb6..1d1342ddd 100644 --- a/src/export/ExportFFmpeg.cpp +++ b/src/export/ExportFFmpeg.cpp @@ -958,7 +958,7 @@ bool ExportFFmpeg::EncodeAudioFrame(int16_t *pFrame, size_t frameSize) // Write the encoded audio frame to the output file. if ((ret = av_interleaved_write_frame(mEncFormatCtx.get(), &pkt)) < 0) { - ShowDiskFullExportErrorDialog(); + ShowDiskFullExportErrorDialog(mName); return false; } } @@ -1038,7 +1038,7 @@ ProgressResult ExportFFmpeg::Export(AudacityProject *project, if (!EncodeAudioFrame( pcmBuffer, (pcmNumSamples)*sizeof(int16_t)*mChannels)) { // All errors should already have been reported. - //ShowDiskFullExportErrorDialog(); + //ShowDiskFullExportErrorDialog(mName); updateResult = ProgressResult::Cancelled; break; } diff --git a/src/export/ExportFLAC.cpp b/src/export/ExportFLAC.cpp index 8f6b9ff91..3a909045c 100644 --- a/src/export/ExportFLAC.cpp +++ b/src/export/ExportFLAC.cpp @@ -407,7 +407,7 @@ ProgressResult ExportFLAC::Export(AudacityProject *project, reinterpret_cast( tmpsmplbuf.get() ), samplesThisRun) ) { // TODO: more precise message - ShowDiskFullExportErrorDialog(); + ShowDiskFullExportErrorDialog(fName); updateResult = ProgressResult::Cancelled; break; } diff --git a/src/export/ExportMP2.cpp b/src/export/ExportMP2.cpp index 6f7967269..9770781c7 100644 --- a/src/export/ExportMP2.cpp +++ b/src/export/ExportMP2.cpp @@ -342,7 +342,7 @@ ProgressResult ExportMP2::Export(AudacityProject *project, if ( outFile.Write(mp2Buffer.get(), mp2BufferNumBytes).GetLastError() ) { // TODO: more precise message - ShowDiskFullExportErrorDialog(); + ShowDiskFullExportErrorDialog(fName); return ProgressResult::Cancelled; } diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index d7b067d43..bb5c46cc8 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -1963,7 +1963,7 @@ ProgressResult ExportMP3::Export(AudacityProject *project, if (bytes > (int)outFile.Write(buffer.get(), bytes)) { // TODO: more precise message - ShowDiskFullExportErrorDialog(); + ShowDiskFullExportErrorDialog(fName); updateResult = ProgressResult::Cancelled; break; } diff --git a/src/export/ExportOGG.cpp b/src/export/ExportOGG.cpp index 129ecf6f8..fe1510fa8 100644 --- a/src/export/ExportOGG.cpp +++ b/src/export/ExportOGG.cpp @@ -338,7 +338,7 @@ ProgressResult ExportOGG::Export(AudacityProject *project, if ( outFile.Write(page.header, page.header_len).GetLastError() || outFile.Write(page.body, page.body_len).GetLastError()) { // TODO: more precise message - ShowDiskFullExportErrorDialog(); + ShowDiskFullExportErrorDialog(fName); return ProgressResult::Cancelled; }