project: use relative filenames if absolute don't exist

This commit is contained in:
itsmattkc
2020-07-06 14:03:22 +10:00
parent 3e9f98e230
commit 936d077077
3 changed files with 36 additions and 0 deletions
+3
View File
@@ -64,6 +64,9 @@ struct XMLNodeData {
QList<BlockLink> block_links;
QHash<quintptr, Item*> item_ptrs;
QString real_project_url;
QString saved_project_url;
};
void XMLConnectNodes(const XMLNodeData& xml_node_data, QUndoCommand* command = nullptr);
+22
View File
@@ -21,6 +21,7 @@
#include "footage.h"
#include <QCoreApplication>
#include <QDir>
#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)) {
+11
View File
@@ -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<QFile*>(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();
}
}