preparations for VST blacklist (paths)
authorRobin Gareus <robin@gareus.org>
Mon, 24 Feb 2014 20:11:22 +0000 (21:11 +0100)
committerRobin Gareus <robin@gareus.org>
Mon, 24 Feb 2014 22:57:28 +0000 (23:57 +0100)
libs/ardour/ardour/filesystem_paths.h
libs/ardour/ardour/vst_info_file.h
libs/ardour/filesystem_paths.cc
libs/ardour/plugin_manager.cc
libs/ardour/vst_info_file.cc

index 0bf25c5153a70d571074eac26a850b1fd40f166f..a398a917f22d0480031c92048e26ceb481bc5313 100644 (file)
@@ -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.
index 21e9d19c65b3d2ffddff4b6e9b873801fd712411..5f191faf255c95b28e6907f014430a9d4bed8597 100644 (file)
@@ -25,6 +25,8 @@
 #include "ardour/vst_types.h"
 #include <vector>
 
+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<VSTInfo *> *infos);
 
 #ifdef LXVST_SUPPORT
index 54f7508b659d92ce55b34410dcbbd1fb35b26f1b..5228e8552723329f651b6e4afb312ca53e50b436 100644 (file)
@@ -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 ()
 {
index 6a20191cf1e34179c49a73bba08c0f527c0c633a..cfdfc6af7f2ca55aa8733711d5db054c8a20966f 100644 (file)
@@ -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<string *> *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<string *> *fsi_files;
+
+               fsi_files = scanner (windows_vst_path, "\\.fsb$", true, true, -1, false);
+               if (fsi_files) {
+                       for (vector<string *>::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<string *> *fsi_files;
+               fsi_files = scanner (lxvst_path, "\\.fsb$", true, true, -1, false);
+               if (fsi_files) {
+                       for (vector<string *>::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<string *> *fsi_files;
+               fsi_files = scanner (personal, "\\.fsb$", true, true, -1, false);
+               if (fsi_files) {
+                       for (vector<string *>::iterator i = fsi_files->begin(); i != fsi_files->end (); ++i) {
+                               ::g_unlink((*i)->c_str());
+                       }
+               }
+               vector_delete(fsi_files);
+       }
+#endif
 }
 
 void
index 67117b2a6aae97de6fcab6ef4c23d250eb589e11..a0dffd016568221ca5bb2f8328d1088e7c3561cd 100644 (file)
@@ -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<VSTInfo *> *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<VSTInfo *> *
 vstfx_get_info_lx (char* dllpath)