From cdf2dbed6c2fd4136371b7b4e51c96ec851016c2 Mon Sep 17 00:00:00 2001 From: Kody Schram <79764769+Kody-Schram@users.noreply.github.com> Date: Tue, 4 Aug 2026 21:37:10 -0700 Subject: [PATCH] Appends last time played for each game in play_time.txt (#4801) * UpdatePlayTime now also appends unix epoch after playtime in play_time.txt * Added explicit include of ctime, cleaned variable initialization * Fix clang formatting --- src/emulator.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index d90c2381b..1b5bd8c34 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include #include @@ -850,13 +851,15 @@ void Emulator::UpdatePlayTime(const std::string& serial) { std::string playTimeSaved = fmt::format("{:d}:{:02d}:{:02d}", hours, minutes, seconds); + const std::time_t last_time_played = std::time(nullptr); + std::ofstream outfile(filePath, std::ios::trunc); bool lineUpdated = false; for (const auto& l : lines) { std::istringstream iss(l); std::string s; if (iss >> s && s == serial) { - outfile << fmt::format("{} {}\n", serial, playTimeSaved); + outfile << fmt::format("{} {} {}\n", serial, playTimeSaved, last_time_played); lineUpdated = true; } else { outfile << l << "\n"; @@ -864,10 +867,10 @@ void Emulator::UpdatePlayTime(const std::string& serial) { } if (!lineUpdated) { - outfile << fmt::format("{} {}\n", serial, playTimeSaved); + outfile << fmt::format("{} {} {}\n", serial, playTimeSaved, last_time_played); } - LOG_INFO(Loader, "Playing time for {}: {}", serial, playTimeSaved); + LOG_INFO(Loader, "Playing time for {}: {} {}", serial, playTimeSaved, last_time_played); } } // namespace Core