blob: 872bfa86114a928a87e16cb2e8f230fedfc7073e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*
* Copyright (C) 2017-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "RetroPlayerAutoSave.h"
#include "URL.h"
#include "games/GameSettings.h"
#include "utils/log.h"
using namespace KODI;
using namespace RETRO;
using namespace std::chrono_literals;
namespace
{
constexpr auto AUTOSAVE_DURATION_SECS = 10s; // Auto-save every 10 seconds
}
CRetroPlayerAutoSave::CRetroPlayerAutoSave(IAutoSaveCallback& callback,
GAME::CGameSettings& settings)
: CThread("CRetroPlayerAutoSave"), m_callback(callback), m_settings(settings)
{
CLog::Log(LOGDEBUG, "RetroPlayer[SAVE]: Initializing autosave");
Create(false);
}
CRetroPlayerAutoSave::~CRetroPlayerAutoSave()
{
CLog::Log(LOGDEBUG, "RetroPlayer[SAVE]: Deinitializing autosave");
StopThread();
}
void CRetroPlayerAutoSave::Process()
{
CLog::Log(LOGDEBUG, "RetroPlayer[SAVE]: Autosave thread started");
while (!m_bStop)
{
CThread::Sleep(AUTOSAVE_DURATION_SECS);
if (m_bStop)
break;
if (!m_settings.AutosaveEnabled())
continue;
if (m_callback.IsAutoSaveEnabled())
{
std::string savePath = m_callback.CreateAutosave();
if (!savePath.empty())
CLog::Log(LOGDEBUG, "RetroPlayer[SAVE]: Saved state to {}", CURL::GetRedacted(savePath));
}
}
CLog::Log(LOGDEBUG, "RetroPlayer[SAVE]: Autosave thread ended");
}
|