diff --git a/defines.hpp b/defines.hpp index eeb441747a..3a6299f01c 100644 --- a/defines.hpp +++ b/defines.hpp @@ -50,16 +50,19 @@ #define CELL2FEATURE_TMP_EXT ".c2f.tmp" #define COUNTRIES_FILE "countries.txt" +#define COUNTRIES_MIGRATE_FILE "countries_mig.txt" #define WORLD_FILE_NAME "World" #define WORLD_COASTS_FILE_NAME "WorldCoasts" +#define WORLD_COASTS_MIGRATE_FILE_NAME "WorldCoasts_mig" #define SETTINGS_FILE_NAME "settings.ini" #define SEARCH_CATEGORIES_FILE_NAME "categories.txt" -#define PACKED_POLYGONS_FILE "packed_polygons.bin" #define PACKED_POLYGONS_INFO_TAG "info" +#define PACKED_POLYGONS_FILE "packed_polygons.bin" +#define PACKED_POLYGONS_MIGRATE_FILE "packed_polygons_mig.bin" #define EXTERNAL_RESOURCES_FILE "external_resources.txt" diff --git a/map/framework.cpp b/map/framework.cpp index 2bcb576d2c..ba2910eed2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1048,8 +1048,16 @@ void Framework::InitCountryInfoGetter() Platform const & platform = GetPlatform(); try { - m_infoGetter.reset(new storage::CountryInfoReader(platform.GetReader(PACKED_POLYGONS_FILE), - platform.GetReader(COUNTRIES_FILE))); + if(platform::migrate::NeedMigrate()) + { + m_infoGetter.reset(new storage::CountryInfoGetter(platform.GetReader(PACKED_POLYGONS_FILE), + platform.GetReader(COUNTRIES_FILE))); + } + else + { + m_infoGetter.reset(new storage::CountryInfoGetter(platform.GetReader(PACKED_POLYGONS_MIGRATE_FILE), + platform.GetReader(COUNTRIES_MIGRATE_FILE))); + } } catch (RootException const & e) { diff --git a/platform/local_country_file_utils.cpp b/platform/local_country_file_utils.cpp index 4d5f610686..4c7aedac99 100644 --- a/platform/local_country_file_utils.cpp +++ b/platform/local_country_file_utils.cpp @@ -3,6 +3,7 @@ #include "platform/country_file.hpp" #include "platform/mwm_version.hpp" #include "platform/platform.hpp" +#include "platform/settings.hpp" #include "coding/file_name_utils.hpp" #include "coding/internal/file_data.hpp" @@ -23,6 +24,25 @@ namespace platform { +namespace migrate +{ + // Set of functions to support migration between different versions of MWM + // with totaly incompatible formats. + // 151218 - Migrate to small single file MWM + uint64_t constexpr kRequiredVersion = 151218; + bool NeedMigrate() + { + uint32_t version; + if (!Settings::Get("LastMigration", version)) + return true; + + if (version >= kRequiredVersion) + return false; + + return true; + } +} // namespace migrate + namespace { char const kBitsExt[] = ".bftsegbits"; @@ -210,7 +230,8 @@ void FindAllLocalMapsAndCleanup(int64_t latestVersion, vector // World and WorldCoasts can be stored in app bundle or in resources // directory, thus it's better to get them via Platform. - for (string const & file : { WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME }) + for (string const & file : { WORLD_FILE_NAME, + (migrate::NeedMigrate() ? WORLD_COASTS_FILE_NAME : WORLD_COASTS_MIGRATE_FILE_NAME) }) { auto i = localFiles.begin(); for (; i != localFiles.end(); ++i) diff --git a/platform/local_country_file_utils.hpp b/platform/local_country_file_utils.hpp index cee7f88e69..3b5a8c8068 100644 --- a/platform/local_country_file_utils.hpp +++ b/platform/local_country_file_utils.hpp @@ -12,6 +12,11 @@ class ModelReader; namespace platform { +namespace migrate +{ + bool NeedMigrate(); +} + // Removes all files downloader creates during downloading of a country. void DeleteDownloaderFilesForCountry(CountryFile const & countryFile, int64_t version); diff --git a/platform/platform_android.cpp b/platform/platform_android.cpp index 239ad36dd5..ad852af6ff 100644 --- a/platform/platform_android.cpp +++ b/platform/platform_android.cpp @@ -37,6 +37,7 @@ 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_COASTS_MIGRATE_FILE_NAME) || strings::StartsWith(file, WORLD_FILE_NAME)); } else if (ext == BOOKMARKS_FILE_EXTENSION || diff --git a/storage/storage.cpp b/storage/storage.cpp index f7d9794f49..eb9d49d2ab 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -458,10 +458,11 @@ void Storage::LoadCountriesFile(bool forceReload) if (m_countries.SiblingsCount() == 0) { string json; - ReaderPtr(GetPlatform().GetReader(COUNTRIES_FILE)).ReadAsString(json); + string name = migrate::NeedMigrate() ? COUNTRIES_FILE : COUNTRIES_MIGRATE_FILE; + ReaderPtr(GetPlatform().GetReader(name)).ReadAsString(json); m_currentVersion = LoadCountries(json, m_countries); if (m_currentVersion < 0) - LOG(LERROR, ("Can't load countries file", COUNTRIES_FILE)); + LOG(LERROR, ("Can't load countries file", name)); } } @@ -691,7 +692,7 @@ void Storage::GetOutdatedCountries(vector & countries) const string const name = GetCountryFile(index).GetNameWithoutExt(); TLocalFilePtr file = GetLatestLocalFile(index); if (file && file->GetVersion() != GetCurrentDataVersion() && - name != WORLD_COASTS_FILE_NAME && name != WORLD_FILE_NAME) + name != WORLD_COASTS_FILE_NAME && name != WORLD_COASTS_MIGRATE_FILE_NAME && name != WORLD_FILE_NAME) { countries.push_back(&CountryByIndex(index)); }