| 146 | } |
| 147 | |
| 148 | void Editor::LoadEdits() |
| 149 | { |
| 150 | CHECK_THREAD_CHECKER(MainThreadChecker, ()); |
| 151 | if (!m_delegate) |
| 152 | { |
| 153 | LOG(LERROR, ("Can't load any map edits, delegate has not been set.")); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | LOG(LINFO, ("Loading OSM edits...")); |
| 158 | |
| 159 | xml_document doc; |
| 160 | bool needRewriteEdits = false; |
| 161 | |
| 162 | if (!m_storage->Load(doc)) |
| 163 | return; |
| 164 | |
| 165 | m_features.Set(make_shared<FeaturesContainer>()); |
| 166 | auto loadedFeatures = make_shared<FeaturesContainer>(); |
| 167 | |
| 168 | auto rootNode = doc.child(kXmlRootNode); |
| 169 | // TODO: Empty rootNode is an OK case for the current logic and unit tests. Check if there is a better way to do it. |
| 170 | for (auto const & mwm : rootNode.children(kXmlMwmNode)) |
| 171 | { |
| 172 | string const mapName = mwm.attribute("name").as_string(""); |
| 173 | int64_t const mapVersion = mwm.attribute("version").as_llong(0); |
| 174 | auto const mwmId = GetMwmIdByMapName(mapName); |
| 175 | |
| 176 | // TODO(mgsergio, milchakov): |mapName| may change between launches. |
| 177 | // The right thing to do here is to try to migrate all changes anyway. |
| 178 | if (!mwmId.IsAlive()) |
| 179 | { |
| 180 | LOG(LINFO, ("Mwm", mapName, "was deleted")); |
| 181 | needRewriteEdits = true; |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | auto const needMigrateEdits = mapVersion != mwmId.GetInfo()->GetVersion(); |
| 186 | needRewriteEdits = needRewriteEdits || needMigrateEdits; |
| 187 | |
| 188 | LoadMwmEdits(*loadedFeatures, mwm, mwmId, needMigrateEdits); |
| 189 | } |
| 190 | // Save edits with new indexes and mwm version to avoid another migration on next startup. |
| 191 | if (needRewriteEdits) |
| 192 | SaveTransaction(loadedFeatures); |
| 193 | else |
| 194 | m_features.Set(loadedFeatures); |
| 195 | } |
| 196 | |
| 197 | bool Editor::Save(FeaturesContainer const & features) const |
| 198 | { |