diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 5d43f1dd6a..3c051f49f3 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -580,7 +580,7 @@ namespace android } try { - FilesContainerR cont(pl.GetCountryReader(localFile, TMapOptions::EMap)); + FilesContainerR cont(platform::GetCountryReader(localFile, TMapOptions::EMap)); if (!cont.IsExist(SEARCH_INDEX_FILE_TAG)) out.push_back(countryFile.GetNameWithoutExt()); } diff --git a/indexer/index.cpp b/indexer/index.cpp index b1c7289fce..c78984a1fd 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -1,13 +1,13 @@ #include "indexer/index.hpp" #include "platform/platform.hpp" +#include "platform/local_country_file_utils.hpp" #include "coding/file_name_utils.hpp" #include "coding/internal/file_data.hpp" #include "base/logging.hpp" - using platform::CountryFile; using platform::LocalCountryFile; @@ -16,8 +16,9 @@ using platform::LocalCountryFile; ////////////////////////////////////////////////////////////////////////////////// MwmValue::MwmValue(LocalCountryFile const & localFile) - : m_cont(GetPlatform().GetCountryReader(localFile, TMapOptions::EMap)), - m_countryFile(localFile.GetCountryFile()), m_table(0) + : m_cont(platform::GetCountryReader(localFile, TMapOptions::EMap)), + m_countryFile(localFile.GetCountryFile()), + m_table(0) { m_factory.Load(m_cont); } diff --git a/map/mwm_tests/mwm_foreach_test.cpp b/map/mwm_tests/mwm_foreach_test.cpp index ef6250a153..72cc83ba85 100644 --- a/map/mwm_tests/mwm_foreach_test.cpp +++ b/map/mwm_tests/mwm_foreach_test.cpp @@ -1,7 +1,5 @@ #include "testing/testing.hpp" -#include "platform/platform.hpp" - #include "map/feature_vec_model.hpp" #include "indexer/data_header.hpp" @@ -10,6 +8,8 @@ #include "indexer/feature_processor.hpp" #include "indexer/classificator.hpp" +#include "platform/local_country_file_utils.hpp" + #include "geometry/rect_intersect.hpp" #include "geometry/robust_orientation.hpp" @@ -258,7 +258,7 @@ void RunTest(string const & countryFileName) vector rects; rects.push_back(src1.GetWorldRect()); - ModelReaderPtr reader = GetPlatform().GetCountryReader(localFile, TMapOptions::EMap); + ModelReaderPtr reader = platform::GetCountryReader(localFile, TMapOptions::EMap); while (!rects.empty()) { 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 & 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 & localFiles) try { - unique_ptr guard(platform.GetReader(file + DATA_FILE_EXTENSION, "er")); + unique_ptr 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 PreparePlaceForCountryFiles(CountryFile const & cou return make_shared(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 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