Fix state features array
[ardour.git] / libs / ardour / vst_info_file.cc
index 16fd2d97c180d554206b7e42c30275eb91e89f87..ca2ef910adef8f803a7668ccd67b2cab117e5d5e 100644 (file)
  *  e.g. its name, creator etc.
  */
 
-#include <iostream>
-#include <fstream>
 #include <cassert>
 
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
@@ -38,7 +35,7 @@
 #include <string.h>
 
 #include <glib.h>
-#include <glib/gstdio.h>
+#include "pbd/gstdio_compat.h"
 #include <glibmm.h>
 
 #include "pbd/error.h"
@@ -55,7 +52,7 @@
 #include "ardour/plugin_types.h"
 #include "ardour/vst_info_file.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 #include "sha1.c"
 
 #define MAX_STRING_LEN 256
@@ -108,6 +105,36 @@ vstfx_infofile_path (const char* dllpath)
 
 /* *** VST Blacklist *** */
 
+static void vstfx_read_blacklist (std::string &bl) {
+       FILE * blacklist_fd = NULL;
+       bl = "";
+
+       string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
+
+       if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
+               return;
+       }
+
+       if (! (blacklist_fd = g_fopen (fn.c_str (), "rb"))) {
+               return;
+       }
+
+       while (!feof (blacklist_fd)) {
+               char buf[1024];
+               size_t s = fread (buf, sizeof(char), 1024, blacklist_fd);
+               if (ferror (blacklist_fd)) {
+                       PBD::error << string_compose (_("error reading VST Blacklist file %1 (%2)"), fn, strerror (errno)) << endmsg;
+                       bl = "";
+                       break;
+               }
+               if (s == 0) {
+                       break;
+               }
+               bl.append (buf, s);
+       }
+       ::fclose (blacklist_fd);
+}
+
 /** mark plugin as blacklisted */
 static void vstfx_blacklist (const char *id)
 {
@@ -133,10 +160,11 @@ static void vstfx_un_blacklist (const char *idcs)
        }
 
        std::string bl;
-       std::ifstream ifs (fn.c_str ());
-       bl.assign ((std::istreambuf_iterator<char> (ifs)), (std::istreambuf_iterator<char> ()));
+       vstfx_read_blacklist (bl);
+
        ::g_unlink (fn.c_str ());
 
+       assert (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS));
        assert (id.find ("\n") == string::npos);
 
        id += "\n"; // add separator
@@ -166,9 +194,9 @@ static bool vst_is_blacklisted (const char *idcs)
        if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
                return false;
        }
+
        std::string bl;
-       std::ifstream ifs (fn.c_str ());
-       bl.assign ((std::istreambuf_iterator<char> (ifs)), (std::istreambuf_iterator<char> ()));
+       vstfx_read_blacklist (bl);
 
        assert (id.find ("\n") == string::npos);
 
@@ -415,11 +443,11 @@ vstfx_infofile_for_read (const char* dllpath)
        string const path = vstfx_infofile_path (dllpath);
 
        if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
-               struct stat dllstat;
-               struct stat fsistat;
+               GStatBuf dllstat;
+               GStatBuf fsistat;
 
-               if (stat (dllpath, &dllstat) == 0) {
-                       if (stat (path.c_str (), &fsistat) == 0) {
+               if (g_stat (dllpath, &dllstat) == 0) {
+                       if (g_stat (path.c_str (), &fsistat) == 0) {
                                if (dllstat.st_mtime <= fsistat.st_mtime) {
                                        /* plugin is older than info file */
                                        return g_fopen (path.c_str (), "rb");