Fix a compiler problem when building 'gtk2_ardour/template_dialog.cc' with MSVC
[ardour.git] / session_utils / common.cc
index 2abfb32d3cb3a1842df3750f67659d112d4e08e0..eb17cfdbeb21e0b4a76d04d1006a201945b04f29 100644 (file)
@@ -120,23 +120,30 @@ static Session * _load_session (string dir, string state)
 
        float sr;
        SampleFormat sf;
+       std::string v;
 
        std::string s = Glib::build_filename (dir, state + statefile_suffix);
-       if (Session::get_info_from_path (s, sr, sf) == 0) {
+
+       if (!Glib::file_test (s, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
+               std::cerr << "Cannot read session '"<< s << "'\n";
+               return 0;
+       }
+
+       if (Session::get_info_from_path (s, sr, sf, v) == 0) {
                if (engine->set_sample_rate (sr)) {
                        std::cerr << "Cannot set session's samplerate.\n";
-                       ::exit (EXIT_FAILURE);
+                       return 0;
                }
        } else {
                std::cerr << "Cannot get samplerate from session.\n";
-               ::exit (EXIT_FAILURE);
+               return 0;
        }
 
        init_post_engine ();
 
        if (engine->start () != 0) {
                std::cerr << "Cannot start Audio/MIDI engine\n";
-               ::exit (EXIT_FAILURE);
+               return 0;
        }
 
        Session* session = new Session (*engine, dir, state);
@@ -145,7 +152,7 @@ static Session * _load_session (string dir, string state)
 }
 
 Session *
-SessionUtils::load_session (string dir, string state)
+SessionUtils::load_session (string dir, string state, bool exit_at_failure)
 {
        Session* s = 0;
        try {
@@ -163,6 +170,9 @@ SessionUtils::load_session (string dir, string state)
                cerr << "unknown exception.\n";
                ::exit (EXIT_FAILURE);
        }
+       if (!s && exit_at_failure) {
+               ::exit (EXIT_FAILURE);
+       }
        return s;
 }