Prepare re-locating missing external files.
This commit is contained in:
parent
75773a43d4
commit
cdc8807728
@ -1145,6 +1145,10 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
|
|||||||
*/
|
*/
|
||||||
static PBD::Signal3<int,Session*,std::string,DataType> MissingFile;
|
static PBD::Signal3<int,Session*,std::string,DataType> MissingFile;
|
||||||
|
|
||||||
|
void set_missing_file_replacement (const std::string& mfr) {
|
||||||
|
_missing_file_replacement = mfr;
|
||||||
|
}
|
||||||
|
|
||||||
/** Emitted when the session wants Ardour to quit */
|
/** Emitted when the session wants Ardour to quit */
|
||||||
static PBD::Signal0<void> Quit;
|
static PBD::Signal0<void> Quit;
|
||||||
|
|
||||||
@ -1260,6 +1264,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
|
|||||||
bool _under_nsm_control;
|
bool _under_nsm_control;
|
||||||
unsigned int _xrun_count;
|
unsigned int _xrun_count;
|
||||||
|
|
||||||
|
std::string _missing_file_replacement;
|
||||||
|
|
||||||
void mtc_status_changed (bool);
|
void mtc_status_changed (bool);
|
||||||
PBD::ScopedConnection mtc_status_connection;
|
PBD::ScopedConnection mtc_status_connection;
|
||||||
void ltc_status_changed (bool);
|
void ltc_status_changed (bool);
|
||||||
|
@ -2198,19 +2198,23 @@ Session::load_sources (const XMLNode& node)
|
|||||||
nlist = node.children();
|
nlist = node.children();
|
||||||
|
|
||||||
set_dirty();
|
set_dirty();
|
||||||
|
std::map<std::string, std::string> relocation;
|
||||||
|
|
||||||
for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
int old_mode = 0;
|
int old_mode = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
XMLNode srcnode (**niter);
|
||||||
|
bool try_replace_abspath = true;
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
try {
|
try {
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
// do not show "insert media" popups (files embedded from removable media).
|
// do not show "insert media" popups (files embedded from removable media).
|
||||||
old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
||||||
#endif
|
#endif
|
||||||
if ((source = XMLSourceFactory (**niter)) == 0) {
|
if ((source = XMLSourceFactory (srcnode)) == 0) {
|
||||||
error << _("Session: cannot create Source from XML description.") << endmsg;
|
error << _("Session: cannot create Source from XML description.") << endmsg;
|
||||||
}
|
}
|
||||||
#ifdef PLATFORM_WINDOWS
|
#ifdef PLATFORM_WINDOWS
|
||||||
@ -2222,10 +2226,25 @@ retry:
|
|||||||
SetErrorMode(old_mode);
|
SetErrorMode(old_mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* try previous abs path replacements first */
|
||||||
|
if (try_replace_abspath && Glib::path_is_absolute (err.path)) {
|
||||||
|
std::string dir = Glib::path_get_dirname (err.path);
|
||||||
|
std::map<std::string, std::string>::const_iterator rl = relocation.find (dir);
|
||||||
|
if (rl != relocation.end ()) {
|
||||||
|
std::string newpath = Glib::build_filename (rl->second, Glib::path_get_basename (err.path));
|
||||||
|
if (Glib::file_test (newpath, Glib::FILE_TEST_EXISTS)) {
|
||||||
|
srcnode.add_property ("origin", newpath);
|
||||||
|
try_replace_abspath = false;
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int user_choice;
|
int user_choice;
|
||||||
|
_missing_file_replacement = "";
|
||||||
|
|
||||||
if (err.type == DataType::MIDI && Glib::path_is_absolute (err.path)) {
|
if (err.type == DataType::MIDI && Glib::path_is_absolute (err.path)) {
|
||||||
error << string_compose (_("A external MIDI file is missing. %1 cannot currently recover from missing external MIDI files"),
|
error << string_compose (_("An external MIDI file is missing. %1 cannot currently recover from missing external MIDI files"),
|
||||||
PROGRAM_NAME) << endmsg;
|
PROGRAM_NAME) << endmsg;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2238,7 +2257,19 @@ retry:
|
|||||||
|
|
||||||
switch (user_choice) {
|
switch (user_choice) {
|
||||||
case 0:
|
case 0:
|
||||||
/* user added a new search location, so try again */
|
/* user added a new search location
|
||||||
|
* or selected a new absolute path,
|
||||||
|
* so try again */
|
||||||
|
if (Glib::path_is_absolute (err.path)) {
|
||||||
|
if (!_missing_file_replacement.empty ()) {
|
||||||
|
/* replace origin, in XML */
|
||||||
|
std::string newpath = Glib::build_filename (
|
||||||
|
_missing_file_replacement, Glib::path_get_basename (err.path));
|
||||||
|
srcnode.add_property ("origin", newpath);
|
||||||
|
relocation[Glib::path_get_dirname (err.path)] = _missing_file_replacement;
|
||||||
|
_missing_file_replacement = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user