1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "storage/storage_helpers.hpp"
#include "storage/country_info_getter.hpp"
#include "storage/storage.hpp"
#include "platform/platform.hpp"
namespace storage
{
bool IsPointCoveredByDownloadedMaps(m2::PointD const & position,
Storage const & storage,
CountryInfoGetter const & countryInfoGetter)
{
return storage.IsNodeDownloaded(countryInfoGetter.GetRegionCountryId(position));
}
bool IsDownloadFailed(Status status)
{
return status == Status::EDownloadFailed || status == Status::EOutOfMemFailed ||
status == Status::EUnknown;
}
bool IsEnoughSpaceForDownload(TMwmSize mwmSize)
{
return GetPlatform().GetWritableStorageStatus(mwmSize) ==
Platform::TStorageStatus::STORAGE_OK;
}
bool IsEnoughSpaceForDownload(TMwmSize mwmSizeDiff, TMwmSize maxMwmSize)
{
// Mwm size is less than |maxMwmSize|. In case of map update at first we download updated map
// and only after that we do delete the obsolete map. So in such a case we might need up to
// |maxMwmSize| of extra space.
return IsEnoughSpaceForDownload(mwmSizeDiff + maxMwmSize);
}
bool IsEnoughSpaceForDownload(TCountryId const & countryId, Storage const & storage)
{
NodeAttrs nodeAttrs;
storage.GetNodeAttrs(countryId, nodeAttrs);
return IsEnoughSpaceForDownload(nodeAttrs.m_mwmSize);
}
bool IsEnoughSpaceForUpdate(TCountryId const & countryId, Storage const & storage)
{
Storage::UpdateInfo updateInfo;
storage.GetUpdateInfo(countryId, updateInfo);
TMwmSize spaceNeedForUpdate = updateInfo.m_sizeDifference > 0 ? updateInfo.m_sizeDifference : 0;
return IsEnoughSpaceForDownload(spaceNeedForUpdate, storage.GetMaxMwmSizeBytes());
}
m2::RectD CalcLimitRect(TCountryId const & countryId,
Storage const & storage,
CountryInfoGetter const & countryInfoGetter)
{
m2::RectD boundingBox;
auto const accumulator =
[&countryInfoGetter, &boundingBox](TCountryId const & descendantId, bool groupNode)
{
if (!groupNode)
boundingBox.Add(countryInfoGetter.GetLimitRectForLeaf(descendantId));
};
storage.ForEachInSubtree(countryId, accumulator);
ASSERT(boundingBox.IsValid(), ());
return boundingBox;
}
} // namespace storage
|