| 273 | } |
| 274 | |
| 275 | void CUpdater::ParseUpdate() |
| 276 | { |
| 277 | char aPath[IO_MAX_PATH_LENGTH]; |
| 278 | void *pBuf; |
| 279 | unsigned Length; |
| 280 | if(!m_pStorage->ReadFile(m_pStorage->GetBinaryPath("update/update.json", aPath, sizeof(aPath)), IStorage::TYPE_ABSOLUTE, &pBuf, &Length)) |
| 281 | return; |
| 282 | |
| 283 | json_value *pVersions = json_parse((json_char *)pBuf, Length); |
| 284 | free(pBuf); |
| 285 | |
| 286 | if(!pVersions || pVersions->type != json_array) |
| 287 | { |
| 288 | if(pVersions) |
| 289 | json_value_free(pVersions); |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | // if we're already downloading a file, or it's been deleted in the latest version, we skip it if it comes up again |
| 294 | std::unordered_set<std::string> SkipSet; |
| 295 | |
| 296 | for(int i = 0; i < json_array_length(pVersions); i++) |
| 297 | { |
| 298 | const json_value *pCurrent = json_array_get(pVersions, i); |
| 299 | if(!pCurrent || pCurrent->type != json_object) |
| 300 | continue; |
| 301 | |
| 302 | const char *pVersion = json_string_get(json_object_get(pCurrent, "version")); |
| 303 | if(!pVersion) |
| 304 | continue; |
| 305 | |
| 306 | if(str_comp(pVersion, GAME_RELEASE_VERSION) == 0) |
| 307 | break; |
| 308 | |
| 309 | if(json_boolean_get(json_object_get(pCurrent, "client"))) |
| 310 | m_ClientUpdate = true; |
| 311 | if(json_boolean_get(json_object_get(pCurrent, "server"))) |
| 312 | m_ServerUpdate = true; |
| 313 | |
| 314 | const json_value *pDownload = json_object_get(pCurrent, "download"); |
| 315 | if(pDownload && pDownload->type == json_array) |
| 316 | { |
| 317 | for(int j = 0; j < json_array_length(pDownload); j++) |
| 318 | { |
| 319 | const char *pName = json_string_get(json_array_get(pDownload, j)); |
| 320 | if(!pName) |
| 321 | continue; |
| 322 | |
| 323 | if(SkipSet.insert(pName).second) |
| 324 | { |
| 325 | AddFileJob(pName, true); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | const json_value *pRemove = json_object_get(pCurrent, "remove"); |
| 331 | if(pRemove && pRemove->type == json_array) |
| 332 | { |
nothing calls this directly
no test coverage detected