[Old map downloader] Migrate implementation

This commit is contained in:
Sergey Yershov 2016-01-22 19:38:05 +03:00
parent dabea56723
commit 8353b766a1
15 changed files with 9284 additions and 6721 deletions

Binary file not shown.

File diff suppressed because it is too large Load diff

7043
data/countries_migrate.txt Normal file

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

View file

@ -237,6 +237,20 @@ void Framework::StopLocationFollow()
CallDrapeFunction(bind(&df::DrapeEngine::StopLocationFollow, _1));
}
void Framework::Migrate()
{
Storage().DeleteAllLocalMaps();
DeregisterAllMaps();
m_model.Clear();
Storage().Migrate();
RegisterAllMaps();
m_searchEngine.reset();
m_infoGetter.reset();
InitCountryInfoGetter();
InitSearchEngine();
InvalidateRect(MercatorBounds::FullRect());
}
Framework::Framework()
: m_bmManager(*this)
, m_fixedSearchResults(0)
@ -515,6 +529,9 @@ void Framework::RegisterAllMaps()
m_storage.RegisterAllLocalMaps();
if(platform::migrate::NeedMigrate())
m_storage.FastMigrateIfPossible();
int minFormat = numeric_limits<int>::max();
vector<shared_ptr<LocalCountryFile>> maps;

View file

@ -150,6 +150,8 @@ public:
Framework();
virtual ~Framework();
void Migrate();
void InitWatchFrameRenderer(float visualScale);
/// @param center - map center in Mercator

View file

@ -58,7 +58,7 @@ void LocalCountryFile::DeleteFromDisk(MapOptions files) const
string LocalCountryFile::GetPath(MapOptions file) const
{
// todo(@m): Refactor with MwmTraits after merge new-search branch.
bool singleFile = GetVersion() > 151126;
bool singleFile = GetVersion() > 151215;
string const & countryFilePath = singleFile ? m_countryFile.GetNameWithExt(MapOptions::Map)
: m_countryFile.GetNameWithExt(file);
return my::JoinFoldersToPath(m_directory, countryFilePath);

View file

@ -28,8 +28,8 @@ 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;
// 160107 - Migrate to small single file MWM
uint32_t constexpr kRequiredVersion = 160107;
bool NeedMigrate()
{
uint32_t version;
@ -41,6 +41,11 @@ namespace migrate
return true;
}
void SetMigrationFlag()
{
Settings::Set("LastMigration", kRequiredVersion);
}
} // namespace migrate
namespace

View file

@ -15,6 +15,7 @@ namespace platform
namespace migrate
{
bool NeedMigrate();
void SetMigrationFlag();
}
// Removes all files downloader creates during downloading of a country.

View file

@ -207,6 +207,20 @@ bool SearchPanel::Try3dModeCmd(QString const & str)
return true;
}
bool SearchPanel::TryMigrate(QString const & str)
{
bool const isMigrate = (str == "?migrate");
if (!isMigrate)
return false;
m_pEditor->setText("");
parentWidget()->hide();
m_pDrawWidget->GetFramework().Migrate();
return true;
}
void SearchPanel::OnSearchTextChanged(QString const & str)
{
QString const normalized = str.normalized(QString::NormalizationForm_KC);
@ -218,6 +232,8 @@ void SearchPanel::OnSearchTextChanged(QString const & str)
return;
if (Try3dModeCmd(normalized))
return;
if (TryMigrate(normalized))
return;
// search even with empty query
if (!normalized.isEmpty())

View file

@ -67,6 +67,7 @@ private slots:
bool TryChangeMapStyleCmd(QString const & str);
bool TryChangeRouterCmd(QString const & str);
bool Try3dModeCmd(QString const & str);
bool TryMigrate(QString const & str);
};
}

View file

@ -6,6 +6,7 @@
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
#include "platform/servers_list.hpp"
#include "platform/settings.hpp"
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
@ -105,6 +106,41 @@ void Storage::Clear()
m_localFilesForFakeCountries.clear();
}
void Storage::FastMigrateIfPossible()
{
bool disableFastMigrate = false;
Settings::Get("DisableFastMigrate", disableFastMigrate);
if(!disableFastMigrate && platform::migrate::NeedMigrate() && m_localFiles.empty())
{
Migrate();
}
}
void Storage::Migrate()
{
platform::migrate::SetMigrationFlag();
Clear();
m_countries.Clear();
LoadCountriesFile(true /* forceReload */);
}
void Storage::DeleteAllLocalMaps(vector<TIndex> * existedCountries /* = nullptr */)
{
for (auto const & localFiles : m_localFiles)
{
for (auto const & localFile : localFiles.second)
{
LOG_SHORT(LINFO, ("Remove:", localFiles.first, DebugPrint(*localFile)));
if (existedCountries)
existedCountries->push_back(localFiles.first);
localFile->SyncWithDisk();
DeleteFromDiskWithIndexes(*localFile, MapOptions::MapWithCarRouting);
}
}
}
void Storage::RegisterAllLocalMaps()
{
m_localFiles.clear();

View file

@ -109,6 +109,12 @@ public:
void Init(TUpdate const & update);
/// Switch on new storage version, remove old mwm
/// and add required mwm's into download queue.
void Migrate();
void FastMigrateIfPossible();
void DeleteAllLocalMaps(vector<TIndex> * existedCountries = nullptr);
// Clears local files registry and downloader's queue.
void Clear();

View file

@ -72,6 +72,16 @@
674A7E391C0DB727003D48E1 /* libstb_image.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 674A7E351C0DB727003D48E1 /* libstb_image.a */; };
674A7E411C0DB7D6003D48E1 /* qtoglcontext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 674A7E3C1C0DB7D6003D48E1 /* qtoglcontext.cpp */; };
674A7E421C0DB7D6003D48E1 /* qtoglcontextfactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 674A7E3E1C0DB7D6003D48E1 /* qtoglcontextfactory.cpp */; };
675340981C5289AC002CF0D9 /* libeditor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 675340951C5289AC002CF0D9 /* libeditor.a */; };
675340991C5289AC002CF0D9 /* liboauthcpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 675340961C5289AC002CF0D9 /* liboauthcpp.a */; };
6753409A1C5289AC002CF0D9 /* libpugixml.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 675340971C5289AC002CF0D9 /* libpugixml.a */; };
6753409F1C5289E0002CF0D9 /* editor_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6753409B1C5289E0002CF0D9 /* editor_dialog.cpp */; };
675340A01C5289E0002CF0D9 /* osm_auth_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6753409D1C5289E0002CF0D9 /* osm_auth_dialog.cpp */; };
675340A11C528A1C002CF0D9 /* editor_dialog.hpp in Sources */ = {isa = PBXBuildFile; fileRef = 6753409C1C5289E0002CF0D9 /* editor_dialog.hpp */; };
675340A21C528A1C002CF0D9 /* osm_auth_dialog.hpp in Sources */ = {isa = PBXBuildFile; fileRef = 6753409E1C5289E0002CF0D9 /* osm_auth_dialog.hpp */; };
675340A61C528F02002CF0D9 /* countries_migrate.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 675340A31C528F02002CF0D9 /* countries_migrate.txt */; };
675340A71C528F02002CF0D9 /* packed_polygons_migrate.bin in CopyFiles */ = {isa = PBXBuildFile; fileRef = 675340A41C528F02002CF0D9 /* packed_polygons_migrate.bin */; };
675340A81C528F02002CF0D9 /* WorldCoasts_migrate.mwm in CopyFiles */ = {isa = PBXBuildFile; fileRef = 675340A51C528F02002CF0D9 /* WorldCoasts_migrate.mwm */; };
675345861A404CB200A0A8C3 /* about.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6753456C1A404CB200A0A8C3 /* about.cpp */; };
675345881A404CB200A0A8C3 /* draw_widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675345701A404CB200A0A8C3 /* draw_widget.cpp */; };
675345891A404CB200A0A8C3 /* info_dialog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675345721A404CB200A0A8C3 /* info_dialog.cpp */; };
@ -132,6 +142,9 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
675340A61C528F02002CF0D9 /* countries_migrate.txt in CopyFiles */,
675340A71C528F02002CF0D9 /* packed_polygons_migrate.bin in CopyFiles */,
675340A81C528F02002CF0D9 /* WorldCoasts_migrate.mwm in CopyFiles */,
67A461A71C2172C400B18739 /* 07_roboto_medium.ttf in CopyFiles */,
6714E5E41BD13F67008AB603 /* drules_proto_clear.bin in CopyFiles */,
6714E5E61BD13F67008AB603 /* drules_proto_dark.bin in CopyFiles */,
@ -221,6 +234,16 @@
674A7E3D1C0DB7D6003D48E1 /* qtoglcontext.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = qtoglcontext.hpp; sourceTree = "<group>"; };
674A7E3E1C0DB7D6003D48E1 /* qtoglcontextfactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = qtoglcontextfactory.cpp; sourceTree = "<group>"; };
674A7E3F1C0DB7D6003D48E1 /* qtoglcontextfactory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = qtoglcontextfactory.hpp; sourceTree = "<group>"; };
675340951C5289AC002CF0D9 /* libeditor.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libeditor.a; path = "/Users/darkserj/mapsme/omim/xcode/editor/../../../omim-xcode-build/Release/libeditor.a"; sourceTree = "<absolute>"; };
675340961C5289AC002CF0D9 /* liboauthcpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liboauthcpp.a; path = "/Users/darkserj/mapsme/omim/xcode/oauthcpp/../../../omim-xcode-build/Release/liboauthcpp.a"; sourceTree = "<absolute>"; };
675340971C5289AC002CF0D9 /* libpugixml.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpugixml.a; path = "/Users/darkserj/mapsme/omim/xcode/pugixml/../../../omim-xcode-build/Release/libpugixml.a"; sourceTree = "<absolute>"; };
6753409B1C5289E0002CF0D9 /* editor_dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = editor_dialog.cpp; sourceTree = "<group>"; };
6753409C1C5289E0002CF0D9 /* editor_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = editor_dialog.hpp; sourceTree = "<group>"; };
6753409D1C5289E0002CF0D9 /* osm_auth_dialog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = osm_auth_dialog.cpp; sourceTree = "<group>"; };
6753409E1C5289E0002CF0D9 /* osm_auth_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = osm_auth_dialog.hpp; sourceTree = "<group>"; };
675340A31C528F02002CF0D9 /* countries_migrate.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = countries_migrate.txt; sourceTree = "<group>"; };
675340A41C528F02002CF0D9 /* packed_polygons_migrate.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; path = packed_polygons_migrate.bin; sourceTree = "<group>"; };
675340A51C528F02002CF0D9 /* WorldCoasts_migrate.mwm */ = {isa = PBXFileReference; lastKnownFileType = file; path = WorldCoasts_migrate.mwm; sourceTree = "<group>"; };
675345491A404C6100A0A8C3 /* MapsMe.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MapsMe.app; sourceTree = BUILT_PRODUCTS_DIR; };
6753454D1A404C6100A0A8C3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6753456C1A404CB200A0A8C3 /* about.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = about.cpp; sourceTree = "<group>"; };
@ -265,6 +288,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
675340981C5289AC002CF0D9 /* libeditor.a in Frameworks */,
675340991C5289AC002CF0D9 /* liboauthcpp.a in Frameworks */,
6753409A1C5289AC002CF0D9 /* libpugixml.a in Frameworks */,
674A7E361C0DB727003D48E1 /* libdrape_frontend.a in Frameworks */,
674A7E371C0DB727003D48E1 /* libdrape.a in Frameworks */,
674A7E381C0DB727003D48E1 /* libsdf_image.a in Frameworks */,
@ -317,6 +343,9 @@
6729A4591A684401007D5872 /* Libs */ = {
isa = PBXGroup;
children = (
675340951C5289AC002CF0D9 /* libeditor.a */,
675340961C5289AC002CF0D9 /* liboauthcpp.a */,
675340971C5289AC002CF0D9 /* libpugixml.a */,
674A7E321C0DB727003D48E1 /* libdrape_frontend.a */,
674A7E331C0DB727003D48E1 /* libdrape.a */,
674A7E341C0DB727003D48E1 /* libsdf_image.a */,
@ -366,6 +395,9 @@
9DA46A1D1C47E9E200EF52BA /* resources-mdpi_legacy */,
9DA46A1E1C47E9E200EF52BA /* resources-xhdpi_legacy */,
9DA46A1F1C47E9E200EF52BA /* resources-xxhdpi_legacy */,
675340A31C528F02002CF0D9 /* countries_migrate.txt */,
675340A41C528F02002CF0D9 /* packed_polygons_migrate.bin */,
675340A51C528F02002CF0D9 /* WorldCoasts_migrate.mwm */,
677A2DE71C0DDD7C00635A00 /* resources-default */,
6714E5DE1BD13F67008AB603 /* drules_proto_clear.bin */,
6714E5E01BD13F67008AB603 /* drules_proto_dark.bin */,
@ -420,6 +452,10 @@
6753454B1A404C6100A0A8C3 /* MapsMe */ = {
isa = PBXGroup;
children = (
6753409B1C5289E0002CF0D9 /* editor_dialog.cpp */,
6753409C1C5289E0002CF0D9 /* editor_dialog.hpp */,
6753409D1C5289E0002CF0D9 /* osm_auth_dialog.cpp */,
6753409E1C5289E0002CF0D9 /* osm_auth_dialog.hpp */,
674A7E3C1C0DB7D6003D48E1 /* qtoglcontext.cpp */,
674A7E3D1C0DB7D6003D48E1 /* qtoglcontext.hpp */,
674A7E3E1C0DB7D6003D48E1 /* qtoglcontextfactory.cpp */,
@ -539,6 +575,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
675340A11C528A1C002CF0D9 /* editor_dialog.hpp in Sources */,
675340A21C528A1C002CF0D9 /* osm_auth_dialog.hpp in Sources */,
670D05991B0CBD5A0013A7AC /* draw_widget.hpp in Sources */,
670D059A1B0CBD5B0013A7AC /* mainwindow.hpp in Sources */,
670D059B1B0CBD5B0013A7AC /* proxystyle.hpp in Sources */,
@ -554,9 +592,11 @@
675345861A404CB200A0A8C3 /* about.cpp in Sources */,
675345911A404CB200A0A8C3 /* slider_ctrl.cpp in Sources */,
6753458D1A404CB200A0A8C3 /* proxystyle.cpp in Sources */,
6753409F1C5289E0002CF0D9 /* editor_dialog.cpp in Sources */,
675345921A404CB200A0A8C3 /* update_dialog.cpp in Sources */,
6753458B1A404CB200A0A8C3 /* mainwindow.cpp in Sources */,
675345881A404CB200A0A8C3 /* draw_widget.cpp in Sources */,
675340A01C5289E0002CF0D9 /* osm_auth_dialog.cpp in Sources */,
674A7E421C0DB7D6003D48E1 /* qtoglcontextfactory.cpp in Sources */,
6753458C1A404CB200A0A8C3 /* preferences_dialog.cpp in Sources */,
6753458A1A404CB200A0A8C3 /* main.cpp in Sources */,