13
0

Consolidate black/white methods in PM

This commit is contained in:
Robin Gareus 2021-07-09 01:07:36 +02:00
parent fd0dc917bf
commit 09a3c97358
3 changed files with 67 additions and 74 deletions

View File

@ -74,15 +74,6 @@ public:
std::string manu;
};
LIBARDOUR_API extern void
auv2_blacklist (std::string const&);
LIBARDOUR_API extern void
auv2_whitelist (std::string);
LIBARDOUR_API extern bool
auv2_is_blacklisted (std::string const&);
LIBARDOUR_API extern std::string
auv2_stringify_descriptor (CAComponentDescription const&);

View File

@ -61,70 +61,6 @@
using namespace std;
using namespace PBD;
void
ARDOUR::auv2_blacklist (std::string const& id)
{
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
FILE* f = NULL;
if (! (f = g_fopen (fn.c_str (), "a"))) {
error << "Cannot append to AU blacklist for '" << id <<"'\n";
return;
}
assert (id.find ("\n") == string::npos);
fprintf (f, "%s\n", id.c_str ());
::fclose (f);
}
void
ARDOUR::auv2_whitelist (std::string id)
{
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
warning << _("Expected AUv2 Blacklist file does not exist.") << endmsg;
return;
}
std::string bl;
try {
bl = Glib::file_get_contents (fn);
} catch (Glib::FileError const& err) {
return;
}
::g_unlink (fn.c_str ());
assert (id.find("\n") == string::npos);
id += "\n"; // add separator
const size_t rpl = bl.find (id);
if (rpl != string::npos) {
bl.replace (rpl, id.size (), "");
}
if (bl.empty ()) {
return;
}
Glib::file_set_contents (fn, bl);
}
bool
ARDOUR::auv2_is_blacklisted (std::string const& id)
{
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
return false;
}
std::string bl;
try {
bl = Glib::file_get_contents (fn);
} catch (Glib::FileError const& err) {
return false;
}
return bl.find (id + "\n") != string::npos;
}
/* ****************************************************************************/
ARDOUR::AUv2DescStr::AUv2DescStr (std::string const& desc)
{
if (desc.empty ()) {

View File

@ -161,6 +161,8 @@ std::string PluginManager::vst3_scanner_bin_path = "";
# endif
#endif
#define AUV2_BLACKLIST "auv2_blacklist.txt"
PluginManager&
PluginManager::instance()
{
@ -704,7 +706,7 @@ void
PluginManager::clear_au_blacklist ()
{
#ifdef AUDIOUNIT_SUPPORT
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), AUV2_BLACKLIST);
if (Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
::g_unlink(fn.c_str());
}
@ -1076,6 +1078,70 @@ PluginManager::lv2_refresh ()
#ifdef AUDIOUNIT_SUPPORT
static void
auv2_blacklist (std::string const& id)
{
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), AUV2_BLACKLIST);
FILE* f = NULL;
if (! (f = g_fopen (fn.c_str (), "a"))) {
error << "Cannot append to AU blacklist for '" << id <<"'\n";
return;
}
assert (id.find ("\n") == string::npos);
fprintf (f, "%s\n", id.c_str ());
::fclose (f);
}
static void
auv2_whitelist (std::string id)
{
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), AUV2_BLACKLIST);
if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
warning << _("Expected AUv2 Blacklist file does not exist.") << endmsg;
return;
}
std::string bl;
try {
bl = Glib::file_get_contents (fn);
} catch (Glib::FileError const& err) {
return;
}
::g_unlink (fn.c_str ());
assert (id.find("\n") == string::npos);
id += "\n"; // add separator
const size_t rpl = bl.find (id);
if (rpl != string::npos) {
bl.replace (rpl, id.size (), "");
}
if (bl.empty ()) {
return;
}
Glib::file_set_contents (fn, bl);
}
static bool
auv2_is_blacklisted (std::string const& id)
{
string fn = Glib::build_filename (ARDOUR::user_cache_directory(), AUV2_BLACKLIST);
if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
return false;
}
std::string bl;
try {
bl = Glib::file_get_contents (fn);
} catch (Glib::FileError const& err) {
return false;
}
return bl.find (id + "\n") != string::npos;
}
/* ****************************************************************************/
static void auv2_scanner_log (std::string msg, PluginScanLogEntry* psle)
{
psle->msg (PluginScanLogEntry::OK, msg);