From 332ed4ab61da0cb49342087800c1d21fe1e348af Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 14 Oct 2020 11:22:49 -0400 Subject: [PATCH] Separate detection of module load failure from error messaging --- src/ModuleManager.cpp | 22 ++++++++++++++++------ src/ModuleManager.h | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/ModuleManager.cpp b/src/ModuleManager.cpp index 0a3d256e3..01fe1ca3d 100755 --- a/src/ModuleManager.cpp +++ b/src/ModuleManager.cpp @@ -95,8 +95,17 @@ Module::~Module() { } -bool Module::Load() +void Module::ShowLoadFailureError(const wxString &Error) { + auto ShortName = wxFileName(mName).GetName(); + AudacityMessageBox(XO("Unable to load the \"%s\" module.\n\nError: %s").Format(ShortName, Error), + XO("Module Unsuitable")); + wxLogMessage(wxT("Unable to load the module \"%s\". Error: %s"), mName, Error); +} + +bool Module::Load(wxString &deferredErrorMessage) +{ + deferredErrorMessage.clear(); // Will this ever happen??? if (mLib->IsLoaded()) { if (mDispatch) { @@ -110,10 +119,7 @@ bool Module::Load() auto ShortName = wxFileName(mName).GetName(); if (!mLib->Load(mName, wxDL_NOW | wxDL_QUIET | wxDL_GLOBAL)) { - auto Error = wxString(wxSysErrorMsg()); - AudacityMessageBox(XO("Unable to load the \"%s\" module.\n\nError: %s").Format(ShortName, Error), - XO("Module Unsuitable")); - wxLogMessage(wxT("Unable to load the module \"%s\". Error: %s"), mName, Error); + deferredErrorMessage = wxString(wxSysErrorMsg()); return false; } @@ -324,8 +330,9 @@ void ModuleManager::Initialize() ModulePrefs::SetModuleStatus( files[i], kModuleFailed ); #endif + wxString Error; auto umodule = std::make_unique(files[i]); - if (umodule->Load()) // it will get rejected if there are version problems + if (umodule->Load(Error)) // it will get rejected if there are version problems { auto module = umodule.get(); @@ -366,6 +373,9 @@ void ModuleManager::Initialize() #endif } } + else if (!Error.empty()) { + umodule->ShowLoadFailureError(Error); + } } ::wxSetWorkingDirectory(saveOldCWD); diff --git a/src/ModuleManager.h b/src/ModuleManager.h index 97f981b1f..cfce59e34 100644 --- a/src/ModuleManager.h +++ b/src/ModuleManager.h @@ -41,7 +41,8 @@ public: Module(const FilePath & name); virtual ~Module(); - bool Load(); + void ShowLoadFailureError(const wxString &Error); + bool Load(wxString &deferredErrorMessage); void Unload(); bool HasDispatch() { return mDispatch != NULL; }; int Dispatch(ModuleDispatchTypes type);