forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor_storage.cpp
76 lines (57 loc) · 1.71 KB
/
editor_storage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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