From 1da1ecf3b6ac76c103ef8b473b1e36b96e419622 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 1 Jun 2011 20:21:19 +0200 Subject: [PATCH] Rewrote logic for maps adding. First, we read all maps from resources, next, replace existing maps from writable data path --- iphone/Maps/Platform/IPhonePlatform.hpp | 1 + iphone/Maps/Platform/IPhonePlatform.mm | 5 ++++ map/framework.cpp | 39 +++++++++++++++++++++++-- map/framework.hpp | 2 +- platform/platform.hpp | 2 ++ platform/qtplatform.cpp | 6 ++++ storage/storage.cpp | 17 ++--------- 7 files changed, 53 insertions(+), 19 deletions(-) diff --git a/iphone/Maps/Platform/IPhonePlatform.hpp b/iphone/Maps/Platform/IPhonePlatform.hpp index f3ce61e707..629713fdee 100644 --- a/iphone/Maps/Platform/IPhonePlatform.hpp +++ b/iphone/Maps/Platform/IPhonePlatform.hpp @@ -10,6 +10,7 @@ public: virtual ~IPhonePlatform(); virtual double TimeInSec() const; virtual string WritableDir() const; + virtual string ResourcesDir() const; virtual string ReadPathForFile(char const * file) const; virtual int GetFilesInDir(string const & directory, string const & mask, FilesList & outFiles) const; virtual bool GetFileSize(string const & file, uint64_t & size) const; diff --git a/iphone/Maps/Platform/IPhonePlatform.mm b/iphone/Maps/Platform/IPhonePlatform.mm index c8bac0ad74..1cb4b49013 100644 --- a/iphone/Maps/Platform/IPhonePlatform.mm +++ b/iphone/Maps/Platform/IPhonePlatform.mm @@ -98,6 +98,11 @@ string IPhonePlatform::ReadPathForFile(char const * file) const return path; } +virtual string IPhonePlatform::ResourcesDir() const +{ + return m_resourcesPath; +} + string IPhonePlatform::WritableDir() const { return m_writablePath; diff --git a/map/framework.cpp b/map/framework.cpp index e0cd85e5ce..723b512ba6 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -463,21 +463,54 @@ void FrameWork::AddRedrawCommandSure() } } + struct PathAppender + { + string const & m_path; + PathAppender(string const & path) : m_path(path) {} + void operator()(string & elem) + { + elem.insert(elem.begin(), m_path.begin(), m_path.end()); + } + }; + template void FrameWork::EnumLocalMaps(Platform::FilesList & filesList) { - // activate all downloaded maps + Platform & p = GetPlatform(); + // scan for pre-installed maps in resources + string const resPath = p.ResourcesDir(); + Platform::FilesList resFiles; + p.GetFilesInDir(resPath, "*" DATA_FILE_EXTENSION, resFiles); + // scan for probably updated maps in data dir string const dataPath = p.WritableDir(); + Platform::FilesList dataFiles; + p.GetFilesInDir(dataPath, "*" DATA_FILE_EXTENSION, dataFiles); + // wipe out same maps from resources, which have updated + // downloaded versions in data path + for (Platform::FilesList::iterator it = resFiles.begin(); it != resFiles.end();) + { + Platform::FilesList::iterator found = find(dataFiles.begin(), dataFiles.end(), *it); + if (found != dataFiles.end()) + it = resFiles.erase(it); + else + ++it; + } + // make full resources paths + for_each(resFiles.begin(), resFiles.end(), PathAppender(resPath)); + // make full data paths + for_each(dataFiles.begin(), dataFiles.end(), PathAppender(dataPath)); + filesList.clear(); - p.GetFilesInDir(dataPath, "*" DATA_FILE_EXTENSION, filesList); + filesList.assign(resFiles.begin(), resFiles.end()); + filesList.insert(filesList.end(), dataFiles.begin(), dataFiles.end()); } template void FrameWork::EnumBenchmarkMaps(Platform::FilesList & filesList) { filesList.clear(); - filesList.push_back("Belarus.mwm"); + filesList.push_back(GetPlatform().ReadPathForFile("Belarus.mwm")); } template diff --git a/map/framework.hpp b/map/framework.hpp index e627dfe2eb..bfe250b766 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -210,7 +210,7 @@ public: bind(&FrameWork::RepaintRect, this, _1), enumMapsFn); LOG(LINFO, ("Storage initialized")); - }; + } void StartLocationService(LocationRetrievedCallbackT observer); void StopLocationService(); diff --git a/platform/platform.hpp b/platform/platform.hpp index fb3279fa6e..8649a83025 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -26,6 +26,8 @@ public: return WritableDir() + file; } + virtual string ResourcesDir() const = 0; + /// Throws FileAbsentException /// @param[in] file just file name which we want to read /// @return fullPath fully resolved path including file name diff --git a/platform/qtplatform.cpp b/platform/qtplatform.cpp index f7be8da79a..6af19652f5 100644 --- a/platform/qtplatform.cpp +++ b/platform/qtplatform.cpp @@ -243,6 +243,12 @@ public: return m_writableDir; } + /// @return path to /data/ with ending slash + virtual string ResourcesDir() const + { + return m_resourcesDir; + } + virtual string ReadPathForFile(char const * file) const { string fullPath = m_writableDir + file; diff --git a/storage/storage.cpp b/storage/storage.cpp index 08d0babb17..103ce9dbbf 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -59,26 +59,13 @@ namespace storage for (Platform::FilesList::iterator it = filesList.begin(); it != filesList.end(); ++it) { // simple way to avoid continuous crashes with invalid data files try { - m_addMap(GetPlatform().WritableDir() + *it); + m_addMap(*it); } catch (std::exception const & e) { - FileWriter::DeleteFileX(GetPlatform().WritableDir() + *it); + FileWriter::DeleteFileX(*it); LOG(LWARNING, (e.what(), "while adding file", *it, "so this file is deleted")); } } - // separate code to activate world data file from resources - // if it's not found in writable data dir - Platform::FilesList::iterator found = std::find(filesList.begin(), filesList.end(), - string(WORLD_FILE_NAME DATA_FILE_EXTENSION)); - if (found == filesList.end()) - { - try { - m_addMap(GetPlatform().ReadPathForFile(WORLD_FILE_NAME DATA_FILE_EXTENSION)); - } catch (std::exception const & e) - { - LOG(LWARNING, (e.what(), "while adding world data file")); - } - } } string Storage::UpdateBaseUrl() const