2020-03-31 13:24:34 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "../../mem/heap.h"
|
|
|
|
#include "../gfx/gfxutils.h"
|
|
|
|
#include "../emmc/emmc.h"
|
|
|
|
#include "../../utils/types.h"
|
|
|
|
#include "../../libs/fatfs/ff.h"
|
|
|
|
#include "../../utils/sprintf.h"
|
2020-05-02 12:33:54 +01:00
|
|
|
#include "../../hid/hid.h"
|
2020-03-31 13:24:34 +01:00
|
|
|
#include "../../gfx/gfx.h"
|
|
|
|
#include "../../utils/util.h"
|
|
|
|
#include "../../storage/emummc.h"
|
|
|
|
#include "parser.h"
|
|
|
|
#include "../common/common.h"
|
|
|
|
#include "../fs/fsactions.h"
|
|
|
|
#include "variables.h"
|
|
|
|
#include "../utils/utils.h"
|
|
|
|
#include "functions.h"
|
2020-03-31 21:01:20 +01:00
|
|
|
#include "../fs/fsutils.h"
|
2020-03-31 23:17:45 +01:00
|
|
|
#include "../../utils/sprintf.h"
|
2020-03-31 23:41:55 +01:00
|
|
|
#include "../fs/fsactions.h"
|
2020-04-04 22:41:09 +01:00
|
|
|
#include "../emmc/emmcoperations.h"
|
|
|
|
#include "../emmc/emmcmenu.h"
|
2020-03-31 13:24:34 +01:00
|
|
|
|
|
|
|
extern FIL scriptin;
|
|
|
|
extern char **argv;
|
|
|
|
extern u32 argc;
|
2020-03-31 23:17:45 +01:00
|
|
|
extern int forceExit;
|
2020-04-04 22:41:09 +01:00
|
|
|
extern short currentlyMounted;
|
2020-03-31 13:24:34 +01:00
|
|
|
|
2020-03-31 14:34:19 +01:00
|
|
|
int parseIntInput(char *in, int *out){
|
|
|
|
if (in[0] == '@'){
|
2020-04-08 16:33:34 +01:00
|
|
|
if (str_int_find(in, out))
|
2020-03-31 14:34:19 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*out = atoi(in);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-12 21:22:40 +01:00
|
|
|
/*
|
2020-03-31 16:58:09 +01:00
|
|
|
int parseJmpInput(char *in, u64 *out){
|
|
|
|
if (in[0] == '?'){
|
2020-04-08 16:33:34 +01:00
|
|
|
if (str_jmp_find(in, out))
|
2020-03-31 16:58:09 +01:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
2020-04-12 21:22:40 +01:00
|
|
|
*/
|
2020-03-31 16:58:09 +01:00
|
|
|
|
2020-03-31 19:13:39 +01:00
|
|
|
int parseStringInput(char *in, char **out){
|
|
|
|
if (in[0] == '$'){
|
|
|
|
if (str_str_find(in, out))
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
*out = in;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
#pragma GCC push_options
|
|
|
|
#pragma GCC optimize ("Os")
|
|
|
|
|
2020-03-31 23:17:45 +01:00
|
|
|
u32 currentcolor = COLOR_WHITE;
|
2020-03-31 13:24:34 +01:00
|
|
|
int part_printf(){
|
2020-03-31 23:17:45 +01:00
|
|
|
SWAPCOLOR(currentcolor);
|
2020-04-15 21:02:19 +01:00
|
|
|
for (int i = 0; i < argc; i++){
|
|
|
|
if (argv[i][0] == '@'){
|
|
|
|
int toprintint;
|
|
|
|
if (parseIntInput(argv[i], &toprintint))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-15 21:02:19 +01:00
|
|
|
|
|
|
|
gfx_printf("%d", toprintint);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *toprintstring;
|
|
|
|
if (parseStringInput(argv[i], &toprintstring))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-15 21:02:19 +01:00
|
|
|
|
|
|
|
gfx_printf(toprintstring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:24:34 +01:00
|
|
|
gfx_printf("\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-31 14:34:19 +01:00
|
|
|
int part_print_int(){
|
|
|
|
int toprint;
|
|
|
|
if (parseIntInput(argv[0], &toprint))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
|
|
|
SWAPCOLOR(currentcolor);
|
2020-03-31 14:34:19 +01:00
|
|
|
gfx_printf("%s: %d\n", argv[0], toprint);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-31 23:17:45 +01:00
|
|
|
int part_Wait(){
|
|
|
|
int arg;
|
|
|
|
u32 begintime;
|
|
|
|
SWAPCOLOR(currentcolor);
|
|
|
|
|
|
|
|
if (parseIntInput(argv[0], &arg))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
|
|
|
|
begintime = get_tmr_s();
|
|
|
|
|
|
|
|
while (begintime + arg > get_tmr_s()){
|
|
|
|
gfx_printf("\r<Wait %d seconds> ", (begintime + arg) - get_tmr_s());
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx_printf("\r \r");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-12 18:21:09 +01:00
|
|
|
int part_Check(){
|
|
|
|
int left, right;
|
|
|
|
if (parseIntInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-12 18:21:09 +01:00
|
|
|
if (parseIntInput(argv[2], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-12 18:21:09 +01:00
|
|
|
|
|
|
|
if (!strcmp(argv[1], "=="))
|
|
|
|
return (left == right);
|
|
|
|
else if (!strcmp(argv[1], "!="))
|
|
|
|
return (left != right);
|
|
|
|
else if (!strcmp(argv[1], ">="))
|
|
|
|
return (left >= right);
|
|
|
|
else if (!strcmp(argv[1], "<="))
|
|
|
|
return (left <= right);
|
|
|
|
else if (!strcmp(argv[1], ">"))
|
|
|
|
return (left > right);
|
|
|
|
else if (!strcmp(argv[1], "<"))
|
|
|
|
return (left < right);
|
|
|
|
else
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-12 18:21:09 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 13:24:34 +01:00
|
|
|
int part_if(){
|
|
|
|
int condition;
|
2020-03-31 14:34:19 +01:00
|
|
|
if (parseIntInput(argv[0], &condition))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 13:24:34 +01:00
|
|
|
|
|
|
|
getfollowingchar('{');
|
|
|
|
|
2020-04-01 18:43:37 +01:00
|
|
|
if (!condition)
|
|
|
|
skipbrackets();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
2020-03-31 13:24:34 +01:00
|
|
|
if (condition)
|
|
|
|
return 0;
|
|
|
|
else {
|
|
|
|
skipbrackets();
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-01 18:43:37 +01:00
|
|
|
*/
|
2020-03-31 13:24:34 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 18:21:09 +01:00
|
|
|
int part_if_args(){
|
|
|
|
int condition;
|
|
|
|
if ((condition = part_Check()) < 0)
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-12 18:21:09 +01:00
|
|
|
|
|
|
|
getfollowingchar('{');
|
|
|
|
|
|
|
|
if (!condition)
|
|
|
|
skipbrackets();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-31 14:34:19 +01:00
|
|
|
int part_Math(){
|
|
|
|
int left, right;
|
|
|
|
if (parseIntInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 14:34:19 +01:00
|
|
|
if (parseIntInput(argv[2], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 14:34:19 +01:00
|
|
|
|
|
|
|
switch (argv[1][0]){
|
|
|
|
case '+':
|
|
|
|
return left + right;
|
|
|
|
case '-':
|
|
|
|
return left - right;
|
|
|
|
case '*':
|
|
|
|
return left * right;
|
|
|
|
case '/':
|
2020-04-01 18:43:37 +01:00
|
|
|
return left / right;
|
2020-03-31 14:34:19 +01:00
|
|
|
}
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 14:34:19 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 16:58:09 +01:00
|
|
|
int part_SetInt(){
|
|
|
|
int out;
|
|
|
|
parseIntInput(argv[0], &out);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:13:39 +01:00
|
|
|
int part_SetString(){
|
2020-03-31 23:17:45 +01:00
|
|
|
char *arg0;
|
|
|
|
if (parseStringInput(argv[0], &arg0))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 19:13:39 +01:00
|
|
|
if (argv[1][0] != '$')
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
|
|
|
|
str_str_add(argv[1], arg0);
|
2020-03-31 19:13:39 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_SetStringIndex(){
|
|
|
|
int index;
|
|
|
|
char *out;
|
|
|
|
if (parseIntInput(argv[0], &index))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 19:13:39 +01:00
|
|
|
if (argv[1][0] != '$')
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 19:13:39 +01:00
|
|
|
if (str_str_index(index, &out))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-05 21:01:07 +01:00
|
|
|
|
2020-03-31 19:13:39 +01:00
|
|
|
str_str_add(argv[1], out);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-31 16:58:09 +01:00
|
|
|
int part_goto(){
|
2020-04-12 18:21:09 +01:00
|
|
|
int target = 0;
|
|
|
|
if (parseIntInput(argv[0], &target))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
|
|
|
|
|
|
|
str_int_add("@RETURN", (int)f_tell(&scriptin));
|
|
|
|
|
2020-03-31 16:58:09 +01:00
|
|
|
f_lseek(&scriptin, target);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-31 21:01:20 +01:00
|
|
|
int part_invert(){
|
|
|
|
int arg;
|
|
|
|
if (parseIntInput(argv[0], &arg))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 21:01:20 +01:00
|
|
|
return (arg) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_exists(){
|
|
|
|
char *path;
|
|
|
|
if (parseStringInput(argv[0], &path))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 21:01:20 +01:00
|
|
|
|
|
|
|
return fsutil_checkfile(path);
|
|
|
|
}
|
|
|
|
|
2020-03-31 23:17:45 +01:00
|
|
|
int part_ConnectMMC(){
|
|
|
|
char *arg;
|
|
|
|
parseStringInput(argv[0], &arg);
|
|
|
|
|
|
|
|
if (!strcmp(arg, "SYSMMC"))
|
|
|
|
connect_mmc(SYSMMC);
|
|
|
|
else if (!strcmp(arg, "EMUMMC"))
|
|
|
|
connect_mmc(EMUMMC);
|
|
|
|
else
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_MountMMC(){
|
|
|
|
char *arg;
|
|
|
|
parseStringInput(argv[0], &arg);
|
|
|
|
return mount_mmc(arg, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_Pause(){
|
2020-05-02 22:35:25 +01:00
|
|
|
Inputs *input = hidWaitMask(KEY_A | KEY_B | KEY_X | KEY_Y | KEY_POW | KEY_VOLP | KEY_VOLM | KEY_LUP | KEY_LDOWN | KEY_LLEFT | KEY_LRIGHT);
|
2020-05-02 12:33:54 +01:00
|
|
|
|
|
|
|
str_int_add("@BTN_POWER", input->pow);
|
|
|
|
str_int_add("@BTN_VOL+", input->volp);
|
|
|
|
str_int_add("@BTN_VOL-", input->volm);
|
|
|
|
str_int_add("@BTN_A", input->a);
|
|
|
|
str_int_add("@BTN_B", input->b);
|
|
|
|
str_int_add("@BTN_X", input->x);
|
|
|
|
str_int_add("@BTN_Y", input->y);
|
|
|
|
str_int_add("@BTN_UP", input->Lup);
|
|
|
|
str_int_add("@BTN_DOWN", input->Ldown);
|
|
|
|
str_int_add("@BTN_LEFT", input->Lleft);
|
|
|
|
str_int_add("@BTN_RIGHT", input->Lright);
|
2020-03-31 23:17:45 +01:00
|
|
|
|
2020-05-02 12:33:54 +01:00
|
|
|
return input->buttons;
|
2020-03-31 23:17:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int part_addstrings(){
|
|
|
|
char *combined, *left, *middle;
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
if (parseStringInput(argv[1], &middle))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
if (argv[2][0] != '$')
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
|
|
|
|
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
|
|
|
|
sprintf(combined, "%s%s", left, middle);
|
|
|
|
|
|
|
|
str_str_add(argv[2], combined);
|
|
|
|
free(combined);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_setColor(){
|
|
|
|
char *arg;
|
|
|
|
if (parseStringInput(argv[0], &arg))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
|
|
|
|
if (!strcmp(arg, "RED"))
|
|
|
|
currentcolor = COLOR_RED;
|
|
|
|
else if (!strcmp(arg, "ORANGE"))
|
|
|
|
currentcolor = COLOR_ORANGE;
|
|
|
|
else if (!strcmp(arg, "YELLOW"))
|
|
|
|
currentcolor = COLOR_YELLOW;
|
|
|
|
else if (!strcmp(arg, "GREEN"))
|
|
|
|
currentcolor = COLOR_GREEN;
|
|
|
|
else if (!strcmp(arg, "BLUE"))
|
|
|
|
currentcolor = COLOR_BLUE;
|
|
|
|
else if (!strcmp(arg, "VIOLET"))
|
|
|
|
currentcolor = COLOR_VIOLET;
|
|
|
|
else if (!strcmp(arg, "WHITE"))
|
|
|
|
currentcolor = COLOR_WHITE;
|
|
|
|
else
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:17:45 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_Exit(){
|
|
|
|
forceExit = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-31 23:41:55 +01:00
|
|
|
int part_fs_Move(){
|
|
|
|
char *left, *right;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
if (parseStringInput(argv[1], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
|
|
|
|
int res;
|
|
|
|
res = f_rename(left, right);
|
|
|
|
if (res)
|
|
|
|
res = f_rename(left, right);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_Delete(){
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &arg))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
|
|
|
|
int res;
|
|
|
|
res = f_unlink(arg);
|
|
|
|
if (res)
|
|
|
|
res = f_unlink(arg);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_DeleteRecursive(){
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &arg))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
|
|
|
|
return fsact_del_recursive(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_Copy(){
|
|
|
|
char *left, *right;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
if (parseStringInput(argv[1], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
|
|
|
|
return fsact_copy(left, right, COPY_MODE_PRINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_CopyRecursive(){
|
|
|
|
char *left, *right;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
if (parseStringInput(argv[1], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
|
|
|
|
return fsact_copy_recursive(left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_MakeDir(){
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &arg))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-03-31 23:41:55 +01:00
|
|
|
|
|
|
|
int res;
|
|
|
|
res = f_mkdir(arg);
|
|
|
|
if (res)
|
|
|
|
res = f_mkdir(arg);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:57:25 +01:00
|
|
|
DIR dir;
|
|
|
|
FILINFO fno;
|
|
|
|
int isdirvalid = false;
|
|
|
|
int part_fs_OpenDir(){
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &path))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
|
|
|
if (f_opendir(&dir, path))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
|
|
|
isdirvalid = true;
|
|
|
|
str_int_add("@ISDIRVALID", isdirvalid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_CloseDir(){
|
|
|
|
if (!isdirvalid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
f_closedir(&dir);
|
|
|
|
isdirvalid = false;
|
|
|
|
str_int_add("@ISDIRVALID", isdirvalid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_fs_ReadDir(){
|
|
|
|
if (!isdirvalid)
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
|
|
|
if (!f_readdir(&dir, &fno) && fno.fname[0]){
|
2020-04-01 15:48:36 +01:00
|
|
|
str_str_add("$FILENAME", fno.fname);
|
2020-04-01 12:57:25 +01:00
|
|
|
str_int_add("@ISDIR", (fno.fattrib & AM_DIR) ? 1 : 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
part_fs_CloseDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_setPrintPos(){
|
|
|
|
int left, right;
|
|
|
|
|
|
|
|
if (parseIntInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
|
|
|
if (parseIntInput(argv[1], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
2020-05-02 19:53:13 +01:00
|
|
|
if (left > 78)
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
2020-05-02 19:53:13 +01:00
|
|
|
if (right > 42)
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 12:57:25 +01:00
|
|
|
|
|
|
|
gfx_con_setpos(left * 16, right * 16);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-01 15:37:32 +01:00
|
|
|
int part_stringcompare(){
|
|
|
|
char *left, *right;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 15:37:32 +01:00
|
|
|
if (parseStringInput(argv[1], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-01 15:37:32 +01:00
|
|
|
|
|
|
|
return (strcmp(left, right)) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:07:42 +01:00
|
|
|
int part_fs_combinePath(){
|
|
|
|
char *combined, *left, *middle;
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-03 18:07:42 +01:00
|
|
|
if (parseStringInput(argv[1], &middle))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-03 18:07:42 +01:00
|
|
|
if (argv[2][0] != '$')
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-03 18:07:42 +01:00
|
|
|
|
|
|
|
combined = fsutil_getnextloc(left, middle);
|
|
|
|
|
|
|
|
str_str_add(argv[2], combined);
|
|
|
|
free(combined);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-04 22:41:09 +01:00
|
|
|
int part_mmc_dumpPart(){
|
|
|
|
char *left, *right;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &left))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-04 22:41:09 +01:00
|
|
|
if (parseStringInput(argv[1], &right))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-04 22:41:09 +01:00
|
|
|
|
|
|
|
if (!strcmp(left, "BOOT")){
|
|
|
|
return emmcDumpBoot(right);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return emmcDumpSpecific(left, right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int part_mmc_restorePart(){
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &path))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-04 22:41:09 +01:00
|
|
|
|
|
|
|
if (currentlyMounted < 0)
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-04 22:41:09 +01:00
|
|
|
|
2020-05-08 19:57:26 +01:00
|
|
|
return mmcFlashFile(path, currentlyMounted, false);
|
2020-04-04 22:41:09 +01:00
|
|
|
}
|
|
|
|
|
2020-04-05 16:07:11 +01:00
|
|
|
int part_fs_extractBisFile(){
|
|
|
|
char *path, *outfolder;
|
|
|
|
|
|
|
|
if (parseStringInput(argv[0], &path))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-05 16:07:11 +01:00
|
|
|
if (parseStringInput(argv[1], &outfolder))
|
2020-05-15 19:17:31 +01:00
|
|
|
return INFUNC_FAIL;
|
2020-04-05 16:07:11 +01:00
|
|
|
|
|
|
|
return extract_bis_file(path, outfolder);
|
|
|
|
}
|
|
|
|
|
2020-04-05 21:01:07 +01:00
|
|
|
int part_clearscreen(){
|
|
|
|
gfx_clearscreen();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-12 18:21:09 +01:00
|
|
|
int part_getPos(){
|
|
|
|
return (int)f_tell(&scriptin);
|
|
|
|
}
|
|
|
|
|
2020-05-15 19:17:31 +01:00
|
|
|
|
|
|
|
|
2020-03-31 13:24:34 +01:00
|
|
|
str_fnc_struct functions[] = {
|
2020-04-15 21:02:19 +01:00
|
|
|
{"printf", part_printf, 255},
|
2020-03-31 16:58:09 +01:00
|
|
|
{"printInt", part_print_int, 1},
|
2020-04-01 12:57:25 +01:00
|
|
|
{"setPrintPos", part_setPrintPos, 2},
|
2020-04-05 21:01:07 +01:00
|
|
|
{"clearscreen", part_clearscreen, 0},
|
2020-03-31 13:24:34 +01:00
|
|
|
{"if", part_if, 1},
|
2020-04-12 18:21:09 +01:00
|
|
|
{"if", part_if_args, 3}, // function overloading
|
2020-03-31 14:34:19 +01:00
|
|
|
{"math", part_Math, 3},
|
|
|
|
{"check", part_Check, 3},
|
2020-03-31 16:58:09 +01:00
|
|
|
{"setInt", part_SetInt, 1},
|
|
|
|
{"goto", part_goto, 1},
|
2020-03-31 19:13:39 +01:00
|
|
|
{"setString", part_SetString, 2},
|
|
|
|
{"setStringIndex", part_SetStringIndex, 2},
|
2020-03-31 23:17:45 +01:00
|
|
|
{"setColor", part_setColor, 1},
|
|
|
|
{"combineStrings", part_addstrings, 3},
|
2020-04-01 15:37:32 +01:00
|
|
|
{"compareStrings", part_stringcompare, 2},
|
2020-03-31 21:01:20 +01:00
|
|
|
{"invert", part_invert, 1},
|
|
|
|
{"fs_exists", part_fs_exists, 1},
|
2020-03-31 23:41:55 +01:00
|
|
|
{"fs_move", part_fs_Move, 2},
|
|
|
|
{"fs_mkdir", part_fs_MakeDir, 1},
|
|
|
|
{"fs_del", part_fs_Delete, 1},
|
|
|
|
{"fs_delRecursive", part_fs_DeleteRecursive, 1},
|
|
|
|
{"fs_copy", part_fs_Copy, 2},
|
|
|
|
{"fs_copyRecursive", part_fs_CopyRecursive, 2},
|
2020-04-01 12:57:25 +01:00
|
|
|
{"fs_openDir", part_fs_OpenDir, 1},
|
|
|
|
{"fs_closeDir", part_fs_CloseDir, 0},
|
|
|
|
{"fs_readDir", part_fs_ReadDir, 0},
|
2020-04-03 18:07:42 +01:00
|
|
|
{"fs_combinePath", part_fs_combinePath, 3},
|
2020-04-05 16:07:11 +01:00
|
|
|
{"fs_extractBisFile", part_fs_extractBisFile, 2},
|
2020-03-31 23:17:45 +01:00
|
|
|
{"mmc_connect", part_ConnectMMC, 1},
|
|
|
|
{"mmc_mount", part_MountMMC, 1},
|
2020-04-04 22:41:09 +01:00
|
|
|
{"mmc_dumpPart", part_mmc_dumpPart, 2},
|
|
|
|
{"mmc_restorePart", part_mmc_restorePart, 1},
|
2020-04-12 18:21:09 +01:00
|
|
|
{"getPosition", part_getPos, 0},
|
2020-03-31 23:17:45 +01:00
|
|
|
{"pause", part_Pause, 0},
|
|
|
|
{"wait", part_Wait, 1},
|
|
|
|
{"exit", part_Exit, 0},
|
2020-03-31 13:24:34 +01:00
|
|
|
{NULL, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2020-05-04 12:55:26 +01:00
|
|
|
#pragma GCC pop_options
|
|
|
|
|
2020-03-31 13:24:34 +01:00
|
|
|
int run_function(char *func_name, int *out){
|
|
|
|
for (u32 i = 0; functions[i].key != NULL; i++){
|
|
|
|
if (!strcmp(functions[i].key, func_name)){
|
2020-04-15 21:02:19 +01:00
|
|
|
if (argc != functions[i].arg_count && functions[i].arg_count != 255)
|
2020-04-12 18:21:09 +01:00
|
|
|
continue;
|
2020-03-31 13:24:34 +01:00
|
|
|
|
|
|
|
*out = functions[i].value();
|
2020-05-15 19:17:31 +01:00
|
|
|
return (*out == INFUNC_FAIL) ? -1 : 0;
|
2020-03-31 13:24:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-05-15 19:17:31 +01:00
|
|
|
return -2;
|
2020-03-31 13:24:34 +01:00
|
|
|
}
|