forked from organicmaps/organicmaps-tmp
Take into account valid local country size.
This commit is contained in:
parent
8828c4da0a
commit
66b7991091
4 changed files with 27 additions and 24 deletions
|
@ -16,14 +16,17 @@
|
|||
namespace storage
|
||||
{
|
||||
|
||||
/// Simple check - if file is present on disk. Incomplete download has different file name.
|
||||
bool IsFileDownloaded(CountryFile const & file)
|
||||
uint32_t CountryFile::GetFileSize() const
|
||||
{
|
||||
uint64_t size = 0;
|
||||
if (!GetPlatform().GetFileSizeByName(file.GetFileWithExt(), size))
|
||||
return false;
|
||||
|
||||
return true;//tile.second == size;
|
||||
if (GetPlatform().GetFileSizeByName(GetFileWithExt(), size))
|
||||
{
|
||||
uint32_t const ret = static_cast<uint32_t>(size);
|
||||
ASSERT_EQUAL ( ret, size, () );
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct CountryBoundsCalculator
|
||||
|
@ -50,8 +53,7 @@ LocalAndRemoteSizeT Country::Size() const
|
|||
uint64_t localSize = 0, remoteSize = 0;
|
||||
for (FilesContainerT::const_iterator it = m_files.begin(); it != m_files.end(); ++it)
|
||||
{
|
||||
if (IsFileDownloaded(*it))
|
||||
localSize += it->m_remoteSize;
|
||||
localSize += it->GetFileSize();
|
||||
remoteSize += it->m_remoteSize;
|
||||
}
|
||||
return LocalAndRemoteSizeT(localSize, remoteSize);
|
||||
|
|
|
@ -28,15 +28,16 @@ namespace storage
|
|||
|
||||
string GetFileWithExt() const { return m_fileName + DATA_FILE_EXTENSION; }
|
||||
|
||||
uint32_t GetFileSize() const;
|
||||
|
||||
string m_fileName; /// Same as id of country\region.
|
||||
uint32_t m_remoteSize;
|
||||
int64_t m_price;
|
||||
};
|
||||
|
||||
typedef buffer_vector<CountryFile, 1> FilesContainerT;
|
||||
typedef pair<uint64_t, uint64_t> LocalAndRemoteSizeT;
|
||||
|
||||
bool IsFileDownloaded(CountryFile const & file);
|
||||
|
||||
/// Serves as a proxy between GUI and downloaded files
|
||||
class Country
|
||||
{
|
||||
|
|
|
@ -131,19 +131,17 @@ namespace storage
|
|||
if (m_failedCountries.count(index) > 0)
|
||||
return EDownloadFailed;
|
||||
|
||||
if (m_indexGeneration.count(index) > 0)
|
||||
return EGeneratingIndex;
|
||||
//if (m_indexGeneration.count(index) > 0)
|
||||
// return EGeneratingIndex;
|
||||
|
||||
LocalAndRemoteSizeT const size = CountryByIndex(index).Size();
|
||||
if (size.first == size.second)
|
||||
{
|
||||
if (size.second == 0)
|
||||
return EUnknown;
|
||||
else
|
||||
return EOnDisk;
|
||||
}
|
||||
if (size.first == 0)
|
||||
return ENotDownloaded;
|
||||
|
||||
return ENotDownloaded;
|
||||
if (size.second == 0)
|
||||
return EUnknown;
|
||||
|
||||
return (size.first == size.second ? EOnDisk : EOnDiskOutOfDate);
|
||||
}
|
||||
|
||||
void Storage::DownloadCountry(TIndex const & index)
|
||||
|
@ -207,7 +205,7 @@ namespace storage
|
|||
FilesContainerT const & tiles = CountryByIndex(index).Files();
|
||||
for (FilesContainerT::const_iterator it = tiles.begin(); it != tiles.end(); ++it)
|
||||
{
|
||||
if (!IsFileDownloaded(*it))
|
||||
if (it->GetFileSize() == 0)
|
||||
{
|
||||
// send Country name for statistics
|
||||
string const postBody = it->m_fileName;
|
||||
|
@ -223,6 +221,7 @@ namespace storage
|
|||
|
||||
// continue with next country
|
||||
m_queue.pop_front();
|
||||
|
||||
// reset total country's download progress
|
||||
if (!m_queue.empty())
|
||||
{
|
||||
|
@ -425,7 +424,7 @@ namespace storage
|
|||
void Storage::UpdateAfterSearchIndex(TIndex const & index, string const & fName)
|
||||
{
|
||||
// remove from index set
|
||||
m_indexGeneration.erase(index);
|
||||
//m_indexGeneration.erase(index);
|
||||
NotifyStatusChanged(index);
|
||||
|
||||
// activate downloaded map piece
|
||||
|
|
|
@ -23,7 +23,8 @@ namespace storage
|
|||
EDownloading,
|
||||
EInQueue,
|
||||
EUnknown,
|
||||
EGeneratingIndex
|
||||
EGeneratingIndex,
|
||||
EOnDiskOutOfDate
|
||||
};
|
||||
|
||||
struct TIndex
|
||||
|
@ -81,7 +82,7 @@ namespace storage
|
|||
TCountriesSet m_failedCountries;
|
||||
|
||||
/// store countries set for which search index is generating
|
||||
TCountriesSet m_indexGeneration;
|
||||
//TCountriesSet m_indexGeneration;
|
||||
|
||||
/// used to correctly calculate total country download progress with more than 1 file
|
||||
/// <current, total>
|
||||
|
|
Loading…
Add table
Reference in a new issue