forked from organicmaps/organicmaps
[storage] CountryTree now initialized in Framework::AddMaps. It’s correct way for Android, when active maps set can be changed.
This commit is contained in:
parent
af9ca30361
commit
9fbe5893b0
10 changed files with 112 additions and 96 deletions
|
@ -493,12 +493,12 @@ namespace android
|
|||
|
||||
void Framework::AddLocalMaps()
|
||||
{
|
||||
m_work.AddLocalMaps();
|
||||
m_work.AddMaps();
|
||||
}
|
||||
|
||||
void Framework::RemoveLocalMaps()
|
||||
{
|
||||
m_work.RemoveLocalMaps();
|
||||
m_work.RemoveMaps();
|
||||
}
|
||||
|
||||
void Framework::GetMapsWithoutSearch(vector<string> & out) const
|
||||
|
@ -508,7 +508,7 @@ namespace android
|
|||
::Platform const & pl = GetPlatform();
|
||||
|
||||
vector<string> v;
|
||||
m_work.GetLocalMaps(v);
|
||||
m_work.GetMaps(v);
|
||||
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
{
|
||||
|
|
|
@ -66,8 +66,7 @@ bool CreateZipFromPathDeflatedAndDefaultCompression(string const & filePath, str
|
|||
if (!zip.Handle())
|
||||
return false;
|
||||
|
||||
// Special syntax to initialize struct with zeroes
|
||||
zip_fileinfo zipInfo = zip_fileinfo();
|
||||
zip_fileinfo zipInfo = {};
|
||||
CreateTMZip(zipInfo.tmz_date);
|
||||
|
||||
string fileName = filePath;
|
||||
|
|
|
@ -1,34 +1,38 @@
|
|||
#include "active_maps_layout.hpp"
|
||||
|
||||
#include "framework.hpp"
|
||||
|
||||
#include "../std/algorithm.hpp"
|
||||
|
||||
|
||||
namespace storage
|
||||
{
|
||||
|
||||
ActiveMapsLayout::ActiveMapsLayout(Framework & framework)
|
||||
: m_framework(framework)
|
||||
{
|
||||
m_subscribeSlotID = m_framework.Storage().Subscribe(bind(&ActiveMapsLayout::StatusChangedCallback, this, _1),
|
||||
bind(&ActiveMapsLayout::ProgressChangedCallback, this, _1, _2));
|
||||
|
||||
Init();
|
||||
m_subscribeSlotID = GetStorage().Subscribe(bind(&ActiveMapsLayout::StatusChangedCallback, this, _1),
|
||||
bind(&ActiveMapsLayout::ProgressChangedCallback, this, _1, _2));
|
||||
}
|
||||
|
||||
ActiveMapsLayout::~ActiveMapsLayout()
|
||||
{
|
||||
m_framework.Storage().Unsubscribe(m_subscribeSlotID);
|
||||
GetStorage().Unsubscribe(m_subscribeSlotID);
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::Init()
|
||||
void ActiveMapsLayout::Init(vector<string> const & maps)
|
||||
{
|
||||
Storage & storage = GetStorage();
|
||||
auto insertIndexFn = [&](TIndex const & index)
|
||||
auto insertIndexFn = [&] (TIndex const & index)
|
||||
{
|
||||
TStatus status;
|
||||
TMapOptions options;
|
||||
storage.CountryStatusEx(index, status, options);
|
||||
if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
m_items.push_back({ index, status, options, options });
|
||||
string const fName = storage.CountryFileNameWithoutExt(index) + DATA_FILE_EXTENSION;
|
||||
if (binary_search(maps.begin(), maps.end(), fName))
|
||||
{
|
||||
TStatus status;
|
||||
TMapOptions options;
|
||||
storage.CountryStatusEx(index, status, options);
|
||||
if (status == TStatus::EOnDisk || status == TStatus::EOnDiskOutOfDate)
|
||||
m_items.push_back({ index, status, options, options });
|
||||
}
|
||||
};
|
||||
|
||||
TIndex root;
|
||||
|
@ -63,7 +67,7 @@ void ActiveMapsLayout::Init()
|
|||
|
||||
sort(m_items.begin(), m_items.end(), comparatorFn);
|
||||
|
||||
m_split = make_pair(0, m_items.size());
|
||||
m_split = { 0, m_items.size() };
|
||||
for (size_t i = 0; i < m_items.size(); ++i)
|
||||
{
|
||||
if (m_items[i].m_status == TStatus::EOnDisk)
|
||||
|
@ -74,6 +78,12 @@ void ActiveMapsLayout::Init()
|
|||
}
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::Clear()
|
||||
{
|
||||
m_items.clear();
|
||||
m_split = { 0, 0 };
|
||||
}
|
||||
|
||||
void ActiveMapsLayout::UpdateAll()
|
||||
{
|
||||
vector<Item> toDownload;
|
||||
|
|
|
@ -83,10 +83,12 @@ private:
|
|||
Storage const & GetStorage() const;
|
||||
Storage & GetStorage();
|
||||
|
||||
void Init(vector<string> const & maps);
|
||||
void Clear();
|
||||
|
||||
bool GetGuideInfo(TIndex const & index, guides::GuideInfo & info) const;
|
||||
|
||||
void ShowMap(TIndex const & index);
|
||||
void Init();
|
||||
|
||||
private:
|
||||
void StatusChangedCallback(TIndex const & index);
|
||||
|
|
|
@ -126,10 +126,7 @@ struct MapsCollector
|
|||
void BenchmarkEngine::PrepareMaps()
|
||||
{
|
||||
// remove all previously added maps in framework constructor
|
||||
Platform::FilesList files;
|
||||
m_framework->GetLocalMaps(files);
|
||||
for_each(files.begin(), files.end(),
|
||||
bind(&Framework::RemoveMap, m_framework, _1));
|
||||
m_framework->RemoveMaps();
|
||||
|
||||
// add only maps needed for benchmarks
|
||||
MapsCollector collector;
|
||||
|
|
|
@ -52,6 +52,17 @@ CountryTree::~CountryTree()
|
|||
GetStorage().Unsubscribe(m_subscribeSlotID);
|
||||
}
|
||||
|
||||
void CountryTree::Init(vector<string> const & maps)
|
||||
{
|
||||
m_layout.Init(maps);
|
||||
}
|
||||
|
||||
void CountryTree::Clear()
|
||||
{
|
||||
ResetRoot();
|
||||
m_layout.Clear();
|
||||
}
|
||||
|
||||
ActiveMapsLayout & CountryTree::GetActiveMapLayout()
|
||||
{
|
||||
return m_layout;
|
||||
|
|
|
@ -29,6 +29,10 @@ public:
|
|||
CountryTree(Framework & framework);
|
||||
~CountryTree();
|
||||
|
||||
/// @param[in] Sorted vector of current .mwm files.
|
||||
void Init(vector<string> const & maps);
|
||||
void Clear();
|
||||
|
||||
ActiveMapsLayout & GetActiveMapLayout();
|
||||
ActiveMapsLayout const & GetActiveMapLayout() const;
|
||||
|
||||
|
|
|
@ -78,29 +78,23 @@ namespace
|
|||
static const int BM_TOUCH_PIXEL_INCREASE = 20;
|
||||
}
|
||||
|
||||
void Framework::AddMap(string const & file)
|
||||
int Framework::AddMap(string const & file)
|
||||
{
|
||||
LOG(LINFO, ("Loading map:", file));
|
||||
|
||||
int const version = m_model.AddMap(file);
|
||||
switch (version)
|
||||
if (version == feature::DataHeader::v1)
|
||||
{
|
||||
case -1:
|
||||
// Error in adding map - do nothing.
|
||||
break;
|
||||
|
||||
case feature::DataHeader::v1:
|
||||
// Now we do force delete of old (April 2011) maps.
|
||||
LOG(LINFO, ("Deleting old map:", file));
|
||||
RemoveMap(file);
|
||||
VERIFY ( my::DeleteFileX(GetPlatform().WritablePathForFile(file)), () );
|
||||
break;
|
||||
|
||||
default:
|
||||
if (m_lowestMapVersion > version)
|
||||
m_lowestMapVersion = version;
|
||||
break;
|
||||
RemoveMap(file);
|
||||
VERIFY(my::DeleteFileX(GetPlatform().WritablePathForFile(file)), ());
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
void Framework::RemoveMap(string const & file)
|
||||
|
@ -108,8 +102,9 @@ void Framework::RemoveMap(string const & file)
|
|||
m_model.RemoveMap(file);
|
||||
}
|
||||
|
||||
void Framework::OnLocationError(TLocationError error)
|
||||
{}
|
||||
void Framework::OnLocationError(TLocationError /*error*/)
|
||||
{
|
||||
}
|
||||
|
||||
void Framework::OnLocationUpdate(GpsInfo const & info)
|
||||
{
|
||||
|
@ -171,12 +166,32 @@ CountryStatusDisplay * Framework::GetCountryStatusDisplay() const
|
|||
return m_informationDisplay.countryStatusDisplay().get();
|
||||
}
|
||||
|
||||
static void GetResourcesMaps(vector<string> & outMaps)
|
||||
void Framework::GetMaps(vector<string> & maps) const
|
||||
{
|
||||
Platform & pl = GetPlatform();
|
||||
pl.GetFilesByExt(pl.ResourcesDir(), DATA_FILE_EXTENSION, outMaps);
|
||||
|
||||
pl.GetFilesByExt(pl.ResourcesDir(), DATA_FILE_EXTENSION, maps);
|
||||
pl.GetFilesByExt(pl.WritableDir(), DATA_FILE_EXTENSION, maps);
|
||||
|
||||
// Remove duplicate maps if they're both present in resources and in WritableDir.
|
||||
sort(maps.begin(), maps.end());
|
||||
maps.erase(unique(maps.begin(), maps.end()), maps.end());
|
||||
|
||||
#ifdef OMIM_OS_ANDROID
|
||||
// On Android World and WorldCoasts can be stored in alternative /Android/obb/ path.
|
||||
char const * arrCheck[] = { WORLD_FILE_NAME DATA_FILE_EXTENSION,
|
||||
WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION };
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(arrCheck); ++i)
|
||||
{
|
||||
auto const it = lower_bound(maps.begin(), maps.end(), arrCheck[i]);
|
||||
if (it == maps.end() || *it != arrCheck[i])
|
||||
maps.insert(it, arrCheck[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Framework::Framework()
|
||||
: m_navigator(m_scales),
|
||||
m_animator(this),
|
||||
|
@ -187,7 +202,6 @@ Framework::Framework()
|
|||
m_guiController(new gui::Controller),
|
||||
m_animController(new anim::Controller),
|
||||
m_informationDisplay(this),
|
||||
m_lowestMapVersion(numeric_limits<int>::max()),
|
||||
m_benchmarkEngine(0),
|
||||
m_bmManager(*this),
|
||||
m_balloonManager(*this),
|
||||
|
@ -236,30 +250,19 @@ Framework::Framework()
|
|||
m_model.InitClassificator();
|
||||
LOG(LDEBUG, ("Classificator initialized"));
|
||||
|
||||
// Get all available maps.
|
||||
vector<string> maps;
|
||||
GetResourcesMaps(maps);
|
||||
// To avoid possible races - init search engine once in constructor.
|
||||
(void)GetSearchEngine();
|
||||
LOG(LDEBUG, ("Search engine initialized"));
|
||||
|
||||
#ifndef OMIM_OS_ANDROID
|
||||
// On Android, local maps are added and removed when external storage is connected/disconnected.
|
||||
GetLocalMaps(maps);
|
||||
AddMaps();
|
||||
#endif
|
||||
|
||||
// Remove duplicate maps if they're both present in resources and in WritableDir.
|
||||
sort(maps.begin(), maps.end());
|
||||
maps.erase(unique(maps.begin(), maps.end()), maps.end());
|
||||
|
||||
// Add founded maps to index.
|
||||
for_each(maps.begin(), maps.end(), bind(&Framework::AddMap, this, _1));
|
||||
LOG(LDEBUG, ("Map index initialized"));
|
||||
LOG(LDEBUG, ("Maps initialized"));
|
||||
|
||||
// Init storage with needed callback.
|
||||
m_storage.Init(bind(&Framework::UpdateAfterDownload, this, _1, _2));
|
||||
LOG(LDEBUG, ("Storage initialized"));
|
||||
|
||||
// To avoid possible races - init search engine once in constructor.
|
||||
(void)GetSearchEngine();
|
||||
LOG(LDEBUG, ("Search engine initialized"));
|
||||
|
||||
#ifndef OMIM_OS_DESKTOP
|
||||
// Init guides manager
|
||||
m_storage.GetGuideManager().RestoreFromFile();
|
||||
|
@ -270,6 +273,7 @@ Framework::Framework()
|
|||
{
|
||||
return GetSearchEngine()->GetCountryFile(pt);
|
||||
}));
|
||||
LOG(LDEBUG, ("Routing engine initialized"));
|
||||
|
||||
LOG(LINFO, ("System languages:", languages::GetPreferred()));
|
||||
}
|
||||
|
@ -367,19 +371,29 @@ void Framework::UpdateAfterDownload(string const & fileName, TMapOptions opt)
|
|||
}
|
||||
}
|
||||
|
||||
void Framework::AddLocalMaps()
|
||||
void Framework::AddMaps()
|
||||
{
|
||||
// add maps to the model
|
||||
Platform::FilesList maps;
|
||||
GetLocalMaps(maps);
|
||||
//ASSERT(m_model.IsEmpty(), ());
|
||||
|
||||
for_each(maps.begin(), maps.end(), bind(&Framework::AddMap, this, _1));
|
||||
int minVersion = numeric_limits<int>::max();
|
||||
|
||||
m_pSearchEngine->SupportOldFormat(m_lowestMapVersion < feature::DataHeader::v3);
|
||||
vector<string> maps;
|
||||
GetMaps(maps);
|
||||
for_each(maps.begin(), maps.end(), [&] (string const & file)
|
||||
{
|
||||
int const v = AddMap(file);
|
||||
if (v != -1 && v < minVersion)
|
||||
minVersion = v;
|
||||
});
|
||||
|
||||
m_countryTree.Init(maps);
|
||||
|
||||
GetSearchEngine()->SupportOldFormat(minVersion < feature::DataHeader::v3);
|
||||
}
|
||||
|
||||
void Framework::RemoveLocalMaps()
|
||||
void Framework::RemoveMaps()
|
||||
{
|
||||
m_countryTree.Clear();
|
||||
m_model.RemoveAll();
|
||||
}
|
||||
|
||||
|
@ -537,22 +551,6 @@ bool Framework::AddBookmarksFile(string const & filePath)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Framework::GetLocalMaps(vector<string> & outMaps) const
|
||||
{
|
||||
Platform & pl = GetPlatform();
|
||||
pl.GetFilesByExt(pl.WritableDir(), DATA_FILE_EXTENSION, outMaps);
|
||||
|
||||
#ifdef OMIM_OS_ANDROID
|
||||
// On Android World and WorldCoasts can be stored in alternative /Android/obb/ path.
|
||||
char const * arrCheck[] = { WORLD_FILE_NAME DATA_FILE_EXTENSION,
|
||||
WORLD_COASTS_FILE_NAME DATA_FILE_EXTENSION };
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(arrCheck); ++i)
|
||||
if (find(outMaps.begin(), outMaps.end(), arrCheck[i]) == outMaps.end())
|
||||
outMaps.push_back(arrCheck[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Framework::PrepareToShutdown()
|
||||
{
|
||||
SetRenderPolicy(0);
|
||||
|
@ -1124,8 +1122,6 @@ search::Engine * Framework::GetSearchEngine() const
|
|||
pl.GetReader(PACKED_POLYGONS_FILE),
|
||||
pl.GetReader(COUNTRIES_FILE),
|
||||
languages::GetCurrentOrig()));
|
||||
|
||||
m_pSearchEngine->SupportOldFormat(m_lowestMapVersion < feature::DataHeader::v3);
|
||||
}
|
||||
catch (RootException const & e)
|
||||
{
|
||||
|
|
|
@ -127,10 +127,6 @@ protected:
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
/// Stores lowest loaded map version or MAX_INT if no maps added.
|
||||
/// @see feature::DataHeader::Version
|
||||
int m_lowestMapVersion;
|
||||
|
||||
void DrawAdditionalInfo(shared_ptr<PaintEvent> const & e);
|
||||
|
||||
BenchmarkEngine * m_benchmarkEngine;
|
||||
|
@ -148,15 +144,16 @@ public:
|
|||
|
||||
/// @name Process storage connecting/disconnecting.
|
||||
//@{
|
||||
void AddLocalMaps();
|
||||
void RemoveLocalMaps();
|
||||
/// @param[out] maps File names without path.
|
||||
void GetMaps(vector<string> & maps) const;
|
||||
|
||||
void AddMap(string const & file);
|
||||
void AddMaps();
|
||||
void RemoveMaps();
|
||||
|
||||
/// @return Inner mwm data version from header or -1 in case of error.
|
||||
int AddMap(string const & file);
|
||||
//@}
|
||||
|
||||
/// @return File names without path.
|
||||
void GetLocalMaps(vector<string> & outMaps) const;
|
||||
|
||||
/// @name This functions is used by Downloader UI.
|
||||
//@{
|
||||
/// options - flags that signal about parts of map that must be deleted
|
||||
|
|
|
@ -395,7 +395,7 @@ UNIT_TEST(Bookmarks_AddressInfo)
|
|||
{
|
||||
// Maps added in constructor (we need minsk-pass.mwm only)
|
||||
Framework fm;
|
||||
fm.RemoveLocalMaps();
|
||||
fm.RemoveMaps();
|
||||
fm.AddMap("minsk-pass.mwm");
|
||||
|
||||
fm.OnSize(800, 600);
|
||||
|
|
Loading…
Add table
Reference in a new issue