diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp index ed44cdccb2..c29cdc1651 100644 --- a/android/jni/com/mapswithme/platform/Platform.cpp +++ b/android/jni/com/mapswithme/platform/Platform.cpp @@ -130,13 +130,6 @@ void Platform::Initialize(JNIEnv * env, jobject functorProcessObject, jstring ap LOG(LINFO, ("Flavor name:", flavor)); LOG(LINFO, ("Build type name:", build)); - if (build == "beta" || build == "debug") - m_androidDefResScope = "fwr"; - else if (flavor.find("google") == 0 || flavor.find("amazon") == 0 || flavor.find("samsung") == 0) // optimization to read World mwm-s faster - m_androidDefResScope = "frw"; - else - m_androidDefResScope = "fwr"; - m_isTablet = isTablet; m_resourcesDir = jni::ToNativeString(env, apkPath); m_privateDir = jni::ToNativeString(env, privatePath); diff --git a/platform/platform.cpp b/platform/platform.cpp index 02761bdaec..6fc706a942 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -145,9 +145,8 @@ string Platform::ReadPathForFile(string const & file, string searchScope) const return fullPath; } - string const possiblePaths = m_writableDir + "\n" + m_resourcesDir + "\n" + m_settingsDir; MYTHROW(FileAbsentException, ("File", file, "doesn't exist in the scope", searchScope, - "Have been looking in:\n", possiblePaths)); + "\nw: ", m_writableDir, "\nr: ", m_resourcesDir, "\ns: ", m_settingsDir)); } string Platform::MetaServerUrl() const diff --git a/platform/platform.hpp b/platform/platform.hpp index 9d1cb9cfb9..0f7eda3920 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -103,10 +103,6 @@ protected: /// Writable directory to store persistent application data std::string m_settingsDir; - /// Default search scope for resource files. - /// Used in Android only and initialized according to the market type (Play, Amazon, Samsung). - std::string m_androidDefResScope; - /// Used in Android only to get corret GUI elements layout. bool m_isTablet; @@ -202,7 +198,7 @@ public: /// @param[in] searchScope looks for file in dirs in given order: \n /// [w]ritable, [r]esources, [s]ettings, by [f]ull path, [e]xternal resources, std::unique_ptr GetReader(std::string const & file, - std::string const & searchScope = std::string()) const; + std::string searchScope = std::string()) const; /// @name File operations //@{ diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index d7a6bcf289..97dd6138c2 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -25,57 +25,8 @@ Platform::Platform() /// @see initialization routine in android/jni/com/.../Platform.hpp } -namespace -{ -enum SourceT -{ - RESOURCE, - WRITABLE_PATH, - SETTINGS_PATH, - FULL_PATH, - SOURCE_COUNT -}; - -bool IsResource(string const & file, string const & ext) -{ - if (ext == DATA_FILE_EXTENSION) - { - return (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) || - strings::StartsWith(file, WORLD_FILE_NAME)); - } - else if (ext == BOOKMARKS_FILE_EXTENSION || - file == SETTINGS_FILE_NAME) - { - return false; - } - - return true; -} - -size_t GetSearchSources(string const & file, string const & searchScope, - SourceT (&arr)[SOURCE_COUNT]) -{ - size_t ret = 0; - - for (size_t i = 0; i < searchScope.size(); ++i) - { - switch (searchScope[i]) - { - case 'w': arr[ret++] = WRITABLE_PATH; break; - case 'r': arr[ret++] = RESOURCE; break; - case 's': arr[ret++] = SETTINGS_PATH; break; - case 'f': - if (strings::StartsWith(file, "/")) - arr[ret++] = FULL_PATH; - break; - default : CHECK(false, ("Unsupported searchScope:", searchScope)); break; - } - } - - return ret; -} - #ifdef DEBUG +namespace { class DbgLogger { public: @@ -86,16 +37,17 @@ public: LOG(LDEBUG, ("Source for file", m_file, "is", m_src)); } - void SetSource(SourceT src) { m_src = src; } + void SetSource(char src) { m_src = src; } private: string const & m_file; - SourceT m_src; + char m_src; }; -#endif } // namespace +#endif -unique_ptr Platform::GetReader(string const & file, string const & searchScope) const + +unique_ptr Platform::GetReader(string const & file, string searchScope) const { string const ext = base::GetFileExtension(file); ASSERT(!ext.empty(), ()); @@ -103,41 +55,41 @@ unique_ptr Platform::GetReader(string const & file, string const & uint32_t const logPageSize = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_SIZE : 10; uint32_t const logPageCount = (ext == DATA_FILE_EXTENSION) ? READER_CHUNK_LOG_COUNT : 4; - SourceT sources[SOURCE_COUNT]; - size_t n = 0; - if (searchScope.empty()) { - // Default behaviour - use predefined scope for resource files and writable path for all others. - - if (IsResource(file, ext)) - n = GetSearchSources(file, m_androidDefResScope, sources); + if (file[0] == '/') + searchScope = "f"; else { - // Add source for map files and other dynamic stored data. - sources[n++] = WRITABLE_PATH; - sources[n++] = FULL_PATH; + if (ext == DATA_FILE_EXTENSION) + { + if (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) || strings::StartsWith(file, WORLD_FILE_NAME)) + searchScope = "wsr"; + else + searchScope = "w"; + } + else if (ext == BOOKMARKS_FILE_EXTENSION) + searchScope = "w"; + else if (file == SETTINGS_FILE_NAME) + searchScope = "s"; + else + searchScope = "rw"; } } - else - { - // Use passed scope as client wishes. - n = GetSearchSources(file, searchScope, sources); - } #ifdef DEBUG DbgLogger logger(file); #endif - for (size_t i = 0; i < n; ++i) + for (char const s : searchScope) { #ifdef DEBUG - logger.SetSource(sources[i]); + logger.SetSource(s); #endif - switch (sources[i]) + switch (s) { - case WRITABLE_PATH: + case 'w': { string const path = m_writableDir + file; if (IsFileExistsByFullPath(path)) @@ -145,7 +97,7 @@ unique_ptr Platform::GetReader(string const & file, string const & break; } - case SETTINGS_PATH: + case 's': { string const path = m_settingsDir + file; if (IsFileExistsByFullPath(path)) @@ -153,12 +105,12 @@ unique_ptr Platform::GetReader(string const & file, string const & break; } - case FULL_PATH: + case 'f': if (IsFileExistsByFullPath(file)) return make_unique(file, logPageSize, logPageCount); break; - case RESOURCE: + case 'r': ASSERT_EQUAL(file.find("assets/"), string::npos, ()); try { @@ -171,12 +123,12 @@ unique_ptr Platform::GetReader(string const & file, string const & break; default: - CHECK(false, ("Unsupported source:", sources[i])); + CHECK(false, ("Unsupported source:", s)); break; } } - LOG(LWARNING, ("Can't get reader for:", file)); + LOG(LWARNING, ("Can't get reader for:", file, "in scope", searchScope)); MYTHROW(FileAbsentException, ("File not found", file)); return nullptr; } diff --git a/platform/platform_ios.mm b/platform/platform_ios.mm index 6286e286d1..8d15747cbe 100644 --- a/platform/platform_ios.mm +++ b/platform/platform_ios.mm @@ -117,9 +117,9 @@ bool Platform::GetFileSizeByName(std::string const & fileName, uint64_t & size) } } -std::unique_ptr Platform::GetReader(std::string const & file, std::string const & searchScope) const +std::unique_ptr Platform::GetReader(std::string const & file, std::string searchScope) const { - return std::make_unique(ReadPathForFile(file, searchScope), READER_CHUNK_LOG_SIZE, + return std::make_unique(ReadPathForFile(file, std::move(searchScope)), READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT); } diff --git a/platform/platform_qt.cpp b/platform/platform_qt.cpp index b3f5ff5584..d613753585 100644 --- a/platform/platform_qt.cpp +++ b/platform/platform_qt.cpp @@ -25,9 +25,9 @@ using namespace std; -unique_ptr Platform::GetReader(string const & file, string const & searchScope) const +unique_ptr Platform::GetReader(string const & file, string searchScope) const { - return make_unique(ReadPathForFile(file, searchScope), + return make_unique(ReadPathForFile(file, move(searchScope)), READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT); }