mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 14:15:35 +08:00
refs #478, updated project
* use env. variables to set status of project (dev.environment, local setup dir) * convert project to string
This commit is contained in:
committed by
Mathew Sutcliffe
parent
2d46a93676
commit
4fce848c59
@@ -10,6 +10,7 @@
|
|||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
#include "blackmisc/blackmiscfreefunctions.h"
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
#include "blackmisc/simulation/simulatorinfo.h"
|
#include "blackmisc/simulation/simulatorinfo.h"
|
||||||
|
|
||||||
@@ -96,26 +97,6 @@ namespace BlackMisc
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CProject::compiledInfo()
|
|
||||||
{
|
|
||||||
static QString info;
|
|
||||||
if (info.isEmpty())
|
|
||||||
{
|
|
||||||
static QStringList sl;
|
|
||||||
if (isCompiledWithBlackCore()) { sl << "BlackCore"; }
|
|
||||||
if (isCompiledWithBlackSound()) { sl << "BlackSound"; }
|
|
||||||
if (isCompiledWithBlackInput()) { sl << "BlackInput"; }
|
|
||||||
if (isCompiledWithGui()) { sl << "BlackGui"; }
|
|
||||||
if (isCompiledWithFs9Support()) { sl << "FS9"; }
|
|
||||||
if (isCompiledWithFsxSupport()) { sl << "FSX"; }
|
|
||||||
if (isCompiledWithXPlaneSupport()) { sl << "XPlane"; }
|
|
||||||
if (isCompiledWithP3DSupport()) { sl << "P3D"; }
|
|
||||||
info = sl.join(", ");
|
|
||||||
if (info.isEmpty()) info = "<none>";
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BlackMisc::Simulation::CSimulatorInfo &CProject::simulators()
|
const BlackMisc::Simulation::CSimulatorInfo &CProject::simulators()
|
||||||
{
|
{
|
||||||
static const BlackMisc::Simulation::CSimulatorInfo simInfo(
|
static const BlackMisc::Simulation::CSimulatorInfo simInfo(
|
||||||
@@ -208,16 +189,22 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CProject::isRunningInDeveloperEnvironment()
|
bool CProject::isRunningInDeveloperEnvironment()
|
||||||
{
|
{
|
||||||
if (!isDebugBuild()) { return false; }
|
static const bool dev = BlackMisc::stringToBool(envVarDevelopmentValue());
|
||||||
QFileInfo executable(QCoreApplication::applicationFilePath());
|
return dev;
|
||||||
QDir p(executable.dir());
|
}
|
||||||
|
|
||||||
// search for typical developer dirs, feel free to improve the "algortithm"
|
bool CProject::useDevelopmentSetup()
|
||||||
if (!p.cdUp()) { return false; }
|
{
|
||||||
bool hasSrc = p.cd("src");
|
static const QString v(envVarDevelopmentValue());
|
||||||
if (!hasSrc) { return false; }
|
if (v.isEmpty())
|
||||||
p.cdUp();
|
{
|
||||||
return p.cd("samples");
|
// no explicit value
|
||||||
|
return isRunningInBetaOrDeveloperEnvironment();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return stringToBool(v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CProject::isRunningInBetaOrDeveloperEnvironment()
|
bool CProject::isRunningInBetaOrDeveloperEnvironment()
|
||||||
@@ -234,6 +221,39 @@ namespace BlackMisc
|
|||||||
return ok ? vi : -1;
|
return ok ? vi : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &CProject::envVarDevelopment()
|
||||||
|
{
|
||||||
|
static const QString s("SWIFT_DEV");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CProject::envVarDevelopmentValue()
|
||||||
|
{
|
||||||
|
return QProcessEnvironment::systemEnvironment().value(envVarDevelopment());
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CProject::envDevelopmentSetup()
|
||||||
|
{
|
||||||
|
static const QString s("SWIFT_DEV_SETUP");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CProject::envDevelopmentSetupValue()
|
||||||
|
{
|
||||||
|
return QProcessEnvironment::systemEnvironment().value(envDevelopmentSetup());
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CProject::envVarPrivateSetupDir()
|
||||||
|
{
|
||||||
|
static const QString s("SWIFT_SETUP_DIR");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CProject::envVarPrivateSetupDirValue()
|
||||||
|
{
|
||||||
|
return QProcessEnvironment::systemEnvironment().value(envVarPrivateSetupDir());
|
||||||
|
}
|
||||||
|
|
||||||
QString CProject::getApplicationDir()
|
QString CProject::getApplicationDir()
|
||||||
{
|
{
|
||||||
QFileInfo executable(QCoreApplication::applicationFilePath());
|
QFileInfo executable(QCoreApplication::applicationFilePath());
|
||||||
@@ -248,6 +268,12 @@ namespace BlackMisc
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CProject::getSwiftPrivateResourceDir()
|
||||||
|
{
|
||||||
|
static const QString dir(envVarPrivateSetupDirValue());
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
QString CProject::getSwiftStaticDbFilesDir()
|
QString CProject::getSwiftStaticDbFilesDir()
|
||||||
{
|
{
|
||||||
QString d(getSwiftResourceDir());
|
QString d(getSwiftResourceDir());
|
||||||
@@ -256,6 +282,82 @@ namespace BlackMisc
|
|||||||
if (dir.cd("swiftDB")) { return dir.absolutePath(); }
|
if (dir.cd("swiftDB")) { return dir.absolutePath(); }
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CProject::getEnvironmentVariables(const QString &separator)
|
||||||
|
{
|
||||||
|
QString e(envDevelopmentSetup());
|
||||||
|
e = e.append(": ").append(envDevelopmentSetupValue());
|
||||||
|
e = e.append(separator);
|
||||||
|
|
||||||
|
e = e.append(envVarDevelopment());
|
||||||
|
e = e.append(": ").append(envVarDevelopmentValue());
|
||||||
|
e = e.append(separator);
|
||||||
|
|
||||||
|
e = e.append(envVarPrivateSetupDir());
|
||||||
|
e = e.append(": ").append(envVarPrivateSetupDirValue());
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CProject::compiledWithInfo(bool shortVersion)
|
||||||
|
{
|
||||||
|
if (shortVersion)
|
||||||
|
{
|
||||||
|
static QString infoShort;
|
||||||
|
if (infoShort.isEmpty())
|
||||||
|
{
|
||||||
|
QStringList sl;
|
||||||
|
if (isCompiledWithBlackCore()) { sl << "BlackCore"; }
|
||||||
|
if (isCompiledWithBlackSound()) { sl << "BlackSound"; }
|
||||||
|
if (isCompiledWithBlackInput()) { sl << "BlackInput"; }
|
||||||
|
if (isCompiledWithGui()) { sl << "BlackGui"; }
|
||||||
|
if (isCompiledWithFs9Support()) { sl << "FS9"; }
|
||||||
|
if (isCompiledWithFsxSupport()) { sl << "FSX"; }
|
||||||
|
if (isCompiledWithXPlaneSupport()) { sl << "XPlane"; }
|
||||||
|
if (isCompiledWithP3DSupport()) { sl << "P3D"; }
|
||||||
|
infoShort = sl.join(", ");
|
||||||
|
if (infoShort.isEmpty()) { infoShort = "<none>"; }
|
||||||
|
}
|
||||||
|
return infoShort;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static QString infoLong;
|
||||||
|
if (infoLong.isEmpty())
|
||||||
|
{
|
||||||
|
infoLong = infoLong.append("BlackCore: ").append(BlackMisc::boolToYesNo(isCompiledWithBlackCore()));
|
||||||
|
infoLong = infoLong.append(" BlackInput: ").append(BlackMisc::boolToYesNo(isCompiledWithBlackInput()));
|
||||||
|
infoLong = infoLong.append(" BlackSound: ").append(BlackMisc::boolToYesNo(isCompiledWithBlackSound()));
|
||||||
|
infoLong = infoLong.append(" GUI: ").append(BlackMisc::boolToYesNo(isCompiledWithGui()));
|
||||||
|
|
||||||
|
infoLong = infoLong.append(" FS9: ").append(BlackMisc::boolToYesNo(isCompiledWithFs9Support()));
|
||||||
|
infoLong = infoLong.append(" FSX: ").append(BlackMisc::boolToYesNo(isCompiledWithFsxSupport()));
|
||||||
|
infoLong = infoLong.append(" P3D: ").append(BlackMisc::boolToYesNo(isCompiledWithP3DSupport()));
|
||||||
|
infoLong = infoLong.append(" XPlane: ").append(BlackMisc::boolToYesNo(isCompiledWithXPlaneSupport()));
|
||||||
|
}
|
||||||
|
return infoLong;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CProject::environmentInfo(const QString &separator)
|
||||||
|
{
|
||||||
|
QString env("Beta: ");
|
||||||
|
env.append(boolToYesNo(isBetaTest()));
|
||||||
|
env = env.append(" dev.env,: ").append(boolToYesNo(isRunningInDeveloperEnvironment()));
|
||||||
|
env = env.append(separator);
|
||||||
|
env.append("Windows: ").append(boolToYesNo(isRunningOnWindowsNtPlatform()));
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CProject::convertToQString(const QString &separator)
|
||||||
|
{
|
||||||
|
QString str(version());
|
||||||
|
str = str.append(" ").append(isReleaseBuild() ? "Release build" : "Debug build");
|
||||||
|
str = str.append(separator);
|
||||||
|
str = str.append(environmentInfo(separator));
|
||||||
|
str = str.append(separator);
|
||||||
|
str.append(compiledWithInfo(false));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
#undef BLACK_VERSION_STR
|
#undef BLACK_VERSION_STR
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Metadata about the project
|
* Metadata about the project
|
||||||
*/
|
*/
|
||||||
@@ -55,9 +54,6 @@ namespace BlackMisc
|
|||||||
//! with GUI?
|
//! with GUI?
|
||||||
static bool isCompiledWithGui();
|
static bool isCompiledWithGui();
|
||||||
|
|
||||||
//! Info string about compilation
|
|
||||||
static const QString &compiledInfo();
|
|
||||||
|
|
||||||
//! Simulator String info
|
//! Simulator String info
|
||||||
static const BlackMisc::Simulation::CSimulatorInfo &simulators();
|
static const BlackMisc::Simulation::CSimulatorInfo &simulators();
|
||||||
|
|
||||||
@@ -97,6 +93,9 @@ namespace BlackMisc
|
|||||||
//! Running in dev.environment, so on a programmers machine
|
//! Running in dev.environment, so on a programmers machine
|
||||||
static bool isRunningInDeveloperEnvironment();
|
static bool isRunningInDeveloperEnvironment();
|
||||||
|
|
||||||
|
//! Use development setup?
|
||||||
|
static bool useDevelopmentSetup();
|
||||||
|
|
||||||
//! Beta / dev.environment?
|
//! Beta / dev.environment?
|
||||||
static bool isRunningInBetaOrDeveloperEnvironment();
|
static bool isRunningInBetaOrDeveloperEnvironment();
|
||||||
|
|
||||||
@@ -106,16 +105,57 @@ namespace BlackMisc
|
|||||||
//! Where resource files (static DB files, ...) etc are located
|
//! Where resource files (static DB files, ...) etc are located
|
||||||
static QString getSwiftResourceDir();
|
static QString getSwiftResourceDir();
|
||||||
|
|
||||||
|
//! Private resource dir for developer's own resource files
|
||||||
|
static QString getSwiftPrivateResourceDir();
|
||||||
|
|
||||||
//! Where resource files (static DB files, ...) etc are located
|
//! Where resource files (static DB files, ...) etc are located
|
||||||
static QString getSwiftStaticDbFilesDir();
|
static QString getSwiftStaticDbFilesDir();
|
||||||
|
|
||||||
|
//! Dump all env.variables
|
||||||
|
static QString getEnvironmentVariables(const QString &separator = QString("\n"));
|
||||||
|
|
||||||
|
//! Info string about compilation
|
||||||
|
static const QString &compiledWithInfo(bool shortVersion = true);
|
||||||
|
|
||||||
|
//! Env.information
|
||||||
|
static QString environmentInfo(const QString &separator = QString("\n"));
|
||||||
|
|
||||||
|
//! Whole info
|
||||||
|
static QString convertToQString(const QString &separator = QString("\n"));
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CProject() {}
|
CProject() {}
|
||||||
|
|
||||||
//! Split version
|
//! Split version
|
||||||
static int getMajorMinor(int index);
|
static int getMajorMinor(int index);
|
||||||
|
|
||||||
|
// --------------- env.vars. -------------
|
||||||
|
// centralized in one place here so we have an overview
|
||||||
|
|
||||||
|
//! Environment variable indicating "dev.environment"
|
||||||
|
static const QString &envVarDevelopment();
|
||||||
|
|
||||||
|
//! Value
|
||||||
|
//! //! \value true|false
|
||||||
|
static QString envVarDevelopmentValue();
|
||||||
|
|
||||||
|
//! Read data from productive or development setupnding on dev. environment yes/no
|
||||||
|
static const QString &envDevelopmentSetup();
|
||||||
|
|
||||||
|
//! Value
|
||||||
|
//! \value true|false
|
||||||
|
//! \remarks If this is set, the explicit value will be used.
|
||||||
|
//! If not set, default will be used depe
|
||||||
|
static QString envDevelopmentSetupValue();
|
||||||
|
|
||||||
|
//! Environment variable private resources
|
||||||
|
static const QString &envVarPrivateSetupDir();
|
||||||
|
|
||||||
|
//! Value
|
||||||
|
//! \value directory path
|
||||||
|
static QString envVarPrivateSetupDirValue();
|
||||||
};
|
};
|
||||||
}
|
} // ns
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user