diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index 451e6a0725..4ad69fdc23 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -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 diff --git a/Source/Core/Common/Timer.h b/Source/Core/Common/Timer.h index e5b828af25..cc6d6549c4 100644 --- a/Source/Core/Common/Timer.h +++ b/Source/Core/Common/Timer.h @@ -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; diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 129aaa15ea..4aaa63dff9 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -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& ret_data) { Flush(); diff --git a/Source/Core/Core/State.h b/Source/Core/Core/State.h index 342f761697..c16a22a299 100644 --- a/Source/Core/Core/State.h +++ b/Source/Core/Core/State.h @@ -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 diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index d79981b56a..a74ce4645f 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -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)