From 6807eb8d356a5bfd4d81c48ec2b8e829b88311f8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 17 Aug 2018 02:25:43 +0200 Subject: [PATCH] Application info: Checking if directory exists (swift version exists) plus fixes in property functions --- .../models/applicationinfolistmodel.cpp | 2 ++ src/blackmisc/applicationinfo.cpp | 20 +++++++++++++++---- src/blackmisc/applicationinfo.h | 6 ++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/blackgui/models/applicationinfolistmodel.cpp b/src/blackgui/models/applicationinfolistmodel.cpp index 10053117c..e77fd41fb 100644 --- a/src/blackgui/models/applicationinfolistmodel.cpp +++ b/src/blackgui/models/applicationinfolistmodel.cpp @@ -31,6 +31,8 @@ namespace BlackGui m_columns.addColumn(CColumn::standardString("version", CApplicationInfo::IndexVersionString)); m_columns.addColumn(CColumn::standardString("OS", CApplicationInfo::IndexPlatformInfo)); m_columns.addColumn(CColumn::standardString("exe.path", CApplicationInfo::IndexExecutablePath)); + m_columns.addColumn(CColumn("e.?", "existing?", CApplicationInfo::IndexExecutablePathExisting, + new CBoolIconFormatter("directory existing", "directory not existing"))); m_columns.addColumn(CColumn::standardString("data.path", CApplicationInfo::IndexApplicationDataPath)); // default sort order diff --git a/src/blackmisc/applicationinfo.cpp b/src/blackmisc/applicationinfo.cpp index d5b418959..1cce7cc00 100644 --- a/src/blackmisc/applicationinfo.cpp +++ b/src/blackmisc/applicationinfo.cpp @@ -13,6 +13,8 @@ #include "blackmisc/iconlist.h" #include "blackmisc/comparefunctions.h" #include "blackconfig/buildconfig.h" + +#include #include using namespace BlackConfig; @@ -59,6 +61,13 @@ namespace BlackMisc return unknown; } + bool CApplicationInfo::isExecutablePathExisting() const + { + if (this->getExecutablePath().isEmpty()) { return false; } + const QDir d(this->getExecutablePath()); + return d.exists(); + } + bool CApplicationInfo::isSampleOrUnitTest() const { const Application a = this->getApplication(); @@ -112,6 +121,7 @@ namespace BlackMisc case IndexApplicationDataPath: return CVariant::fromValue(this->getApplicationDataDirectory()); case IndexCompileInfo: return CVariant::fromValue(this->getCompileInfo()); case IndexExecutablePath: return CVariant::fromValue(this->getExecutablePath()); + case IndexExecutablePathExisting: return CVariant::fromValue(this->isExecutablePathExisting()); case IndexPlatformInfo: return CVariant::fromValue(this->getPlatform()); case IndexProcessInfo: return m_process.propertyByIndex(index.copyFrontRemoved()); case IndexVersionString: return CVariant::fromValue(this->getVersionString()); @@ -132,10 +142,11 @@ namespace BlackMisc case IndexApplicationDataPath: this->setApplicationDataDirectory(variant.toQString()); break; case IndexCompileInfo: this->setCompileInfo(variant.toQString()); break; case IndexExecutablePath: this->setExecutablePath(variant.toQString()); break; + case IndexExecutablePathExisting: break; case IndexPlatformInfo: this->setPlatformInfo(variant.toQString()); break; case IndexProcessInfo: m_process.setPropertyByIndex(index.copyFrontRemoved(), variant); break; case IndexVersionString: this->setVersionString(variant.toQString()); break; - case IndexWordSize: return this->setWordSize(variant.toInt()); break; + case IndexWordSize: this->setWordSize(variant.toInt()); break; default: CValueObject::setPropertyByIndex(index, variant); break; } } @@ -146,9 +157,10 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexApplicationDataPath: this->getApplicationDataDirectory().compare(compareValue.getApplicationDataDirectory()); - case IndexCompileInfo: this->getCompileInfo().compare(compareValue.getCompileInfo()); - case IndexExecutablePath: this->getExecutablePath().compare(compareValue.getExecutablePath()); + case IndexApplicationDataPath: return this->getApplicationDataDirectory().compare(compareValue.getApplicationDataDirectory()); + case IndexCompileInfo: return this->getCompileInfo().compare(compareValue.getCompileInfo()); + case IndexExecutablePath: return this->getExecutablePath().compare(compareValue.getExecutablePath()); + case IndexExecutablePathExisting: return Compare::compare(this->isExecutablePathExisting(), compareValue.isExecutablePathExisting()); case IndexPlatformInfo: return this->getPlatform().compare(compareValue.getPlatform()); case IndexProcessInfo: return this->getProcessInfo().processName().compare(compareValue.getProcessInfo().processName()); case IndexVersionString: return this->getVersionString().compare(compareValue.getVersionString()); diff --git a/src/blackmisc/applicationinfo.h b/src/blackmisc/applicationinfo.h index 3cb7f9980..648f1a04d 100644 --- a/src/blackmisc/applicationinfo.h +++ b/src/blackmisc/applicationinfo.h @@ -47,6 +47,7 @@ namespace BlackMisc IndexApplicationDataPath, IndexCompileInfo, IndexExecutablePath, + IndexExecutablePathExisting, IndexPlatformInfo, IndexProcessInfo, IndexVersionString, @@ -74,6 +75,11 @@ namespace BlackMisc //! Get executable path. const QString &getExecutablePath() const { return m_exePath; } + //! Is the executable path existing? + //! \remark this indicates if the swift version is still existing + //! \remark file check, relatively slow + bool isExecutablePathExisting() const; + //! Set application data dir //! \remark rootdir of settings, cache and logs void setApplicationDataDirectory(const QString &appDataDir) { m_applicationDataDir = appDataDir; }