MCPcopy Create free account
hub / github.com/comaps/comaps / RunCountriesCheckAsync

Method RunCountriesCheckAsync

libs/storage/storage.cpp:1325–1362  ·  view source on GitHub ↗

@todo(pastk): cleanup unused functions

Source from the content-addressed store, hash-verified

1323
1324/// @todo(pastk): cleanup unused functions
1325void Storage::RunCountriesCheckAsync()
1326{
1327 m_downloader->DownloadAsString(SERVER_MAPS_FILE, [this](std::string const & buffer)
1328 {
1329 LOG(LDEBUG, (SERVER_MAPS_FILE, "downloaded"));
1330
1331 int64_t const dataVersion = ParseIndexAndGetDataVersion(buffer);
1332 if (dataVersion <= m_currentVersion)
1333 return false;
1334
1335 LOG(LDEBUG, ("Try download", COUNTRIES_FILE, "for", dataVersion));
1336
1337 m_downloader->DownloadAsString(downloader::GetFileDownloadUrl(COUNTRIES_FILE, dataVersion),
1338 [this, dataVersion](std::string const & buffer)
1339 {
1340 LOG(LDEBUG, (COUNTRIES_FILE, "downloaded"));
1341
1342 std::shared_ptr<Storage> storage(new Storage(7 /* dummy */));
1343 storage->m_currentVersion =
1344 LoadCountriesFromBuffer(buffer, storage->m_countries, storage->m_affiliations, storage->m_countryNameSynonyms,
1345 storage->m_mwmTopCityGeoIds, storage->m_mwmTopCountryGeoIds, storage->m_mapSeries);
1346 if (storage->m_currentVersion > 0)
1347 {
1348 LOG(LDEBUG, ("Apply new version", storage->m_currentVersion, dataVersion));
1349 ASSERT_EQUAL(storage->m_currentVersion, dataVersion, ());
1350
1351 /// @todo Or use simple but reliable strategy: download new file and ask to restart the app?
1352 GetPlatform().RunTask(Platform::Thread::Gui,
1353 [this, storage, buffer = std::move(buffer)]() { ApplyCountries(buffer, *storage); });
1354 }
1355
1356 return false;
1357 }, true /* force reset */);
1358
1359 // True when new download was requested.
1360 return true;
1361 }, false /* force reset */);
1362}
1363
1364int64_t Storage::ParseIndexAndGetDataVersion(std::string const & index) const
1365{

Callers

nothing calls this directly

Calls 4

GetFileDownloadUrlFunction · 0.85
LoadCountriesFromBufferFunction · 0.85
DownloadAsStringMethod · 0.80
RunTaskMethod · 0.80

Tested by

no test coverage detected