diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index d48b57977..0979718de 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -30,6 +30,7 @@ #include using namespace BlackMisc; +using namespace BlackMisc::Db; using namespace BlackMisc::Network; using namespace BlackCore; using namespace BlackCore::Data; @@ -226,17 +227,19 @@ namespace BlackCore void CSetupReader::ps_readUpdateInfo() { - const CUrl url(this->m_updateInfoUrls.obtainNextWorkingUrl()); + // const CUrl url(this->m_updateInfoUrls.obtainNextWorkingUrl()); + + const CUrl url("https://datastore.swift-project.org/shared/0.7.0/updateinfo/updateinfo2.json"); if (url.isEmpty()) { CLogMessage(this).warning("Cannot read update info, URLs: %1, failed URLs: %2") << this->m_updateInfoUrls << this->m_updateInfoUrls.getFailedUrls(); - this->manageUpdateAvailability(false); + this->manageDistributionsInfoAvailability(false); return; } if (m_shutdown) { return; } - sApp->getFromNetwork(url.toNetworkRequest(), { this, &CSetupReader::ps_parseUpdateInfoFile}); + sApp->getFromNetwork(url.toNetworkRequest(), { this, &CSetupReader::ps_parseDistributionsFile}); } void CSetupReader::ps_setupChanged() @@ -382,7 +385,7 @@ namespace BlackCore } } - void CSetupReader::ps_parseUpdateInfoFile(QNetworkReply *nwReplyPtr) + void CSetupReader::ps_parseDistributionsFile(QNetworkReply *nwReplyPtr) { // wrap pointer, make sure any exit cleans up reply // required to use delete later as object is created in a different thread @@ -395,50 +398,48 @@ namespace BlackCore if (nwReply->error() == QNetworkReply::NoError) { - qint64 lastModified = CNetworkUtils::lastModifiedMsSinceEpoch(nwReply.data()); - QString setupJson(nwReplyPtr->readAll()); + const qint64 lastModified = CNetworkUtils::lastModifiedMsSinceEpoch(nwReply.data()); + const QString distributionJson(nwReplyPtr->readAll()); nwReplyPtr->close(); - if (setupJson.isEmpty()) + if (distributionJson.isEmpty()) { - CLogMessage(this).info("No update info file"); + CLogMessage(this).info("No distribution file content"); // try next URL } else { try { - CUpdateInfo currentUpdateInfo(m_updateInfo.get()); // from cache - CUpdateInfo loadedUpdateInfo; - loadedUpdateInfo.convertFromJson(Json::jsonObjectFromString(setupJson)); - if (lastModified > 0 && lastModified > loadedUpdateInfo.getMSecsSinceEpoch()) { loadedUpdateInfo.setMSecsSinceEpoch(lastModified); } - const bool sameVersionLoaded = (loadedUpdateInfo == currentUpdateInfo); - if (sameVersionLoaded) + const CDistributionList loadedDistributions = CDistributionList::fromDatabaseJson( + Json::jsonArrayFromString(distributionJson) + ); + if (loadedDistributions.isEmpty()) { - CLogMessage(this).info("Same update info version loaded from %1 as already in data cache %2") << urlString << m_setup.getFilename(); - this->manageUpdateAvailability(true); - return; // success - } - - CStatusMessage m = m_updateInfo.set(loadedUpdateInfo, loadedUpdateInfo.getMSecsSinceEpoch()); - if (!m.isEmpty()) - { - m.addCategories(getLogCategories()); - CLogMessage::preformatted(m); - this->manageUpdateAvailability(false); - return; // issue with cache + CLogMessage(this).error("Loading of distribution yielded no data"); + this->manageDistributionsInfoAvailability(false); } else { - CLogMessage(this).info("Update info: Updated data cache in %1") << m_updateInfo.getFilename(); - this->manageUpdateAvailability(true); - return; // success - } // cache + CStatusMessage m = m_distributions.set(loadedDistributions, lastModified); + if (m.isFailure()) + { + m.addCategories(getLogCategories()); + CLogMessage::preformatted(m); + this->manageDistributionsInfoAvailability(false); + } + else + { + CLogMessage(this).info("Distribution info: Updated data cache in '%1'") << m_distributions.getFilename(); + this->manageDistributionsInfoAvailability(true); + } // cache + } + return; } catch (const CJsonException &ex) { // we downloaded an unparsable JSON file. // as we control those files something is wrong - const QString errorMsg = QString("Update file loaded from '%1' cannot be parsed").arg(urlString); + const QString errorMsg = QString("Distribution file loaded from '%1' cannot be parsed").arg(urlString); const CStatusMessage msg = ex.toStatusMessage(this, errorMsg); CLogMessage::preformatted(msg); @@ -488,9 +489,9 @@ namespace BlackCore return m_setup.get(); } - CUpdateInfo CSetupReader::getUpdateInfo() const + CDistributionList CSetupReader::getDistributionInfo() const { - return m_updateInfo.get(); + return m_distributions.get(); } CStatusMessageList CSetupReader::getLastSetupReadErrorMessages() const @@ -549,23 +550,23 @@ namespace BlackCore if (!webRead && !localRead) { msgs.push_back(CStatusMessage(this).warning("Since setup was not updated this time, will not start loading of update information")); - this->manageUpdateAvailability(false); + this->manageDistributionsInfoAvailability(false); } return msgs; } - void CSetupReader::manageUpdateAvailability(bool webRead) + void CSetupReader::manageDistributionsInfoAvailability(bool webRead) { if (webRead) { - this->m_updateInfoAvailable = true; - emit updateInfoAvailable(true); + this->m_distributionInfoAvailable = true; + emit distributionInfoAvailable(true); } else { - bool cached = this->m_updateInfo.isSaved(); - this->m_updateInfoAvailable = cached; - emit updateInfoAvailable(cached); + const bool cached = this->m_distributions.isSaved(); + this->m_distributionInfoAvailable = cached; + emit distributionInfoAvailable(cached); } } } // namespace diff --git a/src/blackcore/setupreader.h b/src/blackcore/setupreader.h index 270c2a456..f7a30d2cf 100644 --- a/src/blackcore/setupreader.h +++ b/src/blackcore/setupreader.h @@ -14,7 +14,7 @@ #include "blackcore/blackcoreexport.h" #include "blackcore/data/globalsetup.h" -#include "blackcore/data/updateinfo.h" +#include "blackmisc/db/distributionlist.h" #include "blackmisc/datacache.h" #include "blackmisc/network/urllist.h" #include "blackmisc/statusmessagelist.h" @@ -39,11 +39,11 @@ namespace BlackCore //! //! \note This class is no(!) BlackCore::CThreadedReader as it will be loaded once during startup //! and reading setup data is fast. The read file is also called "bootstrap" file as it tells - //! swift which data are located where. Without that file we cannot start. Once the file is in place (ie in the cache) - //! it can be automatically updated. + //! swift which data and versions are located where. Without that file we cannot start. + //! Once the file is in place (i.e. in the cache) it can be automatically updated. //! //! \sa BlackCore::Data::TGlobalSetup - //! \sa BlackCore::Data::TUpdateInfo + //! \sa BlackMisc::Db::TDistributionInfo class BLACKCORE_EXPORT CSetupReader : public QObject { Q_OBJECT @@ -53,7 +53,7 @@ namespace BlackCore //! Categories static const BlackMisc::CLogCategoryList &getLogCategories(); - //! Has a given cmd line argument for bootstrap URL + //! Has a given cmd line argument for bootstrap URL? bool hasCmdLineBootstrapUrl() const; //! CMD line argument for bootstrap URL @@ -64,9 +64,9 @@ namespace BlackCore //! \threadsafe BlackCore::Data::CGlobalSetup getSetup() const; - //! Update info (version, updates, download URLs) + //! Distributions info (channel, version, platforms, download URLs) //! \threadsafe - BlackCore::Data::CUpdateInfo getUpdateInfo() const; + BlackMisc::Db::CDistributionList getDistributionInfo() const; //! Last setup parsing error messages (if any) BlackMisc::CStatusMessageList getLastSetupReadErrorMessages() const; @@ -76,7 +76,7 @@ namespace BlackCore void setupHandlingCompleted(bool available); //! Setup avialable (from web, cache - void updateInfoAvailable(bool available); + void distributionInfoAvailable(bool available); protected: //! Constructor @@ -100,14 +100,14 @@ namespace BlackCore //! Version info available? //! \threadsafe - bool isUpdateInfoAvailable() const { return m_updateInfoAvailable; } + bool isUpdateInfoAvailable() const { return m_distributionInfoAvailable; } private slots: //! Setup has been read (aka bootstrap file) void ps_parseSetupFile(QNetworkReply *nwReply); //! Update info has been read - void ps_parseUpdateInfoFile(QNetworkReply *nwReplyPtr); + void ps_parseDistributionsFile(QNetworkReply *nwReplyPtr); //! Do reading void ps_readSetup(); @@ -129,7 +129,7 @@ namespace BlackCore bool m_shutdown = false; std::atomic m_setupAvailable { false }; - std::atomic m_updateInfoAvailable { false }; + std::atomic m_distributionInfoAvailable { false }; QString m_localSetupFileValue; //! Local file for setup, passed by cmd line arguments QString m_bootstrapUrlFileValue; //! Bootstrap URL if not local BootstrapMode m_bootstrapMode = Explicit; //! How to bootstrap @@ -139,8 +139,8 @@ namespace BlackCore QCommandLineOption m_cmdBootstrapMode; //!< bootstrap mode mutable QReadWriteLock m_lockSetup; //!< lock for setup BlackMisc::CStatusMessageList m_setupReadErrorMsgs; //!< last parsing error messages - BlackMisc::CData m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup - BlackMisc::CData m_updateInfo {this}; //!< data cache update info + BlackMisc::CData m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup + BlackMisc::CData m_distributions {this}; //!< data cache distributions //! Read by local individual file and update cache from that BlackMisc::CStatusMessageList readLocalBootstrapFile(QString &fileName); @@ -154,7 +154,7 @@ namespace BlackCore //! Emit the available signal //! \threadsafe - void manageUpdateAvailability(bool webRead); + void manageDistributionsInfoAvailability(bool webRead); //! Set last setup parsing messages void setLastSetupReadErrorMessages(const BlackMisc::CStatusMessageList &messages);