1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

more guarded calls

This commit is contained in:
Paul Licameli 2016-12-20 16:15:20 -05:00
parent 01c5f25a19
commit f508493561
3 changed files with 20 additions and 4 deletions

View File

@ -849,6 +849,11 @@ bool AudacityApp::MRUOpen(const wxString &fullPathStr) {
return(true); return(true);
} }
bool AudacityApp::SafeMRUOpen(const wxString &fullPathStr)
{
return GuardedCall< bool >( [&]{ return MRUOpen( fullPathStr ); } );
}
void AudacityApp::OnMRUClear(wxCommandEvent& WXUNUSED(event)) void AudacityApp::OnMRUClear(wxCommandEvent& WXUNUSED(event))
{ {
mRecentFiles->Clear(); mRecentFiles->Clear();
@ -866,13 +871,16 @@ void AudacityApp::OnMRUFile(wxCommandEvent& event) {
// because we don't want to RemoveFileFromHistory() just because it already exists, // because we don't want to RemoveFileFromHistory() just because it already exists,
// and AudacityApp::OnMacOpenFile() calls MRUOpen() directly. // and AudacityApp::OnMacOpenFile() calls MRUOpen() directly.
// that method does not return the bad result. // that method does not return the bad result.
// PRL: Don't call SafeMRUOpen
// -- if open fails for some exceptional reason of resource exhaustion that
// the user can correct, leave the file in history.
if (!AudacityProject::IsAlreadyOpen(fullPathStr) && !MRUOpen(fullPathStr)) if (!AudacityProject::IsAlreadyOpen(fullPathStr) && !MRUOpen(fullPathStr))
mRecentFiles->RemoveFileFromHistory(n); mRecentFiles->RemoveFileFromHistory(n);
} }
void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event)) void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
{ {
// Filenames are queued when Audacity receives the a few of the // Filenames are queued when Audacity receives a few of the
// AppleEvent messages (via wxWidgets). So, open any that are // AppleEvent messages (via wxWidgets). So, open any that are
// in the queue and clean the queue. // in the queue and clean the queue.
if (gInited) { if (gInited) {
@ -901,7 +909,9 @@ void AudacityApp::OnTimer(wxTimerEvent& WXUNUSED(event))
// LL: In all but one case an appropriate message is already displayed. The // LL: In all but one case an appropriate message is already displayed. The
// instance that a message is NOT displayed is when a failure to write // instance that a message is NOT displayed is when a failure to write
// to the config file has occurred. // to the config file has occurred.
if (!MRUOpen(name)) { // PRL: Catch any exceptions, don't try this file again, continue to
// other files.
if (!SafeMRUOpen(name)) {
wxFAIL_MSG(wxT("MRUOpen failed")); wxFAIL_MSG(wxT("MRUOpen failed"));
} }
} }
@ -1615,7 +1625,9 @@ bool AudacityApp::OnInit()
#if !defined(__WXMAC__) #if !defined(__WXMAC__)
for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++) for (size_t i = 0, cnt = parser->GetParamCount(); i < cnt; i++)
{ {
MRUOpen(parser->GetParam(i)); // PRL: Catch any exceptions, don't try this file again, continue to
// other files.
SafeMRUOpen(parser->GetParam(i));
} }
#endif #endif
} }

View File

@ -87,6 +87,8 @@ class AudacityApp final : public wxApp {
void OnMRUFile(wxCommandEvent &event); void OnMRUFile(wxCommandEvent &event);
// Backend for above - returns true for success, false for failure // Backend for above - returns true for success, false for failure
bool MRUOpen(const wxString &fileName); bool MRUOpen(const wxString &fileName);
// A wrapper of the above that does not throw
bool SafeMRUOpen(const wxString &fileName);
void OnReceiveCommand(AppCommandEvent &event); void OnReceiveCommand(AppCommandEvent &event);

View File

@ -2509,7 +2509,9 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
wxYES_NO | wxCANCEL | wxICON_QUESTION, wxYES_NO | wxCANCEL | wxICON_QUESTION,
this); this);
if (result == wxCANCEL || (result == wxYES && !Save())) { if (result == wxCANCEL || (result == wxYES &&
!GuardedCall<bool>( [&]{ return Save(); } )
)) {
event.Veto(); event.Veto();
return; return;
} }