2025-02-10 15:28:57 -05:00
|
|
|
// Copyright 2025 Dolphin Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#include "Core/TimePlayed.h"
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
|
#include "Common/IniFile.h"
|
|
|
|
|
#include "Common/NandPaths.h"
|
|
|
|
|
|
2025-04-12 15:15:18 +02:00
|
|
|
TimePlayed::TimePlayed() : m_ini_path(File::GetUserPath(D_CONFIG_IDX) + "TimePlayed.ini")
|
2025-02-10 15:28:57 -05:00
|
|
|
{
|
|
|
|
|
Reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimePlayed::~TimePlayed() = default;
|
|
|
|
|
|
2025-04-12 15:15:18 +02:00
|
|
|
void TimePlayed::AddTime(const std::string& game_id, std::chrono::milliseconds time_emulated)
|
2025-02-10 15:28:57 -05:00
|
|
|
{
|
2025-04-12 15:15:18 +02:00
|
|
|
std::string filtered_game_id = Common::EscapeFileName(game_id);
|
2025-02-10 15:28:57 -05:00
|
|
|
u64 previous_time;
|
2025-04-12 15:15:18 +02:00
|
|
|
m_time_list->Get(filtered_game_id, &previous_time);
|
|
|
|
|
m_time_list->Set(filtered_game_id, previous_time + static_cast<u64>(time_emulated.count()));
|
2025-02-10 15:28:57 -05:00
|
|
|
m_ini.Save(m_ini_path);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-12 15:15:18 +02:00
|
|
|
std::chrono::milliseconds TimePlayed::GetTimePlayed(const std::string& game_id) const
|
2025-02-10 15:28:57 -05:00
|
|
|
{
|
|
|
|
|
std::string filtered_game_id = Common::EscapeFileName(game_id);
|
|
|
|
|
u64 previous_time;
|
|
|
|
|
m_time_list->Get(filtered_game_id, &previous_time);
|
|
|
|
|
return std::chrono::milliseconds(previous_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimePlayed::Reload()
|
|
|
|
|
{
|
|
|
|
|
m_ini.Load(m_ini_path);
|
|
|
|
|
m_time_list = m_ini.GetOrCreateSection("TimePlayed");
|
|
|
|
|
}
|