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:
Klaus Basan
2015-10-14 02:25:25 +02:00
committed by Mathew Sutcliffe
parent 2d46a93676
commit 4fce848c59
2 changed files with 176 additions and 34 deletions

View File

@@ -10,6 +10,7 @@
#include "project.h"
#include <QStringList>
#include <QCoreApplication>
#include <QProcessEnvironment>
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/simulation/simulatorinfo.h"
@@ -96,26 +97,6 @@ namespace BlackMisc
#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()
{
static const BlackMisc::Simulation::CSimulatorInfo simInfo(
@@ -208,16 +189,22 @@ namespace BlackMisc
bool CProject::isRunningInDeveloperEnvironment()
{
if (!isDebugBuild()) { return false; }
QFileInfo executable(QCoreApplication::applicationFilePath());
QDir p(executable.dir());
static const bool dev = BlackMisc::stringToBool(envVarDevelopmentValue());
return dev;
}
// search for typical developer dirs, feel free to improve the "algortithm"
if (!p.cdUp()) { return false; }
bool hasSrc = p.cd("src");
if (!hasSrc) { return false; }
p.cdUp();
return p.cd("samples");
bool CProject::useDevelopmentSetup()
{
static const QString v(envVarDevelopmentValue());
if (v.isEmpty())
{
// no explicit value
return isRunningInBetaOrDeveloperEnvironment();
}
else
{
return stringToBool(v);
}
}
bool CProject::isRunningInBetaOrDeveloperEnvironment()
@@ -234,6 +221,39 @@ namespace BlackMisc
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()
{
QFileInfo executable(QCoreApplication::applicationFilePath());
@@ -248,6 +268,12 @@ namespace BlackMisc
return "";
}
QString CProject::getSwiftPrivateResourceDir()
{
static const QString dir(envVarPrivateSetupDirValue());
return dir;
}
QString CProject::getSwiftStaticDbFilesDir()
{
QString d(getSwiftResourceDir());
@@ -256,6 +282,82 @@ namespace BlackMisc
if (dir.cd("swiftDB")) { return dir.absolutePath(); }
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
#undef BLACK_VERSION_STR

View File

@@ -18,7 +18,6 @@
namespace BlackMisc
{
/*!
* Metadata about the project
*/
@@ -55,9 +54,6 @@ namespace BlackMisc
//! with GUI?
static bool isCompiledWithGui();
//! Info string about compilation
static const QString &compiledInfo();
//! Simulator String info
static const BlackMisc::Simulation::CSimulatorInfo &simulators();
@@ -97,6 +93,9 @@ namespace BlackMisc
//! Running in dev.environment, so on a programmers machine
static bool isRunningInDeveloperEnvironment();
//! Use development setup?
static bool useDevelopmentSetup();
//! Beta / dev.environment?
static bool isRunningInBetaOrDeveloperEnvironment();
@@ -106,16 +105,57 @@ namespace BlackMisc
//! Where resource files (static DB files, ...) etc are located
static QString getSwiftResourceDir();
//! Private resource dir for developer's own resource files
static QString getSwiftPrivateResourceDir();
//! Where resource files (static DB files, ...) etc are located
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:
//! Constructor
CProject() {}
//! Split version
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