From 56048c1cf7bd4d9c41ef6736d195e6b79927be0a Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 8 Oct 2014 22:51:21 +0300 Subject: [PATCH] Review fixes. --- storage/country.hpp | 2 +- storage/storage.cpp | 34 ++++++++++++++++++++++++++-------- storage/storage.hpp | 1 + 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/storage/country.hpp b/storage/country.hpp index a62870ed81..95e5287ec0 100644 --- a/storage/country.hpp +++ b/storage/country.hpp @@ -25,7 +25,7 @@ namespace storage uint32_t m_mapSize, m_routingSize; public: - CountryFile() {} + CountryFile() : m_mapSize(0), m_routingSize(0) {} CountryFile(string const & fName, uint32_t mapSize, uint32_t routingSize) : m_fileName(fName), m_mapSize(mapSize), m_routingSize(routingSize) { diff --git a/storage/storage.cpp b/storage/storage.cpp index c43bc18b7c..4861a05c26 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -59,7 +59,7 @@ namespace storage void Storage::QueuedCountry::AddOptions(TMapOptions opt) { - TMapOptions arr[] = { TMapOptions::EMapOnly, TMapOptions::ECarRouting }; + TMapOptions const arr[] = { TMapOptions::EMapOnly, TMapOptions::ECarRouting }; for (size_t i = 0; i < ARRAY_SIZE(arr); ++i) { if (opt & arr[i] && !(m_init & arr[i])) @@ -82,6 +82,20 @@ namespace storage return true; } + bool Storage::QueuedCountry::Correct() + { + if ((m_init & TMapOptions::ECarRouting) && + (m_pFile->GetFileSize(TMapOptions::ECarRouting) == 0)) + { + if (m_init & TMapOptions::EMapOnly) + m_init = m_left = m_current = TMapOptions::EMapOnly; + else + return false; + } + + return true; + } + uint64_t Storage::QueuedCountry::GetDownloadSize() const { return m_pFile->GetRemoteSize(m_current); @@ -90,13 +104,13 @@ namespace storage LocalAndRemoteSizeT Storage::QueuedCountry::GetFullSize() const { LocalAndRemoteSizeT res(0, 0); - TMapOptions arr[] = { TMapOptions::EMapOnly, TMapOptions::ECarRouting }; + TMapOptions const arr[] = { TMapOptions::EMapOnly, TMapOptions::ECarRouting }; for (size_t i = 0; i < ARRAY_SIZE(arr); ++i) { if (m_init & arr[i]) { - res.first += m_pFile->GetFileSize(m_current); - res.second += m_pFile->GetRemoteSize(m_current); + res.first += m_pFile->GetFileSize(arr[i]); + res.second += m_pFile->GetRemoteSize(arr[i]); } } return res; @@ -198,7 +212,7 @@ namespace storage TStatus Storage::CountryStatus(TIndex const & index) const { // first, check if we already downloading this country or have in in the queue - auto found = find(m_queue.begin(), m_queue.end(), index); + auto const found = find(m_queue.begin(), m_queue.end(), index); if (found != m_queue.end()) { if (found == m_queue.begin()) @@ -265,7 +279,7 @@ namespace storage void Storage::DownloadCountry(TIndex const & index, TMapOptions opt) { // check if we already downloading this country - auto found = find(m_queue.begin(), m_queue.end(), index); + auto const found = find(m_queue.begin(), m_queue.end(), index); if (found != m_queue.end()) { found->AddOptions(opt); @@ -276,7 +290,11 @@ namespace storage // remove it from failed list m_failedCountries.erase(index); + // add it into the queue + QueuedCountry cnt(*this, index, opt); + if (!cnt.Correct()) + return; m_queue.push_back(QueuedCountry(*this, index, opt)); // and start download if necessary @@ -332,7 +350,7 @@ namespace storage bool Storage::DeleteFromDownloader(TIndex const & index) { // check if we already downloading this country - auto found = find(m_queue.begin(), m_queue.end(), index); + auto const found = find(m_queue.begin(), m_queue.end(), index); if (found != m_queue.end()) { if (found == m_queue.begin()) @@ -476,7 +494,7 @@ namespace storage GetServerListFromRequest(request, urls); // append actual version and file name - string fileName = cnt.GetFileName(); + string const fileName = cnt.GetFileName(); for (size_t i = 0; i < urls.size(); ++i) urls[i] = GetFileDownloadUrl(urls[i], fileName); diff --git a/storage/storage.hpp b/storage/storage.hpp index 7dce7fb8b5..4953da9db9 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -41,6 +41,7 @@ namespace storage void AddOptions(TMapOptions opt); bool MoveNextFile(); + bool Correct(); TIndex const & GetIndex() const { return m_index; } TMapOptions GetInitOptions() const { return m_init; }