move copying demo sessions into NewUserWizard
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Oct 2019 02:52:46 +0000 (20:52 -0600)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 10 Oct 2019 22:52:00 +0000 (16:52 -0600)
gtk2_ardour/new_user_wizard.cc

index 0481f0c63ec66ff5bd8fdaf829dad40711c22d48..cfcb1bd591e39137153b8f0ae68d61dca991a479 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <gtkmm.h>
 
+#include "pbd/basename.h"
 #include "pbd/failed_constructor.h"
 #include "pbd/scoped_file_descriptor.h"
 #include "pbd/file_utils.h"
@@ -439,7 +440,8 @@ NewUserWizard::setup_final_page ()
 }
 
 void
-NewUserWizard::discover_plugins () {
+NewUserWizard::discover_plugins ()
+{
        plugin_disco_button.set_sensitive (false);
        PluginManager::instance().refresh();
 }
@@ -494,6 +496,42 @@ NewUserWizard::on_apply ()
 
        }
 
+       if (ARDOUR::Profile->get_mixbus () && Config->get_copy_demo_sessions ()) {
+               std::string dspd (Config->get_default_session_parent_dir());
+               Searchpath ds (ARDOUR::ardour_data_search_path());
+               ds.add_subdirectory_to_paths ("sessions");
+               vector<string> demos;
+               find_files_matching_pattern (demos, ds, ARDOUR::session_archive_suffix);
+
+               ARDOUR::RecentSessions rs;
+               ARDOUR::read_recent_sessions (rs);
+
+               for (vector<string>::iterator i = demos.begin(); i != demos.end (); ++i) {
+                       /* "demo-session" must be inside "demo-session.<session_archive_suffix>" */
+                       std::string name = basename_nosuffix (basename_nosuffix (*i));
+                       std::string path = Glib::build_filename (dspd, name);
+                       /* skip if session-dir already exists */
+                       if (Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR)) {
+                               continue;
+                       }
+                       /* skip sessions that are already in 'recent'.
+                        * eg. a new user changed <session-default-dir> shorly after installation
+                        */
+                       for (ARDOUR::RecentSessions::iterator r = rs.begin(); r != rs.end(); ++r) {
+                               if ((*r).first == name) {
+                                       continue;
+                               }
+                       }
+                       try {
+                               PBD::FileArchive ar (*i);
+                               if (0 == ar.inflate (dspd)) {
+                                       store_recent_sessions (name, path);
+                                       info << string_compose (_("Copied Demo Session %1."), name) << endmsg;
+                               }
+                       } catch (...) {}
+               }
+       }
+
        _signal_response (int (RESPONSE_OK));
 }