diff --git a/source/ui/error.c b/source/ui/error.c index d0aa690..e2c71a8 100644 --- a/source/ui/error.c +++ b/source/ui/error.c @@ -562,7 +562,6 @@ static void error_onresponse(ui_view* view, void* data, bool response) { *errorData->dismissed = true; } - prompt_destroy(view); free(data); } @@ -577,7 +576,7 @@ void error_display(volatile bool* dismissed, void* data, void (*drawTop)(ui_view vsnprintf(errorData->fullText, 4096, text, list); va_end(list); - ui_push(prompt_create("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse)); + prompt_display("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse); } void error_display_res(volatile bool* dismissed, void* data, void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), Result result, const char* text, ...) { @@ -598,7 +597,7 @@ void error_display_res(volatile bool* dismissed, void* data, void (*drawTop)(ui_ int description = R_DESCRIPTION(result); snprintf(errorData->fullText, 4096, "%s\nResult code: 0x%08lX\nLevel: %s (%d)\nSummary: %s (%d)\nModule: %s (%d)\nDesc: %s (%d)", textBuf, result, level_to_string(result), level, summary_to_string(result), summary, module_to_string(result), module, description_to_string(result), description); - ui_push(prompt_create("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse)); + prompt_display("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse); } void error_display_errno(volatile bool* dismissed, void* data, void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), int err, const char* text, ...) { @@ -613,7 +612,7 @@ void error_display_errno(volatile bool* dismissed, void* data, void (*drawTop)(u vsnprintf(textBuf, 1024, text, list); va_end(list); - snprintf(errorData->fullText, 4096, "%s\nError: %s (%d)", textBuf, strerror(err), err); + snprintf(errorData->fullText, 4096, "%s\nI/O Error: %s (%d)", textBuf, strerror(err), err); - ui_push(prompt_create("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse)); + prompt_display("Error", errorData->fullText, COLOR_TEXT, false, errorData, NULL, error_draw_top, error_onresponse); } \ No newline at end of file diff --git a/source/ui/info.c b/source/ui/info.c new file mode 100644 index 0000000..8a4a037 --- /dev/null +++ b/source/ui/info.c @@ -0,0 +1,88 @@ +#include <3ds.h> +#include + +#include "info.h" +#include "../screen.h" + +typedef struct { + bool bar; + void* data; + float progress; + char text[PROGRESS_TEXT_MAX]; + void (*update)(ui_view* view, void* data, float* progress, char* text); + void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2); +} info_data; + +static void info_update(ui_view* view, void* data, float bx1, float by1, float bx2, float by2) { + info_data* infoData = (info_data*) data; + + if(infoData->update != NULL) { + infoData->update(view, infoData->data, &infoData->progress, infoData->text); + } +} + +static void info_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { + info_data* infoData = (info_data*) data; + + if(infoData->drawTop != NULL) { + infoData->drawTop(view, infoData->data, x1, y1, x2, y2); + } +} + +static void info_draw_bottom(ui_view* view, void* data, float x1, float y1, float x2, float y2) { + info_data* infoData = (info_data*) data; + + float textWidth; + float textHeight; + screen_get_string_size(&textWidth, &textHeight, infoData->text, 0.5f, 0.5f); + + float textX = x1 + (x2 - x1 - textWidth) / 2; + float textY = y1 + (y2 - y1 - textHeight) / 2; + + if(infoData->bar) { + u32 progressBarBgWidth; + u32 progressBarBgHeight; + screen_get_texture_size(&progressBarBgWidth, &progressBarBgHeight, TEXTURE_PROGRESS_BAR_BG); + + float progressBarBgX = x1 + (x2 - x1 - progressBarBgWidth) / 2; + float progressBarBgY = y1 + (y2 - y1 - progressBarBgHeight) / 2; + screen_draw_texture(TEXTURE_PROGRESS_BAR_BG, progressBarBgX, progressBarBgY, progressBarBgWidth, progressBarBgHeight); + + u32 progressBarContentWidth; + u32 progressBarContentHeight; + screen_get_texture_size(&progressBarContentWidth, &progressBarContentHeight, TEXTURE_PROGRESS_BAR_CONTENT); + + float progressBarContentX = x1 + (x2 - x1 - progressBarContentWidth) / 2; + float progressBarContentY = y1 + (y2 - y1 - progressBarContentHeight) / 2; + screen_draw_texture_crop(TEXTURE_PROGRESS_BAR_CONTENT, progressBarContentX, progressBarContentY, progressBarContentWidth * infoData->progress, progressBarContentHeight); + + textX = x1 + (x2 - x1 - textWidth) / 2; + textY = progressBarBgY + progressBarBgHeight + 10; + } + + screen_draw_string(infoData->text, textX, textY, 0.5f, 0.5f, COLOR_TEXT, false); +} + +void info_display(const char* name, const char* info, bool bar, void* data, void (*update)(ui_view* view, void* data, float* progress, char* text), + void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2)) { + info_data* infoData = (info_data*) calloc(1, sizeof(info_data)); + infoData->bar = bar; + infoData->data = data; + infoData->progress = 0; + infoData->update = update; + infoData->drawTop = drawTop; + + ui_view* view = (ui_view*) calloc(1, sizeof(ui_view)); + view->name = name; + view->info = info; + view->data = infoData; + view->update = info_update; + view->drawTop = info_draw_top; + view->drawBottom = info_draw_bottom; + ui_push(view); +} + +void info_destroy(ui_view* view) { + free(view->data); + free(view); +} \ No newline at end of file diff --git a/source/ui/progressbar.h b/source/ui/info.h similarity index 55% rename from source/ui/progressbar.h rename to source/ui/info.h index b3c5196..8e2f729 100644 --- a/source/ui/progressbar.h +++ b/source/ui/info.h @@ -4,8 +4,6 @@ #define PROGRESS_TEXT_MAX 512 -ui_view* progressbar_create(const char* name, const char* info, void* data, void (*update)(ui_view* view, void* data, float* progress, char* progressText), +void info_display(const char* name, const char* info, bool bar, void* data, void (*update)(ui_view* view, void* data, float* progress, char* text), void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2)); -void progressbar_destroy(ui_view* view); -void* progressbar_get_data(ui_view* view); -char* progressbar_get_progress_text(ui_view* view); \ No newline at end of file +void info_destroy(ui_view* view); \ No newline at end of file diff --git a/source/ui/list.c b/source/ui/list.c index 939c52d..76493da 100644 --- a/source/ui/list.c +++ b/source/ui/list.c @@ -209,8 +209,8 @@ static void list_draw_bottom(ui_view* view, void* data, float x1, float y1, floa } } -ui_view* list_create(const char* name, const char* info, void* data, void (*update)(ui_view* view, void* data, list_item** contents, u32** itemCount, list_item* selected, bool selectedTouched), - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected)) { +void list_display(const char* name, const char* info, void* data, void (*update)(ui_view* view, void* data, list_item** contents, u32** itemCount, list_item* selected, bool selectedTouched), + void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected)) { list_data* listData = (list_data*) calloc(1, sizeof(list_data)); listData->data = data; listData->items = NULL; @@ -230,14 +230,10 @@ ui_view* list_create(const char* name, const char* info, void* data, void (*upda view->update = list_update; view->drawTop = list_draw_top; view->drawBottom = list_draw_bottom; - return view; + ui_push(view); } void list_destroy(ui_view* view) { free(view->data); free(view); -} - -void* list_get_data(ui_view* view) { - return ((list_data*) view->data)->data; } \ No newline at end of file diff --git a/source/ui/list.h b/source/ui/list.h index 98427e2..e233c57 100644 --- a/source/ui/list.h +++ b/source/ui/list.h @@ -10,7 +10,6 @@ typedef struct { void* data; } list_item; -ui_view* list_create(const char* name, const char* info, void* data, void (*update)(ui_view* view, void* data, list_item** contents, u32** itemCount, list_item* selected, bool selectedTouched), - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected)); -void list_destroy(ui_view* view); -void* list_get_data(ui_view* view); \ No newline at end of file +void list_display(const char* name, const char* info, void* data, void (*update)(ui_view* view, void* data, list_item** contents, u32** itemCount, list_item* selected, bool selectedTouched), + void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected)); +void list_destroy(ui_view* view); \ No newline at end of file diff --git a/source/ui/mainmenu.c b/source/ui/mainmenu.c index c47ad51..0752f29 100644 --- a/source/ui/mainmenu.c +++ b/source/ui/mainmenu.c @@ -66,5 +66,5 @@ static void mainmenu_update(ui_view* view, void* data, list_item** items, u32** } void mainmenu_open() { - ui_push(list_create("Main Menu", "A: Select, START: Exit", NULL, mainmenu_update, mainmenu_draw_top)); + list_display("Main Menu", "A: Select, START: Exit", NULL, mainmenu_update, mainmenu_draw_top); } diff --git a/source/ui/progressbar.c b/source/ui/progressbar.c deleted file mode 100644 index 490cdad..0000000 --- a/source/ui/progressbar.c +++ /dev/null @@ -1,89 +0,0 @@ -#include <3ds.h> -#include - -#include "progressbar.h" -#include "../screen.h" - -typedef struct { - bool cancellable; - void* data; - float progress; - char progressText[PROGRESS_TEXT_MAX]; - void (*update)(ui_view* view, void* data, float* progress, char* progressText); - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2); -} progressbar_data; - -static void progressbar_update(ui_view* view, void* data, float bx1, float by1, float bx2, float by2) { - progressbar_data* progressBarData = (progressbar_data*) data; - - if(progressBarData->update != NULL) { - progressBarData->update(view, progressBarData->data, &progressBarData->progress, progressBarData->progressText); - } -} - -static void progressbar_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { - progressbar_data* progressBarData = (progressbar_data*) data; - - if(progressBarData->drawTop != NULL) { - progressBarData->drawTop(view, progressBarData->data, x1, y1, x2, y2); - } -} - -static void progressbar_draw_bottom(ui_view* view, void* data, float x1, float y1, float x2, float y2) { - progressbar_data* progressBarData = (progressbar_data*) data; - - u32 progressBarBgWidth; - u32 progressBarBgHeight; - screen_get_texture_size(&progressBarBgWidth, &progressBarBgHeight, TEXTURE_PROGRESS_BAR_BG); - - float progressBarBgX = x1 + (x2 - x1 - progressBarBgWidth) / 2; - float progressBarBgY = y1 + (y2 - y1 - progressBarBgHeight) / 2; - screen_draw_texture(TEXTURE_PROGRESS_BAR_BG, progressBarBgX, progressBarBgY, progressBarBgWidth, progressBarBgHeight); - - u32 progressBarContentWidth; - u32 progressBarContentHeight; - screen_get_texture_size(&progressBarContentWidth, &progressBarContentHeight, TEXTURE_PROGRESS_BAR_CONTENT); - - float progressBarContentX = x1 + (x2 - x1 - progressBarContentWidth) / 2; - float progressBarContentY = y1 + (y2 - y1 - progressBarContentHeight) / 2; - screen_draw_texture_crop(TEXTURE_PROGRESS_BAR_CONTENT, progressBarContentX, progressBarContentY, progressBarContentWidth * progressBarData->progress, progressBarContentHeight); - - float progressTextWidth; - float progressTextHeight; - screen_get_string_size(&progressTextWidth, &progressTextHeight, progressBarData->progressText, 0.5f, 0.5f); - - float progressTextX = x1 + (x2 - x1 - progressTextWidth) / 2; - float progressTextY = progressBarBgY + progressBarBgHeight + 10; - screen_draw_string(progressBarData->progressText, progressTextX, progressTextY, 0.5f, 0.5f, COLOR_TEXT, false); -} - -ui_view* progressbar_create(const char* name, const char* info, void* data, void (*update)(ui_view* view, void* data, float* progress, char* progressText), - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2)) { - progressbar_data* progressBarData = (progressbar_data*) calloc(1, sizeof(progressbar_data)); - progressBarData->data = data; - progressBarData->progress = 0; - progressBarData->update = update; - progressBarData->drawTop = drawTop; - - ui_view* view = (ui_view*) calloc(1, sizeof(ui_view)); - view->name = name; - view->info = info; - view->data = progressBarData; - view->update = progressbar_update; - view->drawTop = progressbar_draw_top; - view->drawBottom = progressbar_draw_bottom; - return view; -} - -void progressbar_destroy(ui_view* view) { - free(view->data); - free(view); -} - -void* progressbar_get_data(ui_view* view) { - return ((progressbar_data*) view->data)->data; -} - -char* progressbar_get_progress_text(ui_view* view) { - return ((progressbar_data*) view->data)->progressText; -} \ No newline at end of file diff --git a/source/ui/prompt.c b/source/ui/prompt.c index 294296e..6b37526 100644 --- a/source/ui/prompt.c +++ b/source/ui/prompt.c @@ -14,61 +14,62 @@ typedef struct { void (*onResponse)(ui_view* view, void* data, bool response); } prompt_data; -static void notify_response(ui_view* view, prompt_data* promptData, bool response) { +static void prompt_notify_response(ui_view* view, prompt_data* promptData, bool response) { ui_pop(); if(promptData->onResponse != NULL) { promptData->onResponse(view, promptData->data, response); } + + free(promptData); + free(view); } static void prompt_update(ui_view* view, void* data, float bx1, float by1, float bx2, float by2) { prompt_data* promptData = (prompt_data*) data; - if(promptData->onResponse != NULL) { - if(!promptData->option && (hidKeysDown() & ~KEY_TOUCH)) { - notify_response(view, promptData, false); - return; - } + if(!promptData->option && (hidKeysDown() & ~KEY_TOUCH)) { + prompt_notify_response(view, promptData, false); + return; + } - if(promptData->option && (hidKeysDown() & (KEY_A | KEY_B))) { - notify_response(view, promptData, (bool) (hidKeysDown() & KEY_A)); - return; - } + if(promptData->option && (hidKeysDown() & (KEY_A | KEY_B))) { + prompt_notify_response(view, promptData, (bool) (hidKeysDown() & KEY_A)); + return; + } - if(hidKeysDown() & KEY_TOUCH) { - touchPosition pos; - hidTouchRead(&pos); + if(hidKeysDown() & KEY_TOUCH) { + touchPosition pos; + hidTouchRead(&pos); - if(promptData->option) { - u32 buttonWidth; - u32 buttonHeight; - screen_get_texture_size(&buttonWidth, &buttonHeight, TEXTURE_BUTTON_SMALL); + if(promptData->option) { + u32 buttonWidth; + u32 buttonHeight; + screen_get_texture_size(&buttonWidth, &buttonHeight, TEXTURE_BUTTON_SMALL); - float yesButtonX = bx1 + (bx2 - bx1) / 2 - 5 - buttonWidth; - float yesButtonY = by2 - 5 - buttonHeight; - if(pos.px >= yesButtonX && pos.py >= yesButtonY && pos.px < yesButtonX + buttonWidth && pos.py < yesButtonY + buttonHeight) { - notify_response(view, promptData, true); - return; - } + float yesButtonX = bx1 + (bx2 - bx1) / 2 - 5 - buttonWidth; + float yesButtonY = by2 - 5 - buttonHeight; + if(pos.px >= yesButtonX && pos.py >= yesButtonY && pos.px < yesButtonX + buttonWidth && pos.py < yesButtonY + buttonHeight) { + prompt_notify_response(view, promptData, true); + return; + } - float noButtonX = bx1 + (bx2 - bx1) / 2 + 5; - float noButtonY = by2 - 5 - buttonHeight; - if(pos.px >= noButtonX && pos.py >= noButtonY && pos.px < noButtonX + buttonWidth && pos.py < noButtonY + buttonHeight) { - notify_response(view, promptData, false); - return; - } - } else { - u32 buttonWidth; - u32 buttonHeight; - screen_get_texture_size(&buttonWidth, &buttonHeight, TEXTURE_BUTTON_LARGE); + float noButtonX = bx1 + (bx2 - bx1) / 2 + 5; + float noButtonY = by2 - 5 - buttonHeight; + if(pos.px >= noButtonX && pos.py >= noButtonY && pos.px < noButtonX + buttonWidth && pos.py < noButtonY + buttonHeight) { + prompt_notify_response(view, promptData, false); + return; + } + } else { + u32 buttonWidth; + u32 buttonHeight; + screen_get_texture_size(&buttonWidth, &buttonHeight, TEXTURE_BUTTON_LARGE); - float okayButtonX = bx1 + (bx2 - bx1 - buttonWidth) / 2; - float okayButtonY = by2 - 5 - buttonHeight; - if(pos.px >= okayButtonX && pos.py >= okayButtonY && pos.px < okayButtonX + buttonWidth && pos.py < okayButtonY + buttonHeight) { - notify_response(view, promptData, false); - return; - } + float okayButtonX = bx1 + (bx2 - bx1 - buttonWidth) / 2; + float okayButtonY = by2 - 5 - buttonHeight; + if(pos.px >= okayButtonX && pos.py >= okayButtonY && pos.px < okayButtonX + buttonWidth && pos.py < okayButtonY + buttonHeight) { + prompt_notify_response(view, promptData, false); + return; } } } @@ -135,9 +136,9 @@ static void prompt_draw_bottom(ui_view* view, void* data, float x1, float y1, fl screen_draw_string(promptData->text, x1 + (x2 - x1 - textWidth) / 2, y1 + (y2 - 5 - buttonHeight - y1 - textHeight) / 2, 0.5f, 0.5f, promptData->rgba, false); } -ui_view* prompt_create(const char* name, const char* text, u32 rgba, bool option, void* data, void (*update)(ui_view* view, void* data), - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), - void (*onResponse)(ui_view* view, void* data, bool response)) { +void prompt_display(const char* name, const char* text, u32 rgba, bool option, void* data, void (*update)(ui_view* view, void* data), + void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), + void (*onResponse)(ui_view* view, void* data, bool response)) { prompt_data* promptData = (prompt_data*) calloc(1, sizeof(prompt_data)); promptData->text = text; promptData->rgba = rgba; @@ -154,14 +155,5 @@ ui_view* prompt_create(const char* name, const char* text, u32 rgba, bool option view->update = prompt_update; view->drawTop = prompt_draw_top; view->drawBottom = prompt_draw_bottom; - return view; -} - -void prompt_destroy(ui_view* view) { - free(view->data); - free(view); -} - -void* prompt_get_data(ui_view* view) { - return ((prompt_data*) view->data)->data; + ui_push(view); } \ No newline at end of file diff --git a/source/ui/prompt.h b/source/ui/prompt.h index 977903b..5206561 100644 --- a/source/ui/prompt.h +++ b/source/ui/prompt.h @@ -2,8 +2,6 @@ #include "ui.h" -ui_view* prompt_create(const char* name, const char* text, u32 rgba, bool option, void* data, void (*update)(ui_view* view, void* data), - void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), - void (*onResponse)(ui_view* view, void* data, bool response)); -void prompt_destroy(ui_view* view); -void* prompt_get_data(ui_view* view); \ No newline at end of file +void prompt_display(const char* name, const char* text, u32 rgba, bool option, void* data, void (*update)(ui_view* view, void* data), + void (*drawTop)(ui_view* view, void* data, float x1, float y1, float x2, float y2), + void (*onResponse)(ui_view* view, void* data, bool response)); \ No newline at end of file diff --git a/source/ui/section/action/copyfiles.c b/source/ui/section/action/copyfiles.c index 99fd595..c2d76b7 100644 --- a/source/ui/section/action/copyfiles.c +++ b/source/ui/section/action/copyfiles.c @@ -6,10 +6,6 @@ #include "../../prompt.h" #include "../../../screen.h" -static void action_copy_files_success_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - void action_copy_contents(file_info* info, bool* populated) { Result res = 0; if(R_FAILED(res = clipboard_set_contents(*info->archive, info->path))) { @@ -18,5 +14,5 @@ void action_copy_contents(file_info* info, bool* populated) { return; } - ui_push(prompt_create("Success", "Content copied to clipboard.", COLOR_TEXT, false, info, NULL, ui_draw_file_info, action_copy_files_success_onresponse)); + prompt_display("Success", "Content copied to clipboard.", COLOR_TEXT, false, info, NULL, ui_draw_file_info, NULL); } \ No newline at end of file diff --git a/source/ui/section/action/deletecontents.c b/source/ui/section/action/deletecontents.c index 1b4bad6..ef86e81 100644 --- a/source/ui/section/action/deletecontents.c +++ b/source/ui/section/action/deletecontents.c @@ -6,11 +6,10 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" #include "../../../util.h" -#include "../task/task.h" typedef struct { file_info* base; @@ -38,11 +37,11 @@ static Result action_delete_contents_delete(void* data, u32 index) { return res; } -static bool action_delete_contents_result_error(void* data, u32 index, Result res) { +static bool action_delete_contents_error(void* data, u32 index, Result res) { delete_contents_data* deleteData = (delete_contents_data*) data; - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Delete cancelled.", COLOR_TEXT, false, deleteData->base, NULL, ui_draw_file_info, NULL)); + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Delete cancelled.", COLOR_TEXT, false, deleteData->base, NULL, ui_draw_file_info, NULL); return false; } else { char* path = deleteData->contents[index]; @@ -62,25 +61,6 @@ static bool action_delete_contents_result_error(void* data, u32 index, Result re return index < deleteData->deleteInfo.total - 1; } -static bool action_delete_contents_io_error(void* data, u32 index, int err) { - delete_contents_data* deleteData = (delete_contents_data*) data; - - char* path = deleteData->contents[index]; - - volatile bool dismissed = false; - if(strlen(path) > 48) { - error_display_errno(&dismissed, deleteData->base, ui_draw_file_info, err, "Failed to delete content.\n%.45s...", path); - } else { - error_display_errno(&dismissed, deleteData->base, ui_draw_file_info, err, "Failed to delete content.\n%.48s", path); - } - - while(!dismissed) { - svcSleepThread(1000000); - } - - return index < deleteData->deleteInfo.total - 1; -} - static void action_delete_contents_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { ui_draw_file_info(view, ((delete_contents_data*) data)->base, x1, y1, x2, y2); } @@ -90,13 +70,7 @@ static void action_delete_contents_free_data(delete_contents_data* data) { free(data); } -static void action_delete_contents_done_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - - action_delete_contents_free_data((delete_contents_data*) data); -} - -static void action_delete_contents_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_contents_update(ui_view* view, void* data, float* progress, char* text) { delete_contents_data* deleteData = (delete_contents_data*) data; if(deleteData->deleteInfo.finished) { @@ -106,15 +80,17 @@ static void action_delete_contents_update(ui_view* view, void* data, float* prog FSUSER_ControlArchive(*deleteData->base->archive, ARCHIVE_ACTION_COMMIT_SAVE_DATA, NULL, 0, NULL, 0); } - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(deleteData->deleteInfo.premature) { action_delete_contents_free_data(deleteData); } else { - ui_push(prompt_create("Success", "Contents deleted.", COLOR_TEXT, false, data, NULL, action_delete_contents_draw_top, action_delete_contents_done_onresponse)); + prompt_display("Success", "Contents deleted.", COLOR_TEXT, false, deleteData->base, NULL, ui_draw_file_info, NULL); } + action_delete_contents_free_data(deleteData); + return; } @@ -123,20 +99,16 @@ static void action_delete_contents_update(ui_view* view, void* data, float* prog } *progress = deleteData->deleteInfo.total > 0 ? (float) deleteData->deleteInfo.processed / (float) deleteData->deleteInfo.total : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%lu / %lu", deleteData->deleteInfo.processed, deleteData->deleteInfo.total); + snprintf(text, PROGRESS_TEXT_MAX, "%lu / %lu", deleteData->deleteInfo.processed, deleteData->deleteInfo.total); } static void action_delete_contents_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - delete_contents_data* deleteData = (delete_contents_data*) data; if(response) { deleteData->cancelEvent = task_data_op(&deleteData->deleteInfo); if(deleteData->cancelEvent != 0) { - ui_view* progressView = progressbar_create("Deleting Contents", "Press B to cancel.", data, action_delete_contents_update, action_delete_contents_draw_top); - snprintf(progressbar_get_progress_text(progressView), PROGRESS_TEXT_MAX, "0 / %lu", deleteData->deleteInfo.total); - ui_push(progressView); + info_display("Deleting Contents", "Press B to cancel.", true, data, action_delete_contents_update, action_delete_contents_draw_top); } else { error_display(NULL, NULL, NULL, "Failed to initiate delete operation."); } @@ -156,8 +128,7 @@ static void action_delete_contents_internal(file_info* info, bool* populated, co data->deleteInfo.delete = action_delete_contents_delete; - data->deleteInfo.resultError = action_delete_contents_result_error; - data->deleteInfo.ioError = action_delete_contents_io_error; + data->deleteInfo.error = action_delete_contents_error; data->cancelEvent = 0; @@ -169,7 +140,7 @@ static void action_delete_contents_internal(file_info* info, bool* populated, co return; } - ui_push(prompt_create("Confirmation", message, COLOR_TEXT, true, data, NULL, action_delete_contents_draw_top, action_delete_contents_onresponse)); + prompt_display("Confirmation", message, COLOR_TEXT, true, data, NULL, action_delete_contents_draw_top, action_delete_contents_onresponse); } void action_delete_contents(file_info* info, bool* populated) { diff --git a/source/ui/section/action/deleteextsavedata.c b/source/ui/section/action/deleteextsavedata.c index 46ee0de..045b949 100644 --- a/source/ui/section/action/deleteextsavedata.c +++ b/source/ui/section/action/deleteextsavedata.c @@ -4,9 +4,8 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" -#include "../task/task.h" #include "../../../screen.h" typedef struct { @@ -18,35 +17,29 @@ static void action_delete_ext_save_data_draw_top(ui_view* view, void* data, floa ui_draw_ext_save_data_info(view, ((delete_ext_save_data_data*) data)->info, x1, y1, x2, y2); } -static void action_delete_ext_save_data_success_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_delete_ext_save_data_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_ext_save_data_update(ui_view* view, void* data, float* progress, char* text) { delete_ext_save_data_data* deleteData = (delete_ext_save_data_data*) data; FS_ExtSaveDataInfo extInfo = {.mediaType = deleteData->info->mediaType, .saveId = deleteData->info->extSaveDataId}; Result res = FSUSER_DeleteExtSaveData(extInfo); - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(R_FAILED(res)) { error_display_res(NULL, deleteData->info, ui_draw_ext_save_data_info, res, "Failed to delete ext save data."); } else { *deleteData->populated = false; - ui_push(prompt_create("Success", "Ext save data deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_ext_save_data_info, action_delete_ext_save_data_success_onresponse)); + prompt_display("Success", "Ext save data deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_ext_save_data_info, NULL); } free(data); } static void action_delete_ext_save_data_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Deleting Ext Save Data", "", data, action_delete_ext_save_data_update, action_delete_ext_save_data_draw_top)); + info_display("Deleting Ext Save Data", "", false, data, action_delete_ext_save_data_update, action_delete_ext_save_data_draw_top); } else { free(data); } @@ -57,5 +50,5 @@ void action_delete_ext_save_data(ext_save_data_info* info, bool* populated) { data->info = info; data->populated = populated; - ui_push(prompt_create("Confirmation", "Delete the selected ext save data?", COLOR_TEXT, true, data, NULL, action_delete_ext_save_data_draw_top, action_delete_ext_save_data_onresponse)); + prompt_display("Confirmation", "Delete the selected ext save data?", COLOR_TEXT, true, data, NULL, action_delete_ext_save_data_draw_top, action_delete_ext_save_data_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/deletependingtitles.c b/source/ui/section/action/deletependingtitles.c index a52c598..1991e28 100644 --- a/source/ui/section/action/deletependingtitles.c +++ b/source/ui/section/action/deletependingtitles.c @@ -5,10 +5,9 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" -#include "../task/task.h" typedef struct { pending_title_info* info; @@ -34,11 +33,11 @@ static Result action_delete_pending_titles_delete(void* data, u32 index) { return res; } -static bool action_delete_pending_titles_result_error(void* data, u32 index, Result res) { +static bool action_delete_pending_titles_error(void* data, u32 index, Result res) { delete_pending_titles_data* deleteData = (delete_pending_titles_data*) data; - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Delete cancelled.", COLOR_TEXT, false, deleteData->info, NULL, deleteData->info != NULL ? ui_draw_pending_title_info : NULL, NULL)); + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Delete cancelled.", COLOR_TEXT, false, deleteData->info, NULL, deleteData->info != NULL ? ui_draw_pending_title_info : NULL, NULL); return false; } else { u64 titleId = deleteData->titleIds[index]; @@ -54,21 +53,6 @@ static bool action_delete_pending_titles_result_error(void* data, u32 index, Res return index < deleteData->deleteInfo.total - 1; } -static bool action_delete_pending_titles_io_error(void* data, u32 index, int err) { - delete_pending_titles_data* deleteData = (delete_pending_titles_data*) data; - - u64 titleId = deleteData->titleIds[index]; - - volatile bool dismissed = false; - error_display_errno(&dismissed, deleteData->info, deleteData->info != NULL ? ui_draw_pending_title_info : NULL, err, "Failed to delete pending title.\n%llX", titleId); - - while(!dismissed) { - svcSleepThread(1000000); - } - - return index < deleteData->deleteInfo.total - 1; -} - static void action_delete_pending_titles_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { delete_pending_titles_data* deleteData = (delete_pending_titles_data*) data; @@ -82,25 +66,21 @@ static void action_delete_pending_titles_free_data(delete_pending_titles_data* d free(data); } -static void action_delete_pending_titles_success_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - - action_delete_pending_titles_free_data((delete_pending_titles_data*) data); -} - -static void action_delete_pending_titles_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_pending_titles_update(ui_view* view, void* data, float* progress, char* text) { delete_pending_titles_data* deleteData = (delete_pending_titles_data*) data; if(deleteData->deleteInfo.finished) { - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(deleteData->deleteInfo.premature) { action_delete_pending_titles_free_data(deleteData); } else { - ui_push(prompt_create("Success", "Pending title(s) deleted.", COLOR_TEXT, false, data, NULL, action_delete_pending_titles_draw_top, action_delete_pending_titles_success_onresponse)); + prompt_display("Success", "Pending title(s) deleted.", COLOR_TEXT, false, deleteData->info, NULL, deleteData->info != NULL ? ui_draw_pending_title_info : NULL, NULL); } + action_delete_pending_titles_free_data(deleteData); + return; } @@ -109,20 +89,16 @@ static void action_delete_pending_titles_update(ui_view* view, void* data, float } *progress = deleteData->deleteInfo.total > 0 ? (float) deleteData->deleteInfo.processed / (float) deleteData->deleteInfo.total : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%lu / %lu", deleteData->deleteInfo.processed, deleteData->deleteInfo.total); + snprintf(text, PROGRESS_TEXT_MAX, "%lu / %lu", deleteData->deleteInfo.processed, deleteData->deleteInfo.total); } static void action_delete_pending_titles_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - delete_pending_titles_data* deleteData = (delete_pending_titles_data*) data; if(response) { deleteData->cancelEvent = task_data_op(&deleteData->deleteInfo); if(deleteData->cancelEvent != 0) { - ui_view* progressView = progressbar_create("Deleting Pending Title(s)", "Press B to cancel.", data, action_delete_pending_titles_update, action_delete_pending_titles_draw_top); - snprintf(progressbar_get_progress_text(progressView), PROGRESS_TEXT_MAX, "0 / %lu", deleteData->deleteInfo.total); - ui_push(progressView); + info_display("Deleting Pending Title(s)", "Press B to cancel.", true, data, action_delete_pending_titles_update, action_delete_pending_titles_draw_top); } else { error_display(NULL, NULL, NULL, "Failed to initiate delete operation."); } @@ -147,12 +123,11 @@ void action_delete_pending_titles(pending_title_info* info, bool* populated, con data->deleteInfo.delete = action_delete_pending_titles_delete; - data->deleteInfo.resultError = action_delete_pending_titles_result_error; - data->deleteInfo.ioError = action_delete_pending_titles_io_error; + data->deleteInfo.error = action_delete_pending_titles_error; data->cancelEvent = 0; - ui_push(prompt_create("Confirmation", message, COLOR_TEXT, true, data, NULL, action_delete_pending_titles_draw_top, action_delete_pending_titles_onresponse)); + prompt_display("Confirmation", message, COLOR_TEXT, true, data, NULL, action_delete_pending_titles_draw_top, action_delete_pending_titles_onresponse); } void action_delete_pending_title(pending_title_info* info, bool* populated) { diff --git a/source/ui/section/action/deletesecurevalue.c b/source/ui/section/action/deletesecurevalue.c index 6d86ebc..39a5e5b 100644 --- a/source/ui/section/action/deletesecurevalue.c +++ b/source/ui/section/action/deletesecurevalue.c @@ -4,40 +4,33 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" -#include "../../../util.h" #include "../../../screen.h" -static void action_delete_secure_value_end_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_delete_secure_value_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_secure_value_update(ui_view* view, void* data, float* progress, char* text) { title_info* info = (title_info*) data; u64 param = ((u64) SECUREVALUE_SLOT_SD << 32) | (info->titleId & 0xFFFFFFF); u8 out = 0; Result res = FSUSER_ControlSecureSave(SECURESAVE_ACTION_DELETE, ¶m, sizeof(param), &out, sizeof(out)); - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(R_FAILED(res)) { error_display_res(NULL, info, ui_draw_title_info, res, "Failed to delete secure value."); } else { - ui_push(prompt_create("Success", "Secure value deleted.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, action_delete_secure_value_end_onresponse)); + prompt_display("Success", "Secure value deleted.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, NULL); } } static void action_delete_secure_value_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Deleting Secure Value", "", data, action_delete_secure_value_update, ui_draw_title_info)); + info_display("Deleting Secure Value", "", false, data, action_delete_secure_value_update, ui_draw_title_info); } } void action_delete_secure_value(title_info* info, bool* populated) { - ui_push(prompt_create("Confirmation", "Delete the secure value of the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_delete_secure_value_onresponse)); + prompt_display("Confirmation", "Delete the secure value of the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_delete_secure_value_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/deletesystemsavedata.c b/source/ui/section/action/deletesystemsavedata.c index 40c822d..9b46f23 100644 --- a/source/ui/section/action/deletesystemsavedata.c +++ b/source/ui/section/action/deletesystemsavedata.c @@ -4,7 +4,7 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" @@ -17,35 +17,29 @@ static void action_delete_system_save_data_draw_top(ui_view* view, void* data, f ui_draw_system_save_data_info(view, ((delete_system_save_data_data*) data)->info, x1, y1, x2, y2); } -static void action_delete_system_save_data_success_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_delete_system_save_data_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_system_save_data_update(ui_view* view, void* data, float* progress, char* text) { delete_system_save_data_data* deleteData = (delete_system_save_data_data*) data; FS_SystemSaveDataInfo sysInfo = {.mediaType = MEDIATYPE_NAND, .saveId = deleteData->info->systemSaveDataId}; Result res = FSUSER_DeleteSystemSaveData(sysInfo); - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(R_FAILED(res)) { error_display_res(NULL, deleteData->info, ui_draw_system_save_data_info, res, "Failed to delete system save data."); } else { *deleteData->populated = false; - ui_push(prompt_create("Success", "System save data deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_system_save_data_info, action_delete_system_save_data_success_onresponse)); + prompt_display("Success", "System save data deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_system_save_data_info, NULL); } free(data); } static void action_delete_system_save_data_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Deleting System Save Data", "", data, action_delete_system_save_data_update, action_delete_system_save_data_draw_top)); + info_display("Deleting System Save Data", "", false, data, action_delete_system_save_data_update, action_delete_system_save_data_draw_top); } else { free(data); } @@ -56,5 +50,5 @@ void action_delete_system_save_data(system_save_data_info* info, bool* populated data->info = info; data->populated = populated; - ui_push(prompt_create("Confirmation", "Delete the selected system save data?", COLOR_TEXT, true, data, NULL, action_delete_system_save_data_draw_top, action_delete_system_save_data_onresponse)); + prompt_display("Confirmation", "Delete the selected system save data?", COLOR_TEXT, true, data, NULL, action_delete_system_save_data_draw_top, action_delete_system_save_data_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/deleteticket.c b/source/ui/section/action/deleteticket.c index d565fe0..9076035 100644 --- a/source/ui/section/action/deleteticket.c +++ b/source/ui/section/action/deleteticket.c @@ -4,7 +4,7 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" @@ -17,34 +17,28 @@ static void action_delete_ticket_draw_top(ui_view* view, void* data, float x1, f ui_draw_ticket_info(view, ((delete_ticket_data*) data)->info, x1, y1, x2, y2); } -static void action_delete_ticket_success_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_delete_ticket_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_ticket_update(ui_view* view, void* data, float* progress, char* text) { delete_ticket_data* deleteData = (delete_ticket_data*) data; Result res = AM_DeleteTicket(deleteData->info->ticketId); - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(R_FAILED(res)) { error_display_res(NULL, deleteData->info, ui_draw_ticket_info, res, "Failed to delete ticket."); } else { *deleteData->populated = false; - ui_push(prompt_create("Success", "Ticket deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_ticket_info, action_delete_ticket_success_onresponse)); + prompt_display("Success", "Ticket deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_ticket_info, NULL); } free(data); } static void action_delete_ticket_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Deleting Ticket", "", data, action_delete_ticket_update, action_delete_ticket_draw_top)); + info_display("Deleting Ticket", "", false, data, action_delete_ticket_update, action_delete_ticket_draw_top); } else { free(data); } @@ -55,5 +49,5 @@ void action_delete_ticket(ticket_info* info, bool* populated) { data->info = info; data->populated = populated; - ui_push(prompt_create("Confirmation", "Delete the selected ticket?", COLOR_TEXT, true, data, NULL, action_delete_ticket_draw_top, action_delete_ticket_onresponse)); + prompt_display("Confirmation", "Delete the selected ticket?", COLOR_TEXT, true, data, NULL, action_delete_ticket_draw_top, action_delete_ticket_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/deletetitle.c b/source/ui/section/action/deletetitle.c index 7a457a1..3ff9c1a 100644 --- a/source/ui/section/action/deletetitle.c +++ b/source/ui/section/action/deletetitle.c @@ -4,7 +4,7 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" @@ -17,34 +17,28 @@ static void action_delete_title_draw_top(ui_view* view, void* data, float x1, fl ui_draw_title_info(view, ((delete_title_data*) data)->info, x1, y1, x2, y2); } -static void action_delete_title_success_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_delete_title_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_delete_title_update(ui_view* view, void* data, float* progress, char* text) { delete_title_data* deleteData = (delete_title_data*) data; Result res = AM_DeleteTitle(deleteData->info->mediaType, deleteData->info->titleId); - progressbar_destroy(view); ui_pop(); + info_destroy(view); if(R_FAILED(res)) { error_display_res(NULL, deleteData->info, ui_draw_title_info, res, "Failed to delete title."); } else { *deleteData->populated = false; - ui_push(prompt_create("Success", "Title deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_title_info, action_delete_title_success_onresponse)); + prompt_display("Success", "Title deleted.", COLOR_TEXT, false, deleteData->info, NULL, ui_draw_title_info, NULL); } free(data); } static void action_delete_title_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Deleting Title", "", data, action_delete_title_update, action_delete_title_draw_top)); + info_display("Deleting Title", "", false, data, action_delete_title_update, action_delete_title_draw_top); } else { free(data); } @@ -55,5 +49,5 @@ void action_delete_title(title_info* info, bool* populated) { data->info = info; data->populated = populated; - ui_push(prompt_create("Confirmation", "Delete the selected title?", COLOR_TEXT, true, data, NULL, action_delete_title_draw_top, action_delete_title_onresponse)); + prompt_display("Confirmation", "Delete the selected title?", COLOR_TEXT, true, data, NULL, action_delete_title_draw_top, action_delete_title_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/exportsecurevalue.c b/source/ui/section/action/exportsecurevalue.c index c8d83b3..feea675 100644 --- a/source/ui/section/action/exportsecurevalue.c +++ b/source/ui/section/action/exportsecurevalue.c @@ -4,16 +4,12 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../util.h" #include "../../../screen.h" -static void action_export_secure_value_end_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_export_secure_value_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_export_secure_value_update(ui_view* view, void* data, float* progress, char* text) { title_info* info = (title_info*) data; Result res = 0; @@ -22,10 +18,10 @@ static void action_export_secure_value_update(ui_view* view, void* data, float* u64 value = 0; if(R_SUCCEEDED(res = FSUSER_GetSaveDataSecureValue(&exists, &value, SECUREVALUE_SLOT_SD, (u32) ((info->titleId >> 8) & 0xFFFFF), (u8) (info->titleId & 0xFF)))) { if(!exists) { - progressbar_destroy(view); ui_pop(); + info_destroy(view); - ui_push(prompt_create("Failure", "Secure value not set.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, action_export_secure_value_end_onresponse)); + prompt_display("Failure", "Secure value not set.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, NULL); return; } @@ -52,29 +48,19 @@ static void action_export_secure_value_update(ui_view* view, void* data, float* } } - if(R_FAILED(res)) { - progressbar_destroy(view); - ui_pop(); - + if(R_SUCCEEDED(res)) { + prompt_display("Success", "Secure value exported.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, NULL); + } else { error_display_res(NULL, info, ui_draw_title_info, res, "Failed to export secure value."); - - return; } - - progressbar_destroy(view); - ui_pop(); - - ui_push(prompt_create("Success", "Secure value exported.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, action_export_secure_value_end_onresponse)); } static void action_export_secure_value_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Exporting Secure Value", "", data, action_export_secure_value_update, ui_draw_title_info)); + info_display("Exporting Secure Value", "", false, data, action_export_secure_value_update, ui_draw_title_info); } } void action_export_secure_value(title_info* info, bool* populated) { - ui_push(prompt_create("Confirmation", "Export the secure value of the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_export_secure_value_onresponse)); + prompt_display("Confirmation", "Export the secure value of the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_export_secure_value_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/importsecurevalue.c b/source/ui/section/action/importsecurevalue.c index fbbcb75..907b2c0 100644 --- a/source/ui/section/action/importsecurevalue.c +++ b/source/ui/section/action/importsecurevalue.c @@ -4,16 +4,12 @@ #include "action.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" #include "../../../util.h" -static void action_import_secure_value_end_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void action_import_secure_value_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_import_secure_value_update(ui_view* view, void* data, float* progress, char* text) { title_info* info = (title_info*) data; char pathBuf[64]; @@ -37,29 +33,22 @@ static void action_import_secure_value_update(ui_view* view, void* data, float* util_free_path_utf8(fsPath); - if(R_FAILED(res)) { - progressbar_destroy(view); - ui_pop(); - - error_display_res(NULL, info, ui_draw_title_info, res, "Failed to import secure value."); - - return; - } - - progressbar_destroy(view); ui_pop(); + info_destroy(view); - ui_push(prompt_create("Success", "Secure value imported.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, action_import_secure_value_end_onresponse)); + if(R_SUCCEEDED(res)) { + prompt_display("Success", "Secure value imported.", COLOR_TEXT, false, info, NULL, ui_draw_title_info, NULL); + } else { + error_display_res(NULL, info, ui_draw_title_info, res, "Failed to import secure value."); + } } static void action_import_secure_value_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Importing Secure Value", "", data, action_import_secure_value_update, ui_draw_title_info)); + info_display("Importing Secure Value", "", false, data, action_import_secure_value_update, ui_draw_title_info); } } void action_import_secure_value(title_info* info, bool* populated) { - ui_push(prompt_create("Confirmation", "Import the secure value of the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_import_secure_value_onresponse)); + prompt_display("Confirmation", "Import the secure value of the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_import_secure_value_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/installcias.c b/source/ui/section/action/installcias.c index 54a3c46..824b433 100644 --- a/source/ui/section/action/installcias.c +++ b/source/ui/section/action/installcias.c @@ -5,9 +5,8 @@ #include <3ds.h> #include "action.h" -#include "../task/task.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" #include "../../../util.h" @@ -81,7 +80,7 @@ static Result action_install_cias_open_dst(void* data, u32 index, void* initialR u8 n3ds = false; if(R_SUCCEEDED(APT_CheckNew3DS(&n3ds)) && !n3ds && ((titleId >> 28) & 0xF) == 2) { - return MAKERESULT(RL_PERMANENT, RS_NOTSUPPORTED, RM_APPLICATION, RD_INVALID_COMBINATION); + return R_FBI_WRONG_SYSTEM; } // Deleting FBI before it reinstalls itself causes issues. @@ -123,17 +122,17 @@ static Result action_install_cias_write_dst(void* data, u32 handle, u32* bytesWr return FSFILE_Write(handle, bytesWritten, offset, buffer, size, 0); } -bool action_install_cias_result_error(void* data, u32 index, Result res) { +bool action_install_cias_error(void* data, u32 index, Result res) { install_cias_data* installData = (install_cias_data*) data; - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Install cancelled.", COLOR_TEXT, false, installData->base, NULL, ui_draw_file_info, NULL)); + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Install cancelled.", COLOR_TEXT, false, installData->base, NULL, ui_draw_file_info, NULL); return false; } else { char* path = installData->contents[index]; volatile bool dismissed = false; - if(res == MAKERESULT(RL_PERMANENT, RS_NOTSUPPORTED, RM_APPLICATION, RD_INVALID_COMBINATION)) { + if(res == R_FBI_WRONG_SYSTEM) { if(strlen(path) > 48) { error_display(&dismissed, installData->base, ui_draw_file_info, "Failed to install CIA file.\n%.45s...\nAttempted to install N3DS title to O3DS.", path); } else { @@ -155,25 +154,6 @@ bool action_install_cias_result_error(void* data, u32 index, Result res) { return index < installData->installInfo.total - 1; } -bool action_install_cias_io_error(void* data, u32 index, int err) { - install_cias_data* installData = (install_cias_data*) data; - - char* path = installData->contents[index]; - - volatile bool dismissed = false; - if(strlen(path) > 48) { - error_display_errno(&dismissed, installData->base, ui_draw_file_info, err, "Failed to install CIA file.\n%.45s...", path); - } else { - error_display_errno(&dismissed, installData->base, ui_draw_file_info, err, "Failed to install CIA file.\n%.48s", path); - } - - while(!dismissed) { - svcSleepThread(1000000); - } - - return index < installData->installInfo.total - 1; -} - static void action_install_cias_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { ui_draw_file_info(view, ((install_cias_data*) data)->base, x1, y1, x2, y2); } @@ -183,13 +163,7 @@ static void action_install_cias_free_data(install_cias_data* data) { free(data); } -static void action_install_cias_done_onresponse(ui_view* view, void* data, bool response) { - action_install_cias_free_data((install_cias_data*) data); - - prompt_destroy(view); -} - -static void action_install_cias_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_install_cias_update(ui_view* view, void* data, float* progress, char* text) { install_cias_data* installData = (install_cias_data*) data; if(installData->installInfo.finished) { @@ -198,14 +172,14 @@ static void action_install_cias_update(ui_view* view, void* data, float* progres } ui_pop(); - progressbar_destroy(view); + info_destroy(view); - if(installData->installInfo.premature) { - action_install_cias_free_data(installData); - } else { - ui_push(prompt_create("Success", "Install finished.", COLOR_TEXT, false, data, NULL, action_install_cias_draw_top, action_install_cias_done_onresponse)); + if(!installData->installInfo.premature) { + prompt_display("Success", "Install finished.", COLOR_TEXT, false, installData->base, NULL, ui_draw_file_info, NULL); } + action_install_cias_free_data(installData); + return; } @@ -214,20 +188,16 @@ static void action_install_cias_update(ui_view* view, void* data, float* progres } *progress = installData->installInfo.currTotal != 0 ? (float) ((double) installData->installInfo.currProcessed / (double) installData->installInfo.currTotal) : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", installData->installInfo.processed, installData->installInfo.total, installData->installInfo.currProcessed / 1024.0 / 1024.0, installData->installInfo.currTotal / 1024.0 / 1024.0); + snprintf(text, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", installData->installInfo.processed, installData->installInfo.total, installData->installInfo.currProcessed / 1024.0 / 1024.0, installData->installInfo.currTotal / 1024.0 / 1024.0); } static void action_install_cias_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - install_cias_data* installData = (install_cias_data*) data; if(response) { installData->cancelEvent = task_data_op(&installData->installInfo); if(installData->cancelEvent != 0) { - ui_view* progressView = progressbar_create("Installing CIA(s)", "Press B to cancel.", data, action_install_cias_update, action_install_cias_draw_top); - snprintf(progressbar_get_progress_text(progressView), PROGRESS_TEXT_MAX, "0 / %lu", installData->installInfo.total); - ui_push(progressView); + info_display("Installing CIA(s)", "Press B to cancel.", true, data, action_install_cias_update, action_install_cias_draw_top); } else { error_display(NULL, installData->base, ui_draw_file_info, "Failed to initiate CIA installation."); @@ -264,8 +234,7 @@ static void action_install_cias_internal(file_info* info, bool* populated, bool data->installInfo.closeDst = action_install_cias_close_dst; data->installInfo.writeDst = action_install_cias_write_dst; - data->installInfo.resultError = action_install_cias_result_error; - data->installInfo.ioError = action_install_cias_io_error; + data->installInfo.error = action_install_cias_error; data->cancelEvent = 0; @@ -277,7 +246,7 @@ static void action_install_cias_internal(file_info* info, bool* populated, bool return; } - ui_push(prompt_create("Confirmation", "Install the selected CIA(s)?", COLOR_TEXT, true, data, NULL, action_install_cias_draw_top, action_install_cias_onresponse)); + prompt_display("Confirmation", "Install the selected CIA(s)?", COLOR_TEXT, true, data, NULL, action_install_cias_draw_top, action_install_cias_onresponse); } void action_install_cias(file_info* info, bool* populated) { diff --git a/source/ui/section/action/installtickets.c b/source/ui/section/action/installtickets.c index d16274a..5a61fa7 100644 --- a/source/ui/section/action/installtickets.c +++ b/source/ui/section/action/installtickets.c @@ -5,9 +5,8 @@ #include <3ds.h> #include "action.h" -#include "../task/task.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" #include "../../../util.h" @@ -69,11 +68,11 @@ static Result action_install_tickets_write_dst(void* data, u32 handle, u32* byte return FSFILE_Write(handle, bytesWritten, offset, buffer, size, 0); } -static bool action_install_tickets_result_error(void* data, u32 index, Result res) { +static bool action_install_tickets_error(void* data, u32 index, Result res) { install_tickets_data* installData = (install_tickets_data*) data; - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Install cancelled.", COLOR_TEXT, false, installData->base, NULL, ui_draw_file_info, NULL)); + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Install cancelled.", COLOR_TEXT, false, installData->base, NULL, ui_draw_file_info, NULL); return false; } else { char* path = installData->contents[index]; @@ -93,25 +92,6 @@ static bool action_install_tickets_result_error(void* data, u32 index, Result re return index < installData->installInfo.total - 1; } -static bool action_install_tickets_io_error(void* data, u32 index, int err) { - install_tickets_data* installData = (install_tickets_data*) data; - - char* path = installData->contents[index]; - - volatile bool dismissed = false; - if(strlen(path) > 48) { - error_display_errno(&dismissed, installData->base, ui_draw_file_info, err, "Failed to install ticket.\n%.45s...", path); - } else { - error_display_errno(&dismissed, installData->base, ui_draw_file_info, err, "Failed to install ticket.\n%.48s", path); - } - - while(!dismissed) { - svcSleepThread(1000000); - } - - return index < installData->installInfo.total - 1; -} - static void action_install_tickets_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { ui_draw_file_info(view, ((install_tickets_data*) data)->base, x1, y1, x2, y2); } @@ -121,25 +101,19 @@ static void action_install_tickets_free_data(install_tickets_data* data) { free(data); } -static void action_install_tickets_done_onresponse(ui_view* view, void* data, bool response) { - action_install_tickets_free_data((install_tickets_data*) data); - - prompt_destroy(view); -} - -static void action_install_tickets_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_install_tickets_update(ui_view* view, void* data, float* progress, char* text) { install_tickets_data* installData = (install_tickets_data*) data; if(installData->installInfo.finished) { ui_pop(); - progressbar_destroy(view); + info_destroy(view); - if(installData->installInfo.premature) { - action_install_tickets_free_data(installData); - } else { - ui_push(prompt_create("Success", "Install finished.", COLOR_TEXT, false, data, NULL, action_install_tickets_draw_top, action_install_tickets_done_onresponse)); + if(!installData->installInfo.premature) { + prompt_display("Success", "Install finished.", COLOR_TEXT, false, installData->base, NULL, ui_draw_file_info, NULL); } + action_install_tickets_free_data(installData); + return; } @@ -148,20 +122,16 @@ static void action_install_tickets_update(ui_view* view, void* data, float* prog } *progress = installData->installInfo.currTotal != 0 ? (float) ((double) installData->installInfo.currProcessed / (double) installData->installInfo.currTotal) : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", installData->installInfo.processed, installData->installInfo.total, installData->installInfo.currProcessed / 1024.0 / 1024.0, installData->installInfo.currTotal / 1024.0 / 1024.0); + snprintf(text, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", installData->installInfo.processed, installData->installInfo.total, installData->installInfo.currProcessed / 1024.0 / 1024.0, installData->installInfo.currTotal / 1024.0 / 1024.0); } static void action_install_tickets_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - install_tickets_data* installData = (install_tickets_data*) data; if(response) { installData->cancelEvent = task_data_op(&installData->installInfo); if(installData->cancelEvent != 0) { - ui_view* progressView = progressbar_create("Installing ticket(s)", "Press B to cancel.", data, action_install_tickets_update, action_install_tickets_draw_top); - snprintf(progressbar_get_progress_text(progressView), PROGRESS_TEXT_MAX, "0 / %lu", installData->installInfo.total); - ui_push(progressView); + info_display("Installing ticket(s)", "Press B to cancel.", true, data, action_install_tickets_update, action_install_tickets_draw_top); } else { error_display(NULL, installData->base, ui_draw_file_info, "Failed to initiate ticket installation."); @@ -194,8 +164,7 @@ void action_install_tickets(file_info* info, bool* populated) { data->installInfo.closeDst = action_install_tickets_close_dst; data->installInfo.writeDst = action_install_tickets_write_dst; - data->installInfo.resultError = action_install_tickets_result_error; - data->installInfo.ioError = action_install_tickets_io_error; + data->installInfo.error = action_install_tickets_error; data->cancelEvent = 0; @@ -207,5 +176,5 @@ void action_install_tickets(file_info* info, bool* populated) { return; } - ui_push(prompt_create("Confirmation", "Install the selected ticket(s)?", COLOR_TEXT, true, data, NULL, action_install_tickets_draw_top, action_install_tickets_onresponse)); + prompt_display("Confirmation", "Install the selected ticket(s)?", COLOR_TEXT, true, data, NULL, action_install_tickets_draw_top, action_install_tickets_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/launchtitle.c b/source/ui/section/action/launchtitle.c index f633350..c741aa9 100644 --- a/source/ui/section/action/launchtitle.c +++ b/source/ui/section/action/launchtitle.c @@ -1,13 +1,12 @@ #include <3ds.h> #include "action.h" -#include "../task/task.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" -static void action_launch_title_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_launch_title_update(ui_view* view, void* data, float* progress, char* text) { title_info* info = (title_info*) data; u8 buf0[0x300]; @@ -23,28 +22,26 @@ static void action_launch_title_update(ui_view* view, void* data, float* progres aptCloseSession(); - progressbar_destroy(view); + info_destroy(view); if(R_SUCCEEDED(res)) { while(ui_peek() != NULL) { ui_pop(); } } else { - progressbar_destroy(view); ui_pop(); + info_destroy(view); error_display_res(NULL, info, ui_draw_title_info, res, "Failed to launch title."); } } static void action_launch_title_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { - ui_push(progressbar_create("Launching Title", "", data, action_launch_title_update, ui_draw_title_info)); + info_display("Launching Title", "", false, data, action_launch_title_update, ui_draw_title_info); } } void action_launch_title(title_info* info, bool* populated) { - ui_push(prompt_create("Confirmation", "Launch the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_launch_title_onresponse)); + prompt_display("Confirmation", "Launch the selected title?", COLOR_TEXT, true, info, NULL, ui_draw_title_info, action_launch_title_onresponse); } \ No newline at end of file diff --git a/source/ui/section/action/pastefiles.c b/source/ui/section/action/pastefiles.c index d63553c..f61322f 100644 --- a/source/ui/section/action/pastefiles.c +++ b/source/ui/section/action/pastefiles.c @@ -7,11 +7,10 @@ #include "action.h" #include "clipboard.h" #include "../../error.h" -#include "../../progressbar.h" +#include "../../info.h" #include "../../prompt.h" #include "../../../screen.h" #include "../../../util.h" -#include "../task/task.h" typedef struct { file_info* base; @@ -103,11 +102,11 @@ static Result action_paste_files_write_dst(void* data, u32 handle, u32* bytesWri return FSFILE_Write(handle, bytesWritten, offset, buffer, size, 0); } -static bool action_paste_files_result_error(void* data, u32 index, Result res) { +static bool action_paste_files_error(void* data, u32 index, Result res) { paste_files_data* pasteData = (paste_files_data*) data; - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Paste cancelled.", COLOR_TEXT, false, pasteData->base, NULL, ui_draw_file_info, NULL)); + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Paste cancelled.", COLOR_TEXT, false, pasteData->base, NULL, ui_draw_file_info, NULL); return false; } else { char* path = pasteData->contents[index]; @@ -127,45 +126,16 @@ static bool action_paste_files_result_error(void* data, u32 index, Result res) { return index < pasteData->pasteInfo.total - 1; } -static bool action_paste_files_io_error(void* data, u32 index, int err) { - paste_files_data* pasteData = (paste_files_data*) data; - - char* path = pasteData->contents[index]; - - volatile bool dismissed = false; - if(strlen(path) > 48) { - error_display_errno(&dismissed, pasteData->base, ui_draw_file_info, err, "Failed to paste content.\n%.45s...", path); - } else { - error_display_errno(&dismissed, pasteData->base, ui_draw_file_info, err, "Failed to paste content.\n%.48s", path); - } - - while(!dismissed) { - svcSleepThread(1000000); - } - - return index < pasteData->pasteInfo.total - 1; -} - static void action_paste_files_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2) { ui_draw_file_info(view, ((paste_files_data*) data)->base, x1, y1, x2, y2); } -static void action_paste_files_clipboard_empty_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - static void action_paste_files_free_data(paste_files_data* data) { util_free_contents(data->contents, data->pasteInfo.total); free(data); } -static void action_paste_files_done_onresponse(ui_view* view, void* data, bool response) { - action_paste_files_free_data((paste_files_data*) data); - - prompt_destroy(view); -} - -static void action_paste_files_update(ui_view* view, void* data, float* progress, char* progressText) { +static void action_paste_files_update(ui_view* view, void* data, float* progress, char* text) { paste_files_data* pasteData = (paste_files_data*) data; if(pasteData->pasteInfo.finished) { @@ -176,14 +146,14 @@ static void action_paste_files_update(ui_view* view, void* data, float* progress } ui_pop(); - progressbar_destroy(view); + info_destroy(view); - if(pasteData->pasteInfo.premature) { - action_paste_files_free_data(pasteData); - } else { - ui_push(prompt_create("Success", "Contents pasted.", COLOR_TEXT, false, data, NULL, action_paste_files_draw_top, action_paste_files_done_onresponse)); + if(!pasteData->pasteInfo.premature) { + prompt_display("Success", "Contents pasted.", COLOR_TEXT, false, pasteData->base, NULL, ui_draw_file_info, NULL); } + action_paste_files_free_data(pasteData); + return; } @@ -192,19 +162,15 @@ static void action_paste_files_update(ui_view* view, void* data, float* progress } *progress = pasteData->pasteInfo.currTotal != 0 ? (float) ((double) pasteData->pasteInfo.currProcessed / (double) pasteData->pasteInfo.currTotal) : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", pasteData->pasteInfo.processed, pasteData->pasteInfo.total, pasteData->pasteInfo.currProcessed / 1024.0 / 1024.0, pasteData->pasteInfo.currTotal / 1024.0 / 1024.0); + snprintf(text, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", pasteData->pasteInfo.processed, pasteData->pasteInfo.total, pasteData->pasteInfo.currProcessed / 1024.0 / 1024.0, pasteData->pasteInfo.currTotal / 1024.0 / 1024.0); } static void action_paste_files_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - paste_files_data* pasteData = (paste_files_data*) data; if(response) { pasteData->cancelEvent = task_data_op(&pasteData->pasteInfo); if(pasteData->cancelEvent != 0) { - ui_view* progressView = progressbar_create("Pasting Contents", "Press B to cancel.", data, action_paste_files_update, action_paste_files_draw_top); - snprintf(progressbar_get_progress_text(progressView), PROGRESS_TEXT_MAX, "0 / %lu", ((paste_files_data*) data)->pasteInfo.total); - ui_push(progressView); + info_display("Pasting Contents", "Press B to cancel.", true, data, action_paste_files_update, action_paste_files_draw_top); } else { error_display(NULL, pasteData->base, ui_draw_file_info, "Failed to initiate paste operation."); } @@ -215,7 +181,7 @@ static void action_paste_files_onresponse(ui_view* view, void* data, bool respon void action_paste_contents(file_info* info, bool* populated) { if(!clipboard_has_contents()) { - ui_push(prompt_create("Failure", "Clipboard empty.", COLOR_TEXT, false, info, NULL, ui_draw_file_info, action_paste_files_clipboard_empty_onresponse)); + prompt_display("Failure", "Clipboard empty.", COLOR_TEXT, false, info, NULL, ui_draw_file_info, NULL); return; } @@ -241,8 +207,7 @@ void action_paste_contents(file_info* info, bool* populated) { data->pasteInfo.closeDst = action_paste_files_close_dst; data->pasteInfo.writeDst = action_paste_files_write_dst; - data->pasteInfo.resultError = action_paste_files_result_error; - data->pasteInfo.ioError = action_paste_files_io_error; + data->pasteInfo.error = action_paste_files_error; data->cancelEvent = 0; @@ -254,5 +219,5 @@ void action_paste_contents(file_info* info, bool* populated) { return; } - ui_push(prompt_create("Confirmation", "Paste clipboard contents to the current directory?", COLOR_TEXT, true, data, NULL, action_paste_files_draw_top, action_paste_files_onresponse)); + prompt_display("Confirmation", "Paste clipboard contents to the current directory?", COLOR_TEXT, true, data, NULL, action_paste_files_draw_top, action_paste_files_onresponse); } \ No newline at end of file diff --git a/source/ui/section/dumpnand.c b/source/ui/section/dumpnand.c index ad659df..d2b7434 100644 --- a/source/ui/section/dumpnand.c +++ b/source/ui/section/dumpnand.c @@ -5,7 +5,7 @@ #include "task/task.h" #include "../error.h" -#include "../progressbar.h" +#include "../info.h" #include "../prompt.h" #include "../../screen.h" @@ -53,9 +53,9 @@ static Result dumpnand_write_dst(void* data, u32 handle, u32* bytesWritten, void return FSFILE_Write(handle, bytesWritten, offset, buffer, size, 0); } -static bool dumpnand_result_error(void* data, u32 index, Result res) { - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Dump cancelled.", COLOR_TEXT, false, NULL, NULL, NULL, NULL)); +static bool dumpnand_error(void* data, u32 index, Result res) { + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Dump cancelled.", COLOR_TEXT, false, NULL, NULL, NULL, NULL); } else { error_display_res(NULL, NULL, NULL, res, "Failed to dump NAND."); } @@ -63,24 +63,15 @@ static bool dumpnand_result_error(void* data, u32 index, Result res) { return false; } -static bool dumpnand_io_error(void* data, u32 index, int err) { - error_display_errno(NULL, NULL, NULL, err, "Failed to dump NAND."); - return false; -} - -static void dumpnand_done_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); -} - -static void dumpnand_update(ui_view* view, void* data, float* progress, char* progressText) { +static void dumpnand_update(ui_view* view, void* data, float* progress, char* text) { dump_nand_data* dumpData = (dump_nand_data*) data; if(dumpData->dumpInfo.finished) { ui_pop(); - progressbar_destroy(view); + info_destroy(view); if(!dumpData->dumpInfo.premature) { - ui_push(prompt_create("Success", "NAND dumped.", COLOR_TEXT, false, NULL, NULL, NULL, dumpnand_done_onresponse)); + prompt_display("Success", "NAND dumped.", COLOR_TEXT, false, NULL, NULL, NULL, NULL); } free(dumpData); @@ -93,18 +84,16 @@ static void dumpnand_update(ui_view* view, void* data, float* progress, char* pr } *progress = dumpData->dumpInfo.currTotal != 0 ? (float) ((double) dumpData->dumpInfo.currProcessed / (double) dumpData->dumpInfo.currTotal) : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%.2f MB / %.2f MB", dumpData->dumpInfo.currProcessed / 1024.0f / 1024.0f, dumpData->dumpInfo.currTotal / 1024.0f / 1024.0f); + snprintf(text, PROGRESS_TEXT_MAX, "%.2f MB / %.2f MB", dumpData->dumpInfo.currProcessed / 1024.0f / 1024.0f, dumpData->dumpInfo.currTotal / 1024.0f / 1024.0f); } static void dumpnand_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - if(response) { dump_nand_data* dumpData = (dump_nand_data*) data; dumpData->cancelEvent = task_data_op(&dumpData->dumpInfo); if(dumpData->cancelEvent != 0) { - ui_push(progressbar_create("Dumping NAND", "Press B to cancel.", data, dumpnand_update, NULL)); + info_display("Dumping NAND", "Press B to cancel.", true, data, dumpnand_update, NULL); } else { error_display(NULL, NULL, NULL, "Failed to initiate NAND dump."); } @@ -136,10 +125,9 @@ void dump_nand() { data->dumpInfo.closeDst = dumpnand_close_dst; data->dumpInfo.writeDst = dumpnand_write_dst; - data->dumpInfo.resultError = dumpnand_result_error; - data->dumpInfo.ioError = dumpnand_io_error; + data->dumpInfo.error = dumpnand_error; data->cancelEvent = 0; - ui_push(prompt_create("Confirmation", "Dump raw NAND image to the SD card?", COLOR_TEXT, true, data, NULL, NULL, dumpnand_onresponse)); + prompt_display("Confirmation", "Dump raw NAND image to the SD card?", COLOR_TEXT, true, data, NULL, NULL, dumpnand_onresponse); } \ No newline at end of file diff --git a/source/ui/section/extsavedata.c b/source/ui/section/extsavedata.c index 08847ed..ffa1272 100644 --- a/source/ui/section/extsavedata.c +++ b/source/ui/section/extsavedata.c @@ -39,8 +39,8 @@ static void extsavedata_action_update(ui_view* view, void* data, list_item** ite extsavedata_action_data* actionData = (extsavedata_action_data*) data; if(hidKeysDown() & KEY_B) { - list_destroy(view); ui_pop(); + list_destroy(view); free(data); @@ -50,8 +50,8 @@ static void extsavedata_action_update(ui_view* view, void* data, list_item** ite if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { void(*action)(ext_save_data_info*, bool*) = (void(*)(ext_save_data_info*, bool*)) selected->data; - list_destroy(view); ui_pop(); + list_destroy(view); action(actionData->info, actionData->populated); @@ -66,12 +66,12 @@ static void extsavedata_action_update(ui_view* view, void* data, list_item** ite } } -static ui_view* extsavedata_action_create(ext_save_data_info* info, bool* populated) { +static void extsavedata_action_open(ext_save_data_info* info, bool* populated) { extsavedata_action_data* data = (extsavedata_action_data*) calloc(1, sizeof(extsavedata_action_data)); data->info = info; data->populated = populated; - return list_create("Ext Save Data Action", "A: Select, B: Return", data, extsavedata_action_update, extsavedata_action_draw_top); + list_display("Ext Save Data Action", "A: Select, B: Return", data, extsavedata_action_update, extsavedata_action_draw_top); } static void extsavedata_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { @@ -94,8 +94,9 @@ static void extsavedata_update(ui_view* view, void* data, list_item** items, u32 } ui_pop(); - free(listData); list_destroy(view); + + free(listData); return; } @@ -114,7 +115,7 @@ static void extsavedata_update(ui_view* view, void* data, list_item** items, u32 } if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { - ui_push(extsavedata_action_create((ext_save_data_info*) selected->data, &listData->populated)); + extsavedata_action_open((ext_save_data_info*) selected->data, &listData->populated); return; } @@ -127,5 +128,5 @@ static void extsavedata_update(ui_view* view, void* data, list_item** items, u32 void extsavedata_open() { extsavedata_data* data = (extsavedata_data*) calloc(1, sizeof(extsavedata_data)); - ui_push(list_create("Ext Save Data", "A: Select, B: Return, X: Refresh", data, extsavedata_update, extsavedata_draw_top)); + list_display("Ext Save Data", "A: Select, B: Return, X: Refresh", data, extsavedata_update, extsavedata_draw_top); } \ No newline at end of file diff --git a/source/ui/section/files.c b/source/ui/section/files.c index 81f8a80..88a3681 100644 --- a/source/ui/section/files.c +++ b/source/ui/section/files.c @@ -118,8 +118,8 @@ static void files_action_update(ui_view* view, void* data, list_item** items, u3 files_action_data* actionData = (files_action_data*) data; if(hidKeysDown() & KEY_B) { - list_destroy(view); ui_pop(); + list_destroy(view); free(data); @@ -129,8 +129,8 @@ static void files_action_update(ui_view* view, void* data, list_item** items, u3 if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { void(*action)(file_info*, bool*) = (void(*)(file_info*, bool*)) selected->data; - list_destroy(view); ui_pop(); + list_destroy(view); action(actionData->info, actionData->populated); @@ -181,12 +181,12 @@ static void files_action_update(ui_view* view, void* data, list_item** items, u3 } } -static ui_view* files_action_create(file_info* info, bool* populated) { +static void files_action_open(file_info* info, bool* populated) { files_action_data* data = (files_action_data*) calloc(1, sizeof(files_action_data)); data->info = info; data->populated = populated; - return list_create(info->isDirectory ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top); + list_display(info->isDirectory ? "Directory Action" : "File Action", "A: Select, B: Return", data, files_action_update, files_action_draw_top); } static void files_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { @@ -258,8 +258,9 @@ static void files_update(ui_view* view, void* data, list_item** items, u32** ite } ui_pop(); - free(listData); list_destroy(view); + + free(listData); return; } else { files_navigate(listData, listData->parentDir.path); @@ -267,7 +268,7 @@ static void files_update(ui_view* view, void* data, list_item** items, u32** ite } if(hidKeysDown() & KEY_Y) { - ui_push(files_action_create(&listData->currDir, &listData->populated)); + files_action_open(&listData->currDir, &listData->populated); return; } @@ -277,7 +278,7 @@ static void files_update(ui_view* view, void* data, list_item** items, u32** ite if(util_is_dir(&listData->archive, fileInfo->path)) { files_navigate(listData, fileInfo->path); } else { - ui_push(files_action_create(fileInfo, &listData->populated)); + files_action_open(fileInfo, &listData->populated); return; } } @@ -326,7 +327,7 @@ void files_open(FS_Archive archive) { memcpy(&data->parentDir, &data->currDir, sizeof(data->parentDir)); - ui_push(list_create("Files", "A: Select, B: Back, X: Refresh, Y: Directory Action", data, files_update, files_draw_top)); + list_display("Files", "A: Select, B: Back, X: Refresh, Y: Directory Action", data, files_update, files_draw_top); } void files_open_sd() { diff --git a/source/ui/section/networkinstall.c b/source/ui/section/networkinstall.c index c817406..bab73d4 100644 --- a/source/ui/section/networkinstall.c +++ b/source/ui/section/networkinstall.c @@ -4,17 +4,14 @@ #include #include #include -#include #include <3ds.h> #include "action/action.h" -#include "task/task.h" #include "../error.h" -#include "../progressbar.h" +#include "../info.h" #include "../prompt.h" #include "../../screen.h" -#include "../../util.h" #include "section.h" typedef struct { @@ -65,7 +62,7 @@ static Result networkinstall_open_src(void* data, u32 index, u32* handle) { u8 ack = 1; if(sendwait(networkInstallData->clientSocket, &ack, sizeof(ack), 0) < 0) { - return -1; + return R_FBI_ERRNO; } return 0; @@ -80,7 +77,7 @@ static Result networkinstall_get_src_size(void* data, u32 handle, u64* size) { u64 netSize = 0; if(recvwait(networkInstallData->clientSocket, &netSize, sizeof(netSize), 0) < 0) { - return -1; + return R_FBI_ERRNO; } *size = __builtin_bswap64(netSize); @@ -92,7 +89,7 @@ static Result networkinstall_read_src(void* data, u32 handle, u32* bytesRead, vo int ret = 0; if((ret = recvwait(networkInstallData->clientSocket, buffer, size, 0)) < 0) { - return -1; + return R_FBI_ERRNO; } *bytesRead = (u32) ret; @@ -112,7 +109,7 @@ static Result networkinstall_open_dst(void* data, u32 index, void* initialReadBl u8 n3ds = false; if(R_SUCCEEDED(APT_CheckNew3DS(&n3ds)) && !n3ds && ((titleId >> 28) & 0xF) == 2) { - return MAKERESULT(RL_PERMANENT, RS_NOTSUPPORTED, RM_APPLICATION, RD_INVALID_COMBINATION); + return R_FBI_WRONG_SYSTEM; } // Deleting FBI before it reinstalls itself causes issues. @@ -154,65 +151,41 @@ static Result networkinstall_write_dst(void* data, u32 handle, u32* bytesWritten return FSFILE_Write(handle, bytesWritten, offset, buffer, size, 0); } -static bool networkinstall_result_error(void* data, u32 index, Result res) { - network_install_data* networkInstallData = (network_install_data*) data; - - if(res == MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED)) { - ui_push(prompt_create("Failure", "Install cancelled.", COLOR_TEXT, false, NULL, NULL, NULL, NULL)); - return false; +static bool networkinstall_error(void* data, u32 index, Result res) { + if(res == R_FBI_CANCELLED) { + prompt_display("Failure", "Install cancelled.", COLOR_TEXT, false, NULL, NULL, NULL, NULL); + } else if(res == R_FBI_ERRNO) { + error_display_errno(NULL, NULL, NULL, errno, "Failed to install CIA file."); + } else if(res == R_FBI_WRONG_SYSTEM) { + error_display(NULL, NULL, NULL, "Failed to install CIA file.\nAttempted to install N3DS title to O3DS."); } else { - volatile bool dismissed = false; - if(res == MAKERESULT(RL_PERMANENT, RS_NOTSUPPORTED, RM_APPLICATION, RD_INVALID_COMBINATION)) { - error_display(&dismissed, NULL, NULL, "Failed to install CIA file.\nAttempted to install N3DS title to O3DS."); - } else { - error_display_res(&dismissed, NULL, NULL, res, "Failed to install CIA file."); - } - - while(!dismissed) { - svcSleepThread(1000000); - } + error_display_res(NULL, NULL, NULL, res, "Failed to install CIA file."); } - return index < networkInstallData->installInfo.total - 1; -} - -static bool networkinstall_io_error(void* data, u32 index, int err) { - network_install_data* networkInstallData = (network_install_data*) data; - - volatile bool dismissed = false; - error_display_errno(&dismissed, NULL, NULL, err, "Failed to install CIA file."); - - while(!dismissed) { - svcSleepThread(1000000); - } - - return index < networkInstallData->installInfo.total - 1; -} - -static void networkinstall_done_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); + return false; } static void networkinstall_close_client(network_install_data* data) { u8 ack = 0; sendwait(data->clientSocket, &ack, sizeof(ack), 0); + close(data->clientSocket); data->currTitleId = 0; data->cancelEvent = 0; } -static void networkinstall_install_update(ui_view* view, void* data, float* progress, char* progressText) { +static void networkinstall_install_update(ui_view* view, void* data, float* progress, char* text) { network_install_data* networkInstallData = (network_install_data*) data; if(networkInstallData->installInfo.finished) { networkinstall_close_client(networkInstallData); ui_pop(); - progressbar_destroy(view); + info_destroy(view); if(!networkInstallData->installInfo.premature) { - ui_push(prompt_create("Success", "Install finished.", COLOR_TEXT, false, data, NULL, NULL, networkinstall_done_onresponse)); + prompt_display("Success", "Install finished.", COLOR_TEXT, false, data, NULL, NULL, NULL); } return; @@ -223,20 +196,16 @@ static void networkinstall_install_update(ui_view* view, void* data, float* prog } *progress = networkInstallData->installInfo.currTotal != 0 ? (float) ((double) networkInstallData->installInfo.currProcessed / (double) networkInstallData->installInfo.currTotal) : 0; - snprintf(progressText, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", networkInstallData->installInfo.processed, networkInstallData->installInfo.total, networkInstallData->installInfo.currProcessed / 1024.0 / 1024.0, networkInstallData->installInfo.currTotal / 1024.0 / 1024.0); + snprintf(text, PROGRESS_TEXT_MAX, "%lu / %lu\n%.2f MB / %.2f MB", networkInstallData->installInfo.processed, networkInstallData->installInfo.total, networkInstallData->installInfo.currProcessed / 1024.0 / 1024.0, networkInstallData->installInfo.currTotal / 1024.0 / 1024.0); } static void networkinstall_confirm_onresponse(ui_view* view, void* data, bool response) { - prompt_destroy(view); - network_install_data* networkInstallData = (network_install_data*) data; if(response) { networkInstallData->cancelEvent = task_data_op(&networkInstallData->installInfo); if(networkInstallData->cancelEvent != 0) { - ui_view* progressView = progressbar_create("Installing CIA(s)", "Press B to cancel.", data, networkinstall_install_update, NULL); - snprintf(progressbar_get_progress_text(progressView), PROGRESS_TEXT_MAX, "0 / %lu", networkInstallData->installInfo.total); - ui_push(progressView); + info_display("Installing CIA(s)", "Press B to cancel.", true, data, networkinstall_install_update, NULL); } else { error_display(NULL, NULL, NULL, "Failed to initiate CIA installation."); @@ -247,15 +216,15 @@ static void networkinstall_confirm_onresponse(ui_view* view, void* data, bool re } } -static void networkinstall_wait_update(ui_view* view, void* data, float bx1, float by1, float bx2, float by2) { +static void networkinstall_wait_update(ui_view* view, void* data, float* progress, char* text) { network_install_data* networkInstallData = (network_install_data*) data; if(hidKeysDown() & KEY_B) { - close(networkInstallData->serverSocket); - - free(networkInstallData); - free(view); ui_pop(); + info_destroy(view); + + close(networkInstallData->serverSocket); + free(networkInstallData); return; } @@ -265,9 +234,6 @@ static void networkinstall_wait_update(ui_view* view, void* data, float bx1, flo int sock = accept(networkInstallData->serverSocket, (struct sockaddr*) &client, &clientLen); if(sock >= 0) { - int bufSize = 1024 * 32; - setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufSize, sizeof(bufSize)); - if(recvwait(sock, &networkInstallData->installInfo.total, sizeof(networkInstallData->installInfo.total), 0) < 0) { close(sock); @@ -278,25 +244,13 @@ static void networkinstall_wait_update(ui_view* view, void* data, float bx1, flo networkInstallData->installInfo.total = ntohl(networkInstallData->installInfo.total); networkInstallData->clientSocket = sock; - ui_push(prompt_create("Confirmation", "Install received CIA(s)?", COLOR_TEXT, true, data, NULL, NULL, networkinstall_confirm_onresponse)); + prompt_display("Confirmation", "Install received CIA(s)?", COLOR_TEXT, true, data, NULL, NULL, networkinstall_confirm_onresponse); } else if(errno != EAGAIN) { error_display_errno(NULL, NULL, NULL, errno, "Failed to open socket."); } -} -static void networkinstall_wait_draw_bottom(ui_view* view, void* data, float x1, float y1, float x2, float y2) { struct in_addr addr = {(in_addr_t) gethostid()}; - - char text[128]; - snprintf(text, 128, "Waiting for connection...\nIP: %s\nPort: 5000", inet_ntoa(addr)); - - float textWidth; - float textHeight; - screen_get_string_size(&textWidth, &textHeight, text, 0.5f, 0.5f); - - float textX = x1 + (x2 - x1 - textWidth) / 2; - float textY = y1 + (y2 - y1 - textHeight) / 2; - screen_draw_string(text, textX, textY, 0.5f, 0.5f, COLOR_TEXT, false); + snprintf(text, PROGRESS_TEXT_MAX, "Waiting for connection...\nIP: %s\nPort: 5000", inet_ntoa(addr)); } void networkinstall_open() { @@ -306,6 +260,9 @@ void networkinstall_open() { return; } + int bufSize = 1024 * 32; + setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufSize, sizeof(bufSize)); + struct sockaddr_in server; server.sin_family = AF_INET; server.sin_port = htons(5000); @@ -351,17 +308,9 @@ void networkinstall_open() { data->installInfo.closeDst = networkinstall_close_dst; data->installInfo.writeDst = networkinstall_write_dst; - data->installInfo.resultError = networkinstall_result_error; - data->installInfo.ioError = networkinstall_io_error; + data->installInfo.error = networkinstall_error; data->cancelEvent = 0; - ui_view* view = (ui_view*) calloc(1, sizeof(ui_view)); - view->name = "Network Install"; - view->info = "B: Return"; - view->data = data; - view->update = networkinstall_wait_update; - view->drawTop = NULL; - view->drawBottom = networkinstall_wait_draw_bottom; - ui_push(view); + info_display("Network Install", "B: Return", false, data, networkinstall_wait_update, NULL); } diff --git a/source/ui/section/pendingtitles.c b/source/ui/section/pendingtitles.c index a70238f..33a8598 100644 --- a/source/ui/section/pendingtitles.c +++ b/source/ui/section/pendingtitles.c @@ -38,8 +38,8 @@ static void pendingtitles_action_update(ui_view* view, void* data, list_item** i pendingtitles_action_data* actionData = (pendingtitles_action_data*) data; if(hidKeysDown() & KEY_B) { - list_destroy(view); ui_pop(); + list_destroy(view); free(data); @@ -49,8 +49,8 @@ static void pendingtitles_action_update(ui_view* view, void* data, list_item** i if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { void(*action)(pending_title_info*, bool*) = (void(*)(pending_title_info*, bool*)) selected->data; - list_destroy(view); ui_pop(); + list_destroy(view); action(actionData->info, actionData->populated); @@ -65,12 +65,12 @@ static void pendingtitles_action_update(ui_view* view, void* data, list_item** i } } -static ui_view* pendingtitles_action_create(pending_title_info* info, bool* populated) { +static void pendingtitles_action_open(pending_title_info* info, bool* populated) { pendingtitles_action_data* data = (pendingtitles_action_data*) calloc(1, sizeof(pendingtitles_action_data)); data->info = info; data->populated = populated; - return list_create("Pending Title Action", "A: Select, B: Return", data, pendingtitles_action_update, pendingtitles_action_draw_top); + list_display("Pending Title Action", "A: Select, B: Return", data, pendingtitles_action_update, pendingtitles_action_draw_top); } static void pendingtitles_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { @@ -93,8 +93,9 @@ static void pendingtitles_update(ui_view* view, void* data, list_item** items, u } ui_pop(); - free(listData); list_destroy(view); + + free(listData); return; } @@ -113,7 +114,7 @@ static void pendingtitles_update(ui_view* view, void* data, list_item** items, u } if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { - ui_push(pendingtitles_action_create((pending_title_info*) selected->data, &listData->populated)); + pendingtitles_action_open((pending_title_info*) selected->data, &listData->populated); return; } @@ -126,5 +127,5 @@ static void pendingtitles_update(ui_view* view, void* data, list_item** items, u void pendingtitles_open() { pendingtitles_data* data = (pendingtitles_data*) calloc(1, sizeof(pendingtitles_data)); - ui_push(list_create("Pending Titles", "A: Select, B: Return, X: Refresh", data, pendingtitles_update, pendingtitles_draw_top)); + list_display("Pending Titles", "A: Select, B: Return, X: Refresh", data, pendingtitles_update, pendingtitles_draw_top); } \ No newline at end of file diff --git a/source/ui/section/systemsavedata.c b/source/ui/section/systemsavedata.c index 4dc4017..a2cd14b 100644 --- a/source/ui/section/systemsavedata.c +++ b/source/ui/section/systemsavedata.c @@ -38,8 +38,8 @@ static void systemsavedata_action_update(ui_view* view, void* data, list_item** systemsavedata_action_data* actionData = (systemsavedata_action_data*) data; if(hidKeysDown() & KEY_B) { - list_destroy(view); ui_pop(); + list_destroy(view); free(data); @@ -49,8 +49,8 @@ static void systemsavedata_action_update(ui_view* view, void* data, list_item** if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { void(*action)(system_save_data_info*, bool*) = (void(*)(system_save_data_info*, bool*)) selected->data; - list_destroy(view); ui_pop(); + list_destroy(view); action(actionData->info, actionData->populated); @@ -65,12 +65,12 @@ static void systemsavedata_action_update(ui_view* view, void* data, list_item** } } -static ui_view* systemsavedata_action_create(system_save_data_info* info, bool* populated) { +static void systemsavedata_action_open(system_save_data_info* info, bool* populated) { systemsavedata_action_data* data = (systemsavedata_action_data*) calloc(1, sizeof(systemsavedata_action_data)); data->info = info; data->populated = populated; - return list_create("System Save Data Action", "A: Select, B: Return", data, systemsavedata_action_update, systemsavedata_action_draw_top); + list_display("System Save Data Action", "A: Select, B: Return", data, systemsavedata_action_update, systemsavedata_action_draw_top); } static void systemsavedata_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { @@ -93,8 +93,9 @@ static void systemsavedata_update(ui_view* view, void* data, list_item** items, } ui_pop(); - free(listData); list_destroy(view); + + free(listData); return; } @@ -113,7 +114,7 @@ static void systemsavedata_update(ui_view* view, void* data, list_item** items, } if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { - ui_push(systemsavedata_action_create((system_save_data_info*) selected->data, &listData->populated)); + systemsavedata_action_open((system_save_data_info*) selected->data, &listData->populated); return; } @@ -126,5 +127,5 @@ static void systemsavedata_update(ui_view* view, void* data, list_item** items, void systemsavedata_open() { systemsavedata_data* data = (systemsavedata_data*) calloc(1, sizeof(systemsavedata_data)); - ui_push(list_create("System Save Data", "A: Select, B: Return, X: Refresh", data, systemsavedata_update, systemsavedata_draw_top)); + list_display("System Save Data", "A: Select, B: Return, X: Refresh", data, systemsavedata_update, systemsavedata_draw_top); } \ No newline at end of file diff --git a/source/ui/section/task/copydata.c b/source/ui/section/task/dataop.c similarity index 88% rename from source/ui/section/task/copydata.c rename to source/ui/section/task/dataop.c index 0e378c9..3c3be31 100644 --- a/source/ui/section/task/copydata.c +++ b/source/ui/section/task/dataop.c @@ -2,7 +2,6 @@ #include #include <3ds.h> -#include #include "../../list.h" #include "../../error.h" @@ -43,7 +42,7 @@ static bool task_data_op_copy(data_op_data* data, u32 index) { bool firstRun = true; while(data->info->currProcessed < data->info->currTotal) { if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) { - res = MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, RD_CANCEL_REQUESTED); + res = R_FBI_CANCELLED; break; } @@ -82,7 +81,7 @@ static bool task_data_op_copy(data_op_data* data, u32 index) { free(buffer); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, RM_APPLICATION, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } } } @@ -95,11 +94,7 @@ static bool task_data_op_copy(data_op_data* data, u32 index) { } if(R_FAILED(res)) { - if(res == -1) { - return data->info->ioError(data->info->data, index, errno); - } else { - return data->info->resultError(data->info->data, index, res); - } + return data->info->error(data->info->data, index, res); } return true; @@ -108,11 +103,7 @@ static bool task_data_op_copy(data_op_data* data, u32 index) { static bool task_data_op_delete(data_op_data* data, u32 index) { Result res = 0; if(R_FAILED(res = data->info->delete(data->info->data, index))) { - if(res == -1) { - return data->info->ioError(data->info->data, index, errno); - } else { - return data->info->resultError(data->info->data, index, res); - } + return data->info->error(data->info->data, index, res); } return true; @@ -174,14 +165,14 @@ Handle task_data_op(data_op_info* info) { Result eventRes = svcCreateEvent(&installData->cancelEvent, 1); if(R_FAILED(eventRes)) { - error_display_res(NULL, NULL, NULL, eventRes, "Failed to create CIA installation cancel event."); + error_display_res(NULL, NULL, NULL, eventRes, "Failed to create data operation cancel event."); free(installData); return 0; } if(threadCreate(task_data_op_thread, installData, 0x4000, 0x18, 1, true) == NULL) { - error_display(NULL, NULL, NULL, "Failed to create CIA installation thread."); + error_display(NULL, NULL, NULL, "Failed to create data operation thread."); svcCloseHandle(installData->cancelEvent); free(installData); diff --git a/source/ui/section/task/listextsavedata.c b/source/ui/section/task/listextsavedata.c index 7587995..8883527 100644 --- a/source/ui/section/task/listextsavedata.c +++ b/source/ui/section/task/listextsavedata.c @@ -94,7 +94,7 @@ static Result task_populate_ext_save_data_from(populate_ext_save_data_data* data free(extSaveDataIds); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } return res; diff --git a/source/ui/section/task/listfiles.c b/source/ui/section/task/listfiles.c index 33955a7..d188eb2 100644 --- a/source/ui/section/task/listfiles.c +++ b/source/ui/section/task/listfiles.c @@ -146,7 +146,7 @@ static void task_populate_files_thread(void* arg) { free(entries); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } FSDIR_Close(dirHandle); diff --git a/source/ui/section/task/listpendingtitles.c b/source/ui/section/task/listpendingtitles.c index ca788a1..418a895 100644 --- a/source/ui/section/task/listpendingtitles.c +++ b/source/ui/section/task/listpendingtitles.c @@ -61,13 +61,13 @@ static Result task_populate_pending_titles_from(populate_pending_titles_data* da free(pendingTitleInfos); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } } free(pendingTitleIds); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } } diff --git a/source/ui/section/task/listsystemsavedata.c b/source/ui/section/task/listsystemsavedata.c index c20833f..6341f31 100644 --- a/source/ui/section/task/listsystemsavedata.c +++ b/source/ui/section/task/listsystemsavedata.c @@ -52,7 +52,7 @@ static void task_populate_system_save_data_thread(void* arg) { free(systemSaveDataIds); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } if(R_FAILED(res)) { diff --git a/source/ui/section/task/listtickets.c b/source/ui/section/task/listtickets.c index 948b12a..6f4540e 100644 --- a/source/ui/section/task/listtickets.c +++ b/source/ui/section/task/listtickets.c @@ -53,7 +53,7 @@ static void task_populate_tickets_thread(void* arg) { free(ticketIds); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } } diff --git a/source/ui/section/task/listtitles.c b/source/ui/section/task/listtitles.c index 348dc1f..521e1df 100644 --- a/source/ui/section/task/listtitles.c +++ b/source/ui/section/task/listtitles.c @@ -198,13 +198,13 @@ static Result task_populate_titles_from(populate_titles_data* data, FS_MediaType free(titleInfos); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } } free(titleIds); } else { - res = MAKERESULT(RL_PERMANENT, RS_INVALIDSTATE, 254, RD_OUT_OF_MEMORY); + res = R_FBI_OUT_OF_MEMORY; } } } else { diff --git a/source/ui/section/task/task.h b/source/ui/section/task/task.h index 15b5abc..aa1c6bc 100644 --- a/source/ui/section/task/task.h +++ b/source/ui/section/task/task.h @@ -68,6 +68,12 @@ typedef struct { ticket_info ticketInfo; } file_info; +#define R_FBI_CANCELLED MAKERESULT(RL_PERMANENT, RS_CANCELED, RM_APPLICATION, 1) +#define R_FBI_ERRNO MAKERESULT(RL_PERMANENT, RS_INTERNAL, RM_APPLICATION, 2) +#define R_FBI_WRONG_SYSTEM MAKERESULT(RL_PERMANENT, RS_NOTSUPPORTED, RM_APPLICATION, 3) + +#define R_FBI_OUT_OF_MEMORY MAKERESULT(RL_FATAL, RS_OUTOFRESOURCE, RM_APPLICATION, RD_OUT_OF_MEMORY) + typedef enum { DATAOP_COPY, DATAOP_DELETE @@ -108,8 +114,7 @@ typedef struct { Result (*delete)(void* data, u32 index); // Errors - bool (*resultError)(void* data, u32 index, Result res); - bool (*ioError)(void* data, u32 index, int err); + bool (*error)(void* data, u32 index, Result res); } data_op_info; bool task_is_quit_all(); diff --git a/source/ui/section/tickets.c b/source/ui/section/tickets.c index f1c94f2..e6114b8 100644 --- a/source/ui/section/tickets.c +++ b/source/ui/section/tickets.c @@ -36,8 +36,8 @@ static void tickets_action_update(ui_view* view, void* data, list_item** items, tickets_action_data* actionData = (tickets_action_data*) data; if(hidKeysDown() & KEY_B) { - list_destroy(view); ui_pop(); + list_destroy(view); free(data); @@ -47,8 +47,8 @@ static void tickets_action_update(ui_view* view, void* data, list_item** items, if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { void(*action)(ticket_info*, bool*) = (void(*)(ticket_info*, bool*)) selected->data; - list_destroy(view); ui_pop(); + list_destroy(view); action(actionData->info, actionData->populated); @@ -63,12 +63,12 @@ static void tickets_action_update(ui_view* view, void* data, list_item** items, } } -static ui_view* tickets_action_create(ticket_info* info, bool* populated) { +static void tickets_action_open(ticket_info* info, bool* populated) { tickets_action_data* data = (tickets_action_data*) calloc(1, sizeof(tickets_action_data)); data->info = info; data->populated = populated; - return list_create("Ticket Action", "A: Select, B: Return", data, tickets_action_update, tickets_action_draw_top); + list_display("Ticket Action", "A: Select, B: Return", data, tickets_action_update, tickets_action_draw_top); } static void tickets_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { @@ -91,8 +91,9 @@ static void tickets_update(ui_view* view, void* data, list_item** items, u32** i } ui_pop(); - free(listData); list_destroy(view); + + free(listData); return; } @@ -111,7 +112,7 @@ static void tickets_update(ui_view* view, void* data, list_item** items, u32** i } if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { - ui_push(tickets_action_create((ticket_info*) selected->data, &listData->populated)); + tickets_action_open((ticket_info*) selected->data, &listData->populated); return; } @@ -124,5 +125,5 @@ static void tickets_update(ui_view* view, void* data, list_item** items, u32** i void tickets_open() { tickets_data* data = (tickets_data*) calloc(1, sizeof(tickets_data)); - ui_push(list_create("Tickets", "A: Select, B: Return, X: Refresh", data, tickets_update, tickets_draw_top)); + list_display("Tickets", "A: Select, B: Return, X: Refresh", data, tickets_update, tickets_draw_top); } \ No newline at end of file diff --git a/source/ui/section/titles.c b/source/ui/section/titles.c index ce06726..08378e9 100644 --- a/source/ui/section/titles.c +++ b/source/ui/section/titles.c @@ -65,8 +65,8 @@ static void titles_action_update(ui_view* view, void* data, list_item** items, u titles_action_data* actionData = (titles_action_data*) data; if(hidKeysDown() & KEY_B) { - list_destroy(view); ui_pop(); + list_destroy(view); free(data); @@ -76,8 +76,8 @@ static void titles_action_update(ui_view* view, void* data, list_item** items, u if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { void(*action)(title_info*, bool*) = (void(*)(title_info*, bool*)) selected->data; - list_destroy(view); ui_pop(); + list_destroy(view); action(actionData->info, actionData->populated); @@ -109,12 +109,12 @@ static void titles_action_update(ui_view* view, void* data, list_item** items, u } } -static ui_view* titles_action_create(title_info* info, bool* populated) { +static void titles_action_open(title_info* info, bool* populated) { titles_action_data* data = (titles_action_data*) calloc(1, sizeof(titles_action_data)); data->info = info; data->populated = populated; - return list_create("Title Action", "A: Select, B: Return", data, titles_action_update, titles_action_draw_top); + list_display("Title Action", "A: Select, B: Return", data, titles_action_update, titles_action_draw_top); } static void titles_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { @@ -137,8 +137,9 @@ static void titles_update(ui_view* view, void* data, list_item** items, u32** it } ui_pop(); - free(listData); list_destroy(view); + + free(listData); return; } @@ -157,7 +158,7 @@ static void titles_update(ui_view* view, void* data, list_item** items, u32** it } if(selected != NULL && selected->data != NULL && (selectedTouched || (hidKeysDown() & KEY_A))) { - ui_push(titles_action_create((title_info*) selected->data, &listData->populated)); + titles_action_open((title_info*) selected->data, &listData->populated); return; } @@ -170,5 +171,5 @@ static void titles_update(ui_view* view, void* data, list_item** items, u32** it void titles_open() { titles_data* data = (titles_data*) calloc(1, sizeof(titles_data)); - ui_push(list_create("Titles", "A: Select, B: Return, X: Refresh", data, titles_update, titles_draw_top)); + list_display("Titles", "A: Select, B: Return, X: Refresh", data, titles_update, titles_draw_top); } \ No newline at end of file