| 1362 | } |
| 1363 | |
| 1364 | int64_t Storage::ParseIndexAndGetDataVersion(std::string const & index) const |
| 1365 | { |
| 1366 | try |
| 1367 | { |
| 1368 | // [ {"start app version" : data version}, ... ] |
| 1369 | base::Json const json(index.c_str()); |
| 1370 | auto root = json.get(); |
| 1371 | |
| 1372 | if (root == nullptr || !json_is_array(root)) |
| 1373 | return 0; |
| 1374 | |
| 1375 | /// @todo Get correct value somehow .. |
| 1376 | int64_t const appVersion = 21042001; |
| 1377 | int64_t dataVersion = 0; |
| 1378 | |
| 1379 | size_t const count = json_array_size(root); |
| 1380 | for (size_t i = 0; i < count; ++i) |
| 1381 | { |
| 1382 | // Make safe parsing here to avoid download errors. |
| 1383 | auto const it = json_object_iter(json_array_get(root, i)); |
| 1384 | if (it) |
| 1385 | { |
| 1386 | auto const key = json_object_iter_key(it); |
| 1387 | auto const val = json_object_iter_value(it); |
| 1388 | |
| 1389 | int appVer; |
| 1390 | if (key && val && json_is_number(val) && strings::to_int(key, appVer)) |
| 1391 | { |
| 1392 | int64_t const dataVer = json_integer_value(val); |
| 1393 | if (appVersion >= appVer && dataVersion < dataVer) |
| 1394 | dataVersion = dataVer; |
| 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | return dataVersion; |
| 1400 | } |
| 1401 | catch (RootException const &) |
| 1402 | { |
| 1403 | return 0; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | void Storage::ApplyCountries(std::string const & countriesBuffer, Storage & storage) |
| 1408 | { |