From 101559e7ab230e9c738510006f191a6cee918f9e Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 9 Mar 2016 10:40:46 +0300 Subject: [PATCH] [new downloader] Implementation of Storage::GetUpdateInfo(). --- storage/storage.cpp | 21 +++++++++++++++++++++ storage/storage.hpp | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/storage/storage.cpp b/storage/storage.cpp index 75faaf95d1..eb56376e3d 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1418,4 +1418,25 @@ void Storage::RetryDownloadNode(TCountryId const & countryId) DownloadNode(descendantId); }); } + +bool Storage::GetUpdateInfo(TCountryId const & countryId, UpdateInfo & updateInfo) const +{ + auto const updateInfoAccumulator = [&updateInfo, this](TCountryTreeNode const & descendantNode) + { + if (descendantNode.ChildrenCount() != 0 || GetNodeStatus(descendantNode).status != NodeStatus::OnDiskOutOfDate) + return; + updateInfo.m_numberOfMwmFilesToUpdate += 1; // It's not a group mwm. + updateInfo.m_totalUpdateSizeInBytes += descendantNode.Value().GetSubtreeMwmCounter(); + }; + + TCountryTreeNode const * const node = m_countries.FindFirst(countryId); + if (!node) + { + ASSERT(false, ()); + return false; + } + updateInfo = UpdateInfo(); + node->ForEachInSubtree(updateInfoAccumulator); + return true; +} } // namespace storage diff --git a/storage/storage.hpp b/storage/storage.hpp index 8fcda53925..7e6833846d 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -251,6 +251,8 @@ public: /// \brief Information for "Update all mwms" button. struct UpdateInfo { + UpdateInfo() : m_numberOfMwmFilesToUpdate(0), m_totalUpdateSizeInBytes(0) {} + size_t m_numberOfMwmFilesToUpdate; size_t m_totalUpdateSizeInBytes; }; @@ -330,7 +332,7 @@ public: /// \brief Get information for mwm update button. /// \return true if updateInfo is filled correctly and false otherwise. - bool GetUpdateInfo(TCountryId const & countryId, UpdateInfo & updateInfo) const { return true; } + bool GetUpdateInfo(TCountryId const & countryId, UpdateInfo & updateInfo) const; /// \brief Calls |toDo| for each node for subtree with |root|. /// For example ForEachInSubtree(GetRootId()) calls |toDo| for every node including