From e3364288228181a3eee4f0bbccd2ce71b39529ab Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 30 Sep 2015 05:02:53 +0200 Subject: [PATCH] refs #475, added functions in project * get some specific directories * detect if running on developer's machine --- src/blackmisc/project.cpp | 78 +++++++++++++++++++++++++++++++++------ src/blackmisc/project.h | 17 +++++++++ 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/src/blackmisc/project.cpp b/src/blackmisc/project.cpp index be10df895..664be15ba 100644 --- a/src/blackmisc/project.cpp +++ b/src/blackmisc/project.cpp @@ -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 +#include #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 = ""; } @@ -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 diff --git a/src/blackmisc/project.h b/src/blackmisc/project.h index fd8f4c322..6c4b37b56 100644 --- a/src/blackmisc/project.h +++ b/src/blackmisc/project.h @@ -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() {}