core: strip drive letters from windows paths
Qt on non-Windows chooses not to recognize Windows paths, so we translate them to a Unix-esque path
This commit is contained in:
+30
-5
@@ -1689,27 +1689,52 @@ void Core::CacheActiveSequence(bool in_out_only)
|
||||
}
|
||||
}
|
||||
|
||||
QString StripWindowsDriveLetter(QString s)
|
||||
{
|
||||
// HACK: On Windows, absolute paths are saved with a drive letter (e.g. "C:\video.mp4"). Below,
|
||||
// we use Qt's relative path system to resolve when an entire project may be in a different
|
||||
// folder, but the files are all in the same place relatively to the project. Unfortunately,
|
||||
// Qt chooses not to understand paths from Windows on non-Windows platforms, which causes
|
||||
// this to break when a project is moving from Windows to non-Windows. To resolve that, if
|
||||
// we're on a non-Windows platform and we detect a Windows path (i.e. a path with a drive
|
||||
// letter at the start), we strip it off. We also convert any back-slashes to forward-slashes
|
||||
// because on Windows they are interchangeable and on non-Windows they are not.
|
||||
#ifndef Q_OS_WINDOWS
|
||||
if (s.size() >= 2) {
|
||||
if (s.at(0).isLetter() && s.at(1) == ':') {
|
||||
s = s.mid(2);
|
||||
s.replace('\\', '/');
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
bool Core::ValidateFootageInLoadedProject(Project* project, const QString& project_saved_url)
|
||||
{
|
||||
QVector<Footage*> project_footage = project->root()->ListChildrenOfType<Footage>();
|
||||
QVector<Footage*> footage_we_couldnt_validate;
|
||||
|
||||
foreach (Footage* footage, project_footage) {
|
||||
if (!QFileInfo::exists(footage->filename()) && !project_saved_url.isEmpty()) {
|
||||
QString footage_fn = StripWindowsDriveLetter(footage->filename());
|
||||
QString project_fn = StripWindowsDriveLetter(project_saved_url);
|
||||
|
||||
if (!QFileInfo::exists(footage_fn) && !project_saved_url.isEmpty()) {
|
||||
// If the footage doesn't exist, it might have moved with the project
|
||||
const QString& project_current_url = project->filename();
|
||||
|
||||
if (project_current_url != project_saved_url) {
|
||||
if (project_current_url != project_fn) {
|
||||
// Project has definitely moved, try to resolve relative paths
|
||||
QDir saved_dir(QFileInfo(project_saved_url).dir());
|
||||
QDir saved_dir(QFileInfo(project_fn).dir());
|
||||
QDir true_dir(QFileInfo(project_current_url).dir());
|
||||
|
||||
QString relative_filename = saved_dir.relativeFilePath(footage->filename());
|
||||
QString relative_filename = saved_dir.relativeFilePath(footage_fn);
|
||||
QString transformed_abs_filename = true_dir.filePath(relative_filename);
|
||||
|
||||
if (QFileInfo::exists(transformed_abs_filename)) {
|
||||
// Use this file instead
|
||||
qInfo() << "Resolved" << footage->filename() << "relatively to" << transformed_abs_filename;
|
||||
qInfo() << "Resolved" << footage_fn << "relatively to" << transformed_abs_filename;
|
||||
footage->set_filename(transformed_abs_filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user