diff options
author | vng <viktor.govako@gmail.com> | 2015-07-23 01:41:07 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:57:22 +0300 |
commit | f93ca5fe5508fdd023c8a04660c66051b58d5bcf (patch) | |
tree | 6a55a78e72947ddf94ff9c33c17d9cc0a4385963 /platform | |
parent | 2a44a8c8102818ff8e0b70c81e5baf38fe610f91 (diff) |
[storage] Fixed bug with missing World/WorldCoasts.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/local_country_file_utils.cpp | 43 | ||||
-rw-r--r-- | platform/platform.cpp | 5 |
2 files changed, 29 insertions, 19 deletions
diff --git a/platform/local_country_file_utils.cpp b/platform/local_country_file_utils.cpp index aa650c1a33..f13f4b599b 100644 --- a/platform/local_country_file_utils.cpp +++ b/platform/local_country_file_utils.cpp @@ -11,6 +11,8 @@ #include "std/algorithm.hpp" #include "std/cctype.hpp" #include "std/sstream.hpp" +#include "std/unique_ptr.hpp" + namespace platform { @@ -79,8 +81,8 @@ void CleanupMapsDirectory() FindAllLocalMaps(localFiles); for (LocalCountryFile & localFile : localFiles) { - CountryFile const countryFile = localFile.GetCountryFile(); - if (countryFile.GetNameWithoutExt() == "Japan" || countryFile.GetNameWithoutExt() == "Brazil") + string const & countryName = localFile.GetCountryFile().GetNameWithoutExt(); + if (countryName == "Japan" || countryName == "Brazil") { localFile.SyncWithDisk(); localFile.DeleteFromDisk(TMapOptions::EMapWithCarRouting); @@ -146,29 +148,34 @@ void FindAllLocalMaps(vector<LocalCountryFile> & localFiles) // World and WorldCoasts can be stored in app bundle or in resources // directory, thus it's better to get them via Platform. - for (string const & file : {WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME}) + for (string const & file : { WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME }) { - bool found = false; - for (LocalCountryFile const & localFile : localFiles) + auto i = localFiles.begin(); + for (; i != localFiles.end(); ++i) { - if (localFile.GetCountryFile().GetNameWithoutExt() == file) - { - found = true; + if (i->GetCountryFile().GetNameWithoutExt() == file) break; - } } - if (!found) + + try { - try - { - ModelReaderPtr reader = platform.GetReader(file + DATA_FILE_EXTENSION); - localFiles.emplace_back(my::GetDirectory(reader.GetName()), CountryFile(file), - 0 /* version */); - } - catch (FileAbsentException const & e) + unique_ptr<ModelReader> guard(platform.GetReader(file + DATA_FILE_EXTENSION, "er")); + UNUSED_VALUE(guard); + + // Assume that empty path means the resource file. + LocalCountryFile worldFile(string(), CountryFile(file), 0 /* version */); + if (i != localFiles.end()) { - LOG(LERROR, ("Can't find map file for", file, ".")); + // Always use resource World files instead of local on disk. + *i = worldFile; } + else + localFiles.push_back(worldFile); + } + catch (RootException const & ex) + { + if (i == localFiles.end()) + LOG(LERROR, ("Can't find any:", file, "Reason:", ex.Msg())); } } } diff --git a/platform/platform.cpp b/platform/platform.cpp index d9253df5d4..c672f2888e 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -146,5 +146,8 @@ void Platform::SetResourceDir(string const & path) ModelReader * Platform::GetCountryReader(platform::LocalCountryFile const & file, TMapOptions options) const { - return GetReader(file.GetPath(options), "f"); + if (file.GetDirectory().empty()) + return GetReader(file.GetCountryName() + DATA_FILE_EXTENSION, "er"); + else + return GetReader(file.GetPath(options), "f"); } |