Define an AudacityException subclass for file errors

This commit is contained in:
Paul Licameli 2016-11-22 14:56:13 -05:00
parent f1cce8aa78
commit 195509a033
6 changed files with 107 additions and 0 deletions

View File

@ -1205,6 +1205,7 @@
28FE4A080ABF4E960056F5C4 /* mmx_optimized.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28FE4A060ABF4E960056F5C4 /* mmx_optimized.cpp */; };
28FE4A090ABF4E960056F5C4 /* sse_optimized.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28FE4A070ABF4E960056F5C4 /* sse_optimized.cpp */; };
5E02BFF21D1164DF00EB7578 /* Distortion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E02BFF01D1164DF00EB7578 /* Distortion.cpp */; };
5E07842E1DEE6B8600CA76EA /* FileException.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E07842C1DEE6B8600CA76EA /* FileException.cpp */; };
5E0A0E311D23019A00CD2567 /* MenusMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E0A0E301D23019A00CD2567 /* MenusMac.cpp */; };
5E74D2E31CC4429700D88B0B /* EditCursorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2DD1CC4429700D88B0B /* EditCursorOverlay.cpp */; };
5E74D2E41CC4429700D88B0B /* PlayIndicatorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2DF1CC4429700D88B0B /* PlayIndicatorOverlay.cpp */; };
@ -2979,6 +2980,8 @@
28FEC1B21A12B6FB00FACE48 /* EffectAutomationParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EffectAutomationParameters.h; path = ../include/audacity/EffectAutomationParameters.h; sourceTree = SOURCE_ROOT; };
5E02BFF01D1164DF00EB7578 /* Distortion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Distortion.cpp; sourceTree = "<group>"; };
5E02BFF11D1164DF00EB7578 /* Distortion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Distortion.h; sourceTree = "<group>"; };
5E07842C1DEE6B8600CA76EA /* FileException.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileException.cpp; sourceTree = "<group>"; };
5E07842D1DEE6B8600CA76EA /* FileException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileException.h; sourceTree = "<group>"; };
5E0A0E301D23019A00CD2567 /* MenusMac.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = MenusMac.cpp; sourceTree = "<group>"; };
5E4685F81CCA9D84008741F2 /* CommandFunctors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommandFunctors.h; sourceTree = "<group>"; };
5E61EE0C1CBAA6BB0009FCF1 /* MemoryX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryX.h; sourceTree = "<group>"; };
@ -3858,6 +3861,7 @@
1790B05F09883BFD008A330A /* Envelope.cpp */,
283135FD0DFBA2E80076D551 /* FFmpeg.cpp */,
1790B07009883BFD008A330A /* FFT.cpp */,
5E07842C1DEE6B8600CA76EA /* FileException.cpp */,
1790B07209883BFD008A330A /* FileFormats.cpp */,
2809C4B60BCB7E560006010F /* FileIO.cpp */,
28F00A900A3E2FF100A3E5F5 /* FileNames.cpp */,
@ -3948,6 +3952,7 @@
1790B06109883BFD008A330A /* Experimental.h */,
283135FE0DFBA2E80076D551 /* FFmpeg.h */,
1790B07109883BFD008A330A /* FFT.h */,
5E07842D1DEE6B8600CA76EA /* FileException.h */,
1790B07309883BFD008A330A /* FileFormats.h */,
2809C4B70BCB7E560006010F /* FileIO.h */,
28F00A910A3E2FF100A3E5F5 /* FileNames.h */,
@ -7519,6 +7524,7 @@
1841B50E0E00AD6E00F386E9 /* ODWaveTrackTaskQueue.cpp in Sources */,
1841B5110E00AD8D00F386E9 /* ODPCMAliasBlockFile.cpp in Sources */,
2860BA240E0F0D8600A13878 /* SoundActivatedRecord.cpp in Sources */,
5E07842E1DEE6B8600CA76EA /* FileException.cpp in Sources */,
2860BA250E0F0D8600A13878 /* TimerRecordDialog.cpp in Sources */,
2860BA280E0F0DD800A13878 /* ExportFFmpeg.cpp in Sources */,
28D587CB0E264CF4009C7DEA /* LoadLV2.cpp in Sources */,

45
src/FileException.cpp Normal file
View File

@ -0,0 +1,45 @@
//
// FileException.cpp
//
//
// Created by Paul Licameli on 11/22/16.
//
//
#include "Audacity.h"
#include "FileException.h"
FileException::~FileException()
{
}
std::unique_ptr< AudacityException > FileException::Move()
{
return std::unique_ptr< AudacityException >
{ safenew FileException{ std::move( *this ) } };
}
wxString FileException::ErrorMessage() const
{
wxString format;
switch (cause) {
case Cause::Open:
format = _("Audacity failed to open a file at %s.\n");
break;
case Cause::Read:
format = _("Audacity failed to read from a file at %s.\n");
break;
case Cause::Write:
format = _(
"Audacity failed to write to a file at %s.\nAttempt this operation again after removing unnecessary files.\nOne way to do that is with the Discard buttons in the History dialog.\nSee the View menu.");
break;
case Cause::Rename:
format = _(
"Audacity successfully wrote the file %s but failed to rename it as %s.");
default:
break;
}
return wxString::Format(
format, fileName.GetFullPath(), renameTarget.GetFullPath() );
}

46
src/FileException.h Normal file
View File

@ -0,0 +1,46 @@
//
// FileException.h
//
//
// Created by Paul Licameli on 11/22/16.
//
//
#ifndef __AUDACITY_FILE_EXCEPTION__
#define __AUDACITY_FILE_EXCEPTION__
#include "AudacityException.h"
#include <wx/filename.h>
class FileException /* not final */ : public MessageBoxException
{
public:
enum class Cause { Open, Read, Write, Rename };
explicit FileException
( Cause cause_, const wxFileName &fileName_,
const wxString &caption = wxString{},
const wxFileName &renameTarget_ = {})
: MessageBoxException{ caption }
, fileName{ fileName_ }, cause{ cause_ }, renameTarget{ renameTarget_ }
{}
FileException(FileException&& that)
: MessageBoxException(std::move(that))
{}
~FileException() override;
protected:
std::unique_ptr< AudacityException > Move() override;
// Format a default, internationalized error message for this exception.
wxString ErrorMessage() const override;
public:
Cause cause;
wxFileName fileName;
wxFileName renameTarget;
};
#endif

View File

@ -133,6 +133,8 @@ audacity_SOURCES = \
FFmpeg.h \
FFT.cpp \
FFT.h \
FileException.cpp \
FileException.h \
FileIO.cpp \
FileIO.h \
FileNames.cpp \

View File

@ -150,6 +150,7 @@
<ClCompile Include="..\..\..\src\Envelope.cpp" />
<ClCompile Include="..\..\..\src\FFmpeg.cpp" />
<ClCompile Include="..\..\..\src\FFT.cpp" />
<ClCompile Include="..\..\..\src\FileException.cpp" />
<ClCompile Include="..\..\..\src\FileFormats.cpp" />
<ClCompile Include="..\..\..\src\FileIO.cpp" />
<ClCompile Include="..\..\..\src\FileNames.cpp" />
@ -435,6 +436,7 @@
<ClInclude Include="..\..\..\src\effects\NoiseReduction.h" />
<ClInclude Include="..\..\..\src\effects\Phaser.h" />
<ClInclude Include="..\..\..\src\effects\VST\VSTControlMSW.h" />
<ClInclude Include="..\..\..\src\FileException.h" />
<ClInclude Include="..\..\..\src\import\FormatClassifier.h" />
<ClInclude Include="..\..\..\src\import\ImportForwards.h" />
<ClInclude Include="..\..\..\src\import\ImportGStreamer.h" />

View File

@ -893,6 +893,9 @@
<ClCompile Include="..\..\..\src\InconsistencyException.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\src\FileException.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\src\AboutDialog.h">
@ -1813,6 +1816,9 @@
<ClInclude Include="..\..\..\src\InconsistencyException.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\FileException.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\audacity.ico">