diff --git a/Application/include/nx/PlayData.hpp b/Application/include/nx/PlayData.hpp index c8edf47..b2102b6 100644 --- a/Application/include/nx/PlayData.hpp +++ b/Application/include/nx/PlayData.hpp @@ -24,12 +24,12 @@ namespace NX { // PlayEvents are parsed PdmPlayEvents containing only necessary information struct PlayEvent { - PlayEventType type; // Type of PlayEvent - AccountUid userID; // UserID - TitleID titleID; // TitleID - EventType eventType; // See EventType enum - u64 clockTimestamp; // Time of event - u64 steadyTimestamp; // Steady timestamp (used for calculating duration) + PlayEventType type; // Type of PlayEvent + AccountUid userID; // UserID + TitleID titleID; // TitleID + EventType eventType; // See EventType enum + u64 clockTimestamp; // Time of event + u64 steadyTimestamp; // Steady timestamp (used for calculating duration) }; // A PlaySession represents a session of play for a game. It contains the start diff --git a/Application/source/Application.ExportJob.cpp b/Application/source/Application.ExportJob.cpp index 2a932bf..a48371a 100644 --- a/Application/source/Application.ExportJob.cpp +++ b/Application/source/Application.ExportJob.cpp @@ -38,7 +38,6 @@ namespace Main { // Check if played, and if not move onto next NX::RecentPlayStatistics * stats = this->app->playdata_->getRecentStatisticsForTitleAndUser(title->titleID(), std::numeric_limits::min(), std::numeric_limits::max(), user->ID()); bool recentLaunched = (stats->launches != 0); - delete stats; // Add title metadata tJson["name"] = title->name(); @@ -94,8 +93,9 @@ namespace Main { bool allLaunched = (stats2->launches != 0); tJson["summary"]["firstPlayed"] = stats2->firstPlayed; tJson["summary"]["lastPlayed"] = stats2->lastPlayed; - tJson["summary"]["playtime"] = stats2->playtime; - tJson["summary"]["launches"] = stats2->launches; + tJson["summary"]["playtime"] = stats->playtime; + tJson["summary"]["launches"] = stats->launches; + delete stats; delete stats2; // Append title if played at least once diff --git a/Application/source/ui/screen/AdjustPlaytime.cpp b/Application/source/ui/screen/AdjustPlaytime.cpp index 3de85e9..d0f8f43 100644 --- a/Application/source/ui/screen/AdjustPlaytime.cpp +++ b/Application/source/ui/screen/AdjustPlaytime.cpp @@ -117,7 +117,8 @@ namespace Screen { } size_t idx = std::distance(this->adjustments.begin(), it); - NX::PlayStatistics * stats = this->app->playdata()->getStatisticsForUser(title->titleID(), this->app->activeUser()->ID()); + NX::RecentPlayStatistics * stats = this->app->playdata()->getRecentStatisticsForTitleAndUser(title->titleID(), std::numeric_limits::min(), std::numeric_limits::max(), this->app->activeUser()->ID()); + //NX::PlayStatistics * stats = this->app->playdata()->getStatisticsForUser(title->titleID(), this->app->activeUser()->ID()); CustomElm::ListAdjust * l = new CustomElm::ListAdjust(title->name(), Utils::playtimeToPlayedForString(stats->playtime), this->getValueString(this->adjustments[idx].value)); delete stats; diff --git a/Application/source/ui/screen/AllActivity.cpp b/Application/source/ui/screen/AllActivity.cpp index d833514..17bdb64 100644 --- a/Application/source/ui/screen/AllActivity.cpp +++ b/Application/source/ui/screen/AllActivity.cpp @@ -129,7 +129,8 @@ namespace Screen { } // Get statistics and append adjustment if needed - NX::PlayStatistics * ps = this->app->playdata()->getStatisticsForUser(t[i]->titleID(), this->app->activeUser()->ID()); + NX::RecentPlayStatistics *ps = this->app->playdata()->getRecentStatisticsForTitleAndUser(t[i]->titleID(), std::numeric_limits::min(), std::numeric_limits::max(), this->app->activeUser()->ID()); + NX::PlayStatistics *ps2 = this->app->playdata()->getStatisticsForUser(t[i]->titleID(), this->app->activeUser()->ID()); std::vector::iterator it = std::find_if(adjustments.begin(), adjustments.end(), [this, t, i](AdjustmentValue val) { return (val.titleID == t[i]->titleID() && val.userID == this->app->activeUser()->ID()); }); @@ -141,12 +142,13 @@ namespace Screen { totalSecs += ps->playtime; if (ps->launches == 0) { // Add in dummy data if not launched before (due to adjustment) - ps->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime())); - ps->lastPlayed = ps->firstPlayed; + ps2->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime())); + ps2->lastPlayed = ps2->firstPlayed; ps->launches = 1; if (ps->playtime == 0) { delete ps; + delete ps2; continue; } } @@ -155,8 +157,8 @@ namespace Screen { SortInfo * si = new SortInfo; si->name = t[i]->name(); si->titleID = t[i]->titleID(); - si->firstPlayed = ps->firstPlayed; - si->lastPlayed = ps->lastPlayed; + si->firstPlayed = ps2->firstPlayed; + si->lastPlayed = ps2->lastPlayed; si->playtime = ps->playtime; si->launches = ps->launches; @@ -165,7 +167,7 @@ namespace Screen { la->setImage(t[i]->imgPtr(), t[i]->imgSize()); la->setTitle(t[i]->name()); la->setPlaytime(Utils::playtimeToPlayedForString(ps->playtime)); - la->setLeftMuted(Utils::lastPlayedToString(ps->lastPlayed)); + la->setLeftMuted(Utils::lastPlayedToString(ps2->lastPlayed)); la->setRightMuted(Utils::launchesToPlayedString(ps->launches)); la->onPress([this, i](){ this->app->setActiveTitle(i); @@ -177,6 +179,9 @@ namespace Screen { la->setMutedColour(this->app->theme()->mutedText()); la->setLineColour(this->app->theme()->mutedLine()); this->list->addElement(la, si); + + delete ps; + delete ps2; } // Sort the list diff --git a/Application/source/ui/screen/Details.cpp b/Application/source/ui/screen/Details.cpp index 9b7f4b5..9bea240 100644 --- a/Application/source/ui/screen/Details.cpp +++ b/Application/source/ui/screen/Details.cpp @@ -268,7 +268,8 @@ namespace Screen { // update sessions // Get relevant play stats - NX::PlayStatistics * pss = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID()); + //NX::PlayStatistics * pss = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID()); + NX::RecentPlayStatistics *pss = this->app->playdata()->getRecentStatisticsForTitleAndUser(this->app->activeTitle()->titleID(), std::numeric_limits::min(), std::numeric_limits::max(), this->app->activeUser()->ID()); std::vector stats = this->app->playdata()->getPlaySessionsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID()); t.tm_min = 0; @@ -378,7 +379,7 @@ namespace Screen { // Add percentage of total playtime std::string str; - double percent = 100 * ((double)playtime / ((ps->playtime == 0 || ps->playtime < playtime) ? playtime : ps->playtime)); + double percent = 100 * ((double)playtime / ((pss->playtime == 0 || pss->playtime < playtime) ? playtime : ps->playtime)); percent = Utils::roundToDecimalPlace(percent, 2); if (percent < 0.01) { str = "< 0.01%"; @@ -642,7 +643,8 @@ namespace Screen { // Get statistics and append adjustment if needed std::vector adjustments = this->app->config()->adjustmentValues(); - NX::PlayStatistics * ps = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID()); + NX::PlayStatistics * pss = this->app->playdata()->getStatisticsForUser(this->app->activeTitle()->titleID(), this->app->activeUser()->ID()); + NX::RecentPlayStatistics *ps = this->app->playdata()->getRecentStatisticsForTitleAndUser(this->app->activeTitle()->titleID(), std::numeric_limits::min(), std::numeric_limits::max(), this->app->activeUser()->ID()); std::vector::iterator it = std::find_if(adjustments.begin(), adjustments.end(), [this](AdjustmentValue val) { return (val.titleID == this->app->activeTitle()->titleID() && val.userID == this->app->activeUser()->ID()); }); @@ -652,8 +654,8 @@ namespace Screen { if (ps->launches == 0) { // Add in dummy data if not launched before (due to adjustment) - ps->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime())); - ps->lastPlayed = ps->firstPlayed; + pss->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime())); + pss->lastPlayed = pss->firstPlayed; ps->launches = 1; } @@ -672,15 +674,16 @@ namespace Screen { this->timeplayed->setX(this->timeplayed->x() - this->timeplayed->w()/2); this->addElement(this->timeplayed); - this->firstplayed = new Aether::Text(1070, 490, Utils::Time::timestampToString(ps->firstPlayed), 20); + this->firstplayed = new Aether::Text(1070, 490, Utils::Time::timestampToString(pss->firstPlayed), 20); this->firstplayed->setColour(this->app->theme()->accent()); this->firstplayed->setX(this->firstplayed->x() - this->firstplayed->w()/2); this->addElement(this->firstplayed); - this->lastplayed = new Aether::Text(1070, 580, Utils::Time::timestampToString(ps->lastPlayed), 20); + this->lastplayed = new Aether::Text(1070, 580, Utils::Time::timestampToString(pss->lastPlayed), 20); this->lastplayed->setColour(this->app->theme()->accent()); this->lastplayed->setX(this->lastplayed->x() - this->lastplayed->w()/2); this->addElement(this->lastplayed); + delete pss; delete ps; // Show update icon if needbe