From b85389c43c28c599af7c891fe5582c1b61f6596a Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sun, 29 May 2016 08:36:46 -0700 Subject: [PATCH] Add support for updating FBI as a 3DSX. --- source/core/util.c | 10 ++++++++++ source/core/util.h | 5 ++++- source/main.c | 2 ++ source/ui/section/update.c | 34 +++++++++++++++++++++++++++------- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/source/core/util.c b/source/core/util.c index 8afc9de..22554fa 100644 --- a/source/core/util.c +++ b/source/core/util.c @@ -356,4 +356,14 @@ bool util_filter_tickets(void* data, const char* name, u32 attributes) { size_t len = strlen(name); return len >= 4 && strncasecmp(name + len - 4, ".tik", 4) == 0; +} + +static const char* path3dsx = NULL; + +const char* util_get_3dsx_path() { + return path3dsx; +} + +void util_set_3dsx_path(const char* path) { + path3dsx = path; } \ No newline at end of file diff --git a/source/core/util.h b/source/core/util.h index bcaa9d9..75862bc 100644 --- a/source/core/util.h +++ b/source/core/util.h @@ -60,4 +60,7 @@ u16 util_get_tmd_content_count(u8* tmd); u8* util_get_tmd_content_chunk(u8* tmd, u32 index); bool util_filter_cias(void* data, const char* name, u32 attributes); -bool util_filter_tickets(void* data, const char* name, u32 attributes); \ No newline at end of file +bool util_filter_tickets(void* data, const char* name, u32 attributes); + +const char* util_get_3dsx_path(); +void util_set_3dsx_path(const char* path); \ No newline at end of file diff --git a/source/main.c b/source/main.c index b563698..6959361 100644 --- a/source/main.c +++ b/source/main.c @@ -43,6 +43,8 @@ int main(int argc, const char* argv[]) { util_panic("Failed to acquire kernel access."); return 1; } + + util_set_3dsx_path(argv[0]); } aptOpenSession(); diff --git a/source/ui/section/update.c b/source/ui/section/update.c index 037304f..7baaf76 100644 --- a/source/ui/section/update.c +++ b/source/ui/section/update.c @@ -11,6 +11,7 @@ #include "../prompt.h" #include "../ui.h" #include "../../core/screen.h" +#include "../../core/util.h" #include "../../json/json.h" #define URL_MAX 1024 @@ -88,14 +89,31 @@ static Result update_read_src(void* data, u32 handle, u32* bytesRead, void* buff } static Result update_open_dst(void* data, u32 index, void* initialReadBlock, u32* handle) { - return AM_StartCiaInstall(MEDIATYPE_SD, handle); + if(util_get_3dsx_path() != NULL) { + FS_Path* path = util_make_path_utf8(util_get_3dsx_path()); + if(path != NULL) { + Result res = FSUSER_OpenFileDirectly(handle, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""), *path, FS_OPEN_WRITE | FS_OPEN_CREATE, 0); + + util_free_path_utf8(path); + return res; + } else { + return R_FBI_OUT_OF_MEMORY; + } + } else { + return AM_StartCiaInstall(MEDIATYPE_SD, handle); + } + } static Result update_close_dst(void* data, u32 index, bool succeeded, u32 handle) { - if(succeeded) { - return AM_FinishCiaInstall(handle); + if(util_get_3dsx_path() != NULL) { + return FSFILE_Close(handle); } else { - return AM_CancelCIAInstall(handle); + if(succeeded) { + return AM_FinishCiaInstall(handle); + } else { + return AM_CancelCIAInstall(handle); + } } } @@ -196,9 +214,11 @@ static void update_check_update(ui_view* view, void* data, float* progress, char } } - if(assetName != NULL && assetUrl != NULL && strncmp(assetName->u.string.ptr, "FBI.cia", assetName->u.string.length) == 0) { - url = assetUrl->u.string.ptr; - break; + if(assetName != NULL && assetUrl != NULL) { + if(strncmp(assetName->u.string.ptr, util_get_3dsx_path() != NULL ? "FBI.3dsx" : "FBI.cia", assetName->u.string.length) == 0) { + url = assetUrl->u.string.ptr; + break; + } } } }