From adcb0faf6ba025d0ed8d79676d9a91ae1e00a9fd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 24 Feb 2014 21:11:22 +0100 Subject: preparations for VST blacklist (paths) --- libs/ardour/ardour/filesystem_paths.h | 8 ++++++ libs/ardour/ardour/vst_info_file.h | 2 ++ libs/ardour/filesystem_paths.cc | 47 +++++++++++++++++++++++++++++++++ libs/ardour/plugin_manager.cc | 49 ++++++++++++++++++++++++++++++++--- libs/ardour/vst_info_file.cc | 38 ++++++++++++++++++++------- 5 files changed, 130 insertions(+), 14 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/filesystem_paths.h b/libs/ardour/ardour/filesystem_paths.h index 0bf25c5153..a398a917f2 100644 --- a/libs/ardour/ardour/filesystem_paths.h +++ b/libs/ardour/ardour/filesystem_paths.h @@ -33,6 +33,14 @@ namespace ARDOUR { */ LIBARDOUR_API std::string user_config_directory (); + /** + * @return the path to the directory used to store user specific + * caches (e.g. plugin indices, blacklist/whitelist) + * it defaults to XDG_CACHE_HOME + */ + LIBARDOUR_API std::string user_cache_directory (); + + /** * @return the path to the directory that contains the system wide ardour * modules. diff --git a/libs/ardour/ardour/vst_info_file.h b/libs/ardour/ardour/vst_info_file.h index 21e9d19c65..5f191faf25 100644 --- a/libs/ardour/ardour/vst_info_file.h +++ b/libs/ardour/ardour/vst_info_file.h @@ -25,6 +25,8 @@ #include "ardour/vst_types.h" #include +LIBARDOUR_API extern std::string get_personal_vst_info_cache_dir (); +LIBARDOUR_API extern std::string get_personal_vst_blacklist_dir (); LIBARDOUR_API extern void vstfx_free_info_list (std::vector *infos); #ifdef LXVST_SUPPORT diff --git a/libs/ardour/filesystem_paths.cc b/libs/ardour/filesystem_paths.cc index 54f7508b65..5228e85527 100644 --- a/libs/ardour/filesystem_paths.cc +++ b/libs/ardour/filesystem_paths.cc @@ -83,6 +83,53 @@ user_config_directory () return p; } +std::string +user_cache_directory () +{ + static std::string p; + + if (!p.empty()) return p; + +#ifdef __APPLE__ + p = Glib::build_filename (Glib::get_home_dir(), "Library/Caches"); +#else + const char* c = 0; + + /* adopt freedesktop standards, and put .ardour3 into $XDG_CONFIG_HOME or ~/.config + */ + + if ((c = getenv ("XDG_CACHE_HOME")) != 0) { + p = c; + } else { + const string home_dir = Glib::get_home_dir(); + + if (home_dir.empty ()) { + error << "Unable to determine home directory" << endmsg; + exit (1); + } + + p = home_dir; + p = Glib::build_filename (p, ".cache"); + } +#endif + + p = Glib::build_filename (p, user_config_dir_name); + + if (!Glib::file_test (p, Glib::FILE_TEST_EXISTS)) { + if (g_mkdir_with_parents (p.c_str(), 0755)) { + error << string_compose (_("Cannot create cache directory %1 - cannot run"), + p) << endmsg; + exit (1); + } + } else if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) { + error << string_compose (_("Cache directory %1 already exists and is not a directory/folder - cannot run"), + p) << endmsg; + exit (1); + } + + return p; +} + std::string ardour_dll_directory () { diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index 6a20191cf1..cfdfc6af7f 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -246,9 +246,7 @@ PluginManager::clear_vst_cache () #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT) { - string personal; - personal = Glib::build_filename (Glib::get_home_dir (), ".fst"); - + string personal = get_personal_vst_info_cache_dir(); PathScanner scanner; vector *fsi_files; fsi_files = scanner (personal, "\\.fsi$", true, true, -1, false); @@ -265,7 +263,50 @@ PluginManager::clear_vst_cache () void PluginManager::clear_vst_blacklist () { - // TODO -> libs/ardour/vst_info_file.cc +#ifdef WINDOWS_VST_SUPPORT + { + PathScanner scanner; + vector *fsi_files; + + fsi_files = scanner (windows_vst_path, "\\.fsb$", true, true, -1, false); + if (fsi_files) { + for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { + ::g_unlink((*i)->c_str()); + } + } + vector_delete(fsi_files); + } +#endif + +#ifdef LXVST_SUPPORT + { + PathScanner scanner; + vector *fsi_files; + fsi_files = scanner (lxvst_path, "\\.fsb$", true, true, -1, false); + if (fsi_files) { + for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { + ::g_unlink((*i)->c_str()); + } + } + vector_delete(fsi_files); + } +#endif + +#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT) + { + string personal = get_personal_vst_blacklist_dir(); + + PathScanner scanner; + vector *fsi_files; + fsi_files = scanner (personal, "\\.fsb$", true, true, -1, false); + if (fsi_files) { + for (vector::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) { + ::g_unlink((*i)->c_str()); + } + } + vector_delete(fsi_files); + } +#endif } void diff --git a/libs/ardour/vst_info_file.cc b/libs/ardour/vst_info_file.cc index 67117b2a6a..a0dffd0165 100644 --- a/libs/ardour/vst_info_file.cc +++ b/libs/ardour/vst_info_file.cc @@ -42,6 +42,7 @@ #include "pbd/error.h" +#include "ardour/filesystem_paths.h" #include "ardour/linux_vst_support.h" #include "ardour/vst_info_file.h" @@ -254,16 +255,7 @@ vstfx_infofile_path (const char* dllpath, int personal) { string dir; if (personal) { - // TODO use XDG_CACHE_HOME - dir = Glib::build_filename (Glib::get_home_dir (), ".fst"); - - /* If the directory doesn't exist, try to create it */ - if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) { - if (g_mkdir (dir.c_str (), 0700)) { - return 0; - } - } - + dir = get_personal_vst_info_cache_dir(); } else { dir = Glib::path_get_dirname (std::string(dllpath)); } @@ -685,6 +677,32 @@ vstfx_free_info_list (vector *infos) delete infos; } +string +get_personal_vst_blacklist_dir() { + string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist"); + /* if the directory doesn't exist, try to create it */ + if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) { + if (g_mkdir (dir.c_str (), 0700)) { + PBD::error << "Cannt create VST cache folder '" << dir << "'" << endmsg; + //exit(1); + } + } + return dir; +} + +string +get_personal_vst_info_cache_dir() { + string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info"); + /* if the directory doesn't exist, try to create it */ + if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) { + if (g_mkdir (dir.c_str (), 0700)) { + PBD::error << "Cannt create VST info folder '" << dir << "'" << endmsg; + //exit(1); + } + } + return dir; +} + #ifdef LXVST_SUPPORT vector * vstfx_get_info_lx (char* dllpath) -- cgit v1.2.3