From 85fc90ca1ed5c839339699504e16ce07e96e40ea Mon Sep 17 00:00:00 2001 From: vng Date: Mon, 25 Mar 2013 19:18:35 +0300 Subject: [PATCH] [android] Move kml files when changing storage path. --- .../jni/com/mapswithme/maps/settings/StoragePathActivity.cpp | 5 ++++- defines.hpp | 1 + map/bookmark.cpp | 2 +- map/bookmark_manager.cpp | 4 +--- map/framework.cpp | 5 ++--- map/map_tests/bookmarks_test.cpp | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp b/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp index 3f6aae019b..e51e16baaa 100644 --- a/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp +++ b/android/jni/com/mapswithme/maps/settings/StoragePathActivity.cpp @@ -29,7 +29,7 @@ extern "C" Platform & pl = GetPlatform(); // Get regexp like this: (\.mwm$|\.ttf$) - string const regexp = "(\\" DATA_FILE_EXTENSION "$|\\.ttf$)"; + string const regexp = "(" "\\"DATA_FILE_EXTENSION"$" "|" "\\"BOOKMARKS_FILE_EXTENSION"$" "|" "\\.ttf$" ")"; Platform::FilesList files; pl.GetFilesByRegExp(from, regexp, files); @@ -51,6 +51,9 @@ extern "C" // Add all maps again. g_framework->AddLocalMaps(); + + // Reload bookmarks again + g_framework->NativeFramework()->LoadBookmarks(); return true; } } diff --git a/defines.hpp b/defines.hpp index 9d910f7460..bfa28febe8 100644 --- a/defines.hpp +++ b/defines.hpp @@ -13,6 +13,7 @@ #define READY_FILE_EXTENSION ".ready" #define RESUME_FILE_EXTENSION ".resume3" #define DOWNLOADING_FILE_EXTENSION ".downloading3" +#define BOOKMARKS_FILE_EXTENSION ".kml" #define COUNTRIES_FILE "countries.txt" diff --git a/map/bookmark.cpp b/map/bookmark.cpp index ae6898dee0..3ed8885e13 100644 --- a/map/bookmark.cpp +++ b/map/bookmark.cpp @@ -456,7 +456,7 @@ string BookmarkCategory::RemoveInvalidSymbols(string const & name) string BookmarkCategory::GenerateUniqueFileName(const string & path, string name) { - string const kmlExt(".kml"); + string const kmlExt(BOOKMARKS_FILE_EXTENSION); // check if file name already contains .kml extension size_t const extPos = name.rfind(kmlExt); diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 4f7449db1e..2d66ef54c1 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -11,8 +11,6 @@ #include "../std/target_os.hpp" #include "../std/vector.hpp" -#define KML_EXTENSION ".kml" -#define KMZ_EXTENSION ".kmz" BookmarkManager::BookmarkManager(Framework& f):m_framework(f) { @@ -59,7 +57,7 @@ void BookmarkManager::LoadBookmarks() string const dir = GetPlatform().WritableDir(); Platform::FilesList files; - Platform::GetFilesByExt(dir, KML_EXTENSION, files); + Platform::GetFilesByExt(dir, BOOKMARKS_FILE_EXTENSION, files); for (size_t i = 0; i < files.size(); ++i) { LoadBookmark(dir+files[i]); diff --git a/map/framework.cpp b/map/framework.cpp index 914f67845e..98c0399fda 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -44,7 +44,6 @@ /// How many pixels around touch point are used to get bookmark or POI #define TOUCH_PIXEL_RADIUS 20 -#define KML_EXTENSION ".kml" #define KMZ_EXTENSION ".kmz" #define DEFAULT_BOOKMARK_TYPE "placemark-red" @@ -531,7 +530,7 @@ bool Framework::AddBookmarksFile(string const & filePath) { string const fileExt = GetFileExt(filePath); string fileSavePath; - if (fileExt == KML_EXTENSION) + if (fileExt == BOOKMARKS_FILE_EXTENSION) { fileSavePath = GenerateValidandUniqFilePathForKLM( GetFileName(filePath) ); if (!my::CopyFileX(filePath, fileSavePath)) @@ -546,7 +545,7 @@ bool Framework::AddBookmarksFile(string const & filePath) string kmlFileName; for (size_t i = 0; i < files.size();++i) { - if (GetFileExt(files[i]) == KML_EXTENSION) + if (GetFileExt(files[i]) == BOOKMARKS_FILE_EXTENSION) { kmlFileName = files[i]; break; diff --git a/map/map_tests/bookmarks_test.cpp b/map/map_tests/bookmarks_test.cpp index 2a4af0ca95..b051ddb7f1 100644 --- a/map/map_tests/bookmarks_test.cpp +++ b/map/map_tests/bookmarks_test.cpp @@ -204,7 +204,7 @@ namespace { string const path = GetPlatform().WritableDir(); for (size_t i = 0; i < N; ++i) - FileWriter::DeleteFileX(path + arrFiles[i] + ".kml"); + FileWriter::DeleteFileX(path + arrFiles[i] + BOOKMARKS_FILE_EXTENSION); } Bookmark const * GetBookmark(Framework const & fm, m2::PointD const & pt) @@ -376,7 +376,7 @@ UNIT_TEST(Bookmarks_IllegalFileName) UNIT_TEST(Bookmarks_UniqueFileName) { string const BASE = "SomeUniqueFileName"; - string const FILENAME = BASE + ".kml"; + string const FILENAME = BASE + BOOKMARKS_FILE_EXTENSION; { FileWriter file(FILENAME);