2021-06-11 05:41:58 +01:00
|
|
|
/*
|
|
|
|
* root_view.cpp
|
|
|
|
*
|
2024-04-12 10:47:36 +01:00
|
|
|
* Copyright (c) 2020-2024, DarkMatterCore <pabloacurielz@gmail.com>.
|
2021-06-11 05:41:58 +01:00
|
|
|
*
|
|
|
|
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
|
|
|
*
|
|
|
|
* nxdumptool is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* nxdumptool is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-04-30 22:01:42 +01:00
|
|
|
#include <views/root_view.hpp>
|
|
|
|
#include <views/gamecard_tab.hpp>
|
|
|
|
#include <views/titles_tab.hpp>
|
|
|
|
#include <views/options_tab.hpp>
|
|
|
|
#include <views/about_tab.hpp>
|
2021-06-11 05:41:58 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
namespace i18n = brls::i18n; /* For getStr(). */
|
|
|
|
using namespace i18n::literals; /* For _i18n. */
|
2021-06-11 05:41:58 +01:00
|
|
|
|
|
|
|
namespace nxdt::views
|
|
|
|
{
|
2024-04-19 11:08:44 +01:00
|
|
|
RootView::RootView() : brls::TabFrame()
|
2021-06-11 05:41:58 +01:00
|
|
|
{
|
Add DataTransferTaskFrame and GameCardImageDumpTaskFrame classes
DataTransferTaskFrame is a template class that's derived from brls::AppletFrame, which automatically starts a background task using an internal object belonging to a class derived from DataTransferTask. A DataTransferProgressDisplay view is used to show progress updates. If the background task hits an error, the class takes care of switching to an ErrorFrame view with the corresponding error message.
GameCardImageDumpTaskFrame is a derived class of DataTransferTaskFrame that uses a GameCardImageDumpTask object as its background task. In layman's terms, this provides a way to fully dump gamecard images using the new UI.
DataTransferTaskFrame depends on the newly added is_base_template helper from goneskiing to check if the class for the provided task is derived from DataTransferTask.
Other changes include:
* DataTransferProgressDisplay: rename setProgress() method to SetProgress().
* DataTransferTask: move post-task-execution code into its own new private method, PostExecutionCallback(), and update both OnCancelled() and OnPostExecute() callbacks to invoke it.
* DataTransferTask: update OnProgressUpdate() to allow sending a last progress update to all event subscribers even if the background task was cancelled.
* DataTransferTask: update OnProgressUpdate() to allow sending a first progress update if no data has been transferred but the total transfer size is already known.
* DataTransferTask: update OnProgressUpdate() to avoid calculating the ETA if the speed isn't greater than 0.
* DumpOptionsFrame: remove UpdateOutputStorages() method.
* DumpOptionsFrame: update class to use the cached output storage value from our RootView.
* DumpOptionsFrame: add GenerateOutputStoragesVector() method, which is used to avoid setting dummy options while initializing the output storages SelectListItem.
* DumpOptionsFrame: update UMS task callback to add the rest of the leftover logic from UpdateOutputStorages().
* DumpOptionsFrame: update RegisterButtonListener() to use a wrapper callback around the user-provided callback to check if the USB host was selected as the output storage but no USB host connection is available.
* ErrorFrame: use const references for all input string arguments.
* FileWriter: fix a localization stirng name typo.
* FileWriter: fix an exception that was previously being thrown by a fmt::format() call because of a wrong format specifier.
* FocusableItem: add a static assert to check if the provided ViewType is derived from brls::View.
* gamecard: redefine global gamecard status variable as an atomic unsigned 8-bit integer, which fixes a "status-hopping" issue previously experienced by repeating tasks running under other threads that periodically call gamecardGetStatus().
* GameCardImageDumpOptionsFrame: define GAMECARD_TOGGLE_ITEM macro, which is used to initialize all ToggleListItem elements from the view.
* GameCardImageDumpOptionsFrame: update button callback to push a GameCardImageDumpTaskFrame view onto the borealis stack.
* GameCardImageDumpTask: move class into its own header and module files.
* GameCardImageDumpTask: update class to also take in the checksum lookup method (not yet implemented).
* GameCardImageDumpTask: update class to send its first progress update as soon as the gamecard image size is known.
* GameCardImageDumpTask: update class to avoid returning a string if the task was cancelled -- DataTransferTaskFrame offers logic to display the appropiate cancel message on its own.
* GameCardTab: update PopulateList() method to display the new version information available in TitleGameCardApplicationMetadataEntry elements as part of the generated TitlesTabItem objects.
* i18n: add new localization strings.
* OptionsTab: update background task callback logic to handle task cancellation, reflecting the changes made to DataTransferTask.
* OptionsTab: reflect changes made to DataTransferProgressDisplay.
* RootView: cache the currently selected output storage value at all times, which is propagated throughout different parts of the UI. Getter and setter helpers have been added to operate with this value.
* RootView: add GetUsbHostSpeed() helper, which can be used by child views to retrieve the USB host speed on demand.
* RootView: update UMS task callback to automatically reset the cached output storage value back to the SD card if a UMS device was previously selected.
* title: define TitleGameCardApplicationMetadataEntry struct, which also holds version-specific information retrieved from the gamecard titles.
* title: refactor titleGetGameCardApplicationMetadataEntries() to return a dynamically allocated array of TitleGameCardApplicationMetadataEntry elements.
* usb: redefine global endpoint max packet size variable as an atomic unsigned 16-bit integer, which fixes a "status-hopping" issue previously experienced by repeating tasks running under other threads that periodically call usbIsReady().
* UsbHostTask: add GetUsbHostSpeed() method.
2024-04-29 14:26:12 +01:00
|
|
|
/* Get Material font ID. */
|
2021-06-25 21:13:39 +01:00
|
|
|
int material = brls::Application::getFontStash()->material;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Set UI properties. */
|
|
|
|
this->setTitle(APP_TITLE);
|
|
|
|
this->setIcon(BOREALIS_ASSET("icon/" APP_TITLE ".jpg"));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 08:02:23 +01:00
|
|
|
/* Check if we're running under applet mode. */
|
2023-04-08 12:34:53 +01:00
|
|
|
this->applet_mode = utilsIsAppletMode();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
Add DataTransferTaskFrame and GameCardImageDumpTaskFrame classes
DataTransferTaskFrame is a template class that's derived from brls::AppletFrame, which automatically starts a background task using an internal object belonging to a class derived from DataTransferTask. A DataTransferProgressDisplay view is used to show progress updates. If the background task hits an error, the class takes care of switching to an ErrorFrame view with the corresponding error message.
GameCardImageDumpTaskFrame is a derived class of DataTransferTaskFrame that uses a GameCardImageDumpTask object as its background task. In layman's terms, this provides a way to fully dump gamecard images using the new UI.
DataTransferTaskFrame depends on the newly added is_base_template helper from goneskiing to check if the class for the provided task is derived from DataTransferTask.
Other changes include:
* DataTransferProgressDisplay: rename setProgress() method to SetProgress().
* DataTransferTask: move post-task-execution code into its own new private method, PostExecutionCallback(), and update both OnCancelled() and OnPostExecute() callbacks to invoke it.
* DataTransferTask: update OnProgressUpdate() to allow sending a last progress update to all event subscribers even if the background task was cancelled.
* DataTransferTask: update OnProgressUpdate() to allow sending a first progress update if no data has been transferred but the total transfer size is already known.
* DataTransferTask: update OnProgressUpdate() to avoid calculating the ETA if the speed isn't greater than 0.
* DumpOptionsFrame: remove UpdateOutputStorages() method.
* DumpOptionsFrame: update class to use the cached output storage value from our RootView.
* DumpOptionsFrame: add GenerateOutputStoragesVector() method, which is used to avoid setting dummy options while initializing the output storages SelectListItem.
* DumpOptionsFrame: update UMS task callback to add the rest of the leftover logic from UpdateOutputStorages().
* DumpOptionsFrame: update RegisterButtonListener() to use a wrapper callback around the user-provided callback to check if the USB host was selected as the output storage but no USB host connection is available.
* ErrorFrame: use const references for all input string arguments.
* FileWriter: fix a localization stirng name typo.
* FileWriter: fix an exception that was previously being thrown by a fmt::format() call because of a wrong format specifier.
* FocusableItem: add a static assert to check if the provided ViewType is derived from brls::View.
* gamecard: redefine global gamecard status variable as an atomic unsigned 8-bit integer, which fixes a "status-hopping" issue previously experienced by repeating tasks running under other threads that periodically call gamecardGetStatus().
* GameCardImageDumpOptionsFrame: define GAMECARD_TOGGLE_ITEM macro, which is used to initialize all ToggleListItem elements from the view.
* GameCardImageDumpOptionsFrame: update button callback to push a GameCardImageDumpTaskFrame view onto the borealis stack.
* GameCardImageDumpTask: move class into its own header and module files.
* GameCardImageDumpTask: update class to also take in the checksum lookup method (not yet implemented).
* GameCardImageDumpTask: update class to send its first progress update as soon as the gamecard image size is known.
* GameCardImageDumpTask: update class to avoid returning a string if the task was cancelled -- DataTransferTaskFrame offers logic to display the appropiate cancel message on its own.
* GameCardTab: update PopulateList() method to display the new version information available in TitleGameCardApplicationMetadataEntry elements as part of the generated TitlesTabItem objects.
* i18n: add new localization strings.
* OptionsTab: update background task callback logic to handle task cancellation, reflecting the changes made to DataTransferTask.
* OptionsTab: reflect changes made to DataTransferProgressDisplay.
* RootView: cache the currently selected output storage value at all times, which is propagated throughout different parts of the UI. Getter and setter helpers have been added to operate with this value.
* RootView: add GetUsbHostSpeed() helper, which can be used by child views to retrieve the USB host speed on demand.
* RootView: update UMS task callback to automatically reset the cached output storage value back to the SD card if a UMS device was previously selected.
* title: define TitleGameCardApplicationMetadataEntry struct, which also holds version-specific information retrieved from the gamecard titles.
* title: refactor titleGetGameCardApplicationMetadataEntries() to return a dynamically allocated array of TitleGameCardApplicationMetadataEntry elements.
* usb: redefine global endpoint max packet size variable as an atomic unsigned 16-bit integer, which fixes a "status-hopping" issue previously experienced by repeating tasks running under other threads that periodically call usbIsReady().
* UsbHostTask: add GetUsbHostSpeed() method.
2024-04-29 14:26:12 +01:00
|
|
|
/* Cache output storage configuration value. */
|
|
|
|
this->output_storage = configGetInteger("output_storage");
|
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
/* Create labels. */
|
|
|
|
this->applet_mode_lbl = new brls::Label(brls::LabelStyle::HINT, "root_view/applet_mode"_i18n);
|
|
|
|
this->applet_mode_lbl->setColor(nvgRGB(255, 0, 0));
|
2021-06-25 21:13:39 +01:00
|
|
|
this->applet_mode_lbl->setFontSize(brls::Application::getStyle()->AppletFrame.titleSize);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->applet_mode_lbl->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->time_lbl = new brls::Label(brls::LabelStyle::SMALL, "");
|
2021-07-19 22:09:58 +01:00
|
|
|
this->time_lbl->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->time_lbl->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->time_lbl->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->battery_icon = new brls::Label(brls::LabelStyle::SMALL, "");
|
2021-06-25 21:13:39 +01:00
|
|
|
this->battery_icon->setFont(material);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->battery_icon->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->battery_icon->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->battery_icon->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->battery_percentage = new brls::Label(brls::LabelStyle::SMALL, "");
|
2021-07-19 22:09:58 +01:00
|
|
|
this->battery_percentage->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->battery_percentage->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->battery_percentage->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->connection_icon = new brls::Label(brls::LabelStyle::SMALL, "");
|
2021-06-25 21:13:39 +01:00
|
|
|
this->connection_icon->setFont(material);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->connection_icon->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->connection_icon->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->connection_icon->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->connection_status_lbl = new brls::Label(brls::LabelStyle::SMALL, "");
|
2021-07-19 22:09:58 +01:00
|
|
|
this->connection_status_lbl->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->connection_status_lbl->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->connection_status_lbl->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-26 00:28:38 +01:00
|
|
|
this->usb_icon = new brls::Label(brls::LabelStyle::SMALL, "\uE1E0");
|
|
|
|
this->usb_icon->setFont(material);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->usb_icon->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->usb_icon->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-26 00:28:38 +01:00
|
|
|
this->usb_icon->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-09-12 19:19:10 +01:00
|
|
|
this->ums_counter_lbl = new brls::Label(brls::LabelStyle::SMALL, i18n::getStr("root_view/ums_counter"_i18n, usbHsFsGetPhysicalDeviceCount()));
|
|
|
|
this->ums_counter_lbl->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
|
|
|
this->ums_counter_lbl->setVerticalAlign(NVG_ALIGN_TOP);
|
|
|
|
this->ums_counter_lbl->setParent(this);
|
|
|
|
|
|
|
|
this->cable_icon = new brls::Label(brls::LabelStyle::SMALL, "\uEFE6");
|
|
|
|
this->cable_icon->setFont(material);
|
|
|
|
this->cable_icon->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
|
|
|
this->cable_icon->setVerticalAlign(NVG_ALIGN_TOP);
|
|
|
|
this->cable_icon->setParent(this);
|
|
|
|
|
|
|
|
this->usb_host_speed_lbl = new brls::Label(brls::LabelStyle::SMALL, "root_view/usb_host_not_connected"_i18n);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->usb_host_speed_lbl->setHorizontalAlign(NVG_ALIGN_RIGHT);
|
2021-06-30 18:48:30 +01:00
|
|
|
this->usb_host_speed_lbl->setVerticalAlign(NVG_ALIGN_TOP);
|
2021-06-26 00:28:38 +01:00
|
|
|
this->usb_host_speed_lbl->setParent(this);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 05:41:58 +01:00
|
|
|
/* Start background tasks. */
|
2021-06-18 08:02:23 +01:00
|
|
|
this->status_info_task = new nxdt::tasks::StatusInfoTask();
|
2024-04-30 22:01:42 +01:00
|
|
|
this->gc_status_task = new nxdt::tasks::GameCardStatusTask();
|
|
|
|
this->title_metadata_task = new nxdt::tasks::TitleMetadataTask();
|
2021-06-11 05:41:58 +01:00
|
|
|
this->ums_task = new nxdt::tasks::UmsTask();
|
|
|
|
this->usb_host_task = new nxdt::tasks::UsbHostTask();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 05:41:58 +01:00
|
|
|
/* Add tabs. */
|
2021-08-11 08:17:57 +01:00
|
|
|
GameCardTab *gamecard_tab = new GameCardTab(this);
|
2021-06-25 21:13:39 +01:00
|
|
|
this->addTab("root_view/tabs/gamecard"_i18n, gamecard_tab);
|
|
|
|
gamecard_tab->SetParentSidebarItem(static_cast<brls::SidebarItem*>(this->sidebar->getChild(this->sidebar->getViewsCount() - 1)));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
this->addSeparator();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
TitlesTab *user_titles_tab = new TitlesTab(this, false);
|
2021-06-25 21:13:39 +01:00
|
|
|
this->addTab("root_view/tabs/user_titles"_i18n, user_titles_tab);
|
|
|
|
user_titles_tab->SetParentSidebarItem(static_cast<brls::SidebarItem*>(this->sidebar->getChild(this->sidebar->getViewsCount() - 1)));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
TitlesTab *system_titles_tab = new TitlesTab(this, true);
|
2021-06-25 21:13:39 +01:00
|
|
|
this->addTab("root_view/tabs/system_titles"_i18n, system_titles_tab);
|
|
|
|
system_titles_tab->SetParentSidebarItem(static_cast<brls::SidebarItem*>(this->sidebar->getChild(this->sidebar->getViewsCount() - 1)));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
this->addSeparator();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
this->addTab("root_view/tabs/options"_i18n, new OptionsTab(this));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-14 21:54:33 +01:00
|
|
|
this->addSeparator();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-14 21:54:33 +01:00
|
|
|
this->addTab("root_view/tabs/about"_i18n, new AboutTab());
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
/* Subscribe to status info event. */
|
2024-04-18 09:46:29 +01:00
|
|
|
this->status_info_task_sub = this->status_info_task->RegisterListener([this](const nxdt::tasks::StatusInfoData& status_info_data) {
|
|
|
|
u32 charge_percentage = status_info_data.charge_percentage;
|
|
|
|
PsmChargerType charger_type = status_info_data.charger_type;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2024-04-18 09:46:29 +01:00
|
|
|
bool connected = status_info_data.connected;
|
|
|
|
NifmInternetConnectionType connection_type = status_info_data.connection_type;
|
|
|
|
const char *ip_addr = status_info_data.ip_addr;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-25 21:13:39 +01:00
|
|
|
/* Update time label. */
|
2024-04-18 09:46:29 +01:00
|
|
|
this->time_lbl->setText(this->GetFormattedDateString(status_info_data.timeinfo));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
/* Update battery labels. */
|
2022-09-12 19:19:10 +01:00
|
|
|
this->battery_icon->setText(charger_type != PsmChargerType_Unconnected ? "\uE1A3" : (charge_percentage >= 100 ? "\uE1A4" : (charge_percentage >= 83 ? "\uEBD2" : \
|
|
|
|
(charge_percentage >= 67 ? "\uEBD4" : (charge_percentage >= 50 ? "\uEBE2" : \
|
|
|
|
(charge_percentage >= 33 ? "\uEBDD" : (charge_percentage >= 17 ? "\uEBE0" : \
|
|
|
|
(charge_percentage > 0 ? "\uEBD9" : "\uEBDC"))))))));
|
|
|
|
|
|
|
|
this->battery_icon->setColor(charger_type != PsmChargerType_Unconnected ? nvgRGB(0, 255, 0) : (charge_percentage <= 15 ? nvgRGB(255, 0, 0) : \
|
|
|
|
brls::Application::getTheme()->textColor));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->battery_percentage->setText(fmt::format("{}%", charge_percentage));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-25 21:13:39 +01:00
|
|
|
/* Update network labels. */
|
2024-04-18 09:46:29 +01:00
|
|
|
this->connection_icon->setText(connected ? (connection_type == NifmInternetConnectionType_WiFi ? "\uE63E" : "\uE8BE") : "\uE195");
|
|
|
|
this->connection_status_lbl->setText(connected ? std::string(ip_addr) : "root_view/not_connected"_i18n);
|
2021-06-18 19:10:19 +01:00
|
|
|
});
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-09-12 19:19:10 +01:00
|
|
|
/* Subscribe to UMS event. */
|
2024-04-18 09:46:29 +01:00
|
|
|
this->ums_task_sub = this->ums_task->RegisterListener([this](const nxdt::tasks::UmsDeviceVector& ums_devices) {
|
2022-09-12 19:19:10 +01:00
|
|
|
/* Update UMS counter label. */
|
|
|
|
this->ums_counter_lbl->setText(i18n::getStr("root_view/ums_counter"_i18n, usbHsFsGetPhysicalDeviceCount()));
|
Add DataTransferTaskFrame and GameCardImageDumpTaskFrame classes
DataTransferTaskFrame is a template class that's derived from brls::AppletFrame, which automatically starts a background task using an internal object belonging to a class derived from DataTransferTask. A DataTransferProgressDisplay view is used to show progress updates. If the background task hits an error, the class takes care of switching to an ErrorFrame view with the corresponding error message.
GameCardImageDumpTaskFrame is a derived class of DataTransferTaskFrame that uses a GameCardImageDumpTask object as its background task. In layman's terms, this provides a way to fully dump gamecard images using the new UI.
DataTransferTaskFrame depends on the newly added is_base_template helper from goneskiing to check if the class for the provided task is derived from DataTransferTask.
Other changes include:
* DataTransferProgressDisplay: rename setProgress() method to SetProgress().
* DataTransferTask: move post-task-execution code into its own new private method, PostExecutionCallback(), and update both OnCancelled() and OnPostExecute() callbacks to invoke it.
* DataTransferTask: update OnProgressUpdate() to allow sending a last progress update to all event subscribers even if the background task was cancelled.
* DataTransferTask: update OnProgressUpdate() to allow sending a first progress update if no data has been transferred but the total transfer size is already known.
* DataTransferTask: update OnProgressUpdate() to avoid calculating the ETA if the speed isn't greater than 0.
* DumpOptionsFrame: remove UpdateOutputStorages() method.
* DumpOptionsFrame: update class to use the cached output storage value from our RootView.
* DumpOptionsFrame: add GenerateOutputStoragesVector() method, which is used to avoid setting dummy options while initializing the output storages SelectListItem.
* DumpOptionsFrame: update UMS task callback to add the rest of the leftover logic from UpdateOutputStorages().
* DumpOptionsFrame: update RegisterButtonListener() to use a wrapper callback around the user-provided callback to check if the USB host was selected as the output storage but no USB host connection is available.
* ErrorFrame: use const references for all input string arguments.
* FileWriter: fix a localization stirng name typo.
* FileWriter: fix an exception that was previously being thrown by a fmt::format() call because of a wrong format specifier.
* FocusableItem: add a static assert to check if the provided ViewType is derived from brls::View.
* gamecard: redefine global gamecard status variable as an atomic unsigned 8-bit integer, which fixes a "status-hopping" issue previously experienced by repeating tasks running under other threads that periodically call gamecardGetStatus().
* GameCardImageDumpOptionsFrame: define GAMECARD_TOGGLE_ITEM macro, which is used to initialize all ToggleListItem elements from the view.
* GameCardImageDumpOptionsFrame: update button callback to push a GameCardImageDumpTaskFrame view onto the borealis stack.
* GameCardImageDumpTask: move class into its own header and module files.
* GameCardImageDumpTask: update class to also take in the checksum lookup method (not yet implemented).
* GameCardImageDumpTask: update class to send its first progress update as soon as the gamecard image size is known.
* GameCardImageDumpTask: update class to avoid returning a string if the task was cancelled -- DataTransferTaskFrame offers logic to display the appropiate cancel message on its own.
* GameCardTab: update PopulateList() method to display the new version information available in TitleGameCardApplicationMetadataEntry elements as part of the generated TitlesTabItem objects.
* i18n: add new localization strings.
* OptionsTab: update background task callback logic to handle task cancellation, reflecting the changes made to DataTransferTask.
* OptionsTab: reflect changes made to DataTransferProgressDisplay.
* RootView: cache the currently selected output storage value at all times, which is propagated throughout different parts of the UI. Getter and setter helpers have been added to operate with this value.
* RootView: add GetUsbHostSpeed() helper, which can be used by child views to retrieve the USB host speed on demand.
* RootView: update UMS task callback to automatically reset the cached output storage value back to the SD card if a UMS device was previously selected.
* title: define TitleGameCardApplicationMetadataEntry struct, which also holds version-specific information retrieved from the gamecard titles.
* title: refactor titleGetGameCardApplicationMetadataEntries() to return a dynamically allocated array of TitleGameCardApplicationMetadataEntry elements.
* usb: redefine global endpoint max packet size variable as an atomic unsigned 16-bit integer, which fixes a "status-hopping" issue previously experienced by repeating tasks running under other threads that periodically call usbIsReady().
* UsbHostTask: add GetUsbHostSpeed() method.
2024-04-29 14:26:12 +01:00
|
|
|
|
|
|
|
/* Update cached output storage value, if needed. */
|
|
|
|
if (this->output_storage > ConfigOutputStorage_UsbHost) this->output_storage = ConfigOutputStorage_SdCard;
|
2022-09-12 19:19:10 +01:00
|
|
|
});
|
|
|
|
|
2021-06-26 00:28:38 +01:00
|
|
|
/* Subscribe to USB host event. */
|
|
|
|
this->usb_host_task_sub = this->usb_host_task->RegisterListener([this](UsbHostSpeed usb_host_speed) {
|
|
|
|
/* Update USB host speed label. */
|
2022-09-12 19:19:10 +01:00
|
|
|
this->usb_host_speed_lbl->setText(usb_host_speed ? i18n::getStr("root_view/usb_host_speed"_i18n, usb_host_speed) : "root_view/usb_host_not_connected"_i18n);
|
2021-06-26 00:28:38 +01:00
|
|
|
});
|
2021-06-11 05:41:58 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2024-04-19 11:08:44 +01:00
|
|
|
RootView::~RootView()
|
2021-06-13 07:18:14 +01:00
|
|
|
{
|
2022-09-12 19:19:10 +01:00
|
|
|
/* Unregister task listeners. */
|
2021-06-26 00:28:38 +01:00
|
|
|
this->usb_host_task->UnregisterListener(this->usb_host_task_sub);
|
2022-09-12 19:19:10 +01:00
|
|
|
this->ums_task->UnregisterListener(this->ums_task_sub);
|
2021-06-18 19:10:19 +01:00
|
|
|
this->status_info_task->UnregisterListener(this->status_info_task_sub);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
/* Stop background tasks. */
|
2021-08-11 08:17:57 +01:00
|
|
|
this->status_info_task->stop();
|
2021-06-23 19:27:06 +01:00
|
|
|
this->gc_status_task->stop();
|
2024-04-30 22:01:42 +01:00
|
|
|
this->title_metadata_task->stop();
|
2021-06-23 19:27:06 +01:00
|
|
|
this->ums_task->stop();
|
|
|
|
this->usb_host_task->stop();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
/* Destroy labels. */
|
|
|
|
delete this->applet_mode_lbl;
|
|
|
|
delete this->time_lbl;
|
|
|
|
delete this->battery_icon;
|
|
|
|
delete this->battery_percentage;
|
|
|
|
delete this->connection_icon;
|
|
|
|
delete this->connection_status_lbl;
|
2021-06-26 00:28:38 +01:00
|
|
|
delete this->usb_icon;
|
2022-09-12 19:19:10 +01:00
|
|
|
delete this->ums_counter_lbl;
|
|
|
|
delete this->cable_icon;
|
2021-06-26 00:28:38 +01:00
|
|
|
delete this->usb_host_speed_lbl;
|
2021-08-07 09:42:03 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-07 09:42:03 +01:00
|
|
|
std::string RootView::GetFormattedDateString(const struct tm& timeinfo)
|
|
|
|
{
|
|
|
|
bool is_am = true;
|
|
|
|
struct tm ts = timeinfo;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-07 09:42:03 +01:00
|
|
|
/* Update time label. */
|
|
|
|
ts.tm_mon++;
|
|
|
|
ts.tm_year += 1900;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-07 09:42:03 +01:00
|
|
|
if ("generic/time_format"_i18n.compare("12") == 0)
|
|
|
|
{
|
|
|
|
/* Adjust time for 12-hour clock. */
|
|
|
|
if (ts.tm_hour > 12)
|
|
|
|
{
|
|
|
|
ts.tm_hour -= 12;
|
|
|
|
is_am = false;
|
|
|
|
} else
|
|
|
|
if (!ts.tm_hour)
|
|
|
|
{
|
|
|
|
ts.tm_hour = 12;
|
|
|
|
}
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-07 09:42:03 +01:00
|
|
|
return i18n::getStr("generic/date"_i18n, ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, is_am ? "AM" : "PM");
|
2021-06-13 07:18:14 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
void RootView::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
|
|
|
|
{
|
2021-06-23 19:27:06 +01:00
|
|
|
brls::AppletFrame::draw(vg, x, y, width, height, style, ctx);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
if (this->applet_mode) this->applet_mode_lbl->frame(ctx);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->time_lbl->frame(ctx);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->battery_icon->frame(ctx);
|
|
|
|
this->battery_percentage->frame(ctx);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
this->connection_icon->frame(ctx);
|
|
|
|
this->connection_status_lbl->frame(ctx);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-26 00:28:38 +01:00
|
|
|
this->usb_icon->frame(ctx);
|
2022-09-12 19:19:10 +01:00
|
|
|
this->ums_counter_lbl->frame(ctx);
|
|
|
|
|
|
|
|
this->cable_icon->frame(ctx);
|
2021-06-26 00:28:38 +01:00
|
|
|
this->usb_host_speed_lbl->frame(ctx);
|
2021-06-18 19:10:19 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
void RootView::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash)
|
|
|
|
{
|
2022-09-12 19:19:10 +01:00
|
|
|
int x_orig = 0, x_pos = 0, y_pos = 0;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
brls::AppletFrame::layout(vg, style, stash);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
if (this->applet_mode)
|
|
|
|
{
|
|
|
|
/* Applet mode label. */
|
2021-06-30 18:48:30 +01:00
|
|
|
x_pos = (this->x + (this->width - this->applet_mode_lbl->getTextWidth()) / 2);
|
2021-06-26 00:28:38 +01:00
|
|
|
y_pos = (this->y + (style->AppletFrame.headerHeightRegular / 2) + style->AppletFrame.titleOffset);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->applet_mode_lbl->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->applet_mode_lbl->invalidate();
|
2021-06-18 19:10:19 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
/* Time label. */
|
2022-09-12 19:19:10 +01:00
|
|
|
x_orig = x_pos = (this->x + this->width - style->AppletFrame.separatorSpacing - style->AppletFrame.footerTextSpacing);
|
2021-06-30 18:48:30 +01:00
|
|
|
y_pos = this->y + style->AppletFrame.imageTopPadding;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->time_lbl->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->time_lbl->invalidate();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-26 00:28:38 +01:00
|
|
|
/* Battery stats and network connection labels. */
|
2021-06-30 18:48:30 +01:00
|
|
|
y_pos += (this->time_lbl->getTextHeight() + 5);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->connection_status_lbl->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->connection_status_lbl->invalidate();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-07-19 22:09:58 +01:00
|
|
|
x_pos -= (5 + this->connection_status_lbl->getTextWidth());
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->connection_icon->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->connection_icon->invalidate();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-07-19 22:09:58 +01:00
|
|
|
x_pos -= (10 + this->connection_icon->getTextWidth());
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->battery_percentage->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->battery_percentage->invalidate();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-07-19 22:09:58 +01:00
|
|
|
x_pos -= (5 + this->battery_percentage->getTextWidth());
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->battery_icon->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->battery_icon->invalidate();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-09-12 19:19:10 +01:00
|
|
|
/* UMS device counter and USB host speed labels. */
|
|
|
|
x_pos = x_orig;
|
2021-06-30 18:48:30 +01:00
|
|
|
y_pos += (this->connection_status_lbl->getTextHeight() + 5);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->usb_host_speed_lbl->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->usb_host_speed_lbl->invalidate();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-07-19 22:09:58 +01:00
|
|
|
x_pos -= (5 + this->usb_host_speed_lbl->getTextWidth());
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-09-12 19:19:10 +01:00
|
|
|
this->cable_icon->setBoundaries(x_pos, y_pos, 0, 0);
|
|
|
|
this->cable_icon->invalidate();
|
|
|
|
|
|
|
|
x_pos -= (10 + this->cable_icon->getTextWidth());
|
|
|
|
|
|
|
|
this->ums_counter_lbl->setBoundaries(x_pos, y_pos, 0, 0);
|
|
|
|
this->ums_counter_lbl->invalidate();
|
|
|
|
|
|
|
|
x_pos -= (5 + this->ums_counter_lbl->getTextWidth());
|
|
|
|
|
2021-06-30 18:48:30 +01:00
|
|
|
this->usb_icon->setBoundaries(x_pos, y_pos, 0, 0);
|
2021-07-19 22:09:58 +01:00
|
|
|
this->usb_icon->invalidate();
|
2021-06-18 19:10:19 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-07-30 22:07:26 +01:00
|
|
|
brls::View* RootView::getDefaultFocus(void)
|
|
|
|
{
|
|
|
|
return this->sidebar->getChild(0);
|
|
|
|
}
|
2021-06-11 05:41:58 +01:00
|
|
|
}
|