forked from organicmaps/organicmaps
[new downloader] Moving maps with error status to downloaded section of downloader.
This commit is contained in:
parent
ab50533017
commit
e6c48fc887
3 changed files with 8 additions and 65 deletions
|
@ -92,12 +92,6 @@ void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & resultCou
|
|||
resultCountries.insert(country.GetCountryId());
|
||||
}
|
||||
|
||||
bool HasCountryId(TCountriesVec const & sortedCountryIds, TCountryId const & countryId)
|
||||
{
|
||||
ASSERT(is_sorted(sortedCountryIds.begin(), sortedCountryIds.end()), ());
|
||||
return binary_search(sortedCountryIds.begin(), sortedCountryIds.end(), countryId);
|
||||
}
|
||||
|
||||
Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */, string const & dataDir /* = string() */)
|
||||
: m_downloader(new HttpMapFilesDownloader()), m_currentSlotId(0), m_dataDir(dataDir),
|
||||
m_downloadMapOnTheMap(nullptr)
|
||||
|
@ -1137,43 +1131,17 @@ void Storage::GetChildrenInGroups(TCountryId const & parent,
|
|||
|
||||
downloadedChildren.clear();
|
||||
availChildren.clear();
|
||||
TCountriesVec localMaps;
|
||||
GetLocalRealMaps(localMaps);
|
||||
for (auto const & downloadingMap : m_queue)
|
||||
localMaps.push_back(downloadingMap.GetCountryId());
|
||||
|
||||
if (localMaps.empty())
|
||||
parentNode->ForEachChild([&](TCountryTreeNode const & childNode)
|
||||
{
|
||||
GetChildren(parent, availChildren);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t const childrenCount = parentNode->ChildrenCount();
|
||||
sort(localMaps.begin(), localMaps.end());
|
||||
|
||||
for (size_t i = 0; i < childrenCount; ++i)
|
||||
{
|
||||
TCountryTreeNode const & child = parentNode->Child(i);
|
||||
TCountryId const & childCountryId = child.Value().Name();
|
||||
if (HasCountryId(localMaps, childCountryId))
|
||||
{ // CountryId of child is a name of an mwm.
|
||||
downloadedChildren.push_back(childCountryId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Child is a group of mwms.
|
||||
bool hasDownloadedDescendant = false;
|
||||
child.ForEachDescendant([&](TCountryTreeNode const & descendant)
|
||||
{
|
||||
TCountryId const & countryId = descendant.Value().Name();
|
||||
if (!hasDownloadedDescendant && HasCountryId(localMaps, countryId))
|
||||
hasDownloadedDescendant = true;
|
||||
});
|
||||
if (hasDownloadedDescendant == true)
|
||||
downloadedChildren.push_back(childCountryId);
|
||||
NodeStatus const childStatus = GetNodeStatus(childNode).status;
|
||||
TCountryId const childValue = childNode.Value().Name();
|
||||
ASSERT_NOT_EQUAL(childStatus, NodeStatus::Undefined, ());
|
||||
if (childStatus == NodeStatus::NotDownloaded)
|
||||
availChildren.push_back(childValue);
|
||||
else
|
||||
availChildren.push_back(childCountryId);
|
||||
}
|
||||
downloadedChildren.push_back(childValue);
|
||||
});
|
||||
}
|
||||
|
||||
bool Storage::IsNodeDownloaded(TCountryId const & countryId) const
|
||||
|
|
|
@ -564,10 +564,6 @@ private:
|
|||
|
||||
void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & resultCountries);
|
||||
|
||||
/// \returns true if |sortedCountryIds| contains |countryId|.
|
||||
/// \note. |sortedCountryIds| should be sorted.
|
||||
bool HasCountryId(TCountriesVec const & sortedCountryIds, TCountryId const & countryId);
|
||||
|
||||
template <class ToDo>
|
||||
void Storage::ForEachInSubtree(TCountryId const & root, ToDo && toDo) const
|
||||
{
|
||||
|
|
|
@ -1045,11 +1045,6 @@ UNIT_TEST(StorageTest_HasCountryId)
|
|||
TCountriesVec middleEarthCountryIdVec =
|
||||
{"Arnor", "Mordor", "Rhovanion", "Rhun", "Gondor", "Eriador", "Rohan"};
|
||||
sort(middleEarthCountryIdVec.begin(), middleEarthCountryIdVec.end());
|
||||
|
||||
TEST(HasCountryId(middleEarthCountryIdVec, "Gondor"), ());
|
||||
TEST(HasCountryId(middleEarthCountryIdVec, "Arnor"), ());
|
||||
TEST(!HasCountryId(middleEarthCountryIdVec, "Azerbaijan"), ());
|
||||
TEST(!HasCountryId(middleEarthCountryIdVec, "Alban"), ());
|
||||
}
|
||||
|
||||
UNIT_TEST(StorageTest_DownloadedMapTests)
|
||||
|
@ -1091,11 +1086,6 @@ UNIT_TEST(StorageTest_DownloadedMapTests)
|
|||
TCountriesVec localRealMaps;
|
||||
storage.GetLocalRealMaps(localRealMaps);
|
||||
sort(localRealMaps.begin(), localRealMaps.end());
|
||||
TEST(HasCountryId(localRealMaps, "Algeria_Central"), ());
|
||||
TEST(HasCountryId(localRealMaps, "Algeria_Coast"), ());
|
||||
TEST(!HasCountryId(localRealMaps, "Algeria_Coast.mwm"), ());
|
||||
TEST(!HasCountryId(localRealMaps, "World"), ());
|
||||
TEST(!HasCountryId(localRealMaps, "WorldCoasts"), ());
|
||||
|
||||
TEST(storage.IsNodeDownloaded("Algeria_Central"), ());
|
||||
TEST(storage.IsNodeDownloaded("Algeria_Coast"), ());
|
||||
|
@ -1109,14 +1099,9 @@ UNIT_TEST(StorageTest_DownloadedMapTests)
|
|||
TCountriesVec downloaded, available;
|
||||
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
|
||||
sort(downloaded.begin(), downloaded.end());
|
||||
TEST(HasCountryId(downloaded, "Algeria"), ());
|
||||
TEST(!HasCountryId(downloaded, "Algeria_Central"), ());
|
||||
TEST(!HasCountryId(downloaded, "Algeria_Coast"), ());
|
||||
|
||||
storage.GetChildrenInGroups("Algeria", downloaded, available);
|
||||
sort(downloaded.begin(), downloaded.end());
|
||||
TEST(HasCountryId(downloaded, "Algeria_Central"), ());
|
||||
TEST(HasCountryId(downloaded, "Algeria_Coast"), ());
|
||||
|
||||
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
|
||||
TEST(downloaded.empty(), ());
|
||||
|
@ -1126,9 +1111,6 @@ UNIT_TEST(StorageTest_DownloadedMapTests)
|
|||
// Algeria_Central has been deleted.
|
||||
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
|
||||
sort(downloaded.begin(), downloaded.end());
|
||||
TEST(HasCountryId(downloaded, "Algeria"), ());
|
||||
TEST(!HasCountryId(downloaded, "Algeria_Central"), ());
|
||||
TEST(!HasCountryId(downloaded, "Algeria_Coast"), ());
|
||||
|
||||
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
|
||||
TEST(downloaded.empty(), ());
|
||||
|
@ -1143,9 +1125,6 @@ UNIT_TEST(StorageTest_DownloadedMapTests)
|
|||
// Storage::GetChildrenInGroups test when Algeria_Coast and Algeria_Central have been deleted.
|
||||
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
|
||||
sort(downloaded.begin(), downloaded.end());
|
||||
TEST(!HasCountryId(downloaded, "Algeria"), ());
|
||||
TEST(!HasCountryId(downloaded, "Algeria_Central"), ());
|
||||
TEST(!HasCountryId(downloaded, "Algeria_Coast"), ());
|
||||
|
||||
TEST(!storage.IsNodeDownloaded("Algeria_Central"), ());
|
||||
TEST(!storage.IsNodeDownloaded("Algeria_Coast"), ());
|
||||
|
|
Loading…
Add table
Reference in a new issue