| 293 | //============================================================================= |
| 294 | |
| 295 | unsigned FSavegameManagerBase::ExtractSaveData(int index) |
| 296 | { |
| 297 | std::unique_ptr<FResourceFile> resf; |
| 298 | FSaveGameNode *node; |
| 299 | |
| 300 | if (index == -1) |
| 301 | { |
| 302 | if (SaveGames.Size() > 0 && SaveGames[0]->bNoDelete) |
| 303 | { |
| 304 | index = LastSaved + 1; |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | index = LastAccessed < 0? 0 : LastAccessed; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | UnloadSaveData(); |
| 313 | |
| 314 | if ((unsigned)index < SaveGames.Size() && |
| 315 | (node = SaveGames[index]) && |
| 316 | !node->Filename.IsEmpty() && |
| 317 | !node->bOldVersion && |
| 318 | ( (resf.reset(FResourceFile::OpenResourceFile(node->Filename.GetChars(), true))), resf != nullptr)) |
| 319 | { |
| 320 | auto info = resf->FindEntry("info.json"); |
| 321 | if (info < 0) |
| 322 | { |
| 323 | // this should not happen because the file has already been verified. |
| 324 | return index; |
| 325 | } |
| 326 | |
| 327 | auto data = resf->Read(info); |
| 328 | FSerializer arc; |
| 329 | if (!arc.OpenReader(data.string(), data.size())) |
| 330 | { |
| 331 | return index; |
| 332 | } |
| 333 | |
| 334 | SaveCommentString = ExtractSaveComment(arc); |
| 335 | |
| 336 | auto pic = resf->FindEntry("savepic.png"); |
| 337 | if (pic >= 0) |
| 338 | { |
| 339 | // This must use READER_CACHED or it will lock the savegame file. |
| 340 | FileReader picreader = resf->GetEntryReader(pic, FileSys::READER_CACHED, FileSys::READERFLAG_SEEKABLE); |
| 341 | PNGHandle *png = M_VerifyPNG(picreader); |
| 342 | if (png != nullptr) |
| 343 | { |
| 344 | SavePic = PNGTexture_CreateFromFile(png, node->Filename); |
| 345 | delete png; |
| 346 | if (SavePic && SavePic->GetDisplayWidth() == 1 && SavePic->GetDisplayHeight() == 1) |
| 347 | { |
| 348 | delete SavePic; |
| 349 | SavePic = nullptr; |
| 350 | } |
| 351 | } |
| 352 | } |
no test coverage detected