Skip to content

Commit

Permalink
Game Save|Refactor: Validate save states as loadable during save stat…
Browse files Browse the repository at this point in the history
…e list population
  • Loading branch information
danij-deng committed Jun 24, 2012
1 parent 3221071 commit e6f3ef5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
35 changes: 0 additions & 35 deletions doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -4548,37 +4548,6 @@ static void writeSaveHeader(const char* saveName, uint gameId)
SV_SaveInfo_Write(&hdr);
}

static boolean saveIsValidForCurrentGameSession(saveinfo_t* saveInfo)
{
if(saveInfo->header.magic != MY_SAVE_MAGIC)
{
Con_Message("Warning: SV_LoadGame: Bad magic.\n");
return false;
}

/**
* Check for unsupported versions.
*/
// A future version?
if(saveInfo->header.version > MY_SAVE_VERSION) return false;

#if __JHEXEN__
// We are incompatible with v3 saves due to an invalid test used to determine
// present sidedefs (ver3 format's sidedefs contain chunks of junk data).
if(saveInfo->header.version == 3) return false;
#endif

// Game Mode missmatch?
if(saveInfo->header.gameMode != gameMode)
{
Con_Message("Warning: SV_LoadGame: Game Mode missmatch (%i!=%i), aborting load.\n",
(int)gameMode, (int)saveInfo->header.gameMode);
return false;
}

return true; // Read was OK.
}

static boolean SV_LoadGame2(saveinfo_t* saveInfo)
{
int i;
Expand All @@ -4594,11 +4563,7 @@ static boolean SV_LoadGame2(saveinfo_t* saveInfo)
saveheader_t tmp;
SV_SaveInfo_Read(&tmp);
}

// Is this loadable?
hdr = &saveInfo->header;
if(!saveIsValidForCurrentGameSession(saveInfo))
return false;

/**
* We now assume that loading will succeed.
Expand Down
29 changes: 27 additions & 2 deletions doomsday/plugins/common/src/p_saveio.c
Expand Up @@ -69,6 +69,31 @@ static void initSaveInfo(saveinfo_t* info)
Str_Init(&info->name);
}

static boolean saveInfoIsValidForCurrentGameSession(saveinfo_t* info)
{
if(!info) return false;

// Magic must match.
if(info->header.magic != MY_SAVE_MAGIC) return false;

/**
* Check for unsupported versions.
*/
// A future version?
if(info->header.version > MY_SAVE_VERSION) return false;

#if __JHEXEN__
// We are incompatible with v3 saves due to an invalid test used to determine
// present sidedefs (ver3 format's sidedefs contain chunks of junk data).
if(info->header.version == 3) return false;
#endif

// Game Mode missmatch?
if(info->header.gameMode != gameMode) return false;

return true; // It's good!
}

static void updateSaveInfo(saveinfo_t* info, ddstring_t* savePath)
{
if(!info) return;
Expand All @@ -82,9 +107,9 @@ static void updateSaveInfo(saveinfo_t* info, ddstring_t* savePath)
return;
}

if(!readGameSaveHeader(info))
if(!readGameSaveHeader(info) || !saveInfoIsValidForCurrentGameSession(info))
{
// Not a valid save file.
// Not a loadable save.
Str_Clear(&info->filePath);
}
}
Expand Down

0 comments on commit e6f3ef5

Please sign in to comment.