Copy demo sessions (if any) for new-users

* Fix demo-session glob (missing "*" + session_archive_suffix)
* Copy demo-session also when copying settings from older version
* Also add demo-session to recent-list if it was previously unpacked
  for new major versions.
This commit is contained in:
Robin Gareus 2022-07-27 01:03:03 +02:00
parent 8cf3ff37ed
commit 84d6a0a75d
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 57 additions and 35 deletions

View File

@ -384,6 +384,12 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
/* "touch" the been-here-before path now that config has been migrated */
PBD::ScopedFileDescriptor fout (g_open (been_here_before_path ().c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));
}
{
Config->load_state (); // need session-parent folder
copy_demo_sessions ();
}
ArdourMessageDialog msg (string_compose (_("Your configuration files were copied. You can now restart %1."), PROGRAM_NAME), true);
msg.run ();
/* configuration was modified, exit immediately */

View File

@ -221,6 +221,7 @@ public:
void load_from_application_api (const std::string& path);
void finish();
int copy_demo_sessions ();
int load_session (const std::string& path, const std::string& snapshot, std::string mix_template = std::string());
bool session_load_in_progress;
int build_session (std::string const& path, std::string const& snapshot, std::string const& session_template, ARDOUR::BusProfile const&, bool from_startup_fsm, bool unnamed);

View File

@ -57,6 +57,7 @@
#include "ardour/filename_extensions.h"
#include "ardour/filesystem_paths.h"
#include "ardour/profile.h"
#include "ardour/recent_sessions.h"
#include "gtkmm2ext/application.h"
@ -581,6 +582,53 @@ ARDOUR_UI::starting ()
return 0;
}
int
ARDOUR_UI::copy_demo_sessions ()
{
int copied = 0;
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, string_compose ("*%1", 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)) {
/* ..but add it to recent-list */
store_recent_sessions (name, path);
continue;
}
/* skip sessions that are already in 'recent'.
* eg. a new user changed <session-default-dir> shortly 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;
++copied;
}
} catch (...) {
info << string_compose (_("Failed to extract demo session `%1'."), name) << endmsg;
}
}
}
return copied;
}
int
ARDOUR_UI::load_session_from_startup_fsm ()
{

View File

@ -47,7 +47,6 @@
#include "ardour/filesystem_paths.h"
#include "ardour/filename_extensions.h"
#include "ardour/plugin_manager.h"
#include "ardour/recent_sessions.h"
#include "ardour/session.h"
#include "ardour/session_state_utils.h"
#include "ardour/template_utils.h"
@ -55,6 +54,7 @@
#include "gtkmm2ext/utils.h"
#include "ardour_ui.h"
#include "new_user_wizard.h"
#include "opts.h"
#include "splash.h"
@ -343,41 +343,8 @@ 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_UI::instance()->copy_demo_sessions ();
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> shortly 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));
}