SaveState/DolphinWX: Display time and date of savestate when a slot is selected, or Empty if no savestate exists in the slot.

This commit is contained in:
Admiral H. Curtiss 2015-07-12 01:49:12 +02:00
parent df20326d45
commit 16272f4975
5 changed files with 38 additions and 3 deletions

View File

@ -225,7 +225,6 @@ std::string Timer::GetTimeFormatted()
}
// Returns a timestamp with decimals for precise time comparisons
// ----------------
double Timer::GetDoubleTime()
{
#ifdef _WIN32
@ -245,7 +244,7 @@ double Timer::GetDoubleTime()
// sure that we are detecting actual actions, perhaps 60 seconds is
// enough really, but I leave a year of seconds anyway, in case the
// user's clock is incorrect or something like that.
TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60);
TmpSeconds = TmpSeconds - DOUBLE_TIME_OFFSET;
// Make a smaller integer that fits in the double
u32 Seconds = (u32)TmpSeconds;
@ -261,4 +260,16 @@ double Timer::GetDoubleTime()
return TmpTime;
}
// Formats a timestamp from GetDoubleTime() into a date and time string
std::string Timer::GetDateTimeFormatted(double time)
{
// revert adjustments from GetDoubleTime() to get a normal Unix timestamp again
time_t seconds = (time_t)time + DOUBLE_TIME_OFFSET;
tm* localTime = localtime(&seconds);
char tmp[32] = {};
strftime(tmp, sizeof(tmp), "%x %X", localTime);
return tmp;
}
} // Namespace Common

View File

@ -26,15 +26,22 @@ public:
static void RestoreResolution();
static u64 GetTimeSinceJan1970();
static u64 GetLocalTimeSinceJan1970();
// Returns a timestamp with decimals for precise time comparisons
static double GetDoubleTime();
static std::string GetTimeFormatted();
// Formats a timestamp from GetDoubleTime() into a date and time string
static std::string GetDateTimeFormatted(double time);
std::string GetTimeElapsedFormatted() const;
u64 GetTimeElapsed();
static u32 GetTimeMs();
static u64 GetTimeUs();
// Arbitrarily chosen value (38 years) that is subtracted in GetDoubleTime()
// to increase sub-second precision of the resulting double timestamp
static const int DOUBLE_TIME_OFFSET = (38 * 365 * 24 * 60 * 60);
private:
u64 m_LastTime;
u64 m_StartTime;

View File

@ -435,6 +435,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();

View File

@ -33,6 +33,10 @@ void EnableCompression(bool compression);
bool ReadHeader(const std::string& filename, StateHeader& header);
// Returns a string containing information of the savestate in the given slot
// which can be presented to the user for identification purposes
std::string GetInfoStringOfSlot(int slot);
// These don't happen instantly - they get scheduled as events.
// ...But only if we're not in the main CPU thread.
// If we're in the main CPU thread then they run immediately instead

View File

@ -1680,7 +1680,7 @@ void CFrame::OnFrameSkip(wxCommandEvent& event)
void CFrame::OnSelectSlot(wxCommandEvent& event)
{
g_saveSlot = event.GetId() - IDM_SELECT_SLOT_1 + 1;
Core::DisplayMessage(StringFromFormat("Selected slot %d", g_saveSlot), 1000);
Core::DisplayMessage(StringFromFormat("Selected slot %d - %s", g_saveSlot, State::GetInfoStringOfSlot(g_saveSlot).c_str()), 2500);
}
void CFrame::OnLoadCurrentSlot(wxCommandEvent& event)