diff --git a/app/common/xmlutils.h b/app/common/xmlutils.h index d8c012559..ec406dbca 100644 --- a/app/common/xmlutils.h +++ b/app/common/xmlutils.h @@ -64,6 +64,9 @@ struct XMLNodeData { QList block_links; QHash item_ptrs; + QString real_project_url; + QString saved_project_url; + }; void XMLConnectNodes(const XMLNodeData& xml_node_data, QUndoCommand* command = nullptr); diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index 4acb16569..d2e62f46e 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -21,6 +21,7 @@ #include "footage.h" #include +#include #include "codec/decoder.h" #include "common/xmlutils.h" @@ -52,6 +53,27 @@ void Footage::Load(QXmlStreamReader *reader, XMLNodeData &xml_node_data, const Q } } + // Validate filename + if (!QFileInfo::exists(filename_)) { + // Absolute filename does not exist, use some heuristics to try relocating the file + + if (xml_node_data.real_project_url != xml_node_data.saved_project_url) { + // Project path has changed, check if the file we're looking for is the same relative to the + // new project path + QDir saved_dir(QFileInfo(xml_node_data.saved_project_url).dir()); + QDir true_dir(QFileInfo(xml_node_data.real_project_url).dir()); + + QString relative_filename = saved_dir.relativeFilePath(filename_); + QString transformed_abs_filename = true_dir.filePath(relative_filename); + + if (QFileInfo::exists(transformed_abs_filename)) { + // Use this file instead + qInfo() << "Footage" << filename_ << "doesn't exist, using relative file" << transformed_abs_filename; + set_filename(transformed_abs_filename); + } + } + } + Decoder::ProbeMedia(this, cancelled); while (XMLReadNextStartElement(reader)) { diff --git a/app/project/project.cpp b/app/project/project.cpp index 653202c02..5b14774d9 100644 --- a/app/project/project.cpp +++ b/app/project/project.cpp @@ -41,6 +41,9 @@ void Project::Load(QXmlStreamReader *reader, MainWindowLayoutInfo* layout, const { XMLNodeData xml_node_data; + // Set project filename (hacky) + xml_node_data.real_project_url = static_cast(reader->device())->fileName(); + while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("folder")) { @@ -69,8 +72,16 @@ void Project::Load(QXmlStreamReader *reader, MainWindowLayoutInfo* layout, const *layout = MainWindowLayoutInfo::fromXml(reader, xml_node_data); + } else if (reader->name() == QStringLiteral("url")) { + + // This should be read in before most other elements + xml_node_data.saved_project_url = reader->readElementText(); + } else { + + // Skip this reader->skipCurrentElement(); + } }