mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
Ref T348, util function to correct FSX/P3D model path
Related: Ref T317 Ref T247 Ref T335
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
#include <QFileInfo>
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackConfig;
|
||||
using namespace BlackMisc;
|
||||
@@ -313,6 +315,38 @@ namespace BlackMisc
|
||||
static const QStringList exclude;
|
||||
return exclude;
|
||||
}
|
||||
|
||||
bool CFsCommonUtil::adjustFileDirectory(CAircraftModel &model, const QString &simObjectsDirectory)
|
||||
{
|
||||
if (model.hasExistingCorrespondingFile()) { return true; }
|
||||
if (simObjectsDirectory.isEmpty()) { return false; }
|
||||
if (!model.hasFileName()) { return false; } // we can do nothing here
|
||||
|
||||
const QString simObjectsDirectoryFix = CFileUtils::fixWindowsUncPath(simObjectsDirectory);
|
||||
const QDir dir(simObjectsDirectoryFix);
|
||||
if (!dir.exists()) { return false; }
|
||||
|
||||
const QString lastSegment = QStringLiteral("/") % CFileUtils::lastPathSegment(simObjectsDirectoryFix) % QStringLiteral("/");
|
||||
const int index = model.getFileName().lastIndexOf(lastSegment);
|
||||
if (index < 0) { return false; }
|
||||
const QString relPart = model.getFileName().mid(index + lastSegment.length());
|
||||
if (relPart.isEmpty()) { return false; }
|
||||
const QString newFile = CFileUtils::appendFilePathsAndFixUnc(simObjectsDirectory, relPart);
|
||||
const QFileInfo nf(newFile);
|
||||
if (!nf.exists()) { return false; }
|
||||
|
||||
model.setFileName(newFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFsCommonUtil::adjustFileDirectory(CAircraftModel &model, const QStringList &simObjectsDirectories)
|
||||
{
|
||||
for (const QString &simObjectDir : simObjectsDirectories)
|
||||
{
|
||||
if (CFsCommonUtil::adjustFileDirectory(model, simObjectDir)) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#ifndef BLACKMISC_SIMULATION_FSCOMMONUTIL_H
|
||||
#define BLACKMISC_SIMULATION_FSCOMMONUTIL_H
|
||||
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
class QStringList;
|
||||
@@ -84,6 +84,12 @@ namespace BlackMisc
|
||||
|
||||
//! Exclude directories for aircraft objects
|
||||
static const QStringList &fs9AircraftObjectsExcludeDirectoryPatterns();
|
||||
|
||||
//! Adjust file directory
|
||||
static bool adjustFileDirectory(CAircraftModel &model, const QString &simObjectsDirectory);
|
||||
|
||||
//! Adjust file directory
|
||||
static bool adjustFileDirectory(CAircraftModel &model, const QStringList &simObjectsDirectories);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user