Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2018-04-12 13:59:32 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2018-04-12 14:48:31 +0300
commit05411dec927ea3ad1b4af2d4f5716f6798b8fba3 (patch)
tree85f288bf54fab3663a1b14e91de509a62b40256f /map/bookmark_manager.cpp
parent9736a7792863e747f6bc0b33dd057a62acd40955 (diff)
Fixed bookmarks sharing
Diffstat (limited to 'map/bookmark_manager.cpp')
-rw-r--r--map/bookmark_manager.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp
index 17e48f50ed..c498e8f99f 100644
--- a/map/bookmark_manager.cpp
+++ b/map/bookmark_manager.cpp
@@ -114,26 +114,22 @@ public:
m2::PointD m_globalCenter;
};
-BookmarkManager::SharingResult GetFileForSharing(kml::MarkGroupId categoryId, std::string const & filePath)
+BookmarkManager::SharingResult GetFileForSharing(BookmarkManager::KMLDataCollectionPtr collection)
{
- if (!GetPlatform().IsFileExistsByFullPath(filePath))
+ auto const & kmlToShare = collection->front();
+ auto const filePath = my::JoinPath(GetPlatform().TmpDir(), GetFileName(kmlToShare.first));
+ MY_SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, filePath));
+
+ auto const categoryId = kmlToShare.second->m_categoryData.m_id;
+
+ if (!SaveKmlFile(*kmlToShare.second, filePath, false /* useBinary */))
{
return BookmarkManager::SharingResult(categoryId, BookmarkManager::SharingResult::Code::FileError,
"Bookmarks file does not exist.");
}
- auto const ext = GetFileExt(filePath);
- std::string fileName = my::GetNameFromFullPathWithoutExt(filePath);
+ auto const fileName = my::GetNameFromFullPathWithoutExt(filePath);
auto const tmpFilePath = my::JoinPath(GetPlatform().TmpDir(), fileName + kKmzExtension);
- if (ext == kKmzExtension)
- {
- if (my::CopyFileX(filePath, tmpFilePath))
- return BookmarkManager::SharingResult(categoryId, tmpFilePath);
-
- return BookmarkManager::SharingResult(categoryId, BookmarkManager::SharingResult::Code::FileError,
- "Could not copy file.");
- }
-
if (!CreateZipFromPathDeflatedAndDefaultCompression(filePath, tmpFilePath))
{
return BookmarkManager::SharingResult(categoryId, BookmarkManager::SharingResult::Code::ArchiveError,
@@ -1517,10 +1513,17 @@ void BookmarkManager::PrepareFileForSharing(kml::MarkGroupId categoryId, Sharing
return;
}
- auto const filePath = GetCategoryFileName(categoryId);
- GetPlatform().RunTask(Platform::Thread::File, [categoryId, filePath, handler = std::move(handler)]()
+ auto collection = PrepareToSaveBookmarks({categoryId});
+ if (!collection || collection->empty())
+ {
+ handler(SharingResult(categoryId, SharingResult::Code::FileError));
+ return;
+ }
+
+ GetPlatform().RunTask(Platform::Thread::File,
+ [collection = std::move(collection), handler = std::move(handler)]() mutable
{
- handler(GetFileForSharing(categoryId, filePath));
+ handler(GetFileForSharing(std::move(collection)));
});
}