Review fixes

This commit is contained in:
Roman Kuznetsov 2018-05-11 13:00:27 +03:00 committed by Aleksandr Zatsepin
parent 3ab1392d6f
commit fdba846006
3 changed files with 41 additions and 25 deletions

View file

@ -8,6 +8,7 @@ std::string GetBookmarkIconType(kml::BookmarkIcon const & icon)
switch (icon)
{
case kml::BookmarkIcon::None: return "default";
case kml::BookmarkIcon::Hotel: return "hotel";
case kml::BookmarkIcon::Count:
ASSERT(false, ("Invalid bookmark icon type"));
return {};

View file

@ -37,6 +37,7 @@
#include <ctime>
#include <fstream>
#include <iomanip>
#include <list>
#include <sstream>
using namespace std::placeholders;
@ -380,14 +381,15 @@ bool MigrateIfNeeded()
}
// Here we read backup and try to restore old-style #placemark-hotel bookmarks.
void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection)
void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection,
bool isMigrationCompleted)
{
static std::string const kSettingsKey = "HotelPlacemarksExtracted";
bool isHotelPlacemarksExtracted;
if (settings::Get(kSettingsKey, isHotelPlacemarksExtracted) && isHotelPlacemarksExtracted)
return;
if (!migration::IsMigrationCompleted())
if (!isMigrationCompleted)
{
settings::Set(kSettingsKey, true);
return;
@ -396,13 +398,13 @@ void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection)
// Find all hotel bookmarks in backup.
Platform::FilesList files;
Platform::GetFilesRecursively(GetBackupFolderName(), files);
std::vector<std::pair<kml::BookmarkData, bool>> hotelBookmarks;
hotelBookmarks.reserve(100);
std::list<kml::BookmarkData> hotelBookmarks;
for (auto const & f : files)
{
if (GetFileExt(f) != kKmzExtension)
continue;
// TODO: use LoadKmzFile after rebase on master.
ZipFileReader::FileListT filesInZip;
ZipFileReader::FilesList(f, filesInZip);
if (filesInZip.empty())
@ -427,10 +429,10 @@ void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection)
if (kmlData == nullptr)
continue;
for (auto const & b : kmlData->m_bookmarksData)
for (auto & b : kmlData->m_bookmarksData)
{
if (b.m_icon == kml::BookmarkIcon::Hotel)
hotelBookmarks.emplace_back(b, false);
hotelBookmarks.push_back(std::move(b));
}
}
if (hotelBookmarks.empty())
@ -446,9 +448,7 @@ void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection)
{
auto fileData = std::make_unique<kml::FileData>();
kml::SetDefaultStr(fileData->m_categoryData.m_name, kHotelsBookmarks);
fileData->m_bookmarksData.reserve(hotelBookmarks.size());
for (auto & hb : hotelBookmarks)
fileData->m_bookmarksData.push_back(std::move(hb.first));
fileData->m_bookmarksData.assign(hotelBookmarks.begin(), hotelBookmarks.end());
collection->emplace_back("", std::move(fileData));
settings::Set(kSettingsKey, true);
return;
@ -462,17 +462,15 @@ void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection)
bool needSave = false;
for (auto & b : p.second->m_bookmarksData)
{
for (auto & hb : hotelBookmarks)
for (auto it = hotelBookmarks.begin(); it != hotelBookmarks.end(); ++it)
{
if (hb.second)
continue;
if (b.m_point.EqualDxDy(hb.first.m_point, kEps))
if (b.m_point.EqualDxDy(it->m_point, kEps))
{
needSave = true;
hb.second = true;
b.m_color = hb.first.m_color;
b.m_icon = hb.first.m_icon;
b.m_color = it->m_color;
b.m_icon = it->m_icon;
hotelBookmarks.erase(it);
break;
}
}
}
@ -486,14 +484,10 @@ void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection)
// Add not-matched hotel bookmarks.
auto fileData = std::make_unique<kml::FileData>();
kml::SetDefaultStr(fileData->m_categoryData.m_name, kHotelsBookmarks);
fileData->m_bookmarksData.reserve(hotelBookmarks.size());
for (auto & hb : hotelBookmarks)
{
if (!hb.second)
fileData->m_bookmarksData.push_back(std::move(hb.first));
}
fileData->m_bookmarksData.assign(hotelBookmarks.begin(), hotelBookmarks.end());
if (!fileData->m_bookmarksData.empty())
collection->emplace_back("", std::move(fileData));
settings::Set(kSettingsKey, true);
}
} // namespace migration
@ -975,13 +969,14 @@ void BookmarkManager::LoadBookmarks()
NotifyAboutStartAsyncLoading();
GetPlatform().RunTask(Platform::Thread::File, [this]()
{
bool const isMigrationCompleted = migration::IsMigrationCompleted();
bool const migrated = migration::MigrateIfNeeded();
std::string const dir = migrated ? GetBookmarksDirectory() : GetPlatform().SettingsDir();
std::string const filesExt = migrated ? kKmbExtension : kKmlExtension;
std::vector<std::string> filePaths;
auto collection = LoadBookmarks(dir, filesExt, migrated, filePaths);
migration::FixUpHotelPlacemarks(collection);
migration::FixUpHotelPlacemarks(collection, isMigrationCompleted);
if (m_needTeardown)
return;

View file

@ -20,6 +20,11 @@
45E4561120584E8F00D9F45E /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 45E4561020584E8F00D9F45E /* libz.tbd */; };
45E456142058509200D9F45E /* testingmain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45E456122058508C00D9F45E /* testingmain.cpp */; };
BB31223C20A0B24500B80260 /* libindexer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BB31223B20A0B24500B80260 /* libindexer.a */; };
EBAAF0D820A5A01700C4D321 /* libeditor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBAAF0D720A5A01700C4D321 /* libeditor.a */; };
EBAAF0DA20A5A01D00C4D321 /* libicu.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBAAF0D920A5A01D00C4D321 /* libicu.a */; };
EBAAF0DC20A5A0BD00C4D321 /* libjansson.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBAAF0DB20A5A0BD00C4D321 /* libjansson.a */; };
EBAAF0DE20A5A0C300C4D321 /* libpugixml.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBAAF0DD20A5A0C300C4D321 /* libpugixml.a */; };
EBAAF0E020A5A0DF00C4D321 /* libprotobuf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBAAF0DF20A5A0DF00C4D321 /* libprotobuf.a */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -57,6 +62,11 @@
45E4561020584E8F00D9F45E /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
45E456122058508C00D9F45E /* testingmain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = testingmain.cpp; path = ../../testing/testingmain.cpp; sourceTree = "<group>"; };
BB31223B20A0B24500B80260 /* libindexer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libindexer.a; sourceTree = BUILT_PRODUCTS_DIR; };
EBAAF0D720A5A01700C4D321 /* libeditor.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libeditor.a; sourceTree = BUILT_PRODUCTS_DIR; };
EBAAF0D920A5A01D00C4D321 /* libicu.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libicu.a; sourceTree = BUILT_PRODUCTS_DIR; };
EBAAF0DB20A5A0BD00C4D321 /* libjansson.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libjansson.a; sourceTree = BUILT_PRODUCTS_DIR; };
EBAAF0DD20A5A0C300C4D321 /* libpugixml.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libpugixml.a; sourceTree = BUILT_PRODUCTS_DIR; };
EBAAF0DF20A5A0DF00C4D321 /* libprotobuf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libprotobuf.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -71,6 +81,11 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
EBAAF0E020A5A0DF00C4D321 /* libprotobuf.a in Frameworks */,
EBAAF0DE20A5A0C300C4D321 /* libpugixml.a in Frameworks */,
EBAAF0DC20A5A0BD00C4D321 /* libjansson.a in Frameworks */,
EBAAF0DA20A5A01D00C4D321 /* libicu.a in Frameworks */,
EBAAF0D820A5A01700C4D321 /* libeditor.a in Frameworks */,
BB31223C20A0B24500B80260 /* libindexer.a in Frameworks */,
45E4560320584E1C00D9F45E /* libkml.a in Frameworks */,
45E4560420584E2600D9F45E /* libplatform.a in Frameworks */,
@ -136,6 +151,11 @@
45E4560220584E1C00D9F45E /* Frameworks */ = {
isa = PBXGroup;
children = (
EBAAF0DF20A5A0DF00C4D321 /* libprotobuf.a */,
EBAAF0DD20A5A0C300C4D321 /* libpugixml.a */,
EBAAF0DB20A5A0BD00C4D321 /* libjansson.a */,
EBAAF0D920A5A01D00C4D321 /* libicu.a */,
EBAAF0D720A5A01700C4D321 /* libeditor.a */,
BB31223B20A0B24500B80260 /* libindexer.a */,
45E4561020584E8F00D9F45E /* libz.tbd */,
45E4560F20584E6A00D9F45E /* libalohalitics.a */,