29#include <wx/tokenzr.h>
48#define REGVERKEY wxString(wxT("/pluginregistryversion"))
49#define REGROOT wxString(wxT("/pluginregistry/"))
52#define SETVERKEY wxString(wxT("/pluginsettingsversion"))
53#define SETVERCUR wxString(wxT("1.0"))
54#define SETROOT wxString(wxT("/pluginsettings/"))
56#define KEY_ID wxT("ID")
57#define KEY_PATH wxT("Path")
58#define KEY_SYMBOL wxT("Symbol")
59#define KEY_NAME wxT("Name")
60#define KEY_VENDOR wxT("Vendor")
61#define KEY_VERSION wxT("Version")
62#define KEY_DESCRIPTION wxT("Description")
63#define KEY_LASTUPDATED wxT("LastUpdated")
64#define KEY_ENABLED wxT("Enabled")
65#define KEY_VALID wxT("Valid")
66#define KEY_PROVIDERID wxT("ProviderID")
67#define KEY_EFFECTTYPE wxT("EffectType")
68#define KEY_EFFECTFAMILY wxT("EffectFamily")
69#define KEY_EFFECTDEFAULT wxT("EffectDefault")
70#define KEY_EFFECTINTERACTIVE wxT("EffectInteractive")
71#define KEY_EFFECTREALTIME wxT("EffectRealtime")
72#define KEY_EFFECTAUTOMATABLE wxT("EffectAutomatable")
73#define KEY_EFFECTTYPE_NONE wxT("None")
74#define KEY_EFFECTTYPE_ANALYZE wxT("Analyze")
75#define KEY_EFFECTTYPE_GENERATE wxT("Generate")
76#define KEY_EFFECTTYPE_PROCESS wxT("Process")
77#define KEY_EFFECTTYPE_TOOL wxT("Tool")
78#define KEY_EFFECTTYPE_HIDDEN wxT("Hidden")
79#define KEY_IMPORTERIDENT wxT("ImporterIdent")
81#define KEY_IMPORTEREXTENSIONS wxT("ImporterExtensions")
114 switch (
desc.GetPluginType() ) {
118 auto family =
desc.GetEffectFamily();
119 if ( family.empty() )
122 return wxT(
'/') + family +
wxT(
"/Enable");
138 if (
auto &descriptor = pair.second; descriptor.GetPath() == path) {
140 descriptor.SetSymbol(
141 { descriptor.GetSymbol().
Internal(), *pName });
224 paths.push_back(ff.GetFullPath());
229#if defined(__WXMAC__)
236 ff.AppendDir(
wxT(
"plug-ins"));
237 paths.push_back(ff.GetPath());
240 for (
const auto &filePath : pathList)
243 const wxString path{ ff.GetFullPath() };
244 if (paths.Index(path, wxFileName::IsCaseSensitive()) == wxNOT_FOUND)
246 paths.push_back(path);
251 for (
size_t i = 0, cnt = paths.size(); i < cnt; i++)
253 ff = paths[i] + wxFILE_SEP_PATH + pattern;
254 wxDir::GetAllFiles(ff.GetPath(), &files, ff.GetFullName(), directories ? wxDIR_DEFAULT : wxDIR_FILES);
348 auto &pluginDesc = it->second;
349 const auto pluginType = pluginDesc.GetPluginType();
356 if(!moduleManager.
CheckPluginExist(pluginDesc.GetProviderID(), pluginDesc.GetPath()))
399 mm.DiscoverProviders();
400 for (
auto& [
id, module] : mm.Providers()) {
403 module->AutoRegisterPlugins(*
this);
414 auto&
desc = p.second;
428 const wxFileName src{ fileName };
432 (mm.CreateProviderInstance(plug.GetID(), plug.GetPath()));
437 const auto &extensions = module->GetFileExtensions();
439 extensions.Index(src.GetExt(),
false) != wxNOT_FOUND ) {
443 module->DiscoverPluginsAtPath(fileName, errMsg, {});
453 dst.SetFullName( src.GetFullName() );
454 if ( dst.Exists() ) {
457 XO(
"Overwrite the plug-in file %s?")
458 .
Format( dst.GetFullPath() ),
461 .ButtonStyle(Button::YesNo)));
468 auto dstPath = dst.GetFullPath();
469 if ( src.FileExists() )
472 src.GetFullPath(), dstPath, true );
482 XO(
"Plug-in file is in use. Failed to overwrite") );
487 std::vector<PluginID> ids;
488 std::vector<wxString>
names;
489 nPlugIns = module->DiscoverPluginsAtPath(dstPath, errMsg,
497 names.push_back(
ident->GetSymbol().Translation() );
503 XO(
"Failed to register:\n%s").
Format( errMsg ) );
508 if (
auto nIds = ids.size()) {
512 "Enable this plug-in?\n",
513 "Enable these plug-ins?\n",
523 .ButtonStyle(Button::YesNo)));
524 for (
const auto &
id : ids)
543 auto ®istry = *pRegistry;
547 if (!registry.HasGroup(
REGROOT))
553 registry.DeleteAll();
569 wxString cfgPath =
REGROOT + group + wxCONFIG_PATH_SEPARATOR;
570 wxArrayString groupsToDelete;
572 registry.SetPath(cfgPath);
573 for (
bool cont = registry.GetFirstGroup(groupName, groupIndex);
575 registry.SetPath(cfgPath),
576 cont = registry.GetNextGroup(groupName, groupIndex))
578 registry.SetPath(groupName);
579 wxString effectSymbol = registry.Read(
KEY_SYMBOL,
"");
580 wxString effectVersion = registry.Read(
KEY_VERSION,
"");
592 }
else if ((effectSymbol ==
"Sample Data Export") && (effectVersion ==
"n/a")) {
593 groupsToDelete.push_back(cfgPath + groupName);
595 }
else if ((effectSymbol ==
"Sample Data Import") && (effectVersion ==
"n/a")) {
596 groupsToDelete.push_back(cfgPath + groupName);
603 for (
unsigned int i = 0; i < groupsToDelete.size(); i++) {
604 registry.DeleteGroup(groupsToDelete[i]);
606 registry.SetPath(
"");
635 wxFileName exeFn{ fullExePath };
637 exeFn.SetName(wxString{});
638 while(exeFn.GetDirCount() && !exeFn.GetDirs().back().EndsWith(
".app"))
639 exeFn.RemoveLastDir();
641 const auto goodPath = exeFn.GetPath();
643 if(exeFn.GetDirCount())
644 exeFn.RemoveLastDir();
645 const auto possiblyBadPath = exeFn.GetPath();
647 auto AcceptPath = [&](
const wxString &path) {
648 if (!path.StartsWith(possiblyBadPath))
651 if (path.StartsWith(goodPath))
657 auto AcceptPath = [](
const wxString&){
return true; };
665 wxString cfgPath =
REGROOT + group + wxCONFIG_PATH_SEPARATOR;
668 for (
bool cont = pRegistry->
GetFirstGroup(groupName, groupIndex);
684 plug.
SetID(groupName);
697 pRegistry->Read(
KEY_PATH, &strVal, wxEmptyString);
698 if (!AcceptPath(strVal))
762 pRegistry->Read(
KEY_VALID, &boolVal,
false);
846 wxStringTokenizer tkr(strVal,
wxT(
":"));
847 while (tkr.HasMoreTokens())
849 extensions.push_back(tkr.GetNextToken());
885 auto ®istry = *pRegistry;
888 registry.DeleteAll();
927 auto & plug = pair.second;
929 if (plug.GetPluginType() != type)
936 pRegistry->Write(
KEY_PATH, plug.GetPath());
939 pRegistry->Write(
KEY_SYMBOL, plug.GetSymbol().Internal());
943 pRegistry->Write(
KEY_NAME, plug.GetSymbol().Msgid().MSGID());
945 pRegistry->Write(
KEY_VERSION, plug.GetUntranslatedVersion());
946 pRegistry->Write(
KEY_VENDOR, plug.GetVendor());
951 pRegistry->Write(
KEY_VALID, plug.IsValid());
987 const auto & extensions = plug.GetImporterExtensions();
989 for (
size_t i = 0, cnt = extensions.size(); i < cnt; i++)
991 strExt += extensions[i] +
wxT(
":");
993 strExt.RemoveLast(1);
1009 std::unique_ptr<EffectDefinitionInterface> effect,
PluginType type)
1027 return plug.
GetID();
1039 return pair.second.GetPluginType() == type; });
1045 return &iter->second;
1049 return plug.
GetID() == ID;
1065 if (!all && !(plug.IsValid() && plug.IsEnabled()))
1067 auto plugType = plug.GetPluginType();
1073 if (!(setting.empty() ||
gPrefs->Read( setting,
true )))
1091, mPluginType{ type }
1099, mEffectType{ type }
1115 return iter->second.IsEnabled();
1123 iter->second.SetEnabled(enable);
1133 return iter->second.GetSymbol();
1139 return it->second.get();
1143 auto&
desc = it->second;
1151 auto result = pluginInterface.get();
1165 const auto&
desc = it->second;
1166 const auto type =
desc.GetPluginType();
1182 provider->AutoRegisterPlugins(*
this);
1196 wxArrayString pathIndex;
1198 auto &plug = pair.second;
1202 pathIndex.push_back(plug.GetPath().BeforeFirst(
wxT(
';')));
1215 std::map<wxString, std::vector<wxString>> newPaths;
1216 for(
auto& [
id, provider] : moduleManager.Providers())
1218 const auto paths = provider->FindModulePaths(*
this);
1219 for(
const auto& path : paths)
1221 const auto modulePath = path.BeforeFirst(
';');
1224 return plug.
GetPath().BeforeFirst(
wxT(
';')) == modulePath;
1228 newPaths[modulePath].push_back(
id);
1243 return wxString::Format(
wxT(
"%s_%s_%s_%s_%s"),
1253 return wxString::Format(
wxT(
"%s_%s_%s_%s_%s"),
1274 auto strings = wxSplit(ID,
'_');
1275 if (strings.size() == 5)
1290 str =
wxT(
"Placeholder");
1320 if (provider ==
nullptr)
1322 wxLogWarning(
"Unable to find a provider for '%s'", providerID);
1326 if (provider->CheckPluginExist(plug.
GetPath()) ==
false)
1328 wxLogWarning(
"Plugin '%s' does not exist", plug.
GetID());
1387 bool res =
settings->HasGroup(group);
1391 wxString oldPath =
settings->GetPath();
1402 if (group.empty() || !
HasGroup(group))
1416 subgroups.push_back(
name);
1435 const auto visitor = [&](
const auto var){
1436 const auto pVar = &var.get();
1438 using Type =
typename decltype(var)::type;
1439 const auto pDefval =
1440 std::get_if<std::reference_wrapper<const Type>>(&defval);
1443 return Visit(visitor, var);
1451 const auto visitor = [&](
const auto value){
1454 return Visit(visitor, value);
1483 wxCONFIG_PATH_SEPARATOR +
1484 (shared ?
wxT(
"shared") :
wxT(
"private")) +
1485 wxCONFIG_PATH_SEPARATOR;
1495 wxFileName ff(group);
1496 if (!ff.GetName().empty())
1498 path += ff.GetFullPath(wxPATH_UNIX) + wxCONFIG_PATH_SEPARATOR;
1508 auto path =
Group(type, ID, group);
1521 if (ID.StartsWith(
wxT(
"base64:")))
1523 wxString
id = ID.Mid(7);
1525 id = wxString::FromUTF8(buf.get(),
Base64::Decode(
id, buf.get()));
1529 const wxCharBuffer & buf = ID.ToUTF8();
@ Internal
Indicates internal failure from Audacity.
Toolkit-neutral facade for basic user interface services.
static const AudacityProject::AttachedObjects::RegisteredFactory key
const TranslatableString name
const TranslatableString desc
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
std::vector< RegistryPath > RegistryPaths
#define XPC(sing, plur, n, c)
auto Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
static CommandHandlerObject & ident(AudacityProject &project)
@ PluginTypeAudacityCommand
bool Regver_lt(const PluginRegistryVersion ®ver1, const PluginRegistryVersion ®ver2)
bool Regver_le(const PluginRegistryVersion ®ver1, const PluginRegistryVersion ®ver2)
wxString PluginRegistryVersion
Type of plugin registry version information.
#define KEY_EFFECTAUTOMATABLE
#define KEY_IMPORTEREXTENSIONS
#define KEY_EFFECTTYPE_TOOL
#define KEY_IMPORTERIDENT
#define KEY_EFFECTTYPE_GENERATE
#define KEY_EFFECTTYPE_PROCESS
#define KEY_EFFECTINTERACTIVE
#define KEY_EFFECTTYPE_HIDDEN
static PluginManager::FileConfigFactory sFactory
#define KEY_EFFECTREALTIME
#define KEY_EFFECTTYPE_NONE
#define KEY_EFFECTTYPE_ANALYZE
#define KEY_EFFECTDEFAULT
#define NYQUIST_PROMPT_ID
Generalized interface for discovery of plug-ins for one protocol.
static const AttachedProjectObjects::RegisteredFactory manager
static Settings & settings()
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
ComponentInterface provides name / vendor / version functions to identify plugins....
virtual PluginPath GetPath() const =0
virtual VendorSymbol GetVendor() const =0
TranslatableString GetName() const
virtual ComponentInterfaceSymbol GetSymbol() const =0
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
const TranslatableString & Msgid() const
EffectDefinitionInterface is a ComponentInterface that adds some basic read-only information about ef...
virtual EffectType GetClassification() const
Determines which menu it appears in; default same as GetType().
virtual bool IsDefault() const =0
Whether the effect sorts "above the line" in the menus.
virtual bool IsInteractive() const =0
Whether the effect needs a dialog for entry of settings.
virtual bool SupportsAutomation() const =0
Whether the effect has any automatable controls.
virtual RealtimeSince RealtimeSupport() const =0
Since which version of Audacity has the effect supported realtime?
virtual EffectFamilySymbol GetFamily() const =0
Report identifier and user-visible name of the effect protocol.
virtual bool DeleteEntry(const wxString &key, bool bDeleteGroupIfEmpty=true) wxOVERRIDE
virtual bool GetNextGroup(wxString &str, long &lIndex) const wxOVERRIDE
virtual bool DeleteGroup(const wxString &key) wxOVERRIDE
virtual bool GetFirstGroup(wxString &str, long &lIndex) const wxOVERRIDE
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
virtual const wxString & GetPath() const wxOVERRIDE
virtual void SetPath(const wxString &strPath) wxOVERRIDE
An explicitly nonlocalized string, not meant for the user to see.
static ModuleManager & Get()
static PluginID GetID(PluginProvider *provider)
static wxString GetPluginTypeString()
PluginProvider * CreateProviderInstance(const PluginID &provider, const PluginPath &path)
bool CheckPluginExist(const PluginID &providerId, const PluginPath &path)
CallbackReturn Publish(const PluginsChangedMessage &message)
Send a message to connected callbacks.
void SetEnabled(bool enable)
void SetEffectLegacy(bool legacy)
void SetImporterExtensions(FileExtensions extensions)
const ComponentInterfaceSymbol & GetSymbol() const
PluginType GetPluginType() const
void SetVendor(const wxString &vendor)
void SetImporterIdentifier(const wxString &identifier)
wxString GetEffectFamily() const
void SetPath(const PluginPath &path)
void SetValid(bool valid)
const wxString & GetID() const
const wxString & GetVendor() const
void SetSymbol(const ComponentInterfaceSymbol &symbol)
void SetProviderID(const PluginID &providerID)
const PluginPath & GetPath() const
void SetID(const PluginID &ID)
void SetEffectType(EffectType type)
void SetEffectFamily(const wxString &family)
void SetPluginType(PluginType type)
const wxString & GetProviderID() const
void SetEffectAutomatable(bool automatable)
void SetEffectDefault(bool dflt)
void SetEffectInteractive(bool interactive)
void SetRealtimeSupport(EffectDefinitionInterface::RealtimeSince realtime)
void SetVersion(const wxString &version)
void DeserializeRealtimeSupport(const wxString &value)
for deserialization
void Advance(bool incrementing)
Iterator(PluginManager &manager)
Iterates all, even disabled.
const PluginManager & mPm
PluginMap::iterator mIterator
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
static PluginID OldGetID(const EffectDefinitionInterface *effect)
bool GetConfigSubgroups(ConfigurationType type, const PluginID &ID, const RegistryPath &group, RegistryPaths &subgroups) override
bool HasConfigGroup(ConfigurationType type, const PluginID &ID, const RegistryPath &group)
bool IsPluginEnabled(const PluginID &ID)
bool GetConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key, ConfigReference var, ConfigConstReference defval) override
std::function< std::unique_ptr< FileConfig >(const FilePath &localFilename) > FileConfigFactory
std::vector< PluginDescriptor > mEffectPluginsCleared
void ClearEffectPlugins()
PluginRegistryVersion mRegver
void SaveGroup(FileConfig *pRegistry, PluginType type)
std::map< wxString, std::vector< wxString > > CheckPluginUpdates()
Ensures that all currently registered plugins still exist and scans for new ones.
void Initialize(FileConfigFactory factory)
bool IsPluginRegistered(const PluginPath &path, const TranslatableString *pSymbol) override
Was the plugin registry already populated for a path (maybe from loading the config file)?
bool IsPluginLoaded(const wxString &ID) const
void LoadGroup(FileConfig *pRegistry, PluginType type)
RegistryPath Group(ConfigurationType type, const PluginID &ID, const RegistryPath &group)
bool HasConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key) override
void Save()
Save to preferences.
void UnregisterPlugin(const PluginID &ID)
void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &files, bool directories=false) override
bool GetSubgroups(const RegistryPath &group, RegistryPaths &subgroups)
FileConfig * GetSettings()
static Identifier GetEffectNameFromID(const PluginID &ID)
static PluginID GetID(PluginProvider *provider)
bool HasGroup(const RegistryPath &group)
void Load()
Load from preferences.
Range PluginsOfType(int type)
PluginDescriptor & CreatePlugin(const PluginID &id, ComponentInterface *ident, PluginType type)
static bool IsPluginAvailable(const PluginDescriptor &plug)
const PluginRegistryVersion & GetRegistryVersion() const override
RegistryPath Key(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key)
static std::unique_ptr< PluginManager > mInstance
RegistryPath GetPluginEnabledSetting(const PluginID &ID) const
bool DropFile(const wxString &fileName)
const PluginDescriptor * GetPlugin(const PluginID &ID) const
void EnablePlugin(const PluginID &ID, bool enable)
void RegisterPlugin(PluginDescriptor &&desc)
bool RemoveConfig(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key) override
std::unique_ptr< FileConfig > mSettings
PluginMap mRegisteredPlugins
wxString ConvertID(const PluginID &ID)
RegistryPath SettingsPath(ConfigurationType type, const PluginID &ID)
bool SetConfigValue(ConfigurationType type, const PluginID &ID, const RegistryPath &group, const RegistryPath &key, ConfigConstReference value) override
int GetPluginCount(PluginType type)
static wxString GetPluginTypeString(PluginType type)
void NotifyPluginsChanged()
bool RemoveConfigSubgroup(ConfigurationType type, const PluginID &ID, const RegistryPath &group) override
std::map< PluginID, std::unique_ptr< ComponentInterface > > mLoadedInterfaces
const ComponentInterfaceSymbol & GetSymbol(const PluginID &ID)
static PluginManager & Get()
static const PluginID & AudacityCommandRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
PluginSettings::ConfigReference ConfigReference
static const PluginID & DefaultRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
PluginSettings::ConfigConstReference ConfigConstReference
virtual EffectFamilySymbol GetOptionalFamilySymbol()=0
A symbol identifying the family of plug-ins provided by this.
virtual std::unique_ptr< ComponentInterface > LoadPlugin(const PluginPath &path)=0
Load the plug-in at a path reported by DiscoverPluginsAtPath.
virtual FilePath InstallPath()=0
Where plug-in files should be copied to install them.
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
STRINGS_API wxString Encode(const void *in, int len)
STRINGS_API int Decode(const wxString &in, void *out)
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
FILES_API bool DoCopyFile(const FilePath &file1, const FilePath &file2, bool overwrite=true)
FILES_API FilePath PluginRegistry()
FILES_API FilePath PluginSettings()
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
static RegisteredToolbarFactory factory
MessageBoxOptions && Caption(TranslatableString caption_) &&