diff options
author | Mario <mariodavo.20@gmail.com> | 2023-08-27 03:19:00 +0200 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2023-08-27 04:20:19 +0200 |
commit | 5464423667dedc0f09d48f85fc7871a3e56127a4 (patch) | |
tree | a981bb0c3f41050a476e791f4440bc4eae9e1ebf /src/yuzu/play_time.h | |
parent | Merge pull request #11356 from lat9nq/console-mode-pg (diff) | |
download | yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.tar yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.tar.gz yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.tar.bz2 yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.tar.lz yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.tar.xz yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.tar.zst yuzu-5464423667dedc0f09d48f85fc7871a3e56127a4.zip |
Diffstat (limited to 'src/yuzu/play_time.h')
-rw-r--r-- | src/yuzu/play_time.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/yuzu/play_time.h b/src/yuzu/play_time.h new file mode 100644 index 000000000..68e40955c --- /dev/null +++ b/src/yuzu/play_time.h @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <QString> + +#include <atomic> +#include <condition_variable> +#include <mutex> +#include <optional> +#include <thread> + +#include "common/common_types.h" +#include "common/fs/fs.h" +#include "common/polyfill_thread.h" +#include "core/core.h" + +namespace PlayTime { +struct PlayTimeElement { + u64 program_id; + u64 play_time; + + inline bool operator==(const PlayTimeElement& other) const { + return program_id == other.program_id; + } + + inline bool operator==(const u64 _program_id) const { + return program_id == _program_id; + } +}; + +class PlayTimeManager { +public: + explicit PlayTimeManager() = default; + ~PlayTimeManager() = default; + +public: + YUZU_NON_COPYABLE(PlayTimeManager); + YUZU_NON_MOVEABLE(PlayTimeManager); + +public: + bool ResetProgramPlayTime(u64 program_id); + void SetProgramId(u64 program_id); + inline void UpdateTimestamp(); + void Start(); + void Stop(); + +private: + u64 running_program_id; + std::chrono::steady_clock::time_point last_timestamp; + std::jthread play_time_thread; + void AutoTimestamp(std::stop_token stop_token); + void Save(); +}; + +std::optional<std::filesystem::path> GetCurrentUserPlayTimePath(); + +bool UpdatePlayTime(u64 program_id, u64 add_play_time); + +[[nodiscard]] bool ReadPlayTimeFile(std::vector<PlayTimeElement>& out_play_time_elements); +[[nodiscard]] bool WritePlayTimeFile(const std::vector<PlayTimeElement>& play_time_elements); + +u64 GetPlayTime(u64 program_id); + +QString ReadablePlayTime(qulonglong time_seconds); + +} // namespace PlayTime |