Automatically determine appropriate CIA destination.

This commit is contained in:
Steven Smith 2016-04-12 18:27:42 -07:00
parent b4c70f0bb6
commit b384008bb1
8 changed files with 24 additions and 58 deletions

View File

@ -8,7 +8,7 @@
#include "section/section.h" #include "section/section.h"
#include "../screen.h" #include "../screen.h"
#define MAINMENU_ITEM_COUNT 13 #define MAINMENU_ITEM_COUNT 12
static u32 mainmenu_item_count = MAINMENU_ITEM_COUNT; static u32 mainmenu_item_count = MAINMENU_ITEM_COUNT;
static list_item mainmenu_items[MAINMENU_ITEM_COUNT] = { static list_item mainmenu_items[MAINMENU_ITEM_COUNT] = {
@ -23,8 +23,7 @@ static list_item mainmenu_items[MAINMENU_ITEM_COUNT] = {
{"Tickets", COLOR_TEXT, tickets_open}, {"Tickets", COLOR_TEXT, tickets_open},
{"Ext Save Data", COLOR_TEXT, extsavedata_open}, {"Ext Save Data", COLOR_TEXT, extsavedata_open},
{"System Save Data", COLOR_TEXT, systemsavedata_open}, {"System Save Data", COLOR_TEXT, systemsavedata_open},
{"Network Install to SD", COLOR_TEXT, networkinstall_open_sd}, {"Network Install", COLOR_TEXT, networkinstall_open},
{"Network Install to NAND", COLOR_TEXT, networkinstall_open_nand},
}; };
static void mainmenu_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) { static void mainmenu_draw_top(ui_view* view, void* data, float x1, float y1, float x2, float y2, list_item* selected) {

View File

@ -9,10 +9,8 @@ void action_delete_ext_save_data(ext_save_data_info* info, bool* populated);
void action_browse_system_save_data(system_save_data_info* info, bool* populated); void action_browse_system_save_data(system_save_data_info* info, bool* populated);
void action_delete_system_save_data(system_save_data_info* info, bool* populated); void action_delete_system_save_data(system_save_data_info* info, bool* populated);
void action_install_cias_nand(file_info* info, bool* populated); void action_install_cias(file_info* info, bool* populated);
void action_install_cias_sd(file_info* info, bool* populated); void action_install_cias_delete(file_info* info, bool* populated);
void action_install_cias_delete_nand(file_info* info, bool* populated);
void action_install_cias_delete_sd(file_info* info, bool* populated);
void action_copy_contents(file_info* info, bool* populated); void action_copy_contents(file_info* info, bool* populated);
void action_delete_contents(file_info* info, bool* populated); void action_delete_contents(file_info* info, bool* populated);
void action_delete_dir_contents(file_info* info, bool* populated); void action_delete_dir_contents(file_info* info, bool* populated);

View File

@ -14,7 +14,6 @@
typedef struct { typedef struct {
file_info* base; file_info* base;
FS_MediaType dest;
bool delete; bool delete;
bool* populated; bool* populated;
Handle currHandle; Handle currHandle;
@ -142,7 +141,7 @@ static void action_install_cias_update(ui_view* view, void* data, float* progres
if(R_SUCCEEDED(res = FSFILE_GetSize(installData->currHandle, &size))) { if(R_SUCCEEDED(res = FSFILE_GetSize(installData->currHandle, &size))) {
installData->currTotal = size; installData->currTotal = size;
installData->installCancelEvent = task_install_cia(&installData->installResult, installData->dest, installData->currTotal, installData, action_install_cias_read); installData->installCancelEvent = task_install_cia(&installData->installResult, installData->currTotal, installData, action_install_cias_read);
if(installData->installCancelEvent == 0) { if(installData->installCancelEvent == 0) {
ui_pop(); ui_pop();
progressbar_destroy(view); progressbar_destroy(view);
@ -192,10 +191,9 @@ static void action_install_cias_onresponse(ui_view* view, void* data, bool respo
} }
} }
static void action_install_cias(file_info* info, bool* populated, FS_MediaType mediaType, bool delete) { static void action_install_cias_internal(file_info* info, bool* populated, bool delete) {
install_cias_data* data = (install_cias_data*) calloc(1, sizeof(install_cias_data)); install_cias_data* data = (install_cias_data*) calloc(1, sizeof(install_cias_data));
data->base = info; data->base = info;
data->dest = mediaType;
data->delete = delete; data->delete = delete;
data->populated = populated; data->populated = populated;
data->installStarted = false; data->installStarted = false;
@ -214,18 +212,10 @@ static void action_install_cias(file_info* info, bool* populated, FS_MediaType m
ui_push(prompt_create("Confirmation", "Install the selected CIA(s)?", COLOR_TEXT, true, data, NULL, action_install_cias_draw_top, action_install_cias_onresponse)); ui_push(prompt_create("Confirmation", "Install the selected CIA(s)?", COLOR_TEXT, true, data, NULL, action_install_cias_draw_top, action_install_cias_onresponse));
} }
void action_install_cias_nand(file_info* info, bool* populated) { void action_install_cias(file_info* info, bool* populated) {
action_install_cias(info, populated, MEDIATYPE_NAND, false); action_install_cias_internal(info, populated, false);
} }
void action_install_cias_sd(file_info* info, bool* populated) { void action_install_cias_delete(file_info* info, bool* populated) {
action_install_cias(info, populated, MEDIATYPE_SD, false); action_install_cias_internal(info, populated, true);
}
void action_install_cias_delete_nand(file_info* info, bool* populated) {
action_install_cias(info, populated, MEDIATYPE_NAND, true);
}
void action_install_cias_delete_sd(file_info* info, bool* populated) {
action_install_cias(info, populated, MEDIATYPE_SD, true);
} }

View File

@ -36,14 +36,12 @@ static list_item files_action_items[FILES_ACTION_COUNT] = {
{"Paste", COLOR_TEXT, action_paste_contents}, {"Paste", COLOR_TEXT, action_paste_contents},
}; };
#define CIA_FILES_ACTION_COUNT 7 #define CIA_FILES_ACTION_COUNT 5
static u32 cia_files_action_count = CIA_FILES_ACTION_COUNT; static u32 cia_files_action_count = CIA_FILES_ACTION_COUNT;
static list_item cia_files_action_items[CIA_FILES_ACTION_COUNT] = { static list_item cia_files_action_items[CIA_FILES_ACTION_COUNT] = {
{"Install CIA to SD", COLOR_TEXT, action_install_cias_sd}, {"Install CIA", COLOR_TEXT, action_install_cias},
{"Install CIA to NAND", COLOR_TEXT, action_install_cias_nand}, {"Install and delete CIA", COLOR_TEXT, action_install_cias_delete},
{"Install CIA to SD and delete", COLOR_TEXT, action_install_cias_delete_sd},
{"Install CIA to NAND and delete", COLOR_TEXT, action_install_cias_delete_nand},
{"Delete", COLOR_TEXT, action_delete_contents}, {"Delete", COLOR_TEXT, action_delete_contents},
{"Copy", COLOR_TEXT, action_copy_contents}, {"Copy", COLOR_TEXT, action_copy_contents},
{"Paste", COLOR_TEXT, action_paste_contents}, {"Paste", COLOR_TEXT, action_paste_contents},
@ -59,14 +57,12 @@ static list_item directories_action_items[DIRECTORIES_ACTION_COUNT] = {
{"Paste", COLOR_TEXT, action_paste_contents}, {"Paste", COLOR_TEXT, action_paste_contents},
}; };
#define CIA_DIRECTORIES_ACTION_COUNT 9 #define CIA_DIRECTORIES_ACTION_COUNT 7
static u32 cia_directories_action_count = CIA_DIRECTORIES_ACTION_COUNT; static u32 cia_directories_action_count = CIA_DIRECTORIES_ACTION_COUNT;
static list_item cia_directories_action_items[CIA_DIRECTORIES_ACTION_COUNT] = { static list_item cia_directories_action_items[CIA_DIRECTORIES_ACTION_COUNT] = {
{"Install all CIAs to SD", COLOR_TEXT, action_install_cias_sd}, {"Install all CIAs", COLOR_TEXT, action_install_cias},
{"Install all CIAs to NAND", COLOR_TEXT, action_install_cias_nand}, {"Install and delete all CIAs", COLOR_TEXT, action_install_cias_delete},
{"Install all CIAs to SD and delete", COLOR_TEXT, action_install_cias_delete_sd},
{"Install all CIAs to NAND and delete", COLOR_TEXT, action_install_cias_delete_nand},
{"Delete all CIAs", COLOR_TEXT, action_delete_dir_cias}, {"Delete all CIAs", COLOR_TEXT, action_delete_dir_cias},
{"Delete all contents", COLOR_TEXT, action_delete_dir_contents}, {"Delete all contents", COLOR_TEXT, action_delete_dir_contents},
{"Delete", COLOR_TEXT, action_delete_contents}, {"Delete", COLOR_TEXT, action_delete_contents},

View File

@ -18,7 +18,6 @@
#include "section.h" #include "section.h"
typedef struct { typedef struct {
FS_MediaType dest;
int serverSocket; int serverSocket;
int clientSocket; int clientSocket;
bool installStarted; bool installStarted;
@ -165,7 +164,7 @@ static void networkinstall_install_update(ui_view* view, void* data, float* prog
} }
networkInstallData->currTotal = __builtin_bswap64(networkInstallData->currTotal); networkInstallData->currTotal = __builtin_bswap64(networkInstallData->currTotal);
networkInstallData->installCancelEvent = task_install_cia(&networkInstallData->installResult, networkInstallData->dest, networkInstallData->currTotal, networkInstallData, networkinstall_read); networkInstallData->installCancelEvent = task_install_cia(&networkInstallData->installResult, networkInstallData->currTotal, networkInstallData, networkinstall_read);
if(networkInstallData->installCancelEvent == 0) { if(networkInstallData->installCancelEvent == 0) {
ui_pop(); ui_pop();
progressbar_destroy(view); progressbar_destroy(view);
@ -245,7 +244,7 @@ static void networkinstall_wait_draw_bottom(ui_view* view, void* data, float x1,
screen_draw_string(text, textX, textY, 0.5f, 0.5f, COLOR_TEXT, false); screen_draw_string(text, textX, textY, 0.5f, 0.5f, COLOR_TEXT, false);
} }
void networkinstall_open(FS_MediaType dest) { void networkinstall_open() {
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if(sock < 0) { if(sock < 0) {
error_display_errno(NULL, NULL, errno, "Failed to open server socket."); error_display_errno(NULL, NULL, errno, "Failed to open server socket.");
@ -274,7 +273,6 @@ void networkinstall_open(FS_MediaType dest) {
} }
network_install_data* data = (network_install_data*) calloc(1, sizeof(network_install_data)); network_install_data* data = (network_install_data*) calloc(1, sizeof(network_install_data));
data->dest = dest;
data->serverSocket = sock; data->serverSocket = sock;
data->clientSocket = 0; data->clientSocket = 0;
data->installStarted = false; data->installStarted = false;
@ -294,12 +292,4 @@ void networkinstall_open(FS_MediaType dest) {
view->drawTop = NULL; view->drawTop = NULL;
view->drawBottom = networkinstall_wait_draw_bottom; view->drawBottom = networkinstall_wait_draw_bottom;
ui_push(view); ui_push(view);
}
void networkinstall_open_sd() {
networkinstall_open(MEDIATYPE_SD);
}
void networkinstall_open_nand() {
networkinstall_open(MEDIATYPE_NAND);
} }

View File

@ -10,9 +10,7 @@ void files_open_ctr_nand();
void files_open_twl_nand(); void files_open_twl_nand();
void files_open_twl_photo(); void files_open_twl_photo();
void files_open_twl_sound(); void files_open_twl_sound();
void networkinstall_open(FS_MediaType dest); void networkinstall_open();
void networkinstall_open_sd();
void networkinstall_open_nand();
void pendingtitles_open(); void pendingtitles_open();
void systemsavedata_open(); void systemsavedata_open();
void tickets_open(); void tickets_open();

View File

@ -14,7 +14,6 @@
typedef struct { typedef struct {
install_cia_result* result; install_cia_result* result;
FS_MediaType dest;
u64 size; u64 size;
void* data; void* data;
Result (*read)(void* data, u32* bytesRead, void* buffer, u32 size); Result (*read)(void* data, u32* bytesRead, void* buffer, u32 size);
@ -86,9 +85,7 @@ static void task_install_cia_thread(void* arg) {
u32 certSize = *(u32*) &buffer[0x08]; u32 certSize = *(u32*) &buffer[0x08];
titleId = bswap_64(*(u64*) &buffer[align(headerSize, 64) + align(certSize, 64) + 0x1DC]); titleId = bswap_64(*(u64*) &buffer[align(headerSize, 64) + align(certSize, 64) + 0x1DC]);
if((titleId >> 32) & 0x8000) { FS_MediaType dest = ((titleId >> 32) & 0x8010) != 0 ? MEDIATYPE_NAND : MEDIATYPE_SD;
data->dest = MEDIATYPE_NAND;
}
u8 n3ds = false; u8 n3ds = false;
if(R_SUCCEEDED(APT_CheckNew3DS(&n3ds)) && !n3ds && ((titleId >> 28) & 0xF) == 2) { if(R_SUCCEEDED(APT_CheckNew3DS(&n3ds)) && !n3ds && ((titleId >> 28) & 0xF) == 2) {
@ -96,12 +93,11 @@ static void task_install_cia_thread(void* arg) {
break; break;
} }
// TODO: Does this fix? AM_DeleteTitle(dest, titleId);
AM_DeleteTitle(data->dest, titleId);
AM_DeleteTicket(titleId); AM_DeleteTicket(titleId);
AM_QueryAvailableExternalTitleDatabase(NULL); AM_QueryAvailableExternalTitleDatabase(NULL);
if(R_FAILED(data->result->result = AM_StartCiaInstall(data->dest, &ciaHandle))) { if(R_FAILED(data->result->result = AM_StartCiaInstall(dest, &ciaHandle))) {
break; break;
} }
} }
@ -138,14 +134,13 @@ static void task_install_cia_thread(void* arg) {
free(data); free(data);
} }
Handle task_install_cia(install_cia_result* result, FS_MediaType dest, u64 size, void* data, Result (*read)(void* data, u32* bytesRead, void* buffer, u32 size)) { Handle task_install_cia(install_cia_result* result, u64 size, void* data, Result (*read)(void* data, u32* bytesRead, void* buffer, u32 size)) {
if(result == NULL || size == 0 || read == NULL) { if(result == NULL || size == 0 || read == NULL) {
return 0; return 0;
} }
install_cia_data* installData = (install_cia_data*) calloc(1, sizeof(install_cia_data)); install_cia_data* installData = (install_cia_data*) calloc(1, sizeof(install_cia_data));
installData->result = result; installData->result = result;
installData->dest = dest;
installData->size = size; installData->size = size;
installData->data = data; installData->data = data;
installData->read = read; installData->read = read;

View File

@ -84,4 +84,4 @@ Handle task_populate_pending_titles(list_item* items, u32* count, u32 max);
Handle task_populate_system_save_data(list_item* items, u32* count, u32 max); Handle task_populate_system_save_data(list_item* items, u32* count, u32 max);
Handle task_populate_tickets(list_item* items, u32* count, u32 max); Handle task_populate_tickets(list_item* items, u32* count, u32 max);
Handle task_populate_titles(list_item* items, u32* count, u32 max); Handle task_populate_titles(list_item* items, u32* count, u32 max);
Handle task_install_cia(install_cia_result* result, FS_MediaType dest, u64 size, void* data, Result (*read)(void* data, u32* bytesRead, void* buffer, u32 size)); Handle task_install_cia(install_cia_result* result, u64 size, void* data, Result (*read)(void* data, u32* bytesRead, void* buffer, u32 size));