diff options
author | Robin Gareus <robin@gareus.org> | 2016-12-27 22:24:24 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-12-27 22:24:24 +0100 |
commit | bbbf8e61274774972b90397be875a4c6c15b8b54 (patch) | |
tree | 7e7d46327471ab4edb4bd7e8b64ffb2ee0bffd1f /libs | |
parent | e71ea821dd0166015b41ade10c198455349dc662 (diff) |
Add backend support to extract session-archives
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/session_utils.h | 2 | ||||
-rw-r--r-- | libs/ardour/find_session.cc | 95 | ||||
-rw-r--r-- | libs/ardour/session.cc | 4 |
3 files changed, 100 insertions, 1 deletions
diff --git a/libs/ardour/ardour/session_utils.h b/libs/ardour/ardour/session_utils.h index 870f3daaa7..5c37a749a2 100644 --- a/libs/ardour/ardour/session_utils.h +++ b/libs/ardour/ardour/session_utils.h @@ -28,6 +28,8 @@ namespace ARDOUR { LIBARDOUR_API extern int find_session (std::string str, std::string& path, std::string& snapshot, bool& isnew); + LIBARDOUR_API extern int inflate_session (const std::string& zipfile, const std::string& target_dir, std::string& path, std::string& snapshot); + LIBARDOUR_API extern std::string inflate_error (int); }; diff --git a/libs/ardour/find_session.cc b/libs/ardour/find_session.cc index af39a47527..3301dfd20d 100644 --- a/libs/ardour/find_session.cc +++ b/libs/ardour/find_session.cc @@ -26,8 +26,11 @@ #include "pbd/gstdio_compat.h" #include <glibmm/miscutils.h> +#include <glibmm/fileutils.h> +#include "pbd/basename.h" #include "pbd/compose.h" +#include "pbd/file_archive.h" #include "pbd/pathexpand.h" #include "pbd/error.h" @@ -185,4 +188,96 @@ find_session (string str, string& path, string& snapshot, bool& isnew) return 0; } +/* check if zip is a session-archive, + * return > 0 if file is not an archive + * return < 0 if unzip failed + * return 0 on success. path and snapshot are set. + */ +int +inflate_session (const std::string& zipfile, const std::string& target_dir, string& path, string& snapshot) +{ + if (zipfile.find (".tar.xz") == string::npos) { + return 1; + } + + try { + PBD::FileArchive ar (zipfile); + std::vector<std::string> files = ar.contents (); + + if (files.size () == 0) { + error << _("Archive is empty") << endmsg; + return 2; + } + + /* session archives are expected to be named after the archive */ + std::string bn = Glib::path_get_dirname (files.front()); + if (bn.empty ()) { + error << _("Archive does not contain a session folder") << endmsg; + return 3; + } + if (bn[bn.length() - 1] == '/') { + bn = bn.substr (0, bn.length() - 1); + } + if (bn.empty ()) { + error << _("Archive does not contain a valid session structure") << endmsg; + return 4; + } + + string sn = Glib::build_filename (bn, bn + statefile_suffix); + + if (std::find (files.begin(), files.end(), sn) == files.end()) { + error << _("Archive does not contain a session file") << endmsg; + return 5; + } + + /* check if target folder exists */ + string dest = Glib::build_filename (target_dir, bn); + if (Glib::file_test (dest, Glib::FILE_TEST_EXISTS)) { + error << string_compose (_("Destination '%1' already exists."), dest) << endmsg; + return -1; + } + + if (0 == ar.inflate (target_dir)) { + info << string_compose (_("Extracted session-archive to '%1'."), dest) << endmsg; + path = dest; + snapshot = bn; + return 0; + } + + } catch (...) { + error << _("Error reading file-archive") << endmsg; + return 6; + } + + error << _("Error extracting file-archive") << endmsg; + return -2; +} + +string inflate_error (int e) { + switch (e) { + case 0: + return _("No Error"); + case 1: + return _("File extension is not .tar.xz"); + case 2: + return _("Archive is empty"); + case 3: + return _("Archive does not contain a session folder"); + case 4: + return _("Archive does not contain a valid session structure"); + case 5: + return _("Archive does not contain a session file"); + case 6: + return _("Error reading file-archive"); + case -1: + return _("Destination folder already exists."); + case -2: + return _("Error extracting file-archive"); + default: + assert (0); + break; + } + return _("Unknown Error"); +} + } // namespace ARDOUR diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index d7393d747e..112a933e19 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -333,7 +333,7 @@ Session::Session (AudioEngine &eng, init_name_id_counter (1); // reset for new sessions, start at 1 VCA::set_next_vca_number (1); // reset for new sessions, start at 1 - pre_engine_init (fullpath); + pre_engine_init (fullpath); // sets _is_new setup_lua (); @@ -479,6 +479,8 @@ Session::Session (AudioEngine &eng, } #endif + ensure_subdirs (); // archived or zipped sessions may lack peaks/ analysis/ etc + _is_new = false; session_loaded (); |