2020-08-25 14:06:08 +00:00
|
|
|
/*!
|
|
|
|
@file FileException.h
|
|
|
|
@brief MessageBoxException for failures of file operations
|
|
|
|
|
|
|
|
|
|
|
|
Created by Paul Licameli on 11/22/16.
|
|
|
|
|
|
|
|
*/
|
2016-11-22 19:56:13 +00:00
|
|
|
|
|
|
|
#ifndef __AUDACITY_FILE_EXCEPTION__
|
|
|
|
#define __AUDACITY_FILE_EXCEPTION__
|
|
|
|
|
|
|
|
#include "AudacityException.h"
|
2018-11-14 16:48:46 +00:00
|
|
|
#include <wx/filename.h> // wxFileName member variable
|
2016-11-22 19:56:13 +00:00
|
|
|
|
2020-08-25 14:06:08 +00:00
|
|
|
//! Thrown for failure of file or database operations in deeply nested places
|
2020-09-28 12:50:18 +00:00
|
|
|
class AUDACITY_DLL_API FileException /* not final */
|
|
|
|
: public MessageBoxException
|
2016-11-22 19:56:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-08-25 14:06:08 +00:00
|
|
|
//! Identifies file operation that failed
|
|
|
|
enum class Cause {
|
|
|
|
Open,
|
|
|
|
Read,
|
|
|
|
Write, //!< most important to detect when storage space is exhausted
|
|
|
|
Rename //!< involves two filenames
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit FileException(
|
|
|
|
Cause cause_, //!< What kind of file operation failed
|
|
|
|
const wxFileName &fileName_, //!< Which file suffered a failure
|
|
|
|
const TranslatableString &caption = XO("File Error"), //!< Shown in message box frame, not the main message
|
|
|
|
const wxFileName &renameTarget_ = {} //!< A second file name, only for renaming failure
|
|
|
|
)
|
2021-06-08 10:40:52 +00:00
|
|
|
// DV: We consider a FileException to be internal for now.
|
|
|
|
// We used to have some odd cases related to the read-only folder in 3.0.0,
|
|
|
|
// so it is good to have a full picture here.
|
2021-06-08 14:58:03 +00:00
|
|
|
// In case we see too many - we will tweak this behavior in the next release.
|
2021-06-08 10:40:52 +00:00
|
|
|
: MessageBoxException{ ExceptionType::Internal, caption }
|
2017-03-24 18:59:22 +00:00
|
|
|
, cause{ cause_ }, fileName{ fileName_ }, renameTarget{ renameTarget_ }
|
2016-11-22 19:56:13 +00:00
|
|
|
{}
|
|
|
|
|
2020-06-05 03:45:28 +00:00
|
|
|
FileException( const FileException &that )
|
|
|
|
: MessageBoxException( that )
|
2017-03-21 16:45:04 +00:00
|
|
|
, cause{ that.cause }
|
|
|
|
, fileName{ that.fileName }
|
|
|
|
, renameTarget{ that.renameTarget }
|
2016-11-22 19:56:13 +00:00
|
|
|
{}
|
|
|
|
|
2017-03-21 16:45:04 +00:00
|
|
|
FileException& operator= (FileException&&) PROHIBITED;
|
|
|
|
|
2016-11-22 19:56:13 +00:00
|
|
|
~FileException() override;
|
|
|
|
|
2020-12-06 19:20:02 +00:00
|
|
|
static TranslatableString WriteFailureMessage(const wxFileName &fileName);
|
2020-09-06 16:17:38 +00:00
|
|
|
|
2016-11-22 19:56:13 +00:00
|
|
|
protected:
|
2020-08-25 14:06:08 +00:00
|
|
|
//! %Format an error message appropriate for the @ref Cause.
|
2019-12-07 15:04:35 +00:00
|
|
|
TranslatableString ErrorMessage() const override;
|
2020-09-14 16:43:28 +00:00
|
|
|
wxString ErrorHelpUrl() const override;
|
2016-11-22 19:56:13 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
Cause cause;
|
|
|
|
wxFileName fileName;
|
|
|
|
wxFileName renameTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|