mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 08:30:06 +02:00
Bug 2229 - Audacity may fail to load a "bad" module silently, with no error message
This commit is contained in:
parent
203d801293
commit
ff20948d57
@ -97,48 +97,54 @@ Module::~Module()
|
|||||||
|
|
||||||
bool Module::Load()
|
bool Module::Load()
|
||||||
{
|
{
|
||||||
|
// Will this ever happen???
|
||||||
if (mLib->IsLoaded()) {
|
if (mLib->IsLoaded()) {
|
||||||
if (mDispatch) {
|
if (mDispatch) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Any messages should have already been generated the first time it was loaded.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mLib->Load(mName, wxDL_LAZY)) {
|
auto ShortName = wxFileName(mName).GetName();
|
||||||
|
|
||||||
|
if (!mLib->Load(mName, wxDL_LAZY | wxDL_QUIET)) {
|
||||||
|
auto Error = wxSysErrorMsgStr();
|
||||||
|
AudacityMessageBox(XO("Unable to load the \"%s\" module.\n\nError: %s").Format(ShortName, Error),
|
||||||
|
XO("Module Unsuitable"));
|
||||||
|
wxLogMessage(_("Unable to load the module \"%s\". Error: %s").Format(mName, Error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check version string matches. (For now, they must match exactly)
|
// Check version string matches. (For now, they must match exactly)
|
||||||
tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
|
tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
|
||||||
if (versionFn == NULL){
|
if (versionFn == NULL){
|
||||||
wxString ShortName = wxFileName( mName ).GetName();
|
|
||||||
AudacityMessageBox(
|
AudacityMessageBox(
|
||||||
XO(
|
XO("The module \"%s\" does not provide a version string.\n\nIt will not be loaded.")
|
||||||
"The module %s does not provide a version string.\nIt will not be loaded.")
|
|
||||||
.Format( ShortName),
|
.Format( ShortName),
|
||||||
XO("Module Unsuitable"));
|
XO("Module Unsuitable"));
|
||||||
wxLogMessage(wxString::Format(_("The module %s does not provide a version string. It will not be loaded."), mName));
|
wxLogMessage(wxString::Format(_("The module \"%s\" does not provide a version string. It will not be loaded."), mName));
|
||||||
mLib->Unload();
|
mLib->Unload();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString moduleVersion = versionFn();
|
wxString moduleVersion = versionFn();
|
||||||
if( moduleVersion != AUDACITY_VERSION_STRING) {
|
if( moduleVersion != AUDACITY_VERSION_STRING) {
|
||||||
wxString ShortName = wxFileName( mName ).GetName();
|
|
||||||
AudacityMessageBox(
|
AudacityMessageBox(
|
||||||
XO(
|
XO("The module \"%s\" is matched with Audacity version \"%s\".\n\nIt will not be loaded.")
|
||||||
"The module %s is matched with Audacity version %s.\n\nIt will not be loaded.")
|
|
||||||
.Format(ShortName, moduleVersion),
|
.Format(ShortName, moduleVersion),
|
||||||
XO("Module Unsuitable"));
|
XO("Module Unsuitable"));
|
||||||
wxLogMessage(wxString::Format(_("The module %s is matched with Audacity version %s. It will not be loaded."), mName, moduleVersion));
|
wxLogMessage(wxString::Format(_("The module \"%s\" is matched with Audacity version \"%s\". It will not be loaded."), mName, moduleVersion));
|
||||||
mLib->Unload();
|
mLib->Unload();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
|
mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
|
||||||
if (!mDispatch) {
|
if (!mDispatch) {
|
||||||
// Module does not provide a dispatch function...
|
// Module does not provide a dispatch function. Special case modules like this could be:
|
||||||
// That can be OK, as long as we never try to call it.
|
// (a) for scripting (RegScriptServerFunc entry point)
|
||||||
|
// (b) for hijacking the entire Audacity panel (MainPanelFunc entry point)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +156,13 @@ bool Module::Load()
|
|||||||
}
|
}
|
||||||
|
|
||||||
mDispatch = NULL;
|
mDispatch = NULL;
|
||||||
|
|
||||||
|
AudacityMessageBox(
|
||||||
|
XO("The module \"%s\" failed to initialize.\n\nIt will not be loaded.").Format(ShortName),
|
||||||
|
XO("Module Unsuitable"));
|
||||||
|
wxLogMessage(wxString::Format(_("The module \"%s\" failed to initialize.\nIt will not be loaded."), mName));
|
||||||
|
mLib->Unload();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,24 +318,45 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
|
|||||||
if (umodule->Load()) // it will get rejected if there are version problems
|
if (umodule->Load()) // it will get rejected if there are version problems
|
||||||
{
|
{
|
||||||
auto module = umodule.get();
|
auto module = umodule.get();
|
||||||
Get().mModules.push_back(std::move(umodule));
|
|
||||||
|
{
|
||||||
// We've loaded and initialised OK.
|
// We've loaded and initialised OK.
|
||||||
// So look for special case functions:
|
// So look for special case functions:
|
||||||
wxLogNull logNo; // Don't show wxWidgets errors if we can't do these. (Was: Fix bug 544.)
|
wxLogNull logNo; // Don't show wxWidgets errors if we can't do these. (Was: Fix bug 544.)
|
||||||
|
|
||||||
// (a) for scripting.
|
// (a) for scripting.
|
||||||
if (scriptFn == NULL)
|
if (scriptFn == NULL)
|
||||||
|
{
|
||||||
scriptFn = (tpRegScriptServerFunc)(module->GetSymbol(wxT(scriptFnName)));
|
scriptFn = (tpRegScriptServerFunc)(module->GetSymbol(wxT(scriptFnName)));
|
||||||
|
}
|
||||||
|
|
||||||
// (b) for hijacking the entire Audacity panel.
|
// (b) for hijacking the entire Audacity panel.
|
||||||
if (pPanelHijack == NULL)
|
if (pPanelHijack == NULL)
|
||||||
{
|
{
|
||||||
pPanelHijack = (tPanelFn)(module->GetSymbol(wxT(mainPanelFnName)));
|
pPanelHijack = (tPanelFn)(module->GetSymbol(wxT(mainPanelFnName)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!module->HasDispatch() && !scriptFn && !pPanelHijack)
|
||||||
|
{
|
||||||
|
auto ShortName = wxFileName(files[i]).GetName();
|
||||||
|
AudacityMessageBox(
|
||||||
|
XO("The module \"%s\" does not provide any of the required functions.\n\nIt will not be loaded.").Format(ShortName),
|
||||||
|
XO("Module Unsuitable"));
|
||||||
|
wxLogMessage(wxString::Format(_("The module \"%s\" does not provide any of the required functions. It will not be loaded."), files[i]));
|
||||||
|
module->Unload();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Get().mModules.push_back(std::move(umodule));
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
// Loaded successfully, restore the status.
|
// Loaded successfully, restore the status.
|
||||||
ModulePrefs::SetModuleStatus(files[i], iModuleStatus);
|
ModulePrefs::SetModuleStatus(files[i], iModuleStatus);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
::wxSetWorkingDirectory(saveOldCWD);
|
::wxSetWorkingDirectory(saveOldCWD);
|
||||||
|
|
||||||
// After loading all the modules, we may have a registered scripting function.
|
// After loading all the modules, we may have a registered scripting function.
|
||||||
|
@ -51,6 +51,7 @@ public:
|
|||||||
|
|
||||||
bool Load();
|
bool Load();
|
||||||
void Unload();
|
void Unload();
|
||||||
|
bool HasDispatch() { return mDispatch != NULL; };
|
||||||
int Dispatch(ModuleDispatchTypes type);
|
int Dispatch(ModuleDispatchTypes type);
|
||||||
void * GetSymbol(const wxString &name);
|
void * GetSymbol(const wxString &name);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user