diff --git a/map/framework.cpp b/map/framework.cpp index 6a68508b94..6e72dd865a 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1717,16 +1717,10 @@ void Framework::UpdateSavedDataVersion() Settings::Set("DataVersion", m_storage.GetCurrentDataVersion()); } -guides::GuidesManager & Framework::GetGuidesManager() +bool Framework::GetGuideInfo(storage::TIndex const & index, guides::GuideInfo & info) const { - return m_storage.GetGuideManager(); -} - -bool Framework::GetGuideInfo(storage::TIndex const & index, guides::GuideInfo & info) -{ - string guideId = m_storage.CountryFileName(index); - storage::TStatus t = GetCountryStatus(index); - return (t == storage::EOnDisk && GetGuidesManager().GetGuideInfo(guideId, info)); + return (GetCountryStatus(index) == storage::EOnDisk && + m_storage.GetGuideManager().GetGuideInfo(m_storage.CountryFileName(index), info)); } void Framework::GetGuidesInfosWithDownloadedMaps(vector & guides) diff --git a/map/framework.hpp b/map/framework.hpp index aca2ca17a9..c5a55f069a 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -482,8 +482,7 @@ public: //@{ public: guides::GuidesManager & GetGuidesManager(); - bool GetGuideInfo(storage::TIndex const & index, guides::GuideInfo & info); - void GetGuidesInfosWithDownloadedMaps(vector & guides); + bool GetGuideInfo(storage::TIndex const & index, guides::GuideInfo & info) const; + void GetGuidesInfosWithDownloadedMaps(vector & guides) const; //@} - }; diff --git a/storage/guides.cpp b/storage/guides.cpp index c9853e8d17..cfe03ee04f 100644 --- a/storage/guides.cpp +++ b/storage/guides.cpp @@ -16,11 +16,13 @@ #include "../../3party/jansson/myjansson.hpp" -#define GUIDE_UPDATE_TIME_KEY "guideUpdateTime" -#define GUIDE_ADVERTISE_KEY "GuideAdvertised: " -#define GUIDE_UPDATE_PERIOD 60 * 60 * 24 +char const * GUIDE_UPDATE_TIME_KEY = "GuideUpdateTime"; +char const * GUIDE_ADVERTISE_KEY "GuideAdvertised:"; +int const GUIDE_UPDATE_PERIOD = 60 * 60 * 24; -using namespace guides; + +namespace guides +{ bool GuidesManager::RestoreFromFile() { @@ -31,9 +33,9 @@ bool GuidesManager::RestoreFromFile() r.ReadAsString(data); return ValidateAndParseGuidesData(data); } - catch (exception e) + catch (RootException const & ex) { - LOG(LWARNING, ("Exception while restring from file", e.what())); + LOG(LWARNING, (ex.Msg())); return false; } } @@ -42,12 +44,15 @@ void GuidesManager::UpdateGuidesData() { if (m_httpRequest) return; + double lastUpdateTime; - bool flag = Settings::Get(GUIDE_UPDATE_TIME_KEY, lastUpdateTime); + bool const flag = Settings::Get(GUIDE_UPDATE_TIME_KEY, lastUpdateTime); + double const currentTime = my::Timer::LocalTime(); if (!flag || ((currentTime - lastUpdateTime) >= GUIDE_UPDATE_PERIOD)) { Settings::Set(GUIDE_UPDATE_TIME_KEY, currentTime); + downloader::HttpRequest::CallbackT onFinish = bind(&GuidesManager::OnFinish, this, _1); m_httpRequest.reset(downloader::HttpRequest::Get(GetGuidesDataUrl(), onFinish)); } @@ -83,10 +88,11 @@ void GuidesManager::OnFinish(downloader::HttpRequest & request) if (ValidateAndParseGuidesData(data)) SaveToFile(); else - LOG(LWARNING, ("Request data is invalid ", request.Data())); + LOG(LWARNING, ("Request data is invalid:", request.Data())); } else - LOG(LWARNING, ("Request is failed to complete", request.Status())); + LOG(LWARNING, ("Request is failed to complete:", request.Status())); + m_httpRequest.reset(); } @@ -111,13 +117,13 @@ bool GuidesManager::ValidateAndParseGuidesData(string const & jsonData) iter = json_object_iter_next(root.get(), iter); } - LOG(LDEBUG, ("Read guides data:", temp.size())); + m_countryToInfoMapping.swap(temp); return true; } catch (my::Json::Exception const &) { - LOG(LDEBUG, ("Failded to read guides data.")); + LOG(LWARNING, ("Failded to parse guides data.")); return false; } } @@ -139,9 +145,9 @@ void GuidesManager::SaveToFile() const string const path = GetPlatform().WritableDir() + GetDataFileName(); FileWriter writer(path); - string const openJson = "{"; - string const closeJson = "}"; - writer.Write(openJson.data(), openJson.size()); + char braces[] = { '{', '}' }; + + writer.Write(&braces[0], 1); if (!m_countryToInfoMapping.empty()) { @@ -164,5 +170,7 @@ void GuidesManager::SaveToFile() const } } - writer.Write(closeJson.data(), closeJson.size()); + writer.Write(&braces[1], 1); +} + } diff --git a/storage/storage.cpp b/storage/storage.cpp index e7526e6279..66e48bd2a9 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -470,14 +470,4 @@ namespace storage return fListNoExt.size(); } - - int64_t Storage::GetCurrentDataVersion() const - { - return m_currentVersion; - } - - guides::GuidesManager & Storage::GetGuideManager() - { - return m_guideManager; - } } diff --git a/storage/storage.hpp b/storage/storage.hpp index b9cc09da4b..123bc234fb 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -109,7 +109,7 @@ namespace storage size_t CountriesCount(TIndex const & index) const; string const & CountryName(TIndex const & index) const; string const & CountryFlag(TIndex const & index) const; - //country file name without extension + /// @return Country file name without extension. string const & CountryFileName(TIndex const & index) const; LocalAndRemoteSizeT CountrySizeInBytes(TIndex const & index) const; TStatus CountryStatus(TIndex const & index) const; @@ -127,10 +127,15 @@ namespace storage /// @return number of outdated countries in the list int GetOutdatedCountries(vector & list) const; - int64_t GetCurrentDataVersion() const; + int64_t GetCurrentDataVersion() const { return m_currentVersion; } + + //@{ private: guides::GuidesManager m_guideManager; + public: - guides::GuidesManager & GetGuideManager(); + guides::GuidesManager const & GetGuideManager() const { return m_guideManager; } + guides::GuidesManager & GetGuideManager() { return m_guideManager; } + //@} }; }