diff options
author | vng <viktor.govako@gmail.com> | 2012-06-21 06:50:14 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:40:04 +0300 |
commit | 66b7991091ec7891e6566663053dc4a20186db1a (patch) | |
tree | b74fe19ccd0649927f6959732b4577e60fe13d8b /storage | |
parent | 8828c4da0a35001b4852ae01cf120689f01fc148 (diff) |
Take into account valid local country size.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/country.cpp | 18 | ||||
-rw-r--r-- | storage/country.hpp | 5 | ||||
-rw-r--r-- | storage/storage.cpp | 23 | ||||
-rw-r--r-- | storage/storage.hpp | 5 |
4 files changed, 27 insertions, 24 deletions
diff --git a/storage/country.cpp b/storage/country.cpp index 5e74061b30..02618a3b00 100644 --- a/storage/country.cpp +++ b/storage/country.cpp @@ -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); diff --git a/storage/country.hpp b/storage/country.hpp index a133c3a6b6..acf9e8ddfa 100644 --- a/storage/country.hpp +++ b/storage/country.hpp @@ -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 { diff --git a/storage/storage.cpp b/storage/storage.cpp index 6c8f8fe98b..5c9dbe9780 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -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 diff --git a/storage/storage.hpp b/storage/storage.hpp index e5ed5c05b6..31e3ef33c7 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -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> |