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
This commit is contained in:
Kody Schram authored and GitHub committed 2026-08-05 07:37:10 +03:00
1 parent e06e4ab0fd
commit cdf2dbed6c
1 file changed
+6 -3
+6 -3
View File
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2025-2026 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <ctime>
#include <filesystem>
#include <fstream>
#include <iostream>
@@ -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