fix typo in prev. commit
[ardour.git] / libs / ardour / plugin_manager.cc
index 2b84c22fe7396c09a77fa003221d624d3ec33ed4..9ffab34a18afbef7e8f167f351b1057543667ce0 100644 (file)
@@ -26,7 +26,9 @@
 #include <sys/types.h>
 #include <cstdio>
 #include <cstdlib>
-#include <fstream>
+
+#include <glib.h>
+#include "pbd/gstdio_compat.h"
 
 #ifdef HAVE_LRDF
 #include <lrdf.h>
@@ -46,7 +48,6 @@
 #include <cstring>
 #endif //LXVST_SUPPORT
 
-#include <glib/gstdio.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/pattern.h>
 #include <glibmm/fileutils.h>
@@ -123,7 +124,7 @@ PluginManager::PluginManager ()
 
 #ifdef PLATFORM_WINDOWS
        // on windows the .exe needs to be in the same folder with libardour.dll
-       vstsp += Glib::build_filename(g_win32_get_package_installation_directory_of_module (0), "bin");
+       vstsp += Glib::build_filename(windows_package_directory_path(), "bin");
 #else
        // on Unices additional internal-use binaries are deployed to $libdir
        vstsp += ARDOUR::ardour_dll_directory();
@@ -225,6 +226,12 @@ PluginManager::~PluginManager()
 void
 PluginManager::refresh (bool cache_only)
 {
+       Glib::Threads::Mutex::Lock lm (_lock, Glib::Threads::TRY_LOCK);
+
+       if (!lm.locked()) {
+               return;
+       }
+
        DEBUG_TRACE (DEBUG::PluginManager, "PluginManager::refresh\n");
        _cancel_scan = false;
 
@@ -236,20 +243,45 @@ PluginManager::refresh (bool cache_only)
 #endif
 #ifdef WINDOWS_VST_SUPPORT
        if (Config->get_use_windows_vst()) {
-               BootMessage (_("Scanning Windows VST Plugins"));
+               if (cache_only) {
+                       BootMessage (_("Scanning Windows VST Plugins"));
+               } else {
+                       BootMessage (_("Discovering Windows VST Plugins"));
+               }
                windows_vst_refresh (cache_only);
        }
 #endif // WINDOWS_VST_SUPPORT
 
 #ifdef LXVST_SUPPORT
        if(Config->get_use_lxvst()) {
-               BootMessage (_("Scanning Linux VST Plugins"));
+               if (cache_only) {
+                       BootMessage (_("Scanning Linux VST Plugins"));
+               } else {
+                       BootMessage (_("Discovering Linux VST Plugins"));
+               }
                lxvst_refresh(cache_only);
        }
 #endif //Native linuxVST SUPPORT
 
+#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
+               if (!cache_only) {
+                       string fn = Glib::build_filename (ARDOUR::user_cache_directory(), VST_BLACKLIST);
+                       if (Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
+                               gchar *bl = NULL;
+                               if (g_file_get_contents(fn.c_str (), &bl, NULL, NULL)) {
+                                       PBD::info << _("VST Blacklist:") << "\n" << bl << "-----" << endmsg;
+                                       g_free (bl);
+                               }
+                       }
+               }
+#endif
+
 #ifdef AUDIOUNIT_SUPPORT
-       BootMessage (_("Scanning AU Plugins"));
+       if (cache_only) {
+               BootMessage (_("Scanning AU Plugins"));
+       } else {
+               BootMessage (_("Discovering AU Plugins"));
+       }
        au_refresh (cache_only);
 #endif
 
@@ -274,8 +306,15 @@ PluginManager::cancel_plugin_timeout ()
 void
 PluginManager::clear_vst_cache ()
 {
-       // see also libs/ardour/vst_info_file.cc - vstfx_infofile_path()
+#if 1 // clean old cache and error files. (remove this code after 4.3 or 5.0)
 #ifdef WINDOWS_VST_SUPPORT
+       {
+               vector<string> fsi_files;
+               find_files_matching_regex (fsi_files, Config->get_plugin_path_vst(), "\\" VST_EXT_INFOFILE "$", true);
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
+               }
+       }
        {
                vector<string> fsi_files;
                find_files_matching_regex (fsi_files, Config->get_plugin_path_vst(), "\\.fsi$", true);
@@ -283,9 +322,23 @@ PluginManager::clear_vst_cache ()
                        ::g_unlink(i->c_str());
                }
        }
+       {
+               vector<string> fsi_files;
+               find_files_matching_regex (fsi_files, Config->get_plugin_path_vst(), "\\.err$", true);
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
+               }
+       }
 #endif
 
 #ifdef LXVST_SUPPORT
+       {
+               vector<string> fsi_files;
+               find_files_matching_regex (fsi_files, Config->get_plugin_path_lxvst(), "\\" VST_EXT_INFOFILE "$", true);
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
+               }
+       }
        {
                vector<string> fsi_files;
                find_files_matching_regex (fsi_files, Config->get_plugin_path_lxvst(), "\\.fsi$", true);
@@ -293,13 +346,29 @@ PluginManager::clear_vst_cache ()
                        ::g_unlink(i->c_str());
                }
        }
+       {
+               vector<string> fsi_files;
+               find_files_matching_regex (fsi_files, Config->get_plugin_path_lxvst(), "\\.err$", true);
+               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
+                       ::g_unlink(i->c_str());
+               }
+       }
 #endif
+#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
+       {
+               string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info");
+               if (Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
+                       PBD::remove_directory (dir);
+               }
+       }
+#endif
+#endif // old cache cleanup
 
 #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
        {
-               string personal = get_personal_vst_info_cache_dir();
+               string dn = Glib::build_filename (ARDOUR::user_cache_directory(), "vst");
                vector<string> fsi_files;
-               find_files_matching_regex (fsi_files, personal, "\\.fsi$", /* user cache is flat, no recursion */ false);
+               find_files_matching_regex (fsi_files, dn, "\\" VST_EXT_INFOFILE "$", /* user cache is flat, no recursion */ false);
                for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
                        ::g_unlink(i->c_str());
                }
@@ -310,6 +379,8 @@ PluginManager::clear_vst_cache ()
 void
 PluginManager::clear_vst_blacklist ()
 {
+#if 1 // remove old blacklist files. (remove this code after 4.3 or 5.0)
+
 #ifdef WINDOWS_VST_SUPPORT
        {
                vector<string> fsi_files;
@@ -329,18 +400,26 @@ PluginManager::clear_vst_blacklist ()
                }
        }
 #endif
-
 #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
        {
-               string personal = get_personal_vst_blacklist_dir();
+               string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist");
+               if (Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
+                       PBD::remove_directory (dir);
+               }
+       }
+#endif
 
-               vector<string> fsi_files;
-               find_files_matching_regex (fsi_files, personal, "\\" VST_EXT_BLACKLIST "$", /* flat user cache */ false);
-               for (vector<string>::iterator i = fsi_files.begin(); i != fsi_files.end (); ++i) {
-                       ::g_unlink(i->c_str());
+#endif // old blacklist cleanup
+
+#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
+       {
+               string fn = Glib::build_filename (ARDOUR::user_cache_directory(), VST_BLACKLIST);
+               if (Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
+                       ::g_unlink (fn.c_str());
                }
        }
 #endif
+
 }
 
 void
@@ -779,7 +858,7 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
                        _windows_vst_plugin_info->push_back (info);
                        discovered++;
                        if (Config->get_verbose_plugin_scan()) {
-                               PBD::info << string_compose (_(" -> OK. (VST Plugin \"%1\" added)."), info->name) << endmsg; 
+                               PBD::info << string_compose (_(" -> OK (VST Plugin \"%1\" was added)."), info->name) << endmsg;
                        }
                }
        }
@@ -928,14 +1007,8 @@ PluginManager::get_status (const PluginInfoPtr& pi)
 void
 PluginManager::save_statuses ()
 {
-       ofstream ofs;
        std::string path = Glib::build_filename (user_config_directory(), "plugin_statuses");
-
-       ofs.open (path.c_str(), ios_base::openmode (ios::out|ios::trunc));
-
-       if (!ofs) {
-               return;
-       }
+       stringstream ofs;
 
        for (PluginStatusList::iterator i = statuses.begin(); i != statuses.end(); ++i) {
                switch ((*i).type) {
@@ -974,19 +1047,19 @@ PluginManager::save_statuses ()
                ofs << (*i).unique_id;;
                ofs << endl;
        }
-
-       ofs.close ();
+       g_file_set_contents (path.c_str(), ofs.str().c_str(), -1, NULL);
 }
 
 void
 PluginManager::load_statuses ()
 {
        std::string path = Glib::build_filename (user_config_directory(), "plugin_statuses");
-       ifstream ifs (path.c_str());
-
-       if (!ifs) {
+       gchar *fbuf = NULL;
+       if (!g_file_get_contents (path.c_str(), &fbuf, NULL, NULL))  {
                return;
        }
+       stringstream ifs (fbuf);
+       g_free (fbuf);
 
        std::string stype;
        std::string sstatus;
@@ -1049,8 +1122,6 @@ PluginManager::load_statuses ()
                strip_whitespace_edges (id);
                set_status (type, id, status);
        }
-
-       ifs.close ();
 }
 
 void