mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2025-04-06 03:58:02 +08:00
Fix potential crash when removing a TitleDB entry to replace with a newer version, add loading indicator to TitleDB list.
This commit is contained in:
parent
0c28a4b604
commit
a59b8f4056
@ -68,6 +68,9 @@ static void task_populate_titledb_thread(void* arg) {
|
||||
json_value* json = json_parse(text, textSize);
|
||||
if(json != NULL) {
|
||||
if(json->type == json_array) {
|
||||
linked_list titles;
|
||||
linked_list_init(&titles);
|
||||
|
||||
for(u32 i = 0; i < json->u.array.length && R_SUCCEEDED(res); i++) {
|
||||
svcWaitSynchronization(task_get_pause_event(), U64_MAX);
|
||||
if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) {
|
||||
@ -123,7 +126,7 @@ static void task_populate_titledb_thread(void* arg) {
|
||||
task_populate_titledb_update_status(item);
|
||||
|
||||
linked_list_iter iter;
|
||||
linked_list_iterate(data->items, &iter);
|
||||
linked_list_iterate(&titles, &iter);
|
||||
|
||||
bool add = true;
|
||||
while(linked_list_iter_has_next(&iter)) {
|
||||
@ -143,7 +146,7 @@ static void task_populate_titledb_thread(void* arg) {
|
||||
}
|
||||
|
||||
if(add) {
|
||||
linked_list_add_sorted(data->items, item, NULL, task_populate_titledb_compare);
|
||||
linked_list_add_sorted(&titles, item, NULL, task_populate_titledb_compare);
|
||||
} else {
|
||||
task_free_titledb(item);
|
||||
}
|
||||
@ -157,6 +160,21 @@ static void task_populate_titledb_thread(void* arg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
linked_list_iter iter;
|
||||
linked_list_iterate(&titles, &iter);
|
||||
|
||||
while(linked_list_iter_has_next(&iter)) {
|
||||
list_item* item = linked_list_iter_next(&iter);
|
||||
|
||||
if(R_SUCCEEDED(res)) {
|
||||
linked_list_add(data->items, item);
|
||||
} else {
|
||||
task_free_titledb(item);
|
||||
}
|
||||
}
|
||||
|
||||
linked_list_destroy(&titles);
|
||||
} else {
|
||||
res = R_FBI_BAD_DATA;
|
||||
}
|
||||
@ -170,6 +188,8 @@ static void task_populate_titledb_thread(void* arg) {
|
||||
res = R_FBI_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
data->itemsListed = true;
|
||||
|
||||
if(R_SUCCEEDED(res)) {
|
||||
linked_list_iter iter;
|
||||
linked_list_iterate(data->items, &iter);
|
||||
@ -242,6 +262,7 @@ Result task_populate_titledb(populate_titledb_data* data) {
|
||||
|
||||
task_clear_titledb(data->items);
|
||||
|
||||
data->itemsListed = false;
|
||||
data->finished = false;
|
||||
data->result = 0;
|
||||
data->cancelEvent = 0;
|
||||
@ -254,6 +275,7 @@ Result task_populate_titledb(populate_titledb_data* data) {
|
||||
}
|
||||
|
||||
if(R_FAILED(res)) {
|
||||
data->itemsListed = true;
|
||||
data->finished = true;
|
||||
|
||||
if(data->cancelEvent != 0) {
|
||||
|
@ -217,6 +217,7 @@ typedef struct populate_titles_data_s {
|
||||
typedef struct populate_titledb_data_s {
|
||||
linked_list* items;
|
||||
|
||||
volatile bool itemsListed;
|
||||
volatile bool finished;
|
||||
Result result;
|
||||
Handle cancelEvent;
|
||||
|
@ -80,7 +80,16 @@ static void titledb_action_open(linked_list* items, list_item* selected) {
|
||||
}
|
||||
|
||||
static void titledb_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) {
|
||||
if(selected != NULL && selected->data != NULL) {
|
||||
titledb_data* listData = (titledb_data*) data;
|
||||
|
||||
if(!listData->populateData.itemsListed) {
|
||||
static const char* text = "Loading title list, please wait...\nNOTE: Cancelling may take up to 15 seconds.";
|
||||
|
||||
float textWidth;
|
||||
float textHeight;
|
||||
screen_get_string_size(&textWidth, &textHeight, text, 0.5f, 0.5f);
|
||||
screen_draw_string(text, x1 + (x2 - x1 - textWidth) / 2, y1 + (y2 - y1 - textHeight) / 2, 0.5f, 0.5f, COLOR_TEXT, true);
|
||||
} else if(selected != NULL && selected->data != NULL) {
|
||||
ui_draw_titledb_info(view, selected->data, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user