| 2078 | } |
| 2079 | |
| 2080 | void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isTemporaryFile) |
| 2081 | { |
| 2082 | GetPlatform().RunTask(Platform::Thread::File, [this, filePath, isTemporaryFile]() |
| 2083 | { |
| 2084 | if (m_needTeardown) |
| 2085 | return; |
| 2086 | |
| 2087 | auto collection = std::make_shared<KMLDataCollection>(); |
| 2088 | |
| 2089 | // Convert KML/KMZ/KMB files to temp KML file and GPX to temp GPX file. |
| 2090 | for (auto const & fileToLoad : GetKMLOrGPXFilesPathsToLoad(filePath)) |
| 2091 | { |
| 2092 | auto const ext = GetLowercaseFileExt(fileToLoad); |
| 2093 | std::unique_ptr<kml::FileData> kmlData; |
| 2094 | if (ext == kKmlExtension) |
| 2095 | kmlData = LoadKmlFile(fileToLoad, KmlFileType::Text); |
| 2096 | else if (ext == kGpxExtension) |
| 2097 | kmlData = LoadKmlFile(fileToLoad, KmlFileType::Gpx); |
| 2098 | else |
| 2099 | ASSERT(false, ("Unsupported bookmarks extension", ext)); |
| 2100 | |
| 2101 | base::DeleteFileX(fileToLoad); |
| 2102 | |
| 2103 | if (m_needTeardown) |
| 2104 | return; |
| 2105 | |
| 2106 | if (kmlData && (!kmlData->m_tracksData.empty() || !kmlData->m_bookmarksData.empty())) |
| 2107 | { |
| 2108 | // Set last modified date for imported tracks before saving them, if it wasn't set in KML/GPX file. |
| 2109 | if (kmlData->m_categoryData.m_lastModified == kml::Timestamp{}) |
| 2110 | kmlData->m_categoryData.m_lastModified = FileModificationTimestamp(filePath); |
| 2111 | |
| 2112 | auto kmlFileToLoad = GenerateValidAndUniqueFilePathForKML(base::GetNameFromFullPathWithoutExt(fileToLoad)); |
| 2113 | |
| 2114 | if (!SaveKmlFileSafe(*kmlData, kmlFileToLoad, KmlFileType::Text)) |
| 2115 | base::DeleteFileX(kmlFileToLoad); |
| 2116 | else |
| 2117 | collection->emplace_back(std::move(kmlFileToLoad), std::move(kmlData)); |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | if (m_needTeardown) |
| 2122 | return; |
| 2123 | |
| 2124 | NotifyAboutFile(!collection->empty() /* success */, filePath, isTemporaryFile); |
| 2125 | NotifyAboutFinishAsyncLoading(std::move(collection)); |
| 2126 | }); |
| 2127 | } |
| 2128 | |
| 2129 | void BookmarkManager::ReloadBookmarkRoutine(std::string const & filePath) |
| 2130 | { |
nothing calls this directly
no test coverage detected