2020-08-02 16:03:30 +02:00
|
|
|
#include "persistent_settings.h"
|
|
|
|
|
|
2020-12-22 09:42:57 +01:00
|
|
|
#include "util/logs.hpp"
|
2021-04-21 22:12:21 +02:00
|
|
|
#include "Emu/system_utils.hpp"
|
2020-12-22 09:42:57 +01:00
|
|
|
|
2020-08-02 16:03:30 +02:00
|
|
|
LOG_CHANNEL(cfg_log, "CFG");
|
2020-01-12 22:17:01 +01:00
|
|
|
|
|
|
|
|
persistent_settings::persistent_settings(QObject* parent) : settings(parent)
|
|
|
|
|
{
|
|
|
|
|
// Don't use the .ini file ending for now, as it will be confused for a regular gui_settings file.
|
2020-03-07 20:58:48 +01:00
|
|
|
m_settings.reset(new QSettings(ComputeSettingsDir() + gui::persistent::persistent_file_name + ".dat", QSettings::Format::IniFormat, parent));
|
2020-01-12 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-22 22:51:22 +02:00
|
|
|
void persistent_settings::SetPlaytime(const QString& serial, quint64 playtime)
|
2020-01-12 22:17:01 +01:00
|
|
|
{
|
2020-09-22 22:51:22 +02:00
|
|
|
m_playtime[serial] = playtime;
|
|
|
|
|
SetValue(gui::persistent::playtime, serial, playtime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void persistent_settings::AddPlaytime(const QString& serial, quint64 elapsed)
|
|
|
|
|
{
|
|
|
|
|
const quint64 playtime = GetValue(gui::persistent::playtime, serial, 0).toULongLong();
|
|
|
|
|
SetPlaytime(serial, playtime + elapsed);
|
2020-01-12 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-21 20:54:14 +02:00
|
|
|
quint64 persistent_settings::GetPlaytime(const QString& serial)
|
2020-01-12 22:17:01 +01:00
|
|
|
{
|
2020-09-21 20:54:14 +02:00
|
|
|
return m_playtime[serial];
|
2020-01-12 22:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void persistent_settings::SetLastPlayed(const QString& serial, const QString& date)
|
|
|
|
|
{
|
|
|
|
|
m_last_played[serial] = date;
|
|
|
|
|
SetValue(gui::persistent::last_played, serial, date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString persistent_settings::GetLastPlayed(const QString& serial)
|
|
|
|
|
{
|
|
|
|
|
return m_last_played[serial];
|
|
|
|
|
}
|
2020-08-02 16:03:30 +02:00
|
|
|
|
|
|
|
|
QString persistent_settings::GetCurrentUser(const QString& fallback) const
|
|
|
|
|
{
|
|
|
|
|
// Load user
|
|
|
|
|
QString user = GetValue(gui::persistent::active_user).toString();
|
|
|
|
|
if (user.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
user = fallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set user if valid
|
2021-04-21 22:12:21 +02:00
|
|
|
if (rpcs3::utils::check_user(user.toStdString()) > 0)
|
2020-08-02 16:03:30 +02:00
|
|
|
{
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 03:45:37 +02:00
|
|
|
cfg_log.fatal("Could not parse user setting: '%s'.", user);
|
2020-08-02 16:03:30 +02:00
|
|
|
return QString();
|
|
|
|
|
}
|