Merge pull request #2742 from AdmiralCurtiss/display-savestate-stats

Display Savestate information in Overlay and Menu.
This commit is contained in:
Scott Mansell
2015-11-08 02:20:56 +13:00
5 changed files with 65 additions and 16 deletions

View File

@ -17,6 +17,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/Host.h"
#include "Core/Movie.h"
#include "Core/State.h"
#include "Core/HW/CPU.h"
@ -118,7 +119,8 @@ void EnableCompression(bool compression)
g_use_compression = compression;
}
static std::string DoState(PointerWrap& p)
// Returns true if state version matches current Dolphin state version, false otherwise.
static bool DoStateVersion(PointerWrap& p, std::string* version_created_by)
{
u32 version = STATE_VERSION;
{
@ -128,15 +130,15 @@ static std::string DoState(PointerWrap& p)
version = cookie - COOKIE_BASE;
}
std::string version_created_by = scm_rev_str;
*version_created_by = scm_rev_str;
if (version > 42)
p.Do(version_created_by);
p.Do(*version_created_by);
else
version_created_by.clear();
version_created_by->clear();
if (version != STATE_VERSION)
{
if (version_created_by.empty() && s_old_versions.count(version))
if (version_created_by->empty() && s_old_versions.count(version))
{
// The savestate is from an old version that doesn't
// save the Dolphin version number to savestates, but
@ -147,9 +149,21 @@ static std::string DoState(PointerWrap& p)
std::string oldest_version = version_range.first;
std::string newest_version = version_range.second;
version_created_by = "Dolphin " + oldest_version + " - " + newest_version;
*version_created_by = "Dolphin " + oldest_version + " - " + newest_version;
}
return false;
}
p.DoMarker("Version");
return true;
}
static std::string DoState(PointerWrap& p)
{
std::string version_created_by;
if (!DoStateVersion(p, &version_created_by))
{
// because the version doesn't match, fail.
// this will trigger an OSD message like "Can't load state from other revisions"
// we could use the version numbers to maintain some level of backward compatibility, but currently don't.
@ -157,8 +171,6 @@ static std::string DoState(PointerWrap& p)
return version_created_by;
}
p.DoMarker("Version");
// Begin with video backend, so that it gets a chance to clear its caches and writeback modified things to RAM
g_video_backend->DoState(p);
p.DoMarker("video_backend");
@ -373,6 +385,7 @@ static void CompressAndDumpState(CompressAndDumpState_args save_args)
}
Core::DisplayMessage(StringFromFormat("Saved State to %s", filename.c_str()), 2000);
Host_UpdateMainFrame();
}
void SaveAs(const std::string& filename, bool wait)
@ -435,6 +448,19 @@ bool ReadHeader(const std::string& filename, StateHeader& header)
return true;
}
std::string GetInfoStringOfSlot(int slot)
{
std::string filename = MakeStateFilename(slot);
if (!File::Exists(filename))
return "Empty";
State::StateHeader header;
if (!ReadHeader(filename, header))
return "Unknown";
return Common::Timer::GetDateTimeFormatted(header.time);
}
static void LoadFileStateData(const std::string& filename, std::vector<u8>& ret_data)
{
Flush();