MCPcopy Create free account
hub / github.com/comaps/comaps / LoadBookmarkRoutine

Method LoadBookmarkRoutine

libs/map/bookmark_manager.cpp:2080–2127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2078}
2079
2080void 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
2129void BookmarkManager::ReloadBookmarkRoutine(std::string const & filePath)
2130{

Callers

nothing calls this directly

Calls 12

GetLowercaseFileExtFunction · 0.85
LoadKmlFileFunction · 0.85
ASSERTFunction · 0.85
DeleteFileXFunction · 0.85
SaveKmlFileSafeFunction · 0.85
RunTaskMethod · 0.80
emptyMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected