mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-26 15:53:36 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
76
editor/editor_storage.cpp
Normal file
76
editor/editor_storage.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "editor/editor_storage.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "coding/internal/file_data.hpp"
|
||||
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace pugi;
|
||||
|
||||
namespace
|
||||
{
|
||||
char const * kEditorXMLFileName = "edits.xml";
|
||||
|
||||
std::string GetEditorFilePath() { return GetPlatform().WritablePathForFile(kEditorXMLFileName); }
|
||||
} // namespace
|
||||
|
||||
namespace editor
|
||||
{
|
||||
// StorageLocal ------------------------------------------------------------------------------------
|
||||
bool LocalStorage::Save(xml_document const & doc)
|
||||
{
|
||||
auto const editorFilePath = GetEditorFilePath();
|
||||
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
|
||||
return base::WriteToTempAndRenameToFile(editorFilePath, [&doc](std::string const & fileName) {
|
||||
return doc.save_file(fileName.data(), " " /* indent */);
|
||||
});
|
||||
}
|
||||
|
||||
bool LocalStorage::Load(xml_document & doc)
|
||||
{
|
||||
auto const editorFilePath = GetEditorFilePath();
|
||||
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
|
||||
auto const result = doc.load_file(editorFilePath.c_str());
|
||||
// Note: status_file_not_found is ok if a user has never made any edits.
|
||||
if (result != status_ok && result != status_file_not_found)
|
||||
{
|
||||
LOG(LERROR, ("Can't load map edits from disk:", editorFilePath));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocalStorage::Reset()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
|
||||
return base::DeleteFileX(GetEditorFilePath());
|
||||
}
|
||||
|
||||
// StorageMemory -----------------------------------------------------------------------------------
|
||||
bool InMemoryStorage::Save(xml_document const & doc)
|
||||
{
|
||||
m_doc.reset(doc);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InMemoryStorage::Load(xml_document & doc)
|
||||
{
|
||||
doc.reset(m_doc);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InMemoryStorage::Reset()
|
||||
{
|
||||
m_doc.reset();
|
||||
return true;
|
||||
}
|
||||
} // namespace editor
|
||||
Reference in New Issue
Block a user