MCPcopy Create free account
hub / github.com/ZDoom/Raze / ExtractSaveData

Method ExtractSaveData

source/common/menu/savegamemanager.cpp:295–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293//=============================================================================
294
295unsigned 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 }

Callers 1

DEFINE_ACTION_FUNCTIONFunction · 0.80

Calls 14

M_VerifyPNGFunction · 0.85
OpenReaderMethod · 0.80
stringMethod · 0.80
GetDisplayWidthMethod · 0.80
GetDisplayHeightMethod · 0.80
SizeMethod · 0.45
IsEmptyMethod · 0.45
resetMethod · 0.45
GetCharsMethod · 0.45
FindEntryMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected