variable plugin port config.
[ardour.git] / libs / ardour / plugin_manager.cc
index 9dd1d4b6805419b1b19a54bd74016cd13b3af8c0..89ddc5ff19f303fb204bd979f96be89e362a3426 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>
 #include "fst.h"
 #include "pbd/basename.h"
 #include <cstring>
+
+// dll-info
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+
 #endif // WINDOWS_VST_SUPPORT
 
 #ifdef LXVST_SUPPORT
@@ -46,7 +55,6 @@
 #include <cstring>
 #endif //LXVST_SUPPORT
 
-#include <glib/gstdio.h>
 #include <glibmm/miscutils.h>
 #include <glibmm/pattern.h>
 #include <glibmm/fileutils.h>
@@ -123,7 +131,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();
@@ -262,6 +270,23 @@ PluginManager::refresh (bool 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)) {
+                                       if (Config->get_verbose_plugin_scan()) {
+                                               PBD::info << _("VST Blacklist: ") << fn << "\n" << bl << "-----" << endmsg;
+                                       } else {
+                                               PBD::info << _("VST Blacklist:") << "\n" << bl << "-----" << endmsg;
+                                       }
+                                       g_free (bl);
+                               }
+                       }
+               }
+#endif
+
 #ifdef AUDIOUNIT_SUPPORT
        if (cache_only) {
                BootMessage (_("Scanning AU Plugins"));
@@ -340,6 +365,14 @@ PluginManager::clear_vst_cache ()
                }
        }
 #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)
@@ -378,6 +411,14 @@ PluginManager::clear_vst_blacklist ()
                }
        }
 #endif
+#if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
+       {
+               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
 
 #endif // old blacklist cleanup
 
@@ -751,13 +792,77 @@ PluginManager::windows_vst_discover_from_path (string path, bool cache_only)
        return ret;
 }
 
+static std::string dll_info (std::string path) {
+       std::string rv;
+       uint8_t buf[68];
+       uint16_t type = 0;
+       off_t pe_hdr_off = 0;
+
+       int fd = g_open(path.c_str(), O_RDONLY, 0444);
+
+       if (fd < 0) {
+               return _("cannot open dll"); // TODO strerror()
+       }
+
+       if (68 != read (fd, buf, 68)) {
+               rv = _("invalid dll, file too small");
+               goto errorout;
+       }
+       if (buf[0] != 'M' && buf[1] != 'Z') {
+               rv = _("not a dll");
+               goto errorout;
+       }
+
+       pe_hdr_off = *((int32_t*) &buf[60]);
+       if (pe_hdr_off !=lseek (fd, pe_hdr_off, SEEK_SET)) {
+               rv = _("cannot determine dll type");
+               goto errorout;
+       }
+       if (6 != read (fd, buf, 6)) {
+               rv = _("cannot read dll PE header");
+               goto errorout;
+       }
+
+       if (buf[0] != 'P' && buf[1] != 'E') {
+               rv = _("invalid dll PE header");
+               goto errorout;
+       }
+
+       type = *((uint16_t*) &buf[4]);
+       switch (type) {
+               case 0x014c:
+                       rv = _("i386 (32-bit)");
+                       break;
+               case  0x0200:
+                       rv = _("Itanium");
+                       break;
+               case 0x8664:
+                       rv = _("x64 (64-bit)");
+                       break;
+               case 0:
+                       rv = _("Native Architecture");
+                       break;
+               default:
+                       rv = _("Unknown Architecture");
+                       break;
+       }
+errorout:
+       assert (rv.length() > 0);
+       close (fd);
+       return rv;
+}
+
 int
 PluginManager::windows_vst_discover (string path, bool cache_only)
 {
        DEBUG_TRACE (DEBUG::PluginManager, string_compose ("windows_vst_discover '%1'\n", path));
 
        if (Config->get_verbose_plugin_scan()) {
-               info << string_compose (_(" *  %1 %2"), path, (cache_only ? _(" (cache only)") : "")) << endmsg;
+               if (cache_only) {
+                       info << string_compose (_(" *  %1 (cache only)"), path) << endmsg;
+               } else {
+                       info << string_compose (_(" *  %1 - %2"), path, dll_info (path)) << endmsg;
+               }
        }
 
        _cancel_timeout = false;
@@ -828,7 +933,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;
                        }
                }
        }
@@ -977,14 +1082,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) {
@@ -1003,6 +1102,10 @@ PluginManager::save_statuses ()
                case LXVST:
                        ofs << "LXVST";
                        break;
+               case Lua:
+                       assert (0);
+                       continue;
+                       break;
                }
 
                ofs << ' ';
@@ -1023,19 +1126,20 @@ PluginManager::save_statuses ()
                ofs << (*i).unique_id;;
                ofs << endl;
        }
-
-       ofs.close ();
+       g_file_set_contents (path.c_str(), ofs.str().c_str(), -1, NULL);
+       PluginStatusesChanged (); /* EMIT SIGNAL */
 }
 
 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;
@@ -1098,8 +1202,6 @@ PluginManager::load_statuses ()
                strip_whitespace_edges (id);
                set_status (type, id, status);
        }
-
-       ifs.close ();
 }
 
 void