diff options
author | Yuri Gorshenin <y@maps.me> | 2015-07-23 20:10:08 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:57:29 +0300 |
commit | 67bac9dd063c6192fa720047f39fed6b896a43c6 (patch) | |
tree | d24b13ee53e00686c6542d42891f4048ce82f5d1 /platform | |
parent | fee868eb36e2573a7665e36c4acd783ebc8d5803 (diff) |
[platform] Fixed World/WorldCoasts lookup on non-Android platforms.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/local_country_file.hpp | 13 | ||||
-rw-r--r-- | platform/local_country_file_utils.cpp | 23 | ||||
-rw-r--r-- | platform/local_country_file_utils.hpp | 5 | ||||
-rw-r--r-- | platform/platform.cpp | 9 | ||||
-rw-r--r-- | platform/platform.hpp | 3 |
5 files changed, 39 insertions, 14 deletions
diff --git a/platform/local_country_file.hpp b/platform/local_country_file.hpp index ae556910d2..b248f0eaf8 100644 --- a/platform/local_country_file.hpp +++ b/platform/local_country_file.hpp @@ -10,6 +10,18 @@ namespace platform { // This class represents a path to disk files corresponding to some // country region. +// +// This class also wraps World.mwm and WorldCoasts.mwm +// files from resource bundle, when they can't be found in a data +// directory. In this exceptional case, directory will be empty and +// SyncWithDisk()/DeleteFromDisk()/GetPath()/GetSize() will return +// incorrect results. +// +// TODO (@gorshenin): fix this hack somehow +// (https://trello.com/c/qcveFw3M/27-world-worldcoasts-mwm-localcountryfile) +// +// In any case, when you're going to read a file LocalCountryFile points to, +// use GetCountryReader(). class LocalCountryFile { public: @@ -69,6 +81,7 @@ public: private: friend string DebugPrint(LocalCountryFile const &); friend void UnitTest_LocalCountryFile_DirectoryLookup(); + friend void FindAllLocalMaps(vector<LocalCountryFile> & localFiles); string m_directory; CountryFile m_countryFile; diff --git a/platform/local_country_file_utils.cpp b/platform/local_country_file_utils.cpp index 44f1f5bcd5..cdb7530392 100644 --- a/platform/local_country_file_utils.cpp +++ b/platform/local_country_file_utils.cpp @@ -4,6 +4,7 @@ #include "coding/file_name_utils.hpp" #include "coding/internal/file_data.hpp" +#include "coding/reader.hpp" #include "base/string_utils.hpp" #include "base/logging.hpp" @@ -13,7 +14,6 @@ #include "std/sstream.hpp" #include "std/unique_ptr.hpp" - namespace platform { namespace @@ -58,6 +58,15 @@ bool MkDirChecked(string const & directory) return false; } } + +string GetSpecialFilesSearchScope() +{ +#if defined(OMIM_OS_ANDROID) + return "er"; +#else + return "r"; +#endif // defined(OMIM_OS_ANDROID) +} } // namespace void CleanupMapsDirectory() @@ -162,11 +171,12 @@ void FindAllLocalMaps(vector<LocalCountryFile> & localFiles) try { - unique_ptr<ModelReader> guard(platform.GetReader(file + DATA_FILE_EXTENSION, "er")); + unique_ptr<ModelReader> guard(platform.GetReader(file + DATA_FILE_EXTENSION, GetSpecialFilesSearchScope())); UNUSED_VALUE(guard); // Assume that empty path means the resource file. LocalCountryFile worldFile(string(), CountryFile(file), 0 /* version */); + worldFile.m_files = TMapOptions::EMap; if (i != localFiles.end()) { // Always use resource World files instead of local on disk. @@ -212,6 +222,15 @@ shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(CountryFile const & cou return make_shared<LocalCountryFile>(directory, countryFile, version); } +ModelReader * GetCountryReader(platform::LocalCountryFile const & file, TMapOptions options) +{ + Platform & platform = GetPlatform(); + // See LocalCountryFile comment for explanation. + if (file.GetDirectory().empty()) + return platform.GetReader(file.GetCountryName() + DATA_FILE_EXTENSION, GetSpecialFilesSearchScope()); + return platform.GetReader(file.GetPath(options), "f"); +} + // static bool CountryIndexes::PreparePlaceOnDisk(LocalCountryFile const & localFile) { diff --git a/platform/local_country_file_utils.hpp b/platform/local_country_file_utils.hpp index eab092e6f8..3bfb199a8e 100644 --- a/platform/local_country_file_utils.hpp +++ b/platform/local_country_file_utils.hpp @@ -7,6 +7,8 @@ #include "std/utility.hpp" #include "std/vector.hpp" +class ModelReader; + namespace platform { // Removes partially downloaded maps, empty directories and old @@ -46,6 +48,9 @@ bool ParseVersion(string const & s, int64_t & version); // directory with name equal to decimal representation of version. shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(CountryFile const & countryFile, int64_t version); + +ModelReader * GetCountryReader(LocalCountryFile const & file, TMapOptions options); + // An API for managing country indexes. class CountryIndexes { diff --git a/platform/platform.cpp b/platform/platform.cpp index 19fad2d7b8..ac62aa15e7 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -145,12 +145,3 @@ void Platform::SetResourceDir(string const & path) { m_resourcesDir = my::AddSlashIfNeeded(path); } - -ModelReader * Platform::GetCountryReader(platform::LocalCountryFile const & file, - TMapOptions options) const -{ - if (file.GetDirectory().empty()) - return GetReader(file.GetCountryName() + DATA_FILE_EXTENSION, "er"); - else - return GetReader(file.GetPath(options), "f"); -} diff --git a/platform/platform.hpp b/platform/platform.hpp index 283614aa61..cf249ef4c2 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -120,9 +120,6 @@ public: /// @return full path to file in the settings directory string SettingsPathForFile(string const & file) const { return SettingsDir() + file; } - ModelReader * GetCountryReader(platform::LocalCountryFile const & file, - TMapOptions options) const; - /// @return reader for file decriptor. /// @throws FileAbsentException /// @param[in] file name or full path which we want to read, don't forget to free memory or wrap it to ReaderPtr |