Skip to content

Commit

Permalink
feat(install): resolve params
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcco committed Apr 3, 2024
1 parent 9c9db80 commit f737b5a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DESCRIPTION := Open source title manager.
AUTHOR := Steveice10

PRODUCT_CODE := CTR-P-CFBI
UNIQUE_ID := 0xF8001
UNIQUE_ID := 0xF8999

ICON_FLAGS := --flags visible,ratingrequired,recordusage --cero 153 --esrb 153 --usk 153 --pegigen 153 --pegiptr 153 --pegibbfc 153 --cob 153 --grb 153 --cgsrr 153

Expand Down
23 changes: 21 additions & 2 deletions source/fbi/action/installurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ static bool action_install_url_error(void* data, u32 index, Result res, ui_view*
return true;
}

extern u64 title_id;
extern int cancel_install;

static void sc_install_done_callback(ui_view* view, void* data, u32 response) {
Result res = 0;
if(R_SUCCEEDED(res = APT_PrepareToDoApplicationJump(0, title_id, 1))) {
u8 param[0x300];
u8 hmac[0x20];

APT_DoApplicationJump(param, sizeof(param), hmac);
}
}

static void action_install_url_install_update(ui_view* view, void* data, float* progress, char* text) {
install_url_data* installData = (install_url_data*) data;

Expand All @@ -261,7 +274,11 @@ static void action_install_url_install_update(ui_view* view, void* data, float*
info_destroy(view);

if(R_SUCCEEDED(installData->installInfo.result)) {
prompt_display_notify("Success", "Install finished.", COLOR_TEXT, NULL, NULL, NULL);
if (title_id != 0) {
prompt_display_notify("Success", "Install finished.", COLOR_TEXT, NULL, NULL, sc_install_done_callback);
} else {
prompt_display_notify("Success", "Install finished.", COLOR_TEXT, NULL, NULL, NULL);
}
}

action_install_url_free_data(installData);
Expand All @@ -270,6 +287,7 @@ static void action_install_url_install_update(ui_view* view, void* data, float*
}

if(hidKeysDown() & KEY_B) {
cancel_install = 1;
svcSignalEvent(installData->installInfo.cancelEvent);
}

Expand Down Expand Up @@ -297,6 +315,7 @@ static void action_install_url_confirm_onresponse(ui_view* view, void* data, u32
action_install_url_free_data(installData);
}
} else {
cancel_install = 1;
action_install_url_free_data(installData);
}
}
Expand Down Expand Up @@ -400,4 +419,4 @@ void action_install_url(const char* confirmMessage, const char* urls, const char
data->installInfo.finished = true;

prompt_display_yes_no("Confirmation", confirmMessage, COLOR_TEXT, data, action_install_url_draw_top, action_install_url_confirm_onresponse);
}
}
82 changes: 65 additions & 17 deletions source/fbi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,28 @@ void cleanup() {

int exit_code = 0;
int use_curl_instead = 0;
int cancel_install = 0;
u64 title_id = 0;

void install_from_remote_done(void* data) {
char *from_3dsx_path = (char *)data;
if(from_3dsx_path != NULL) {
loader_launch_file(from_3dsx_path, NULL);
exit_code = 1;
if (envIsHomebrew()) {
char *from_3dsx_path = (char *)data;
if(from_3dsx_path != NULL) {
loader_launch_file(from_3dsx_path, NULL);
exit_code = 1;
}
} else if (title_id != 0 && cancel_install) {
Result res = 0;

if(R_SUCCEEDED(res = APT_PrepareToDoApplicationJump(0, title_id, 1))) {
u8 param[0x300];
u8 hmac[0x20];

APT_DoApplicationJump(param, sizeof(param), hmac);
}
}
}

static bool remoteinstall_get_urls_by_path(const char* path, char* out, size_t size) {
if(out == NULL || size == 0) {
return false;
Expand Down Expand Up @@ -214,19 +228,53 @@ int main(int argc, const char* argv[]) {
mainmenu_open();

// Install from URL if a URL was passed as an argument.
if(argc > 2) {
use_curl_instead = 1;
char* url = (char*) calloc(1, DOWNLOAD_URL_MAX * INSTALL_URLS_MAX);
remoteinstall_get_urls_by_path(argv[1], url, DOWNLOAD_URL_MAX * INSTALL_URLS_MAX);
action_install_url("Install From URL?",
url,
fs_get_3dsx_path(),
(void *)argv[2],
NULL,
install_from_remote_done,
NULL
);
free(url);
if (envIsHomebrew()) {
if(argc > 2) {
use_curl_instead = 1;
char* url = (char*) calloc(1, DOWNLOAD_URL_MAX * INSTALL_URLS_MAX);
remoteinstall_get_urls_by_path(argv[1], url, DOWNLOAD_URL_MAX * INSTALL_URLS_MAX);
action_install_url("Install From URL?",
url,
fs_get_3dsx_path(),
(void *)argv[2],
NULL,
install_from_remote_done,
NULL
);
free(url);
}
} else {
u8 param[0x300];
u8 hmac[0x20];
bool received = false;
APT_ReceiveDeliverArg(param, 0x300, hmac, &title_id, &received);
if (received) {
int len = 0;
for (int i = 0; i < 0x300; i++) {
if (param[i] == 0) {
len = i;
break;
}
}
if (len > 0) {
char *params_str = (char *)param;
if (strncmp(params_str, "sc:", 3) == 0) {
use_curl_instead = 1;
char *path = params_str + 3;
char* url = (char*) calloc(1, DOWNLOAD_URL_MAX * INSTALL_URLS_MAX);
remoteinstall_get_urls_by_path(path, url, DOWNLOAD_URL_MAX * INSTALL_URLS_MAX);
action_install_url("Install From URL?",
url,
fs_get_3dsx_path(),
NULL,
NULL,
install_from_remote_done,
NULL
);
free(url);
}
}
}
}
while(aptMainLoop() && ui_update());

Expand Down

0 comments on commit f737b5a

Please sign in to comment.