diff --git a/generator/borders_generator.cpp b/generator/borders_generator.cpp index 31d8997675..0ede044ed0 100644 --- a/generator/borders_generator.cpp +++ b/generator/borders_generator.cpp @@ -81,6 +81,7 @@ namespace osm relationIds = osmData.RelationsByKey(searchKey); else relationIds = osmData.RelationsByTag(OsmTag(searchKey, searchValue)); + CHECK(!relationIds.empty(), ("No relation found with tag", searchKey, searchValue)); CHECK_EQUAL(relationIds.size(), 1, ("Found more than one relation with tag", searchKey, searchValue)); diff --git a/generator/borders_loader.cpp b/generator/borders_loader.cpp index 17fc369c90..3cf73a6a53 100644 --- a/generator/borders_loader.cpp +++ b/generator/borders_loader.cpp @@ -83,6 +83,7 @@ namespace borders if (line.empty()) continue; + /// @todo no need to tokenize by '|' strings::Tokenize(line, "|", bind(ref(toDo), _1)); toDo.Finish(); } diff --git a/generator/update_generator.cpp b/generator/update_generator.cpp index 183891a485..87e3da5fb9 100644 --- a/generator/update_generator.cpp +++ b/generator/update_generator.cpp @@ -20,12 +20,12 @@ using namespace storage; namespace update { // we don't support files without name or without extension + /* bool SplitExtension(string const & file, string & name, string & ext) { // get extension size_t const index = file.find_last_of('.'); - if (index == string::npos || (index + 1) == file.size() || index == 0 - || file == "." || file == "..") + if (index == string::npos || (index + 1) == file.size() || index == 0 || file == "." || file == "..") { name = file; ext.clear(); @@ -35,39 +35,46 @@ namespace update name = file.substr(0, index); return true; } + */ class SizeUpdater { size_t m_processedFiles; string m_dataDir; - Platform::FilesList m_allFiles; + Platform::FilesList & m_files; public: - SizeUpdater(string const & dataDir) : m_processedFiles(0), m_dataDir(dataDir) + SizeUpdater(string const & dataDir, Platform::FilesList & files) + : m_processedFiles(0), m_dataDir(dataDir), m_files(files) { - Platform::GetFilesInDir(m_dataDir, "*.mwm", m_allFiles); } ~SizeUpdater() { LOG(LINFO, (m_processedFiles, "file sizes were updated in the country list")); - if (!m_allFiles.empty()) - LOG(LINFO, ("Files left unprocessed:", m_allFiles)); + + if (!m_files.empty()) + LOG(LWARNING, ("Files left unprocessed:", m_files)); } - template - void operator()(T & c) + + template void operator() (T & c) { for (size_t i = 0; i < c.Value().m_files.size(); ++i) { ++m_processedFiles; + uint64_t size = 0; string const fname = c.Value().m_files[i].GetFileWithExt(); if (!GetPlatform().GetFileSizeByFullPath(m_dataDir + fname, size)) LOG(LERROR, ("File was not found:", fname)); + CHECK_GREATER(size, 0, ("Zero file size?", fname)); + c.Value().m_files[i].m_remoteSize = size; - Platform::FilesList::iterator found = find(m_allFiles.begin(), m_allFiles.end(), fname); - if (found != m_allFiles.end()) - m_allFiles.erase(found); + Platform::FilesList::iterator found = find(m_files.begin(), m_files.end(), fname); + if (found != m_files.end()) + m_files.erase(found); + else + LOG(LWARNING, ("No file ", fname, " on disk for the record in countries.txt")); } } }; @@ -75,12 +82,15 @@ namespace update bool UpdateCountries(string const & dataDir) { Platform::FilesList mwmFiles; - GetPlatform().GetFilesInDir(dataDir, "*" DATA_FILE_EXTENSION, mwmFiles); + GetPlatform().GetFilesInDir(dataDir, "*"DATA_FILE_EXTENSION, mwmFiles); // remove some files from list - char const * filesToRemove[] = {"minsk-pass"DATA_FILE_EXTENSION, - WORLD_FILE_NAME DATA_FILE_EXTENSION, - WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION}; + char const * filesToRemove[] = { + "minsk-pass"DATA_FILE_EXTENSION, + WORLD_FILE_NAME DATA_FILE_EXTENSION, + WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION + }; + for (size_t i = 0; i < ARRAY_SIZE(filesToRemove); ++i) { Platform::FilesList::iterator found = std::find(mwmFiles.begin(), mwmFiles.end(), @@ -90,20 +100,19 @@ namespace update } if (mwmFiles.empty()) - { - LOG(LERROR, ("Can't find any files at path", dataDir)); return false; - } else - LOG_SHORT(LINFO, (mwmFiles.size(), "mwm files were found")); + LOG(LINFO, (mwmFiles.size(), "mwm files were found")); // load current countries information to update file sizes storage::CountriesContainerT countries; string jsonBuffer; - ReaderPtr(GetPlatform().GetReader(COUNTRIES_FILE)).ReadAsString(jsonBuffer); - storage::LoadCountries(jsonBuffer, countries); { - SizeUpdater sizeUpdater(dataDir); + ReaderPtr(GetPlatform().GetReader(COUNTRIES_FILE)).ReadAsString(jsonBuffer); + storage::LoadCountries(jsonBuffer, countries); + + // using move semantics for mwmFiles + SizeUpdater sizeUpdater(dataDir, mwmFiles); countries.ForEachChildren(sizeUpdater); }