diff --git a/map/framework.cpp b/map/framework.cpp index 5b72f5abf1..05718e46f6 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -236,15 +236,30 @@ void Framework::StopLocationFollow() CallDrapeFunction(bind(&df::DrapeEngine::StopLocationFollow, _1)); } +void Framework::PreMigrate(ms::LatLon const & position, + storage::Storage::TChangeCountryFunction const & change, + storage::Storage::TProgressFunction const & progress) +{ + Storage().PrefetchMigrateData(); + + storage::CountryInfoReader infoGetter(GetPlatform().GetReader(PACKED_POLYGONS_MIGRATE_FILE), + GetPlatform().GetReader(COUNTRIES_MIGRATE_FILE)); + + TCountryId currentCountryId = infoGetter.GetRegionCountryId(MercatorBounds::FromLatLon(position)); + + Storage().m_prefetchStorage->Subscribe(change, progress); + Storage().m_prefetchStorage->DownloadNode(currentCountryId); +} + void Framework::Migrate() { m_searchEngine.reset(); m_infoGetter.reset(); - Storage().DeleteAllLocalMaps(); + TCountriesVec existedCountries; + Storage().DeleteAllLocalMaps(&existedCountries); DeregisterAllMaps(); m_model.Clear(); - // @TODO(syershov) Implement it correctly please. - // Storage().Migrate(); + Storage().Migrate(existedCountries); InitCountryInfoGetter(); InitSearchEngine(); RegisterAllMaps(); @@ -522,12 +537,11 @@ void Framework::RegisterAllMaps() { bool disableFastMigrate = false; Settings::Get("DisableFastMigrate", disableFastMigrate); - // @TODO(syershov) Implement it correctly please. -// if (!disableFastMigrate && !m_storage.HaveDownloadedCountries()) -// { -// Migrate(); -// return; -// } + if (!disableFastMigrate && !m_storage.HaveDownloadedCountries()) + { + Migrate(); + return; + } } int minFormat = numeric_limits::max(); diff --git a/map/framework.hpp b/map/framework.hpp index f0414683e2..4e97469ac1 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -150,6 +150,9 @@ public: Framework(); virtual ~Framework(); + /// Migrate to new version of very different data. + void PreMigrate(ms::LatLon const & position, storage::Storage::TChangeCountryFunction const & change, + storage::Storage::TProgressFunction const & progress); void Migrate(); void InitWatchFrameRenderer(float visualScale); diff --git a/qt/search_panel.cpp b/qt/search_panel.cpp index 8bf37450f1..3787a78dce 100644 --- a/qt/search_panel.cpp +++ b/qt/search_panel.cpp @@ -217,8 +217,27 @@ bool SearchPanel::TryMigrate(QString const & str) m_pEditor->setText(""); parentWidget()->hide(); - m_pDrawWidget->GetFramework().Migrate(); + auto stateChanged = [&](storage::TCountryId const & id) + { + storage::TStatus const nextStatus = m_pDrawWidget->GetFramework().Storage().m_prefetchStorage->CountryStatusEx(id); + LOG_SHORT(LINFO, (id, "status :", nextStatus)); + if (nextStatus == storage::TStatus::EOnDisk) + { + LOG_SHORT(LINFO, ("Prefetch done. Ready to migrate.")); + m_pDrawWidget->GetFramework().Migrate(); + } + }; + + auto progressChanged = [](storage::TCountryId const & id, storage::LocalAndRemoteSizeT const & sz) + { + LOG(LINFO, (id, "downloading progress:", sz)); + }; + + ms::LatLon curPos(55.7, 37.7); + + m_pDrawWidget->GetFramework().PreMigrate(curPos, stateChanged, progressChanged); return true; + } void SearchPanel::OnSearchTextChanged(QString const & str) diff --git a/storage/storage.cpp b/storage/storage.cpp index 14e898bda8..5f69e2aab8 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -123,6 +123,11 @@ void Storage::DeleteAllLocalMaps(TCountriesVec * existedCountries /* = nullptr * } } +bool Storage::HaveDownloadedCountries() const +{ + return !m_localFiles.empty(); +} + void Storage::PrefetchMigrateData() { m_prefetchStorage.reset(new Storage(COUNTRIES_MIGRATE_FILE, "migrate")); diff --git a/storage/storage.hpp b/storage/storage.hpp index 667ff7a158..8a4fec9e44 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -208,11 +208,6 @@ public: TOnStatusChangedCallback m_onStatusChanged; }; - unique_ptr m_prefetchStorage; - void PrefetchMigrateData(); - void SaveDownloadQueue(); - void RestoreDownloadQueue(); - /// \brief Returns root country id of the county tree. TCountryId const GetRootId() const; /// \param childrenId is filled with children node ids by a parent. For example GetChildren(GetRootId()) @@ -303,6 +298,17 @@ public: void Init(TUpdate const & update); + /// Do we have downloaded countries + bool HaveDownloadedCountries() const; + + /// Prefetch MWMs before migrate + unique_ptr m_prefetchStorage; + void PrefetchMigrateData(); + + void SaveDownloadQueue(); + void RestoreDownloadQueue(); + + /// Delete local maps and aggregate their Id if needed void DeleteAllLocalMaps(TCountriesVec * existedCountries = nullptr);