2021-06-11 05:41:58 +01:00
|
|
|
/*
|
|
|
|
* root_view.hpp
|
|
|
|
*
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __ROOT_VIEW_HPP__
|
|
|
|
#define __ROOT_VIEW_HPP__
|
|
|
|
|
2024-04-30 22:01:42 +01:00
|
|
|
#include "../tasks/status_info_task.hpp"
|
|
|
|
#include "../tasks/gamecard_status_task.hpp"
|
|
|
|
#include "../tasks/title_metadata_task.hpp"
|
|
|
|
#include "../tasks/ums_task.hpp"
|
|
|
|
#include "../tasks/usb_host_task.hpp"
|
2021-06-11 05:41:58 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
#define EVENT_SUBSCRIPTION(func_name, event_type, task_name) \
|
|
|
|
ALWAYS_INLINE nxdt::tasks::event_type::Subscription Register##func_name##Listener(nxdt::tasks::event_type::Callback cb) { return this->task_name->RegisterListener(cb); } \
|
|
|
|
ALWAYS_INLINE void Unregister##func_name##Listener(nxdt::tasks::event_type::Subscription subscription) { this->task_name->UnregisterListener(subscription); }
|
|
|
|
|
2021-06-11 05:41:58 +01:00
|
|
|
namespace nxdt::views
|
|
|
|
{
|
|
|
|
class RootView: public brls::TabFrame
|
|
|
|
{
|
|
|
|
private:
|
2021-06-18 08:02:23 +01:00
|
|
|
bool applet_mode = false;
|
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
|
|
|
int output_storage = ConfigOutputStorage_SdCard;
|
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
brls::Label *applet_mode_lbl = nullptr;
|
|
|
|
brls::Label *time_lbl = nullptr;
|
|
|
|
brls::Label *battery_icon = nullptr, *battery_percentage = nullptr;
|
|
|
|
brls::Label *connection_icon = nullptr, *connection_status_lbl = nullptr;
|
2022-09-12 19:19:10 +01:00
|
|
|
brls::Label *usb_icon = nullptr, *ums_counter_lbl = nullptr;
|
|
|
|
brls::Label *cable_icon = nullptr, *usb_host_speed_lbl = nullptr;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 08:02:23 +01:00
|
|
|
nxdt::tasks::StatusInfoTask *status_info_task = nullptr;
|
2024-04-30 22:01:42 +01:00
|
|
|
nxdt::tasks::GameCardStatusTask *gc_status_task = nullptr;
|
|
|
|
nxdt::tasks::TitleMetadataTask *title_metadata_task = nullptr;
|
2021-06-11 05:41:58 +01:00
|
|
|
nxdt::tasks::UmsTask *ums_task = nullptr;
|
|
|
|
nxdt::tasks::UsbHostTask *usb_host_task = nullptr;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-23 19:27:06 +01:00
|
|
|
nxdt::tasks::StatusInfoEvent::Subscription status_info_task_sub;
|
2022-09-12 19:19:10 +01:00
|
|
|
nxdt::tasks::UmsEvent::Subscription ums_task_sub;
|
2021-06-26 00:28:38 +01:00
|
|
|
nxdt::tasks::UsbHostEvent::Subscription usb_host_task_sub;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-18 19:10:19 +01:00
|
|
|
protected:
|
|
|
|
void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) override;
|
|
|
|
void layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) override;
|
2021-07-30 22:07:26 +01:00
|
|
|
brls::View *getDefaultFocus(void) override;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-11 05:41:58 +01:00
|
|
|
public:
|
2024-04-19 11:08:44 +01:00
|
|
|
RootView();
|
|
|
|
~RootView();
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-07 09:42:03 +01:00
|
|
|
static std::string GetFormattedDateString(const struct tm& timeinfo);
|
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
|
|
|
/* Helpers used to propagate the selected output storage throughout different parts of the UI. */
|
|
|
|
|
|
|
|
ALWAYS_INLINE int GetOutputStorage(void)
|
|
|
|
{
|
|
|
|
return this->output_storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE void SetOutputStorage(int value)
|
|
|
|
{
|
|
|
|
this->output_storage = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wrappers for task methods. */
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
ALWAYS_INLINE bool IsInternetConnectionAvailable(void)
|
|
|
|
{
|
|
|
|
return this->status_info_task->IsInternetConnectionAvailable();
|
|
|
|
}
|
2024-05-05 20:42:32 +01:00
|
|
|
|
|
|
|
ALWAYS_INLINE const GameCardStatus& GetGameCardStatus(void)
|
|
|
|
{
|
|
|
|
return this->gc_status_task->GetGameCardStatus();
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2024-05-05 23:41:41 +01:00
|
|
|
ALWAYS_INLINE const nxdt::tasks::TitleApplicationMetadataInfo& GetApplicationMetadataInfo(bool is_system)
|
2021-08-11 08:17:57 +01:00
|
|
|
{
|
2024-05-05 23:41:41 +01:00
|
|
|
return this->title_metadata_task->GetApplicationMetadataInfo(is_system);
|
2021-08-11 08:17:57 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2024-04-18 09:46:29 +01:00
|
|
|
ALWAYS_INLINE const nxdt::tasks::UmsDeviceVector& GetUmsDevices(void)
|
2022-09-12 19:19:10 +01:00
|
|
|
{
|
|
|
|
return this->ums_task->GetUmsDevices();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ALWAYS_INLINE const UsbHostSpeed& GetUsbHostSpeed(void)
|
|
|
|
{
|
|
|
|
return this->usb_host_task->GetUsbHostSpeed();
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(StatusInfoTask, StatusInfoEvent, status_info_task);
|
2024-04-30 22:01:42 +01:00
|
|
|
EVENT_SUBSCRIPTION(GameCardStatusTask, GameCardStatusEvent, gc_status_task);
|
|
|
|
EVENT_SUBSCRIPTION(TitleMetadataTask, UserTitleEvent, title_metadata_task);
|
2021-08-11 08:17:57 +01:00
|
|
|
EVENT_SUBSCRIPTION(UmsTask, UmsEvent, ums_task);
|
|
|
|
EVENT_SUBSCRIPTION(UsbHostTask, UsbHostEvent, usb_host_task);
|
2021-06-11 05:41:58 +01:00
|
|
|
};
|
|
|
|
}
|
2021-06-13 07:18:14 +01:00
|
|
|
|
2021-08-11 08:17:57 +01:00
|
|
|
#undef EVENT_SUBSCRIPTION
|
|
|
|
|
2021-06-13 07:18:14 +01:00
|
|
|
#endif /* __ROOT_VIEW_HPP__ */
|