Use glib to open our 'recent file' list, rather than opening directly with ifstream...
authorJohn Emmas <johne53@tiscali.co.uk>
Tue, 8 Sep 2015 14:43:23 +0000 (15:43 +0100)
committerJohn Emmas <johne53@tiscali.co.uk>
Tue, 8 Sep 2015 14:45:34 +0000 (15:45 +0100)
(on Windows, ifstream & ofstream don't support UTF8)

libs/ardour/recent_sessions.cc

index 7458c32ff8ac979ed7e937aacd3006c68be77e67..b70d017edc925a9f02f0f1a78fb25288b6a2b225 100644 (file)
 #include <cstring>
 #include <cerrno>
 #include <fstream>
+#include <iostream>
 #include <algorithm>
 
+#include <glib/gstdio.h>
 #include <glibmm/miscutils.h>
 
 #include "pbd/error.h"
@@ -47,10 +49,9 @@ int
 ARDOUR::read_recent_sessions (RecentSessions& rs)
 {
        std::string path = Glib::build_filename (user_config_directory(), recent_file_name);
+       FILE* fin = g_fopen (path.c_str(), "rb");
 
-       ifstream recent (path.c_str());
-
-       if (!recent) {
+       if (!fin) {
                if (errno != ENOENT) {
                        error << string_compose (_("cannot open recent session file %1 (%2)"), path, strerror (errno)) << endmsg;
                        return -1;
@@ -59,6 +60,8 @@ ARDOUR::read_recent_sessions (RecentSessions& rs)
                }
        }
 
+       ifstream recent (fin);
+
        while (true) {
 
                pair<string,string> newpair;
@@ -82,6 +85,7 @@ ARDOUR::read_recent_sessions (RecentSessions& rs)
         * natural order will be broken
         */
 
+       fclose (fin);
        return 0;
 }
 
@@ -120,18 +124,27 @@ ARDOUR::read_recent_templates (std::deque<std::string>& rt)
 int
 ARDOUR::write_recent_sessions (RecentSessions& rs)
 {
-       std::string path = Glib::build_filename (user_config_directory(), recent_file_name);
-
-       ofstream recent (path.c_str());
+       FILE* fout = g_fopen (Glib::build_filename (user_config_directory(), recent_file_name).c_str(), "wb");
 
-       if (!recent) {
+       if (!fout) {
                return -1;
        }
 
-       for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
-               recent << (*i).first << '\n' << (*i).second << endl;
+       {
+               ofstream recent (fout);
+
+               if (!recent) {
+                       fclose (fout);
+                       return -1;
+               }
+
+               for (RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) {
+                       recent << (*i).first << '\n' << (*i).second << endl;
+               }
        }
 
+       fclose (fout);
+
        return 0;
 }