Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: show time of day in 'last played' game info, log current time when RPCS3 boots #11220

Merged
merged 9 commits into from Feb 23, 2022
Merged
26 changes: 21 additions & 5 deletions rpcs3/main.cpp
Expand Up @@ -2,6 +2,9 @@
// by Sacha Refshauge, Megamouse and flash-fire

#include <iostream>
#include <chrono>
#include <sstream>
#include <iomanip>

#include <QApplication>
#include <QCommandLineParser>
Expand Down Expand Up @@ -362,6 +365,16 @@ void log_q_debug(QtMsgType type, const QMessageLogContext& context, const QStrin
}
}

template <>
void fmt_class_string<std::chrono::sys_time<typename std::chrono::system_clock::duration>>::format(std::string& out, u64 arg)
{
std::ostringstream ss;
const std::time_t dateTime = std::chrono::system_clock::to_time_t(get_object(arg));
const std::tm tm = *std::localtime(&dateTime);
ss << std::put_time(&tm, "%Y-%m-%eT%H:%M:%S");
out += ss.str();
}



int main(int argc, char** argv)
Expand Down Expand Up @@ -460,21 +473,24 @@ int main(int argc, char** argv)
{
// Write RPCS3 version
logs::stored_message ver{sys_log.always()};
ver.text = fmt::format("RPCS3 v%s | %s", rpcs3::get_version().to_string(), rpcs3::get_branch());
ver.text = fmt::format("RPCS3 v%s | %s", rpcs3::get_version().to_string(), rpcs3::get_branch());

// Write System information
logs::stored_message sys{sys_log.always()};
sys.text = utils::get_system_info();
sys.text = utils::get_system_info();

// Write OS version
logs::stored_message os{sys_log.always()};
os.text = utils::get_OS_version();
os.text = utils::get_OS_version();

// Write Qt version
logs::stored_message qt{(strcmp(QT_VERSION_STR, qVersion()) != 0) ? sys_log.error : sys_log.notice};
qt.text = fmt::format("Qt version: Compiled against Qt %s | Run-time uses Qt %s", QT_VERSION_STR, qVersion());
qt.text = fmt::format("Qt version: Compiled against Qt %s | Run-time uses Qt %s", QT_VERSION_STR, qVersion());

logs::stored_message time{sys_log.always()};
time.text = fmt::format("Current Time: %s", std::chrono::system_clock::now());

logs::set_init({std::move(ver), std::move(sys), std::move(os), std::move(qt)});
logs::set_init({std::move(ver), std::move(sys), std::move(os), std::move(qt), std::move(time)});
}

#ifdef _WIN32
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Expand Up @@ -2401,16 +2401,16 @@ void game_list_frame::PopulateGameList()
const quint64 elapsed_ms = m_persistent_settings->GetPlaytime(serial);

// Last played (support outdated values)
QDate last_played;
QDateTime last_played;
const QString last_played_str = GetLastPlayedBySerial(serial);

if (!last_played_str.isEmpty())
{
last_played = QDate::fromString(last_played_str, gui::persistent::last_played_date_format);
last_played = QDateTime::fromString(last_played_str, gui::persistent::last_played_date_format);

if (!last_played.isValid())
{
last_played = QDate::fromString(last_played_str, gui::persistent::last_played_date_format_old);
last_played = QDateTime::fromString(last_played_str, gui::persistent::last_played_date_format_old);
}
}

Expand All @@ -2425,7 +2425,7 @@ void game_list_frame::PopulateGameList()
m_game_list->setItem(row, gui::column_resolution, new custom_table_widget_item(GetStringFromU32(game->info.resolution, localized.resolution.mode, true)));
m_game_list->setItem(row, gui::column_sound, new custom_table_widget_item(GetStringFromU32(game->info.sound_format, localized.sound.format, true)));
m_game_list->setItem(row, gui::column_parental, new custom_table_widget_item(GetStringFromU32(game->info.parental_lvl, localized.parental.level), Qt::UserRole, game->info.parental_lvl));
m_game_list->setItem(row, gui::column_last_play, new custom_table_widget_item(locale.toString(last_played, gui::persistent::last_played_date_format_new), Qt::UserRole, last_played));
m_game_list->setItem(row, gui::column_last_play, new custom_table_widget_item(locale.toString(last_played, last_played >= QDateTime::currentDateTime().addDays(-7) ? gui::persistent::last_played_date_with_time_of_day_format : gui::persistent::last_played_date_format_new), Qt::UserRole, last_played));
m_game_list->setItem(row, gui::column_playtime, new custom_table_widget_item(elapsed_ms == 0 ? tr("Never played") : localized.GetVerboseTimeByMs(elapsed_ms), Qt::UserRole, elapsed_ms));
m_game_list->setItem(row, gui::column_compat, compat_item);

Expand Down
6 changes: 3 additions & 3 deletions rpcs3/rpcs3qt/gui_application.cpp
Expand Up @@ -449,7 +449,7 @@ void gui_application::StartPlaytime(bool start_playtime = true)
return;
}

m_persistent_settings->SetLastPlayed(serial, QDate::currentDate().toString(gui::persistent::last_played_date_format));
m_persistent_settings->SetLastPlayed(serial, QDateTime::currentDateTime().toString(gui::persistent::last_played_date_format));
m_timer_playtime.start();
m_timer.start(10000); // Update every 10 seconds in case the emulation crashes
}
Expand All @@ -471,7 +471,7 @@ void gui_application::UpdatePlaytime()
}

m_persistent_settings->AddPlaytime(serial, m_timer_playtime.restart());
m_persistent_settings->SetLastPlayed(serial, QDate::currentDate().toString(gui::persistent::last_played_date_format));
m_persistent_settings->SetLastPlayed(serial, QDateTime::currentDateTime().toString(gui::persistent::last_played_date_format));
}

void gui_application::StopPlaytime()
Expand All @@ -489,7 +489,7 @@ void gui_application::StopPlaytime()
}

m_persistent_settings->AddPlaytime(serial, m_timer_playtime.restart());
m_persistent_settings->SetLastPlayed(serial, QDate::currentDate().toString(gui::persistent::last_played_date_format));
m_persistent_settings->SetLastPlayed(serial, QDateTime::currentDateTime().toString(gui::persistent::last_played_date_format));
m_timer_playtime.invalidate();
}

Expand Down
7 changes: 4 additions & 3 deletions rpcs3/rpcs3qt/persistent_settings.h
Expand Up @@ -16,9 +16,10 @@ namespace gui
const QString titles = "Titles";

// Date format
const QString last_played_date_format_old = "MMMM d yyyy";
const QString last_played_date_format_new = "MMMM d, yyyy";
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;
const QString last_played_date_format_old = "MMMM d yyyy";
const QString last_played_date_format_new = "MMMM d, yyyy";
const QString last_played_date_with_time_of_day_format = "MMMM d, yyyy HH:mm";
const Qt::DateFormat last_played_date_format = Qt::DateFormat::ISODate;

// GUI Saves
const gui_save save_notes = gui_save(savedata, "notes", QVariantMap());
Expand Down