Not thread-safe, use only for initialization.
| 72 | |
| 73 | /// Not thread-safe, use only for initialization. |
| 74 | bool Load(std::string const & fileName, std::list<editor::Note> & notes, uint32_t & uploadedNotesCount) |
| 75 | { |
| 76 | std::string content; |
| 77 | try |
| 78 | { |
| 79 | auto const reader = GetPlatform().GetReader(fileName); |
| 80 | reader->ReadAsString(content); |
| 81 | } |
| 82 | catch (FileAbsentException const &) |
| 83 | { |
| 84 | // It's normal if no notes file is present. |
| 85 | return true; |
| 86 | } |
| 87 | catch (Reader::Exception const & e) |
| 88 | { |
| 89 | LOG(LERROR, ("Can't process file.", fileName, e.Msg())); |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | pugi::xml_document xml; |
| 94 | if (!xml.load_buffer(content.data(), content.size())) |
| 95 | { |
| 96 | LOG(LERROR, ("Can't load notes, XML is ill-formed.", content)); |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | notes.clear(); |
| 101 | if (!LoadFromXml(xml, notes, uploadedNotesCount)) |
| 102 | { |
| 103 | LOG(LERROR, ("Can't load notes, file is ill-formed.", content)); |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | /// Not thread-safe, use synchronization. |
| 111 | bool Save(std::string const & fileName, std::list<editor::Note> const & notes, uint32_t const uploadedNotesCount) |