mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T631, Adding FG default directories
Only works on windows so far
This commit is contained in:
committed by
Klaus Basan
parent
60401e92d9
commit
8b69b7a637
@@ -51,7 +51,7 @@ namespace BlackMisc
|
||||
{
|
||||
aircraftIt.next();
|
||||
if (CFileUtils::isExcludedDirectory(aircraftIt.fileInfo(), excludeDirectories, Qt::CaseInsensitive)) { continue; }
|
||||
if (aircraftIt.filePath().toStdString().find("/AI/Aircraft") != std::string::npos) { continue; }
|
||||
if (aircraftIt.filePath().contains("/AI/Aircraft")) { continue; }
|
||||
CAircraftModel model;
|
||||
QString modelName = aircraftIt.fileName();
|
||||
modelName = modelName.remove("-set.xml");
|
||||
@@ -108,11 +108,14 @@ namespace BlackMisc
|
||||
CAircraftModelList allModels;
|
||||
for (const QString &rootDirectory : rootDirectories)
|
||||
{
|
||||
if (QDir(rootDirectory + "/AI/Aircraft").exists())
|
||||
QString dir = rootDirectory;
|
||||
dir.replace('\\','/');
|
||||
if (dir.contains("/AI/Aircraft"))
|
||||
{
|
||||
allModels.push_back(parseAIAirplanes(rootDirectory + "/AI/Aircraft", excludeDirectories));
|
||||
allModels.push_back(parseAIAirplanes(dir, excludeDirectories));
|
||||
} else {
|
||||
allModels.push_back(parseFlyableAirplanes(dir, excludeDirectories));
|
||||
}
|
||||
allModels.push_back(parseFlyableAirplanes(rootDirectory, excludeDirectories));
|
||||
}
|
||||
|
||||
return allModels;
|
||||
|
||||
73
src/blackmisc/simulation/flightgear/flightgearutil.cpp
Normal file
73
src/blackmisc/simulation/flightgear/flightgearutil.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "flightgearutil.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/directoryutils.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "qsystemdetection.h"
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QIODevice>
|
||||
#include <QTextStream>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace BlackConfig;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Flightgear
|
||||
{
|
||||
|
||||
const QString &CFlightgearUtil::flightgearRootDir()
|
||||
{
|
||||
static QString flightgearRootDir;
|
||||
if (CBuildConfig::isRunningOnWindowsNtPlatform()){
|
||||
QSettings flightgearRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\FlightGear_is1", QSettings::NativeFormat);
|
||||
flightgearRootDir = flightgearRegistry.value("InstallLocation").toString().trimmed();
|
||||
}
|
||||
return flightgearRootDir;
|
||||
}
|
||||
|
||||
|
||||
bool CFlightgearUtil::isFlightgearRootDirExisting()
|
||||
{
|
||||
static const bool exists = QDir(flightgearRootDir()).exists();
|
||||
return exists;
|
||||
}
|
||||
|
||||
QStringList CFlightgearUtil::modelDirectoriesFromSimDir(const QString &simulatorDir)
|
||||
{
|
||||
QStringList dirs;
|
||||
if (CBuildConfig::isRunningOnWindowsNtPlatform() && !simulatorDir.isEmpty()){
|
||||
QString terraSyncFolder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/Flightgear/Aircraft";
|
||||
if(QDir(terraSyncFolder).exists()){ dirs.append(terraSyncFolder); }
|
||||
QString fgdataAIFolder = simulatorDir + "data/AI/Aircraft";
|
||||
if (QDir(fgdataAIFolder).exists()) { dirs.append(fgdataAIFolder); }
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
const QStringList &CFlightgearUtil::flightgearModelDirectories()
|
||||
{
|
||||
static const QStringList dirs = flightgearRootDir().isEmpty() ? QStringList() : modelDirectoriesFromSimDir(flightgearRootDir());
|
||||
return dirs;
|
||||
}
|
||||
|
||||
const QStringList &CFlightgearUtil::flightgearModelExcludeDirectoryPatterns()
|
||||
{
|
||||
static const QStringList empty;
|
||||
return empty;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
51
src/blackmisc/simulation/flightgear/flightgearutil.h
Normal file
51
src/blackmisc/simulation/flightgear/flightgearutil.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_FLIGHTGEAR_FLIGHTGEARUTIL_H
|
||||
#define BLACKMISC_SIMULATION_FLIGHTGEAR_FLIGHTGEARUTIL_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Flightgear
|
||||
{
|
||||
//! Flightgear utils
|
||||
class BLACKMISC_EXPORT CFlightgearUtil
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CFlightgearUtil() = delete;
|
||||
|
||||
//! Flightgear root directory
|
||||
//! Currently only available for windows and if Flightgear is installed through installer.
|
||||
static const QString &flightgearRootDir();
|
||||
|
||||
//! Is the flightgearRootDir existing?
|
||||
static bool isFlightgearRootDirExisting();
|
||||
|
||||
//! Model directories from simulator directory
|
||||
static QStringList modelDirectoriesFromSimDir(const QString &simulatorDir);
|
||||
|
||||
//! Directories with models
|
||||
static const QStringList &flightgearModelDirectories();
|
||||
|
||||
//! Exclude directories for models
|
||||
static const QStringList &flightgearModelExcludeDirectoryPatterns();
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/fscommon/fscommonutil.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/simulation/flightgear/flightgearutil.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include <QStringBuilder>
|
||||
@@ -18,6 +19,7 @@ using namespace BlackConfig;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
using namespace BlackMisc::Simulation::Flightgear;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -497,7 +499,7 @@ namespace BlackMisc
|
||||
QStringList dirs;
|
||||
switch (m_simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FG: break;
|
||||
case CSimulatorInfo::FG: dirs = QStringList(CFlightgearUtil::modelDirectoriesFromSimDir(s)); break;
|
||||
case CSimulatorInfo::FS9: dirs = QStringList({CFsCommonUtil::fs9AircraftDirFromSimDir(s)}); break;
|
||||
case CSimulatorInfo::FSX: dirs = QStringList({CFsCommonUtil::fsxSimObjectsDirFromSimDir(s)}); break;
|
||||
case CSimulatorInfo::P3D:
|
||||
@@ -570,7 +572,7 @@ namespace BlackMisc
|
||||
{
|
||||
case CSimulatorInfo::FG:
|
||||
{
|
||||
return e;
|
||||
return CFlightgearUtil::flightgearModelDirectories();
|
||||
}
|
||||
case CSimulatorInfo::FS9:
|
||||
{
|
||||
@@ -607,7 +609,7 @@ namespace BlackMisc
|
||||
static const QString empty;
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FG: return empty;
|
||||
case CSimulatorInfo::FG: return CFlightgearUtil::flightgearRootDir();
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9Dir();
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxDir();
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dDir();
|
||||
@@ -625,7 +627,7 @@ namespace BlackMisc
|
||||
static const QStringList empty;
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FG: return empty;
|
||||
case CSimulatorInfo::FG: return CFlightgearUtil::flightgearModelExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsExcludeDirectoryPatterns();
|
||||
|
||||
Reference in New Issue
Block a user