mirror of
https://gitlab.com/Theopse/fbi-i18n-zh.git
synced 2025-06-15 19:49:17 +08:00
Add action to update all TitleDB titles, make URL install buffer allocation use max constants.
This commit is contained in:
parent
39e1718c8d
commit
e72c6c1cea
@ -4,6 +4,9 @@ typedef struct ticket_info_s ticket_info;
|
|||||||
typedef struct linked_list_s linked_list;
|
typedef struct linked_list_s linked_list;
|
||||||
typedef struct list_item_s list_item;
|
typedef struct list_item_s list_item;
|
||||||
|
|
||||||
|
#define INSTALL_URL_MAX 1024
|
||||||
|
#define INSTALL_URLS_MAX 128
|
||||||
|
|
||||||
void action_browse_boss_ext_save_data(linked_list* items, list_item* selected);
|
void action_browse_boss_ext_save_data(linked_list* items, list_item* selected);
|
||||||
void action_browse_user_ext_save_data(linked_list* items, list_item* selected);
|
void action_browse_user_ext_save_data(linked_list* items, list_item* selected);
|
||||||
void action_delete_ext_save_data(linked_list* items, list_item* selected);
|
void action_delete_ext_save_data(linked_list* items, list_item* selected);
|
||||||
@ -51,4 +54,5 @@ void action_delete_secure_value(linked_list* items, list_item* selected);
|
|||||||
|
|
||||||
void action_url_install(const char* confirmMessage, const char* urls, void* finishedData, void (*finished)(void* data));
|
void action_url_install(const char* confirmMessage, const char* urls, void* finishedData, void (*finished)(void* data));
|
||||||
|
|
||||||
void action_install_titledb(linked_list* items, list_item* selected);
|
void action_install_titledb(linked_list* items, list_item* selected);
|
||||||
|
void action_update_titledb(linked_list* items, list_item* selected);
|
@ -1,14 +1,45 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
|
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "../task/task.h"
|
#include "../task/task.h"
|
||||||
|
#include "../../error.h"
|
||||||
#include "../../list.h"
|
#include "../../list.h"
|
||||||
|
#include "../../../core/linkedlist.h"
|
||||||
|
|
||||||
void action_install_titledb(linked_list* items, list_item* selected) {
|
void action_install_titledb(linked_list* items, list_item* selected) {
|
||||||
char url[128];
|
char* url = (char*) calloc(1, INSTALL_URL_MAX);
|
||||||
snprintf(url, sizeof(url), "https://api.titledb.com/v0/proxy/%016llX", ((titledb_info*) selected->data)->titleId);
|
if(url != NULL) {
|
||||||
|
snprintf(url, INSTALL_URL_MAX, "https://api.titledb.com/v0/proxy/%016llX", ((titledb_info*) selected->data)->titleId);
|
||||||
|
action_url_install("Install the selected title from TitleDB?", url, NULL, NULL);
|
||||||
|
|
||||||
action_url_install("Install the selected title from TitleDB?", url, NULL, NULL);
|
free(url);
|
||||||
|
} else {
|
||||||
|
error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void action_update_titledb(linked_list* items, list_item* selected) {
|
||||||
|
char* urls = (char*) calloc(1, INSTALL_URL_MAX * INSTALL_URLS_MAX);
|
||||||
|
if(urls != NULL) {
|
||||||
|
linked_list_iter iter;
|
||||||
|
linked_list_iterate(items, &iter);
|
||||||
|
|
||||||
|
size_t pos = 0;
|
||||||
|
while(linked_list_iter_has_next(&iter) && pos < INSTALL_URL_MAX * INSTALL_URLS_MAX) {
|
||||||
|
titledb_info* info = (titledb_info*) ((list_item*) linked_list_iter_next(&iter))->data;
|
||||||
|
|
||||||
|
if(info->installed) {
|
||||||
|
pos += snprintf(urls + pos, (INSTALL_URL_MAX * INSTALL_URLS_MAX) - pos, "https://api.titledb.com/v0/proxy/%016llX\n", info->titleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
action_url_install("Update installed titles from TitleDB?", urls, NULL, NULL);
|
||||||
|
|
||||||
|
free(urls);
|
||||||
|
} else {
|
||||||
|
error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer.");
|
||||||
|
}
|
||||||
}
|
}
|
@ -13,11 +13,8 @@
|
|||||||
#include "../../../core/screen.h"
|
#include "../../../core/screen.h"
|
||||||
#include "../../../core/util.h"
|
#include "../../../core/util.h"
|
||||||
|
|
||||||
#define URL_MAX 1024
|
|
||||||
#define URLS_MAX 128
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char urls[URLS_MAX][URL_MAX];
|
char urls[INSTALL_URLS_MAX][INSTALL_URL_MAX];
|
||||||
|
|
||||||
void* finishedData;
|
void* finishedData;
|
||||||
void (*finished)(void* data);
|
void (*finished)(void* data);
|
||||||
@ -306,7 +303,7 @@ void action_url_install(const char* confirmMessage, const char* urls, void* fini
|
|||||||
size_t payloadLen = strlen(urls);
|
size_t payloadLen = strlen(urls);
|
||||||
if(payloadLen > 0) {
|
if(payloadLen > 0) {
|
||||||
const char* currStart = urls;
|
const char* currStart = urls;
|
||||||
while(data->installInfo.total < URLS_MAX && currStart - urls < payloadLen) {
|
while(data->installInfo.total < INSTALL_URLS_MAX && currStart - urls < payloadLen) {
|
||||||
const char* currEnd = strchr(currStart, '\n');
|
const char* currEnd = strchr(currStart, '\n');
|
||||||
if(currEnd == NULL) {
|
if(currEnd == NULL) {
|
||||||
currEnd = urls + payloadLen;
|
currEnd = urls + payloadLen;
|
||||||
@ -315,15 +312,15 @@ void action_url_install(const char* confirmMessage, const char* urls, void* fini
|
|||||||
u32 len = currEnd - currStart;
|
u32 len = currEnd - currStart;
|
||||||
|
|
||||||
if((len < 7 || strncmp(currStart, "http://", 7) != 0) && (len < 8 || strncmp(currStart, "https://", 8) != 0)) {
|
if((len < 7 || strncmp(currStart, "http://", 7) != 0) && (len < 8 || strncmp(currStart, "https://", 8) != 0)) {
|
||||||
if(len > URL_MAX - 7) {
|
if(len > INSTALL_URL_MAX - 7) {
|
||||||
len = URL_MAX - 7;
|
len = INSTALL_URL_MAX - 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(data->urls[data->installInfo.total], "http://", 7);
|
strncpy(data->urls[data->installInfo.total], "http://", 7);
|
||||||
strncpy(&data->urls[data->installInfo.total][7], currStart, len);
|
strncpy(&data->urls[data->installInfo.total][7], currStart, len);
|
||||||
} else {
|
} else {
|
||||||
if(len > URL_MAX) {
|
if(len > INSTALL_URL_MAX) {
|
||||||
len = URL_MAX;
|
len = INSTALL_URL_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(data->urls[data->installInfo.total], currStart, len);
|
strncpy(data->urls[data->installInfo.total], currStart, len);
|
||||||
|
@ -425,21 +425,32 @@ void remoteinstall_manually_enter_urls() {
|
|||||||
swkbdSetFeatures(&swkbd, SWKBD_MULTILINE);
|
swkbdSetFeatures(&swkbd, SWKBD_MULTILINE);
|
||||||
swkbdSetHintText(&swkbd, "Enter URL(s)");
|
swkbdSetHintText(&swkbd, "Enter URL(s)");
|
||||||
|
|
||||||
char textBuf[1024];
|
char* textBuf = (char*) calloc(1, INSTALL_URL_MAX * INSTALL_URLS_MAX);
|
||||||
if(swkbdInputText(&swkbd, textBuf, sizeof(textBuf)) == SWKBD_BUTTON_CONFIRM) {
|
if(textBuf != NULL) {
|
||||||
remoteinstall_set_last_urls(textBuf);
|
if(swkbdInputText(&swkbd, textBuf, INSTALL_URL_MAX * INSTALL_URLS_MAX) == SWKBD_BUTTON_CONFIRM) {
|
||||||
|
remoteinstall_set_last_urls(textBuf);
|
||||||
|
|
||||||
action_url_install("Install from the entered URL(s)?", textBuf, NULL, NULL);
|
action_url_install("Install from the entered URL(s)?", textBuf, NULL, NULL);
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
free(textBuf);
|
||||||
|
} else {
|
||||||
|
error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void remoteinstall_repeat_last_request() {
|
void remoteinstall_repeat_last_request() {
|
||||||
char textBuf[4096];
|
char* textBuf = (char*) calloc(1, INSTALL_URL_MAX * INSTALL_URLS_MAX);
|
||||||
if(remoteinstall_get_last_urls(textBuf, sizeof(textBuf))) {
|
if(textBuf != NULL) {
|
||||||
action_url_install("Install from the last requested URL(s)?", textBuf, NULL, NULL);
|
if(remoteinstall_get_last_urls(textBuf, INSTALL_URL_MAX * INSTALL_URLS_MAX)) {
|
||||||
|
action_url_install("Install from the last requested URL(s)?", textBuf, NULL, NULL);
|
||||||
|
} else {
|
||||||
|
prompt_display("Failure", "No previously requested URL(s) could be found.", COLOR_TEXT, false, NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(textBuf);
|
||||||
} else {
|
} else {
|
||||||
prompt_display("Failure", "No previously requested URL(s) could be found.", COLOR_TEXT, false, NULL, NULL, NULL);
|
error_display_res(NULL, NULL, R_FBI_OUT_OF_MEMORY, "Failed to allocate URL text buffer.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,14 +86,16 @@ static void task_populate_titledb_thread(void* arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AM_TitleEntry entry;
|
||||||
|
titledbInfo->installed = R_SUCCEEDED(AM_GetTitleInfo(util_get_title_destination(titledbInfo->titleId), 1, &titledbInfo->titleId, &entry));
|
||||||
|
|
||||||
if(strlen(titledbInfo->meta.shortDescription) > 0) {
|
if(strlen(titledbInfo->meta.shortDescription) > 0) {
|
||||||
strncpy(item->name, titledbInfo->meta.shortDescription, LIST_ITEM_NAME_MAX);
|
strncpy(item->name, titledbInfo->meta.shortDescription, LIST_ITEM_NAME_MAX);
|
||||||
} else {
|
} else {
|
||||||
snprintf(item->name, LIST_ITEM_NAME_MAX, "%016llX", titledbInfo->titleId);
|
snprintf(item->name, LIST_ITEM_NAME_MAX, "%016llX", titledbInfo->titleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
AM_TitleEntry entry;
|
if(titledbInfo->installed) {
|
||||||
if(R_SUCCEEDED(AM_GetTitleInfo(util_get_title_destination(titledbInfo->titleId), 1, &titledbInfo->titleId, &entry))) {
|
|
||||||
item->color = COLOR_INSTALLED;
|
item->color = COLOR_INSTALLED;
|
||||||
} else {
|
} else {
|
||||||
item->color = COLOR_NOT_INSTALLED;
|
item->color = COLOR_NOT_INSTALLED;
|
||||||
|
@ -73,6 +73,7 @@ typedef struct file_info_s {
|
|||||||
typedef struct titledb_info_s {
|
typedef struct titledb_info_s {
|
||||||
u64 titleId;
|
u64 titleId;
|
||||||
u64 size;
|
u64 size;
|
||||||
|
bool installed;
|
||||||
meta_info meta;
|
meta_info meta;
|
||||||
} titledb_info;
|
} titledb_info;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "../../core/screen.h"
|
#include "../../core/screen.h"
|
||||||
|
|
||||||
static list_item install = {"Install", COLOR_TEXT, action_install_titledb};
|
static list_item install = {"Install", COLOR_TEXT, action_install_titledb};
|
||||||
|
static list_item update_all = {"Update All", COLOR_TEXT, action_update_titledb};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
populate_titledb_data populateData;
|
populate_titledb_data populateData;
|
||||||
@ -56,6 +57,7 @@ static void titledb_action_update(ui_view* view, void* data, linked_list* items,
|
|||||||
|
|
||||||
if(linked_list_size(items) == 0) {
|
if(linked_list_size(items) == 0) {
|
||||||
linked_list_add(items, &install);
|
linked_list_add(items, &install);
|
||||||
|
linked_list_add(items, &update_all);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user