From 2c7d07b24584b4dcd25973cc14f143abc392b632 Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Thu, 12 Jun 2025 02:22:52 -0400 Subject: [PATCH] Qt: Implement reset play time for disc sets --- src/core/game_list.cpp | 36 +++++++++++++++++++++++++++++++ src/core/game_list.h | 9 +++++--- src/duckstation-qt/mainwindow.cpp | 25 +++++++++------------ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index 0e60711ff..3465160e4 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1487,6 +1487,42 @@ void GameList::ClearPlayedTimeForSerial(const std::string& serial) } } +void GameList::ClearPlayedTimeForEntry(const GameList::Entry* entry) +{ + std::unique_lock lock(s_mutex); + std::vector serials; + + if (entry->IsDiscSet()) + { + for (const GameList::Entry* member : GetDiscSetMembers(entry->path)) + { + if (!member->serial.empty()) + serials.push_back(member->serial); + } + } + else + { + if (!entry->serial.empty()) + serials.push_back(entry->serial); + } + + auto played_time_file = GetPlayedTimeFile(); + for (const auto& serial : serials) + { + VERBOSE_LOG("Resetting played time for {}", serial); + UpdatePlayedTimeFile(played_time_file, serial, 0, 0); + } + + for (GameList::Entry& list_entry : s_entries) + { + if (std::find(serials.begin(), serials.end(), list_entry.serial) == serials.end()) + continue; + + list_entry.last_played_time = 0; + list_entry.total_played_time = 0; + } +} + std::time_t GameList::GetCachedPlayedTimeForSerial(const std::string& serial) { if (serial.empty()) diff --git a/src/core/game_list.h b/src/core/game_list.h index 22d570626..a2c87a555 100644 --- a/src/core/game_list.h +++ b/src/core/game_list.h @@ -18,8 +18,6 @@ class ProgressCallback; -struct SystemBootParameters; - namespace GameList { enum class EntryType : u8 { @@ -116,8 +114,13 @@ EntryList TakeEntryList(); /// Add played time for the specified serial. void AddPlayedTimeForSerial(const std::string& serial, std::time_t last_time, std::time_t add_time); + +/// Resets played time for the specified serial to zero. void ClearPlayedTimeForSerial(const std::string& serial); +/// Resets played time for the specified entry to zero. +void ClearPlayedTimeForEntry(const Entry* entry); + /// Returns the total time played for a game. Requires the game to be scanned in the list. std::time_t GetCachedPlayedTimeForSerial(const std::string& serial); @@ -160,7 +163,7 @@ void UpdateAchievementData(const std::span hash, u32 game_id, u32 num_ac u32 num_unlocked_hardcore); void UpdateAllAchievementData(); -}; // namespace GameList +} // namespace GameList namespace Host { /// Asynchronously starts refreshing the game list. diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 381519a8e..67644f812 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -1047,7 +1047,7 @@ void MainWindow::onCheatsMenuAboutToShow() const GameList::Entry* MainWindow::resolveDiscSetEntry(const GameList::Entry* entry, std::unique_lock& lock) { - if (!entry || entry->type != GameList::EntryType::DiscSet) + if (!entry || !entry->IsDiscSet()) return entry; // disc set... need to figure out the disc we want @@ -1523,14 +1523,6 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point) switchToEmulationView(); }); } - - menu.addSeparator(); - - connect(menu.addAction(tr("Exclude From List")), &QAction::triggered, - [this, entry]() { getSettingsWindow()->getGameListSettingsWidget()->addExcludedPath(entry->path); }); - - connect(menu.addAction(tr("Reset Play Time")), &QAction::triggered, - [this, entry]() { clearGameListEntryPlayTime(entry); }); } else { @@ -1555,12 +1547,15 @@ void MainWindow::onGameListEntryContextMenuRequested(const QPoint& point) menu.addSeparator(); connect(menu.addAction(tr("Select Disc")), &QAction::triggered, this, &MainWindow::onGameListEntryActivated); - - menu.addSeparator(); - - connect(menu.addAction(tr("Exclude From List")), &QAction::triggered, - [this, entry]() { getSettingsWindow()->getGameListSettingsWidget()->addExcludedPath(entry->path); }); } + + menu.addSeparator(); + + connect(menu.addAction(tr("Exclude From List")), &QAction::triggered, + [this, entry]() { getSettingsWindow()->getGameListSettingsWidget()->addExcludedPath(entry->path); }); + + connect(menu.addAction(tr("Reset Play Time")), &QAction::triggered, + [this, entry]() { clearGameListEntryPlayTime(entry); }); } menu.addSeparator(); @@ -1628,7 +1623,7 @@ void MainWindow::clearGameListEntryPlayTime(const GameList::Entry* entry) return; } - GameList::ClearPlayedTimeForSerial(entry->serial); + GameList::ClearPlayedTimeForEntry(entry); m_game_list_widget->refresh(false); }