mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-22 10:16:39 +00:00
TitleMetadataTask: use a struct instead of a vector
The struct has been typedef'd as TitleApplicationMetadataInfo. It holds the pointer to the array returned by titleGetApplicationMetadataEntries(), as well as the number of elements available in the array. There's no point in populating a vector when we already have an array we can work with.
This commit is contained in:
parent
5cc387c9b6
commit
d9c8d93180
5 changed files with 38 additions and 45 deletions
|
@ -31,23 +31,26 @@
|
|||
|
||||
namespace nxdt::tasks
|
||||
{
|
||||
/* Used to hold pointers to application metadata entries. */
|
||||
typedef std::vector<TitleApplicationMetadata*> TitleApplicationMetadataVector;
|
||||
/* Used to hold an application metadata array + its number of elements. */
|
||||
typedef struct {
|
||||
TitleApplicationMetadata **app_metadata;
|
||||
u32 app_metadata_count;
|
||||
} TitleApplicationMetadataInfo;
|
||||
|
||||
/* Custom event type. */
|
||||
typedef brls::Event<const TitleApplicationMetadataVector&> UserTitleEvent;
|
||||
typedef brls::Event<const TitleApplicationMetadataInfo&> UserTitleEvent;
|
||||
|
||||
/* Title metadata task. */
|
||||
/* Its event provides a const reference to a TitleApplicationMetadataVector with metadata for user titles (system titles don't change at runtime). */
|
||||
/* Its event provides a const reference to a TitleApplicationMetadataInfo with metadata for user titles (system titles don't change at runtime). */
|
||||
class TitleMetadataTask: public brls::RepeatingTask
|
||||
{
|
||||
private:
|
||||
UserTitleEvent user_title_event;
|
||||
|
||||
TitleApplicationMetadataVector system_metadata{};
|
||||
TitleApplicationMetadataVector user_metadata{};
|
||||
TitleApplicationMetadataInfo system_metadata_info{};
|
||||
TitleApplicationMetadataInfo user_metadata_info{};
|
||||
|
||||
void PopulateApplicationMetadataVector(bool is_system);
|
||||
void PopulateApplicationMetadataInfo(bool is_system);
|
||||
|
||||
protected:
|
||||
void run(retro_time_t current_time) override;
|
||||
|
@ -57,9 +60,9 @@ namespace nxdt::tasks
|
|||
~TitleMetadataTask();
|
||||
|
||||
/* Intentionally left here to let views retrieve title metadata on-demand. */
|
||||
ALWAYS_INLINE const TitleApplicationMetadataVector& GetApplicationMetadata(bool is_system)
|
||||
ALWAYS_INLINE const TitleApplicationMetadataInfo& GetApplicationMetadataInfo(bool is_system)
|
||||
{
|
||||
return (is_system ? this->system_metadata : this->user_metadata);
|
||||
return (is_system ? this->system_metadata_info : this->user_metadata_info);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE UserTitleEvent::Subscription RegisterListener(UserTitleEvent::Callback cb)
|
||||
|
|
|
@ -95,9 +95,9 @@ namespace nxdt::views
|
|||
return this->gc_status_task->GetGameCardStatus();
|
||||
}
|
||||
|
||||
ALWAYS_INLINE const nxdt::tasks::TitleApplicationMetadataVector& GetApplicationMetadata(bool is_system)
|
||||
ALWAYS_INLINE const nxdt::tasks::TitleApplicationMetadataInfo& GetApplicationMetadataInfo(bool is_system)
|
||||
{
|
||||
return this->title_metadata_task->GetApplicationMetadata(is_system);
|
||||
return this->title_metadata_task->GetApplicationMetadataInfo(is_system);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE const nxdt::tasks::UmsDeviceVector& GetUmsDevices(void)
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace nxdt::views
|
|||
nxdt::tasks::UserTitleEvent::Subscription title_task_sub;
|
||||
bool is_system = false;
|
||||
|
||||
void PopulateList(const nxdt::tasks::TitleApplicationMetadataVector& app_metadata);
|
||||
void PopulateList(const nxdt::tasks::TitleApplicationMetadataInfo& app_metadata_info);
|
||||
|
||||
public:
|
||||
TitlesTab(RootView *root_view, bool is_system);
|
||||
|
|
|
@ -30,10 +30,10 @@ namespace nxdt::tasks
|
|||
LOG_MSG_DEBUG("Title metadata task started.");
|
||||
|
||||
/* Get system metadata entries. */
|
||||
this->PopulateApplicationMetadataVector(true);
|
||||
this->PopulateApplicationMetadataInfo(true);
|
||||
|
||||
/* Get user metadata entries. */
|
||||
this->PopulateApplicationMetadataVector(false);
|
||||
this->PopulateApplicationMetadataInfo(false);
|
||||
|
||||
/* Start task. */
|
||||
brls::RepeatingTask::start();
|
||||
|
@ -41,9 +41,9 @@ namespace nxdt::tasks
|
|||
|
||||
TitleMetadataTask::~TitleMetadataTask()
|
||||
{
|
||||
/* Clear application metadata vectors. */
|
||||
this->system_metadata.clear();
|
||||
this->user_metadata.clear();
|
||||
/* Free application metadata arrays. */
|
||||
if (this->system_metadata_info.app_metadata) free(this->system_metadata_info.app_metadata);
|
||||
if (this->user_metadata_info.app_metadata) free(this->user_metadata_info.app_metadata);
|
||||
|
||||
LOG_MSG_DEBUG("Title metadata task stopped.");
|
||||
}
|
||||
|
@ -54,37 +54,27 @@ namespace nxdt::tasks
|
|||
|
||||
if (titleIsGameCardInfoUpdated())
|
||||
{
|
||||
/* Update user metadata vector. */
|
||||
this->PopulateApplicationMetadataVector(false);
|
||||
/* Update user metadata array. */
|
||||
this->PopulateApplicationMetadataInfo(false);
|
||||
|
||||
/* Fire task event. */
|
||||
this->user_title_event.fire(this->user_metadata);
|
||||
this->user_title_event.fire(this->user_metadata_info);
|
||||
|
||||
//brls::Application::notify("tasks/notifications/user_titles"_i18n);
|
||||
LOG_MSG_DEBUG("Title info updated.");
|
||||
}
|
||||
}
|
||||
|
||||
void TitleMetadataTask::PopulateApplicationMetadataVector(bool is_system)
|
||||
void TitleMetadataTask::PopulateApplicationMetadataInfo(bool is_system)
|
||||
{
|
||||
TitleApplicationMetadata **app_metadata = nullptr;
|
||||
u32 app_metadata_count = 0;
|
||||
|
||||
/* Get pointer to output vector. */
|
||||
TitleApplicationMetadataVector& vector = (is_system ? this->system_metadata : this->user_metadata);
|
||||
vector.clear();
|
||||
/* Get reference to output struct. */
|
||||
TitleApplicationMetadataInfo& info = (is_system ? this->system_metadata_info : this->user_metadata_info);
|
||||
if (info.app_metadata) free(info.app_metadata);
|
||||
info.app_metadata_count = 0;
|
||||
|
||||
/* Get application metadata entries. */
|
||||
app_metadata = titleGetApplicationMetadataEntries(is_system, &app_metadata_count);
|
||||
if (app_metadata)
|
||||
{
|
||||
/* Fill output vector. */
|
||||
for(u32 i = 0; i < app_metadata_count; i++) vector.push_back(app_metadata[i]);
|
||||
info.app_metadata = titleGetApplicationMetadataEntries(is_system, &(info.app_metadata_count));
|
||||
|
||||
/* Free application metadata array. */
|
||||
free(app_metadata);
|
||||
}
|
||||
|
||||
LOG_MSG_DEBUG("Retrieved %u %s metadata %s.", app_metadata_count, is_system ? "system" : "user", app_metadata_count == 1 ? "entry" : "entries");
|
||||
LOG_MSG_DEBUG("Retrieved %u %s metadata %s.", info.app_metadata_count, is_system ? "system" : "user", info.app_metadata_count == 1 ? "entry" : "entries");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,14 +82,14 @@ namespace nxdt::views
|
|||
TitlesTab::TitlesTab(RootView *root_view, bool is_system) : LayeredErrorFrame("titles_tab/no_titles_available"_i18n), root_view(root_view), is_system(is_system)
|
||||
{
|
||||
/* Populate list. */
|
||||
this->PopulateList(this->root_view->GetApplicationMetadata(this->is_system));
|
||||
this->PopulateList(this->root_view->GetApplicationMetadataInfo(this->is_system));
|
||||
|
||||
/* Subscribe to the title event if this is the user titles tab. */
|
||||
if (!this->is_system)
|
||||
{
|
||||
this->title_task_sub = this->root_view->RegisterTitleMetadataTaskListener([this](const nxdt::tasks::TitleApplicationMetadataVector& app_metadata) {
|
||||
this->title_task_sub = this->root_view->RegisterTitleMetadataTaskListener([this](const nxdt::tasks::TitleApplicationMetadataInfo& app_metadata_info) {
|
||||
/* Update list. */
|
||||
this->PopulateList(app_metadata);
|
||||
this->PopulateList(app_metadata_info);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -100,34 +100,34 @@ namespace nxdt::views
|
|||
if (!this->is_system) this->root_view->UnregisterTitleMetadataTaskListener(this->title_task_sub);
|
||||
}
|
||||
|
||||
void TitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataVector& app_metadata)
|
||||
void TitlesTab::PopulateList(const nxdt::tasks::TitleApplicationMetadataInfo& app_metadata_info)
|
||||
{
|
||||
/* Block user inputs. */
|
||||
brls::Application::blockInputs();
|
||||
|
||||
/* Populate variables. */
|
||||
size_t app_metadata_count = app_metadata.size();
|
||||
bool update_focused_view = this->IsListItemFocused();
|
||||
int focus_stack_index = this->GetFocusStackViewIndex();
|
||||
|
||||
/* If needed, switch to the error frame *before* cleaning up our list. */
|
||||
if (!app_metadata_count) this->SwitchLayerView(true);
|
||||
if (!app_metadata_info.app_metadata_count) this->SwitchLayerView(true);
|
||||
|
||||
/* Clear list. */
|
||||
this->list->clear();
|
||||
this->list->invalidate(true);
|
||||
|
||||
/* Return immediately if we have no application metadata. */
|
||||
if (!app_metadata_count)
|
||||
if (!app_metadata_info.app_metadata_count)
|
||||
{
|
||||
brls::Application::unblockInputs();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Populate list. */
|
||||
for(const TitleApplicationMetadata *cur_app_metadata : app_metadata)
|
||||
for(u32 i = 0; i < app_metadata_info.app_metadata_count; i++)
|
||||
{
|
||||
/* Create list item. */
|
||||
const TitleApplicationMetadata *cur_app_metadata = app_metadata_info.app_metadata[i];
|
||||
TitlesTabItem *item = new TitlesTabItem(cur_app_metadata, this->is_system);
|
||||
|
||||
/* Register click event. */
|
||||
|
|
Loading…
Reference in a new issue