From be05afa542096a7a3156547b8baca21e5c2f09e5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 25 Dec 2017 13:12:56 +0100 Subject: [PATCH] Ref T199, data directory will be tagged A information JSON file will be written into the data directory. This can be used to display other swift versions. --- src/blackcore/application.cpp | 23 +++++++++++++++++------ src/blackcore/application.h | 5 ++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index ecc6f1d9a..afc08bb63 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -18,6 +18,7 @@ #include "blackcore/setupreader.h" #include "blackcore/webdataservices.h" #include "blackmisc/atomicfile.h" +#include "blackmisc/applicationinfo.h" #include "blackmisc/datacache.h" #include "blackmisc/dbusserver.h" #include "blackmisc/directoryutils.h" @@ -102,7 +103,7 @@ namespace BlackCore CApplication::CApplication(const QString &applicationName, CApplicationInfo::Application application, bool init) : m_accessManager(new QNetworkAccessManager(this)), - m_applicationInfo(application, QCoreApplication::applicationDirPath(), CBuildConfig::getVersionString(), CProcessInfo::currentProcess()), + m_applicationInfo(application), m_cookieManager( {}, this), m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty()) { Q_ASSERT_X(!sApp, Q_FUNC_INFO, "already initialized"); @@ -131,6 +132,7 @@ namespace BlackCore m_alreadyRunning = CApplication::getRunningApplications().containsApplication(CApplication::getSwiftApplication()); this->initParser(); this->initLogging(); + this->tagApplicationDataDirectory(); // // cmd line arguments not yet parsed here @@ -221,16 +223,17 @@ namespace BlackCore this->gracefulShutdown(); } - CApplicationInfo CApplication::getApplicationInfo() const + const CApplicationInfo &CApplication::getApplicationInfo() const { - return { CApplication::getSwiftApplication(), QCoreApplication::applicationFilePath(), CBuildConfig::getVersionString(), CProcessInfo::currentProcess() }; + static const CApplicationInfo a(CApplication::getSwiftApplication()); + return a; } CApplicationInfoList CApplication::getRunningApplications() { CApplicationInfoList apps; apps.convertFromJsonNoThrow(CFileUtils::readLockedFileToString(swiftDataRoot() + "apps.json"), {}, {}); - apps.removeIf([](const CApplicationInfo & info) { return !info.processInfo().exists(); }); + apps.removeIf([](const CApplicationInfo & info) { return !info.getProcessInfo().exists(); }); return apps; } @@ -267,8 +270,6 @@ namespace BlackCore m_singleApplication = singleApplication; } - - QString CApplication::getExecutableForApplication(CApplicationInfo::Application application) const { QString search; @@ -1535,4 +1536,14 @@ namespace BlackCore } return reply; } + + void CApplication::tagApplicationDataDirectory() + { + const QString d = CDirectoryUtils::normalizedApplicationDataDirectory(); + const QDir dir(d); + if (!dir.exists() || !dir.isReadable()) { return; } + const QString aiStr(this->getApplicationInfo().toJsonString()); + const QString filePath(CFileUtils::appendFilePaths(dir.path(), CApplicationInfo::fileName())); // will be overridden by next swift app + CFileUtils::writeStringToFile(aiStr, filePath); + } } // ns diff --git a/src/blackcore/application.h b/src/blackcore/application.h index 397b7df54..117c2ba91 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -111,7 +111,7 @@ namespace BlackCore virtual ~CApplication(); //! Application information - BlackMisc::CApplicationInfo getApplicationInfo() const; + const BlackMisc::CApplicationInfo &getApplicationInfo() const; //! Information about all running apps (including this one only if exec() has already been called) static BlackMisc::CApplicationInfoList getRunningApplications(); @@ -589,6 +589,9 @@ namespace BlackCore int maxRedirects, std::function requestOrPostMethod); + //! Write meta information into the application directory so other swift versions can display them + void tagApplicationDataDirectory(); + QNetworkAccessManager *m_accessManager = nullptr; //!< single network access manager BlackMisc::CApplicationInfo m_applicationInfo; //!< Application if specified QScopedPointer m_coreFacade; //!< core facade if any