From 8c092660c71478a43124774ec9b310d089ba9db8 Mon Sep 17 00:00:00 2001 From: Damien Zhao Date: Sun, 24 Nov 2024 00:52:06 +0800 Subject: [PATCH] some fixes 1. Fixed crash when deleting import json file. 2. Updates all lang json files. 3. Fixed first/last play data missing for imported play data. Signed-off-by: Damien Zhao --- Application/romfs/lang | 2 +- Application/source/Application.ImportJob.cpp | 4 +-- Application/source/Application.cpp | 18 ----------- Application/source/nx/PlayData.cpp | 26 +++++++-------- Application/source/ui/screen/AllActivity.cpp | 2 +- Application/source/ui/screen/Details.cpp | 3 +- Application/source/ui/screen/Settings.cpp | 34 ++++---------------- 7 files changed, 22 insertions(+), 67 deletions(-) diff --git a/Application/romfs/lang b/Application/romfs/lang index a937a74..c55046b 160000 --- a/Application/romfs/lang +++ b/Application/romfs/lang @@ -1 +1 @@ -Subproject commit a937a7467c4d1c28a7407b064344d33c05479700 +Subproject commit c55046b142f5e751a7849c6fd07052457282ebda diff --git a/Application/source/Application.ImportJob.cpp b/Application/source/Application.ImportJob.cpp index 86e616e..01bd8f8 100644 --- a/Application/source/Application.ImportJob.cpp +++ b/Application/source/Application.ImportJob.cpp @@ -132,8 +132,8 @@ namespace Main { nlohmann::json s = title["summary"]; if (s["firstPlayed"] != nullptr && s["lastPlayed"] != nullptr && s["playtime"] != nullptr && s["launches"] != nullptr) { tJson["summary"] = nlohmann::json(); - tJson["summary"]["firstPlayed"] = Utils::Time::posixTimestampToPdm(s["firstPlayed"].get()); - tJson["summary"]["lastPlayed"] = Utils::Time::posixTimestampToPdm(s["lastPlayed"].get()); + tJson["summary"]["firstPlayed"] = s["firstPlayed"].get(); + tJson["summary"]["lastPlayed"] = s["lastPlayed"].get(); tJson["summary"]["playtime"] = s["playtime"]; tJson["summary"]["launches"] = s["launches"]; } diff --git a/Application/source/Application.cpp b/Application/source/Application.cpp index 241fb63..1091c77 100644 --- a/Application/source/Application.cpp +++ b/Application/source/Application.cpp @@ -5,7 +5,6 @@ #include "utils/Lang.hpp" #include "utils/UpdateUtils.hpp" #include "utils/Utils.hpp" -#include "utils/Debug.hpp" #include "ui/screen/AdjustPlaytime.hpp" #include "ui/screen/AllActivity.hpp" @@ -25,28 +24,22 @@ namespace Main { // Start all required services Utils::NX::startServices(); Utils::Curl::init(); - Utils::write_log("Services started and Crul init finished!"); // Create config object and read in values this->config_ = new Config(); this->config_->readConfig(); - Utils::write_log("Read config file finished!"); // Set language if (!Utils::Lang::setLanguage(this->config_->gLang())) { this->window->exit(); } - Utils::write_log("Set language finished!"); this->playdata_ = new NX::PlayData(); - Utils::write_log("NX::PlayData() finished!"); this->theme_ = new Theme(this->config_->gTheme()); - Utils::write_log("Theme(this->config_->gTheme()) finished!"); // Start update thread this->hasUpdate_ = false; this->updateThread = std::async(std::launch::async, &Application::checkForUpdate, this); - Utils::write_log("Start update thread finished!"); // Check if launched via user page and if so only use the chosen user NX::User * u = Utils::NX::getUserPageUser(); @@ -55,7 +48,6 @@ namespace Main { this->isUserPage_ = true; this->users.push_back(u); } - Utils::write_log("Check user page finished!"); // Set view to today and by day this->tm = Utils::Time::getTmForCurrentTime(); @@ -75,14 +67,12 @@ namespace Main { } this->tmCopy = this->tm; this->viewTypeCopy = this->viewType; - Utils::write_log("Set view to today and by day finished!"); // Populate users vector if (!this->isUserPage_) { this->users = Utils::NX::getUserObjects(); } this->userIdx = 0; - Utils::write_log("Populate users vector finished!"); // Populate titles vector this->titles = Utils::NX::getTitleObjects(this->users); @@ -91,28 +81,24 @@ namespace Main { this->titles.push_back(title); } this->titleIdx = 0; - Utils::write_log("Populate titles vector finished!"); // Create Aether instance (ignore log messages for now) this->window = new Aether::Window("NX-Activity-Log", 1280, 720, [](const std::string message, const bool important) { }); // this->window->showDebugInfo(true); - Utils::write_log("Create Aether instance finished!"); // Create overlays this->dtpicker = nullptr; this->periodpicker = new Aether::PopupList("common.view.heading"_lang); this->periodpicker->setBackLabel("common.buttonHint.back"_lang); this->periodpicker->setOKLabel("common.buttonHint.ok"_lang); - Utils::write_log("Create overlays finished!"); // Setup screens this->setDisplayTheme(); this->createReason = ScreenCreate::Normal; this->createScreens(); this->reinitScreens_ = ReinitState::False; - Utils::write_log("Setup screens finished!"); if (this->isUserPage_) { // Skip UserSelect screen if launched via user page @@ -123,7 +109,6 @@ namespace Main { this->window->setFadeOut(true); this->setScreen(ScreenID::UserSelect); } - Utils::write_log("Start screens finished!"); } void Application::checkForUpdate() { @@ -470,16 +455,13 @@ namespace Main { // Check if screens should be recreated if (this->reinitScreens_ == ReinitState::Wait) { this->reinitScreens_ = ReinitState::True; - Utils::write_log("Waiting for reinit screens..."); } else if (this->reinitScreens_ == ReinitState::True) { - Utils::write_log("Reinit screens start!"); this->reinitScreens_ = ReinitState::False; this->window->removeScreen(); this->deleteScreens(); this->setDisplayTheme(); this->createScreens(); this->setScreen(this->screen); - Utils::write_log("Reinit screens finished!"); } } } diff --git a/Application/source/nx/PlayData.cpp b/Application/source/nx/PlayData.cpp index fdfe3e0..1becee6 100644 --- a/Application/source/nx/PlayData.cpp +++ b/Application/source/nx/PlayData.cpp @@ -165,8 +165,6 @@ namespace NX { } PlayEventsAndSummaries PlayData::readPlayDataFromPdm() { - Utils::write_log("readPlayDataFromPdm() enter"); - PlayEventsAndSummaries ret; // Position of first event to read @@ -275,17 +273,14 @@ namespace NX { } #endif - Utils::write_log("readPlayDataFromPdm() exit"); return ret; } PlayEventsAndSummaries PlayData::readPlayDataFromImport() { PlayEventsAndSummaries ret; - Utils::write_log("readPlayDataFromImport() enter"); // Abort if no file if (!std::filesystem::exists("/switch/NX-Activity-Log/importedData.json")) { - Utils::write_log("readPlayDataFromImport() exit"); return ret; } @@ -351,18 +346,13 @@ namespace NX { } } } - - Utils::write_log("Parse user data from importedData.json finished!"); } - - Utils::write_log("readPlayDataFromImport() exit"); return ret; } std::vector PlayData::mergePlayEvents(std::vector & one, std::vector & two) { std::vector merged = one; - Utils::write_log("mergePlayEvents enter"); for (PlayEvent * event : two) { std::vector::iterator it = std::find_if(one.begin(), one.end(), [event](PlayEvent * pot) { return (event->type == pot->type && event->titleID == pot->titleID && @@ -379,7 +369,6 @@ namespace NX { one.clear(); two.clear(); - Utils::write_log("mergePlayEvents exit"); return merged; } @@ -395,10 +384,8 @@ namespace NX { PlayEventsAndSummaries pdmData = pdmThread.get(); PlayEventsAndSummaries impData = impThread.get(); - Utils::write_log("Read in all data simultaneously finished"); this->events = this->mergePlayEvents(pdmData.first, impData.first); this->summaries = impData.second; - Utils::write_log("mergePlayEvents() finished"); } std::vector PlayData::getMissingTitles(std::vector<Title *> passed) { @@ -507,8 +494,17 @@ namespace NX { PdmPlayStatistics tmp; pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(titleID, userID, false, &tmp); PlayStatistics * stats = new PlayStatistics; - stats->firstPlayed = tmp.first_timestamp_user; - stats->lastPlayed = tmp.last_timestamp_user; + if (tmp.first_timestamp_user != 0 && tmp.last_timestamp_user != 0) { + stats->firstPlayed = tmp.first_timestamp_user; + stats->lastPlayed = tmp.last_timestamp_user; + } else { + auto it = std::find_if(this->summaries.begin(), this->summaries.end(), [titleID](auto s){ return (s->titleID == titleID); }); + if (it != this->summaries.end()) { + stats->firstPlayed = (*it)->firstPlayed; + stats->lastPlayed = (*it)->lastPlayed; + } + } + stats->playtime = tmp.playtime / 1000 / 1000 / 1000; //the unit of playtime in PdmPlayStatistics is ns stats->launches = tmp.total_launches; return stats; diff --git a/Application/source/ui/screen/AllActivity.cpp b/Application/source/ui/screen/AllActivity.cpp index 17bdb64..896a167 100644 --- a/Application/source/ui/screen/AllActivity.cpp +++ b/Application/source/ui/screen/AllActivity.cpp @@ -142,7 +142,7 @@ namespace Screen { totalSecs += ps->playtime; if (ps->launches == 0) { // Add in dummy data if not launched before (due to adjustment) - ps2->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime())); + ps2->firstPlayed = Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime()); ps2->lastPlayed = ps2->firstPlayed; ps->launches = 1; diff --git a/Application/source/ui/screen/Details.cpp b/Application/source/ui/screen/Details.cpp index a872934..80b6996 100644 --- a/Application/source/ui/screen/Details.cpp +++ b/Application/source/ui/screen/Details.cpp @@ -4,7 +4,6 @@ #include "ui/element/ListSession.hpp" #include "utils/Utils.hpp" #include "utils/Time.hpp" -#include "utils/Debug.hpp" // Values for summary appearance #define SUMMARY_BOX_HEIGHT 60 @@ -656,7 +655,7 @@ namespace Screen { if (ps->launches == 0) { // Add in dummy data if not launched before (due to adjustment) - pss->firstPlayed = Utils::Time::posixTimestampToPdm(Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime())); + pss->firstPlayed = Utils::Time::getTimeT(Utils::Time::getTmForCurrentTime()); pss->lastPlayed = pss->firstPlayed; ps->launches = 1; } diff --git a/Application/source/ui/screen/Settings.cpp b/Application/source/ui/screen/Settings.cpp index ef37656..1f821b3 100644 --- a/Application/source/ui/screen/Settings.cpp +++ b/Application/source/ui/screen/Settings.cpp @@ -239,38 +239,14 @@ namespace Screen { } void Settings::showDeleteImportedOverlay() { - // Create msgbox - this->prepareMessageBox(); - this->msgbox->addLeftButton("common.buttonHint.cancel"_lang, [this]() { - this->msgbox->close(); - }); - this->msgbox->addRightButton("common.delete"_lang, [this](){ - // Delete file - std::filesystem::remove("/switch/NX-Activity-Log/importedData.json"); - - // Disable button + // Update delete button status + bool hasData = std::filesystem::exists("/switch/NX-Activity-Log/importedData.json"); + if (!hasData) { this->optionDeleteImport->setTextColour(this->app->theme()->mutedLine()); this->optionDeleteImport->setSelectable(false); this->optionDeleteImport->setTouchable(false); - this->list->setFocused(this->optionHide); - - this->msgbox->close(); this->setupGenericMessageOverlay("settings.importExport.deleteSuccessful"_lang); - }); - - // Add message box body - int bw, bh; - this->msgbox->getBodySize(&bw, &bh); - Aether::Element * body = new Aether::Element(0, 0, bw, bh); - Aether::TextBlock * tb = new Aether::TextBlock(50, 40, "settings.importExport.confirmDelete"_lang, 24, bw - 100); - tb->setColour(this->app->theme()->text()); - body->addElement(tb); - tb = new Aether::TextBlock(50, tb->y() + tb->h() + 20, "settings.importExport.confirmDeleteBody"_lang, 20, bw - 100); - tb->setColour(this->app->theme()->mutedText()); - body->addElement(tb); - this->msgbox->setBodySize(bw, tb->y() + tb->h() + 40); - this->msgbox->setBody(body); - this->app->addOverlay(this->msgbox); + } } void Settings::update(uint32_t dt) { @@ -519,6 +495,8 @@ namespace Screen { // DELETE IMPORTED DATA bool hasData = std::filesystem::exists("/switch/NX-Activity-Log/importedData.json"); this->optionDeleteImport = new Aether::ListButton("settings.importExport.deleteImport"_lang, [this]() { + // Delete file + std::filesystem::remove("/switch/NX-Activity-Log/importedData.json"); this->showDeleteImportedOverlay(); }); this->optionDeleteImport->setLineColour(this->app->theme()->mutedLine());