mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 09:20:16 +01:00
Some factoring of ModuleManager::Initialize
This commit is contained in:
@@ -237,22 +237,20 @@ ModuleManager::~ModuleManager()
|
|||||||
builtinModuleList().clear();
|
builtinModuleList().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ModuleManager::Initialize()
|
void ModuleManager::FindModules(FilePaths &files)
|
||||||
{
|
{
|
||||||
const auto &audacityPathList = FileNames::AudacityPathList();
|
const auto &audacityPathList = FileNames::AudacityPathList();
|
||||||
FilePaths pathList;
|
FilePaths pathList;
|
||||||
FilePaths files;
|
|
||||||
wxString pathVar;
|
wxString pathVar;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
// Code from LoadLadspa that might be useful in load modules.
|
// Code from LoadLadspa that might be useful in load modules.
|
||||||
pathVar = wxGetenv(wxT("AUDACITY_MODULES_PATH"));
|
pathVar = wxGetenv(wxT("AUDACITY_MODULES_PATH"));
|
||||||
if (!pathVar.empty())
|
if (!pathVar.empty())
|
||||||
FileNames::AddMultiPathsToPathList(pathVar, pathList);
|
FileNames::AddMultiPathsToPathList(pathVar, pathList);
|
||||||
|
|
||||||
for (i = 0; i < audacityPathList.size(); i++) {
|
for (const auto &path : audacityPathList) {
|
||||||
wxString prefix = audacityPathList[i] + wxFILE_SEP_PATH;
|
wxString prefix = path + wxFILE_SEP_PATH;
|
||||||
FileNames::AddUniquePathToPathList(prefix + wxT("modules"),
|
FileNames::AddUniquePathToPathList(prefix + wxT("modules"),
|
||||||
pathList);
|
pathList);
|
||||||
if (files.size()) {
|
if (files.size()) {
|
||||||
@@ -265,25 +263,29 @@ void ModuleManager::Initialize()
|
|||||||
#else
|
#else
|
||||||
FileNames::FindFilesInPathList(wxT("*.so"), pathList, files);
|
FileNames::FindFilesInPathList(wxT("*.so"), pathList, files);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModuleManager::TryLoadModules(const FilePaths &files)
|
||||||
|
{
|
||||||
FilePaths checked;
|
FilePaths checked;
|
||||||
wxString saveOldCWD = ::wxGetCwd();
|
wxString saveOldCWD = ::wxGetCwd();
|
||||||
for (i = 0; i < files.size(); i++) {
|
auto cleanup = finally([&]{ ::wxSetWorkingDirectory(saveOldCWD); });
|
||||||
|
for (const auto &file : files) {
|
||||||
// As a courtesy to some modules that might be bridges to
|
// As a courtesy to some modules that might be bridges to
|
||||||
// open other modules, we set the current working
|
// open other modules, we set the current working
|
||||||
// directory to be the module's directory.
|
// directory to be the module's directory.
|
||||||
auto prefix = ::wxPathOnly(files[i]);
|
auto prefix = ::wxPathOnly(file);
|
||||||
::wxSetWorkingDirectory(prefix);
|
::wxSetWorkingDirectory(prefix);
|
||||||
|
|
||||||
// Only process the first module encountered in the
|
// Only process the first module encountered in the
|
||||||
// defined search sequence.
|
// defined search sequence.
|
||||||
wxString ShortName = wxFileName( files[i] ).GetName();
|
wxString ShortName = wxFileName( file ).GetName();
|
||||||
if( checked.Index( ShortName, false ) != wxNOT_FOUND )
|
if( checked.Index( ShortName, false ) != wxNOT_FOUND )
|
||||||
continue;
|
continue;
|
||||||
checked.Add( ShortName );
|
checked.Add( ShortName );
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
int iModuleStatus = ModulePrefs::GetModuleStatus( files[i] );
|
int iModuleStatus = ModulePrefs::GetModuleStatus( file );
|
||||||
if( iModuleStatus == kModuleDisabled )
|
if( iModuleStatus == kModuleDisabled )
|
||||||
continue;
|
continue;
|
||||||
if( iModuleStatus == kModuleFailed )
|
if( iModuleStatus == kModuleFailed )
|
||||||
@@ -292,7 +294,7 @@ void ModuleManager::Initialize()
|
|||||||
if( iModuleStatus == kModuleNew ){
|
if( iModuleStatus == kModuleNew ){
|
||||||
// To ensure it is noted in config file and so
|
// To ensure it is noted in config file and so
|
||||||
// appears on modules page.
|
// appears on modules page.
|
||||||
ModulePrefs::SetModuleStatus( files[i], kModuleNew);
|
ModulePrefs::SetModuleStatus( file, kModuleNew);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,13 +313,13 @@ void ModuleManager::Initialize()
|
|||||||
action = ShowMultiDialog(msg, XO("Audacity Module Loader"),
|
action = ShowMultiDialog(msg, XO("Audacity Module Loader"),
|
||||||
buttons,
|
buttons,
|
||||||
"",
|
"",
|
||||||
XO("Try and load this module?"),
|
XO("Try and load this module?"),
|
||||||
false);
|
false);
|
||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
// If we're not prompting always, accept the answer permanently
|
// If we're not prompting always, accept the answer permanently
|
||||||
if( iModuleStatus == kModuleNew ){
|
if( iModuleStatus == kModuleNew ){
|
||||||
iModuleStatus = (action==1)?kModuleDisabled : kModuleEnabled;
|
iModuleStatus = (action==1)?kModuleDisabled : kModuleEnabled;
|
||||||
ModulePrefs::SetModuleStatus( files[i], iModuleStatus );
|
ModulePrefs::SetModuleStatus( file, iModuleStatus );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(action == 1){ // "No"
|
if(action == 1){ // "No"
|
||||||
@@ -327,11 +329,11 @@ void ModuleManager::Initialize()
|
|||||||
#ifdef EXPERIMENTAL_MODULE_PREFS
|
#ifdef EXPERIMENTAL_MODULE_PREFS
|
||||||
// Before attempting to load, we set the state to bad.
|
// Before attempting to load, we set the state to bad.
|
||||||
// That way, if we crash, we won't try again.
|
// That way, if we crash, we won't try again.
|
||||||
ModulePrefs::SetModuleStatus( files[i], kModuleFailed );
|
ModulePrefs::SetModuleStatus( file, kModuleFailed );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxString Error;
|
wxString Error;
|
||||||
auto umodule = std::make_unique<Module>(files[i]);
|
auto umodule = std::make_unique<Module>(file);
|
||||||
if (umodule->Load(Error)) // 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();
|
auto module = umodule.get();
|
||||||
@@ -356,11 +358,11 @@ void ModuleManager::Initialize()
|
|||||||
|
|
||||||
if (!module->HasDispatch() && !scriptFn && !pPanelHijack)
|
if (!module->HasDispatch() && !scriptFn && !pPanelHijack)
|
||||||
{
|
{
|
||||||
auto ShortName = wxFileName(files[i]).GetName();
|
auto ShortName = wxFileName(file).GetName();
|
||||||
AudacityMessageBox(
|
AudacityMessageBox(
|
||||||
XO("The module \"%s\" does not provide any of the required functions.\n\nIt will not be loaded.").Format(ShortName),
|
XO("The module \"%s\" does not provide any of the required functions.\n\nIt will not be loaded.").Format(ShortName),
|
||||||
XO("Module Unsuitable"));
|
XO("Module Unsuitable"));
|
||||||
wxLogMessage(wxT("The module \"%s\" does not provide any of the required functions. It will not be loaded."), files[i]);
|
wxLogMessage(wxT("The module \"%s\" does not provide any of the required functions. It will not be loaded."), file);
|
||||||
module->Unload();
|
module->Unload();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -369,7 +371,7 @@ void ModuleManager::Initialize()
|
|||||||
|
|
||||||
#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(file, iModuleStatus);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +379,15 @@ void ModuleManager::Initialize()
|
|||||||
umodule->ShowLoadFailureError(Error);
|
umodule->ShowLoadFailureError(Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
::wxSetWorkingDirectory(saveOldCWD);
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void ModuleManager::Initialize()
|
||||||
|
{
|
||||||
|
FilePaths files;
|
||||||
|
FindModules(files);
|
||||||
|
|
||||||
|
TryLoadModules(files);
|
||||||
|
|
||||||
// After loading all the modules, we may have a registered scripting function.
|
// After loading all the modules, we may have a registered scripting function.
|
||||||
if(scriptFn)
|
if(scriptFn)
|
||||||
|
|||||||
@@ -75,7 +75,12 @@ public:
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
static ModuleManager & Get();
|
static ModuleManager & Get();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void FindModules(FilePaths &files);
|
||||||
|
static void TryLoadModules(const FilePaths &files);
|
||||||
|
|
||||||
|
public:
|
||||||
void Initialize();
|
void Initialize();
|
||||||
int Dispatch(ModuleDispatchTypes type);
|
int Dispatch(ModuleDispatchTypes type);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user