ensured totalTimePlayed is allways greater than 0

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-10-15 16:03:14 +03:00
parent 2ab48a43dd
commit b075711be0
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -278,6 +278,8 @@ void BaseInstance::setRunning(bool running)
QDateTime timeEnded = QDateTime::currentDateTime();
qint64 current = settings()->get("totalTimePlayed").toLongLong();
if (current < 0)
current = 0;
settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
settings()->set("lastTimePlayed", m_timeStarted.secsTo(timeEnded));
@ -290,6 +292,8 @@ void BaseInstance::setRunning(bool running)
int64_t BaseInstance::totalTimePlayed() const
{
qint64 current = m_settings->get("totalTimePlayed").toLongLong();
if (current < 0)
current = 0;
if (m_isRunning) {
QDateTime timeNow = QDateTime::currentDateTime();
return current + m_timeStarted.secsTo(timeNow);