From dee324cc36787d84612fd636cfceb4d964792db6 Mon Sep 17 00:00:00 2001 From: John Emmas Date: Tue, 8 Sep 2015 15:43:23 +0100 Subject: Use glib to open our 'recent file' list, rather than opening directly with ifstream / ofstream (on Windows, ifstream & ofstream don't support UTF8) --- libs/ardour/recent_sessions.cc | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'libs/ardour/recent_sessions.cc') diff --git a/libs/ardour/recent_sessions.cc b/libs/ardour/recent_sessions.cc index 7458c32ff8..b70d017edc 100644 --- a/libs/ardour/recent_sessions.cc +++ b/libs/ardour/recent_sessions.cc @@ -20,8 +20,10 @@ #include #include #include +#include #include +#include #include #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 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& 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; } -- cgit v1.2.3