diff options
author | Roman Kuznetsov <r.kuznetsow@gmail.com> | 2018-02-17 14:24:01 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2018-02-19 12:49:33 +0300 |
commit | 402f11a34afd944b479fa5ecf1d0e5e366ec3041 (patch) | |
tree | efbbd17ba6e0a17a515ea8b99364df90b6266aee /map/bookmark_manager.cpp | |
parent | 02792847654792855532fdb0291bebdbda7b4e38 (diff) |
Added new bookmarks sharing interface
Diffstat (limited to 'map/bookmark_manager.cpp')
-rw-r--r-- | map/bookmark_manager.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index d66e71ba06..909fde800b 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -17,6 +17,7 @@ #include "coding/file_writer.hpp" #include "coding/hex.hpp" #include "coding/internal/file_data.hpp" +#include "coding/zip_creator.hpp" #include "coding/zip_reader.hpp" #include "geometry/transformations.hpp" @@ -1173,6 +1174,63 @@ void BookmarkManager::SetInvalidTokenHandler(Cloud::InvalidTokenHandler && onInv m_bookmarkCloud.SetInvalidTokenHandler(std::move(onInvalidToken)); } +std::string BookmarkManager::BeginSharing(df::MarkGroupID categoryId) +{ + auto const it = m_activeSharing.find(categoryId); + if (it != m_activeSharing.end()) + { + if (GetPlatform().IsFileExistsByFullPath(it->second)) + return it->second; + } + + auto const f = GetFileForSharing(categoryId); + if (f.empty()) + { + m_activeSharing.erase(categoryId); + return {}; + } + + m_activeSharing[categoryId] = f; + return f; +} + +void BookmarkManager::EndSharing(df::MarkGroupID categoryId) +{ + auto const it = m_activeSharing.find(categoryId); + if (it == m_activeSharing.end()) + return; + + if (GetPlatform().IsFileExistsByFullPath(it->second)) + my::DeleteFileX(it->second); + + m_activeSharing.erase(categoryId); +} + +std::string BookmarkManager::GetFileForSharing(df::MarkGroupID categoryId) +{ + auto const filePath = GetCategoryFileName(categoryId); + if (!GetPlatform().IsFileExistsByFullPath(filePath)) + return {}; + + auto ext = my::GetFileExtension(filePath); + strings::AsciiToLower(ext); + std::string fileName = filePath; + my::GetNameFromFullPath(fileName); + my::GetNameWithoutExt(fileName); + auto const tmpFilePath = my::JoinFoldersToPath(GetPlatform().TmpDir(), fileName + KMZ_EXTENSION); + if (ext == KMZ_EXTENSION) + { + if (!my::CopyFileX(filePath, tmpFilePath)) + return {}; + return tmpFilePath; + } + + if (CreateZipFromPathDeflatedAndDefaultCompression(filePath, tmpFilePath)) + return tmpFilePath; + + return {}; +} + df::GroupIDSet BookmarkManager::MarksChangesTracker::GetAllGroupIds() const { auto const & groupIds = m_bmManager.GetBmGroupsIdList(); |