Skip to content

Commit

Permalink
[ci skip] GameCardImageDumpOptionsFrame: add gamecard task subscription
Browse files Browse the repository at this point in the history
Lets us pop the frame itself from the view stack as soon as the gamecard is ejected. We're all about making this as fool-proof as possible.
  • Loading branch information
DarkMatterCore committed Apr 21, 2024
1 parent 1181a95 commit ec99386
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/dump_options_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ namespace nxdt::views
{
class DumpOptionsFrame: public brls::ThumbnailFrame
{
private:
protected:
RootView *root_view = nullptr;

private:
std::string storage_prefix{}, base_output_path{}, raw_filename{}, extension{};

brls::List *list = nullptr;
Expand Down
14 changes: 14 additions & 0 deletions include/gamecard_image_dump_options_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace nxdt::views
class GameCardImageDumpOptionsFrame: public DumpOptionsFrame
{
private:
nxdt::tasks::GameCardStatusEvent::Subscription gc_task_sub;
brls::VoidEvent gc_ejected_event;

brls::ToggleListItem *prepend_key_area = nullptr;
brls::ToggleListItem *keep_certificate = nullptr;
brls::ToggleListItem *trim_dump = nullptr;
Expand All @@ -39,6 +42,17 @@ namespace nxdt::views

public:
GameCardImageDumpOptionsFrame(RootView *root_view, std::string raw_filename);
~GameCardImageDumpOptionsFrame();

ALWAYS_INLINE brls::VoidEvent::Subscription RegisterGameCardEjectionListener(brls::VoidEvent::Callback cb)
{
return this->gc_ejected_event.subscribe(cb);
}

ALWAYS_INLINE void UnregisterGameCardEjectionListener(brls::VoidEvent::Subscription subscription)
{
this->gc_ejected_event.unsubscribe(subscription);
}
};
}

Expand Down
2 changes: 1 addition & 1 deletion source/dump_options_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace nxdt::views
/* Unregister all button click event listeners. */
this->button_click_event->unsubscribeAll();

/* Unregister task listener. */
/* Unregister UMS task listener. */
this->root_view->UnregisterUmsTaskListener(this->ums_task_sub);
}

Expand Down
2 changes: 1 addition & 1 deletion source/error_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace nxdt::views
{
ErrorFrame::ErrorFrame(std::string msg): brls::View()
ErrorFrame::ErrorFrame(std::string msg) : brls::View()
{
this->label = new brls::Label(brls::LabelStyle::REGULAR, msg, true);
this->label->setHorizontalAlign(NVG_ALIGN_CENTER);
Expand Down
21 changes: 21 additions & 0 deletions source/gamecard_image_dump_options_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ namespace nxdt::views
GameCardImageDumpOptionsFrame::GameCardImageDumpOptionsFrame(RootView *root_view, std::string raw_filename) :
DumpOptionsFrame(root_view, "gamecard_tab/list/dump_card_image/label"_i18n, std::string(GAMECARD_SUBDIR), raw_filename, std::string(".xci"))
{
/* Subscribe to the gamecard task event. */
this->gc_task_sub = this->root_view->RegisterGameCardTaskListener([this](const GameCardStatus& gc_status) {
/* Realistically speaking, this should always match a NotInserted status, but it's always better to be safe than sorry. */
if (gc_status != GameCardStatus_NotInserted) return;

/* Fire gamecard ejection event. */
this->gc_ejected_event.fire();

/* Pop view from stack immediately. */
brls::Application::popView();
});

/* Prepend KeyArea data. */
this->prepend_key_area = new brls::ToggleListItem("dump_options/prepend_key_area/label"_i18n, configGetBoolean("gamecard/prepend_key_area"), "dump_options/prepend_key_area/description"_i18n,
"generic/value_enabled"_i18n, "generic/value_disabled"_i18n);
Expand Down Expand Up @@ -141,4 +153,13 @@ namespace nxdt::views
LOG_MSG_DEBUG("Output file path: %s", this->GetOutputFilePath().c_str());
});
}

GameCardImageDumpOptionsFrame::~GameCardImageDumpOptionsFrame()
{
/* Unregister all gamecard ejection event listeners. */
this->gc_ejected_event.unsubscribeAll();

/* Unregister gamecard task listener. */
this->root_view->UnregisterGameCardTaskListener(this->gc_task_sub);
}
}

0 comments on commit ec99386

Please sign in to comment.