Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/platform.cpp29
-rw-r--r--platform/platform.hpp8
-rw-r--r--platform/platform_android.cpp115
3 files changed, 126 insertions, 26 deletions
diff --git a/platform/platform.cpp b/platform/platform.cpp
index a2fcf1bb03..70d5e3bdde 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -14,9 +14,11 @@ string Platform::ReadPathForFile(string const & file) const
fullPath = m_resourcesDir + file;
if (!IsFileExistsByFullPath(fullPath))
{
- fullPath = file;
- if (!IsFileExistsByFullPath(fullPath))
- MYTHROW(FileAbsentException, ("File doesn't exist", fullPath));
+ // default behaviour - assume that we have full path here
+ if (!IsFileExistsByFullPath(file))
+ MYTHROW(FileAbsentException, ("File doesn't exist", file));
+ else
+ return file;
}
}
return fullPath;
@@ -60,19 +62,22 @@ void Platform::GetFontNames(FilesList & res) const
{
GetSystemFontNames(res);
- // Do not search inside apk for the fonts in Android.
- string const paths[] = {
- WritableDir()
-#ifndef OMIM_OS_ANDROID
- , ResourcesDir()
+ size_t n = 0;
+ string const * arrPaths[4];
+
+ arrPaths[n++] = &m_writableDir;
+#ifdef OMIM_OS_ANDROID
+ for (size_t i = 0; i < m_extResFiles.size(); ++i)
+ arrPaths[n++] = &m_extResFiles[i];
+#else
+ arrPaths[n++] = &m_resourcesDir;
#endif
- };
FilesList fonts;
- for (size_t i = 0; i < ARRAY_SIZE(paths); ++i)
+ for (size_t i = 0; i < n; ++i)
{
- LOG(LDEBUG, ("Searching for fonts in", paths[i]));
- GetFilesByExt(paths[i], ".ttf", fonts);
+ LOG(LDEBUG, ("Searching for fonts in", *(arrPaths[i])));
+ GetFilesByExt(*(arrPaths[i]), FONT_FILE_EXTENSION, fonts);
}
sort(fonts.begin(), fonts.end());
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 89c87ac1d9..5bc1899fa6 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -29,8 +29,12 @@ protected:
/// Flag that it's a paid PRO version of app.
bool m_isPro;
- /// Internal function to use files from writable dir
- /// if they override the same file in the resources dir
+ /// Extended resource files.
+ /// Used in Android only (downloaded zip files as a container).
+ vector<string> m_extResFiles;
+
+ /// Internal function to get full path for input file.
+ /// Uses m_writeableDir and m_resourcesDir.
string ReadPathForFile(string const & file) const;
/// Hash some unique string into uniform format.
diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp
index f24b22a0ca..c59623f067 100644
--- a/platform/platform_android.cpp
+++ b/platform/platform_android.cpp
@@ -3,12 +3,14 @@
#include "constants.hpp"
#include "../coding/zip_reader.hpp"
+#include "../coding/file_name_utils.hpp"
#include "../base/logging.hpp"
#include "../base/thread.hpp"
#include "../base/regexp.hpp"
+#include "../base/string_utils.hpp"
-#include <unistd.h>
+#include <unistd.h> // for sysconf
Platform::Platform()
@@ -16,26 +18,115 @@ Platform::Platform()
/// @see initialization routine in android/jni/com/.../Platform.hpp
}
-ModelReader * Platform::GetReader(string const & file) const
+namespace
+{
+
+enum SourceT { EXTERNAL_RESOURCE, RESOURCE, WRITABLE_PATH, FULL_PATH };
+
+size_t GetSearchSources(string const & file, SourceT (&arr)[4])
{
- if (IsFileExistsByFullPath(m_writableDir + file))
+ size_t ret = 0;
+ string const ext = my::GetFileExtension(file);
+ ASSERT ( !ext.empty(), () );
+
+ if (ext == DATA_FILE_EXTENSION)
{
- return new FileReader(ReadPathForFile(file),
- READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ if (strings::StartsWith(file, WORLD_COASTS_FILE_NAME) ||
+ strings::StartsWith(file, WORLD_FILE_NAME))
+ {
+ arr[ret++] = EXTERNAL_RESOURCE;
+ }
+ arr[ret++] = WRITABLE_PATH;
}
- if (IsFileExistsByFullPath(file))
+ else if (ext == FONT_FILE_EXTENSION)
{
- return new FileReader(ReadPathForFile(file),
- READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ // system fonts have absolute unix path
+ if (strings::StartsWith(file, "/"))
+ arr[ret++] = FULL_PATH;
+ else
+ {
+ arr[ret++] = EXTERNAL_RESOURCE;
+ arr[ret++] = WRITABLE_PATH;
+ }
}
else
+ arr[ret++] = RESOURCE;
+
+ return ret;
+}
+
+#ifdef DEBUG
+class DbgLogger
+{
+ string const & m_file;
+ SourceT m_src;
+public:
+ DbgLogger(string const & file) : m_file(file) {}
+ void SetSource(SourceT src) { m_src = src; }
+ ~DbgLogger()
{
- ASSERT_EQUAL ( file.find("assets/"), string::npos, () );
+ LOG(LDEBUG, ("Source for file", m_file, "is", m_src));
+ }
+};
+#endif
+
+}
- /// @note If you push some maps to the bundle, it's better to set
- /// better values for chunk size and chunks count. @see constants.hpp
- return new ZipFileReader(m_resourcesDir, "assets/" + file);
+ModelReader * Platform::GetReader(string const & file) const
+{
+ SourceT sources[4];
+ size_t const n = GetSearchSources(file, sources);
+
+#ifdef DEBUG
+ DbgLogger logger(file);
+#endif
+
+ for (size_t i = 0; i < n; ++i)
+ {
+#ifdef DEBUG
+ logger.SetSource(sources[i]);
+#endif
+
+ switch (sources[i])
+ {
+ case EXTERNAL_RESOURCE:
+ {
+ for (size_t j = 0; j < m_extResFiles.size(); ++j)
+ {
+ try
+ {
+ return new ZipFileReader(m_extResFiles[j], file,
+ READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ }
+ catch (Reader::OpenException const &)
+ {
+ }
+ }
+ break;
+ }
+
+ case WRITABLE_PATH:
+ {
+ string const path = m_writableDir + file;
+ if (IsFileExistsByFullPath(path))
+ return new FileReader(path, READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT);
+ break;
+ }
+
+ case FULL_PATH:
+ if (IsFileExistsByFullPath(file))
+ return new FileReader(file);
+ break;
+
+ default:
+ ASSERT_EQUAL ( sources[i], RESOURCE, () );
+ ASSERT_EQUAL ( file.find("assets/"), string::npos, () );
+ return new ZipFileReader(m_resourcesDir, "assets/" + file);
+ }
}
+
+ MYTHROW(FileAbsentException, ("File not found", file));
+ return 0;
}
void Platform::GetFilesByRegExp(string const & directory, string const & regexp, FilesList & res)