mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
refs #475, added functions in project
* get some specific directories * detect if running on developer's machine
This commit is contained in:
committed by
Mathew Sutcliffe
parent
68d0b8cc98
commit
e336428822
@@ -1,5 +1,15 @@
|
||||
/* Copyright (C) 2013
|
||||
* 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 and at http://www.swift-project.org/license.html. 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 "project.h"
|
||||
#include <QStringList>
|
||||
#include <QCoreApplication>
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
|
||||
@@ -8,7 +18,6 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
bool CProject::isCompiledWithBlackCore()
|
||||
{
|
||||
#ifdef WITH_BLACKCORE
|
||||
@@ -93,13 +102,14 @@ namespace BlackMisc
|
||||
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 (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>";
|
||||
}
|
||||
@@ -119,7 +129,8 @@ namespace BlackMisc
|
||||
|
||||
const char *CProject::simulatorsChar()
|
||||
{
|
||||
return simulators().toQString().toUtf8().constData();
|
||||
static const QByteArray sims(simulators().toQString().toUtf8());
|
||||
return sims.constData();
|
||||
}
|
||||
|
||||
const QString &CProject::version()
|
||||
@@ -134,7 +145,14 @@ namespace BlackMisc
|
||||
|
||||
const QString &CProject::swiftVersionString()
|
||||
{
|
||||
static QString s = QString("swift %1").arg(version());
|
||||
static const QString s(QString("swift %1").arg(version()));
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CProject::swiftVersionStringDevInfo()
|
||||
{
|
||||
if (!isRunningInDeveloperEnvironment()) { return swiftVersionString(); }
|
||||
static const QString s(swiftVersionString() + " [DEV]");
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -182,6 +200,20 @@ namespace BlackMisc
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isRunningInDeveloperEnvironment()
|
||||
{
|
||||
if (!isDebugBuild()) { return false; }
|
||||
QFileInfo executable(QCoreApplication::applicationFilePath());
|
||||
QDir p(executable.dir());
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
int CProject::getMajorMinor(int index)
|
||||
{
|
||||
QString v = version();
|
||||
@@ -190,7 +222,31 @@ namespace BlackMisc
|
||||
int vi = v.split(".")[index].toInt(&ok);
|
||||
return ok ? vi : -1;
|
||||
}
|
||||
}
|
||||
|
||||
QString CProject::getApplicationDir()
|
||||
{
|
||||
QFileInfo executable(QCoreApplication::applicationFilePath());
|
||||
QDir p(executable.dir());
|
||||
return p.absolutePath();
|
||||
}
|
||||
|
||||
QString CProject::getSwiftResourceDir()
|
||||
{
|
||||
QDir dir(getApplicationDir());
|
||||
if (!dir.cdUp()) { return ""; }
|
||||
if (dir.cd("resources")) { return dir.absolutePath(); }
|
||||
return "";
|
||||
}
|
||||
|
||||
QString CProject::getSwiftStaticDbFilesDir()
|
||||
{
|
||||
QString d(getSwiftResourceDir());
|
||||
if (d.isEmpty()) { return ""; }
|
||||
QDir dir(d);
|
||||
if (dir.cd("swiftDB")) { return dir.absolutePath(); }
|
||||
return "";
|
||||
}
|
||||
} // ns
|
||||
|
||||
#undef BLACK_VERSION_STR
|
||||
#undef BLACK_VERSION_STR_X
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_CPROJECT_H
|
||||
#define BLACKMISC_CPROJECT_H
|
||||
|
||||
@@ -68,6 +70,9 @@ namespace BlackMisc
|
||||
//! System's name and version
|
||||
static const QString &swiftVersionString();
|
||||
|
||||
//! System's name and version + info if dev.environemnt
|
||||
static const QString &swiftVersionStringDevInfo();
|
||||
|
||||
//! System's name and version
|
||||
static const char *swiftVersionChar();
|
||||
|
||||
@@ -86,6 +91,18 @@ namespace BlackMisc
|
||||
//! Running on Windows NT platform?
|
||||
static bool isRunningOnWindowsNtPlatform();
|
||||
|
||||
//! Running in dev.environment, so on a programmers machine
|
||||
static bool isRunningInDeveloperEnvironment();
|
||||
|
||||
//! Application directory where current application is located
|
||||
static QString getApplicationDir();
|
||||
|
||||
//! Where resource files (static DB files, ...) etc are located
|
||||
static QString getSwiftResourceDir();
|
||||
|
||||
//! Where resource files (static DB files, ...) etc are located
|
||||
static QString getSwiftStaticDbFilesDir();
|
||||
|
||||
private:
|
||||
//! Constructor
|
||||
CProject() {}
|
||||
|
||||
Reference in New Issue
Block a user