mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-27 06:07:59 +02:00
Exception safety in: importing functions...
... Side effects on preferences may persist even after errors.
This commit is contained in:
parent
0c8bedc59a
commit
0bb6a3d971
@ -5767,6 +5767,9 @@ void AudacityProject::OnImport()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PRL: This affects FFmpegImportPlugin::Open which resets the preference
|
||||||
|
// to false. Should it also be set to true on other paths that reach
|
||||||
|
// AudacityProject::Import ?
|
||||||
gPrefs->Write(wxT("/NewImportingSession"), true);
|
gPrefs->Write(wxT("/NewImportingSession"), true);
|
||||||
|
|
||||||
//sort selected files by OD status. Load non OD first so user can edit asap.
|
//sort selected files by OD status. Load non OD first so user can edit asap.
|
||||||
@ -5774,6 +5777,14 @@ void AudacityProject::OnImport()
|
|||||||
selectedFiles.Sort(CompareNoCaseFileName);
|
selectedFiles.Sort(CompareNoCaseFileName);
|
||||||
ODManager::Pauser pauser;
|
ODManager::Pauser pauser;
|
||||||
|
|
||||||
|
auto cleanup = finally( [&] {
|
||||||
|
gPrefs->Write(wxT("/LastOpenType"),wxT(""));
|
||||||
|
|
||||||
|
gPrefs->Flush();
|
||||||
|
|
||||||
|
HandleResize(); // Adjust scrollers for NEW track sizes.
|
||||||
|
} );
|
||||||
|
|
||||||
for (size_t ff = 0; ff < selectedFiles.GetCount(); ff++) {
|
for (size_t ff = 0; ff < selectedFiles.GetCount(); ff++) {
|
||||||
wxString fileName = selectedFiles[ff];
|
wxString fileName = selectedFiles[ff];
|
||||||
|
|
||||||
@ -5782,12 +5793,6 @@ void AudacityProject::OnImport()
|
|||||||
|
|
||||||
Import(fileName);
|
Import(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
gPrefs->Write(wxT("/LastOpenType"),wxT(""));
|
|
||||||
|
|
||||||
gPrefs->Flush();
|
|
||||||
|
|
||||||
HandleResize(); // Adjust scrollers for NEW track sizes.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityProject::OnImportLabels()
|
void AudacityProject::OnImportLabels()
|
||||||
|
@ -452,17 +452,16 @@ public:
|
|||||||
return GuardedCall< bool > ( [&] {
|
return GuardedCall< bool > ( [&] {
|
||||||
//sort by OD non OD. load Non OD first so user can start editing asap.
|
//sort by OD non OD. load Non OD first so user can start editing asap.
|
||||||
wxArrayString sortednames(filenames);
|
wxArrayString sortednames(filenames);
|
||||||
|
sortednames.Sort(CompareNoCaseFileName);
|
||||||
|
|
||||||
ODManager::Pauser pauser;
|
ODManager::Pauser pauser;
|
||||||
|
|
||||||
sortednames.Sort(CompareNoCaseFileName);
|
auto cleanup = finally( [&] {
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sortednames.GetCount(); i++) {
|
|
||||||
|
|
||||||
mProject->Import(sortednames[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mProject->HandleResize(); // Adjust scrollers for NEW track sizes.
|
mProject->HandleResize(); // Adjust scrollers for NEW track sizes.
|
||||||
|
} );
|
||||||
|
|
||||||
|
for (const auto &name : sortednames)
|
||||||
|
mProject->Import(name);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} );
|
} );
|
||||||
@ -4081,33 +4080,10 @@ bool AudacityProject::Import(const wxString &fileName, WaveTrackArray* pTrackArr
|
|||||||
TrackHolders newTracks;
|
TrackHolders newTracks;
|
||||||
wxString errorMessage = wxEmptyString;
|
wxString errorMessage = wxEmptyString;
|
||||||
|
|
||||||
|
{
|
||||||
// Backup Tags, before the import. Be prepared to roll back changes.
|
// Backup Tags, before the import. Be prepared to roll back changes.
|
||||||
struct TempTags {
|
auto cleanup = valueRestorer( mTags,
|
||||||
TempTags(std::shared_ptr<Tags> & pTags_)
|
mTags ? mTags->Duplicate() : decltype(mTags){} );
|
||||||
: pTags(pTags_)
|
|
||||||
{
|
|
||||||
oldTags = pTags;
|
|
||||||
if (oldTags)
|
|
||||||
pTags = oldTags->Duplicate();
|
|
||||||
}
|
|
||||||
|
|
||||||
~TempTags()
|
|
||||||
{
|
|
||||||
if (oldTags) {
|
|
||||||
// roll back
|
|
||||||
pTags = oldTags;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Commit()
|
|
||||||
{
|
|
||||||
oldTags.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Tags> & pTags;
|
|
||||||
std::shared_ptr<Tags> oldTags;
|
|
||||||
};
|
|
||||||
TempTags tempTags(mTags);
|
|
||||||
|
|
||||||
bool success = Importer::Get().Import(fileName,
|
bool success = Importer::Get().Import(fileName,
|
||||||
GetTrackFactory(),
|
GetTrackFactory(),
|
||||||
@ -4116,10 +4092,10 @@ bool AudacityProject::Import(const wxString &fileName, WaveTrackArray* pTrackArr
|
|||||||
errorMessage);
|
errorMessage);
|
||||||
|
|
||||||
if (!errorMessage.IsEmpty()) {
|
if (!errorMessage.IsEmpty()) {
|
||||||
// Version that goes to internet...
|
// Version that goes to internet...
|
||||||
// ShowErrorDialog(this, _("Error Importing"),
|
// ShowErrorDialog(this, _("Error Importing"),
|
||||||
// errorMessage, wxT("http://audacity.sourceforge.net/help/faq?s=files&i=wma-proprietary"));
|
// errorMessage, wxT("http://audacity.sourceforge.net/help/faq?s=files&i=wma-proprietary"));
|
||||||
// Version that looks locally for the text.
|
// Version that looks locally for the text.
|
||||||
ShowErrorDialog(this, _("Error Importing"),
|
ShowErrorDialog(this, _("Error Importing"),
|
||||||
errorMessage, wxT("innerlink:wma-proprietary"));
|
errorMessage, wxT("innerlink:wma-proprietary"));
|
||||||
}
|
}
|
||||||
@ -4128,8 +4104,9 @@ bool AudacityProject::Import(const wxString &fileName, WaveTrackArray* pTrackArr
|
|||||||
|
|
||||||
wxGetApp().AddFileToHistory(fileName);
|
wxGetApp().AddFileToHistory(fileName);
|
||||||
|
|
||||||
// no more errors
|
// no more errors, commit
|
||||||
tempTags.Commit();
|
cleanup.release();
|
||||||
|
}
|
||||||
|
|
||||||
// for LOF ("list of files") files, do not import the file as if it
|
// for LOF ("list of files") files, do not import the file as if it
|
||||||
// were an audio file itself
|
// were an audio file itself
|
||||||
|
@ -336,7 +336,7 @@ bool Importer::Import(const wxString &fName,
|
|||||||
wxString &errorMessage)
|
wxString &errorMessage)
|
||||||
{
|
{
|
||||||
AudacityProject *pProj = GetActiveProject();
|
AudacityProject *pProj = GetActiveProject();
|
||||||
pProj->mbBusyImporting = true;
|
auto cleanup = valueRestorer( pProj->mbBusyImporting, true );
|
||||||
|
|
||||||
wxString extension = fName.AfterLast(wxT('.'));
|
wxString extension = fName.AfterLast(wxT('.'));
|
||||||
|
|
||||||
@ -509,7 +509,6 @@ bool Importer::Import(const wxString &fName,
|
|||||||
|
|
||||||
if (ImportDlg.ShowModal() == wxID_CANCEL)
|
if (ImportDlg.ShowModal() == wxID_CANCEL)
|
||||||
{
|
{
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -524,21 +523,18 @@ bool Importer::Import(const wxString &fName,
|
|||||||
// LOF ("list-of-files") has different semantics
|
// LOF ("list-of-files") has different semantics
|
||||||
if (extension.IsSameAs(wxT("lof"), false))
|
if (extension.IsSameAs(wxT("lof"), false))
|
||||||
{
|
{
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tracks.size() > 0)
|
if (tracks.size() > 0)
|
||||||
{
|
{
|
||||||
// success!
|
// success!
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == ProgressResult::Cancelled || res == ProgressResult::Failed)
|
if (res == ProgressResult::Cancelled || res == ProgressResult::Failed)
|
||||||
{
|
{
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +556,6 @@ bool Importer::Import(const wxString &fName,
|
|||||||
errorMessage.Printf(_("This version of Audacity was not compiled with %s support."),
|
errorMessage.Printf(_("This version of Audacity was not compiled with %s support."),
|
||||||
unusableImportPlugin->
|
unusableImportPlugin->
|
||||||
GetPluginFormatDescription().c_str());
|
GetPluginFormatDescription().c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,7 +566,6 @@ bool Importer::Import(const wxString &fName,
|
|||||||
// MIDI files must be imported, not opened
|
// MIDI files must be imported, not opened
|
||||||
if ((extension.IsSameAs(wxT("midi"), false))||(extension.IsSameAs(wxT("mid"), false))) {
|
if ((extension.IsSameAs(wxT("midi"), false))||(extension.IsSameAs(wxT("mid"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" \nis a MIDI file, not an audio file. \nAudacity cannot open this type of file for playing, but you can\nedit it by clicking File > Import > MIDI."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -582,87 +576,74 @@ bool Importer::Import(const wxString &fName,
|
|||||||
if (extension.IsSameAs(wxT("cda"), false)) {
|
if (extension.IsSameAs(wxT("cda"), false)) {
|
||||||
/* i18n-hint: %s will be the filename */
|
/* i18n-hint: %s will be the filename */
|
||||||
errorMessage.Printf(_("\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is an audio CD track. \nAudacity cannot open audio CDs directly. \nExtract (rip) the CD tracks to an audio format that \nAudacity can import, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// playlist type files
|
// playlist type files
|
||||||
if ((extension.IsSameAs(wxT("m3u"), false))||(extension.IsSameAs(wxT("ram"), false))||(extension.IsSameAs(wxT("pls"), false))) {
|
if ((extension.IsSameAs(wxT("m3u"), false))||(extension.IsSameAs(wxT("ram"), false))||(extension.IsSameAs(wxT("pls"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a playlist file. \nAudacity cannot open this file because it only contains links to other files. \nYou may be able to open it in a text editor and download the actual audio files."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//WMA files of various forms
|
//WMA files of various forms
|
||||||
if ((extension.IsSameAs(wxT("wma"), false))||(extension.IsSameAs(wxT("asf"), false))) {
|
if ((extension.IsSameAs(wxT("wma"), false))||(extension.IsSameAs(wxT("asf"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a Windows Media Audio file. \nAudacity cannot open this type of file due to patent restrictions. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//AAC files of various forms (probably not encrypted)
|
//AAC files of various forms (probably not encrypted)
|
||||||
if ((extension.IsSameAs(wxT("aac"), false))||(extension.IsSameAs(wxT("m4a"), false))||(extension.IsSameAs(wxT("m4r"), false))||(extension.IsSameAs(wxT("mp4"), false))) {
|
if ((extension.IsSameAs(wxT("aac"), false))||(extension.IsSameAs(wxT("m4a"), false))||(extension.IsSameAs(wxT("m4r"), false))||(extension.IsSameAs(wxT("mp4"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is an Advanced Audio Coding file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is an Advanced Audio Coding file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// encrypted itunes files
|
// encrypted itunes files
|
||||||
if ((extension.IsSameAs(wxT("m4p"), false))) {
|
if ((extension.IsSameAs(wxT("m4p"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is an encrypted audio file. \nThese typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is an encrypted audio file. \nThese typically are from an online music store. \nAudacity cannot open this type of file due to the encryption. \nTry recording the file into Audacity, or burn it to audio CD then \nextract the CD track to a supported audio format such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Real Inc. files of various sorts
|
// Real Inc. files of various sorts
|
||||||
if ((extension.IsSameAs(wxT("ra"), false))||(extension.IsSameAs(wxT("rm"), false))||(extension.IsSameAs(wxT("rpm"), false))) {
|
if ((extension.IsSameAs(wxT("ra"), false))||(extension.IsSameAs(wxT("rm"), false))||(extension.IsSameAs(wxT("rpm"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a RealPlayer media file. \nAudacity cannot open this proprietary format. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other notes-based formats
|
// Other notes-based formats
|
||||||
if ((extension.IsSameAs(wxT("kar"), false))||(extension.IsSameAs(wxT("mod"), false))||(extension.IsSameAs(wxT("rmi"), false))) {
|
if ((extension.IsSameAs(wxT("kar"), false))||(extension.IsSameAs(wxT("mod"), false))||(extension.IsSameAs(wxT("rmi"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a notes-based file, not an audio file. \nAudacity cannot open this type of file. \nTry converting it to an audio file such as WAV or AIFF and \nthen import it, or record it into Audacity."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a notes-based file, not an audio file. \nAudacity cannot open this type of file. \nTry converting it to an audio file such as WAV or AIFF and \nthen import it, or record it into Audacity."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MusePack files
|
// MusePack files
|
||||||
if ((extension.IsSameAs(wxT("mp+"), false))||(extension.IsSameAs(wxT("mpc"), false))||(extension.IsSameAs(wxT("mpp"), false))) {
|
if ((extension.IsSameAs(wxT("mp+"), false))||(extension.IsSameAs(wxT("mpc"), false))||(extension.IsSameAs(wxT("mpp"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a Musepack audio file. \nAudacity cannot open this type of file. \nIf you think it might be an mp3 file, rename it to end with \".mp3\" \nand try importing it again. Otherwise you need to convert it to a supported audio \nformat, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a Musepack audio file. \nAudacity cannot open this type of file. \nIf you think it might be an mp3 file, rename it to end with \".mp3\" \nand try importing it again. Otherwise you need to convert it to a supported audio \nformat, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// WavPack files
|
// WavPack files
|
||||||
if ((extension.IsSameAs(wxT("wv"), false))||(extension.IsSameAs(wxT("wvc"), false))) {
|
if ((extension.IsSameAs(wxT("wv"), false))||(extension.IsSameAs(wxT("wvc"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a Wavpack audio file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a Wavpack audio file. \nAudacity cannot open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AC3 files
|
// AC3 files
|
||||||
if ((extension.IsSameAs(wxT("ac3"), false))) {
|
if ((extension.IsSameAs(wxT("ac3"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a Dolby Digital audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a Dolby Digital audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speex files
|
// Speex files
|
||||||
if ((extension.IsSameAs(wxT("spx"), false))) {
|
if ((extension.IsSameAs(wxT("spx"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is an Ogg Speex audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is an Ogg Speex audio file. \nAudacity cannot currently open this type of file. \nYou need to convert it to a supported audio format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Video files of various forms
|
// Video files of various forms
|
||||||
if ((extension.IsSameAs(wxT("mpg"), false))||(extension.IsSameAs(wxT("mpeg"), false))||(extension.IsSameAs(wxT("avi"), false))||(extension.IsSameAs(wxT("wmv"), false))||(extension.IsSameAs(wxT("rv"), false))) {
|
if ((extension.IsSameAs(wxT("mpg"), false))||(extension.IsSameAs(wxT("mpeg"), false))||(extension.IsSameAs(wxT("avi"), false))||(extension.IsSameAs(wxT("wmv"), false))||(extension.IsSameAs(wxT("rv"), false))) {
|
||||||
errorMessage.Printf(_("\"%s\" is a video file. \nAudacity cannot currently open this type of file. \nYou need to extract the audio to a supported format, such as WAV or AIFF."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is a video file. \nAudacity cannot currently open this type of file. \nYou need to extract the audio to a supported format, such as WAV or AIFF."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Audacity project
|
// Audacity project
|
||||||
if (extension.IsSameAs(wxT("aup"), false)) {
|
if (extension.IsSameAs(wxT("aup"), false)) {
|
||||||
errorMessage.Printf(_("\"%s\" is an Audacity Project file. \nUse the 'File > Open' command to open Audacity Projects."), fName.c_str());
|
errorMessage.Printf(_("\"%s\" is an Audacity Project file. \nUse the 'File > Open' command to open Audacity Projects."), fName.c_str());
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,7 +666,6 @@ bool Importer::Import(const wxString &fName,
|
|||||||
errorMessage.Printf(_("Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format."),fName.c_str(), pluglist.c_str());
|
errorMessage.Printf(_("Audacity recognized the type of the file '%s'.\nImporters supposedly supporting such files are:\n%s,\nbut none of them understood this file format."),fName.c_str(), pluglist.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
pProj->mbBusyImporting = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user