2020-12-24 23:20:30 +00:00
|
|
|
#include "filemenu.h"
|
|
|
|
#include "../../err.h"
|
|
|
|
#include "../../gfx/menu.h"
|
2020-12-25 20:16:24 +00:00
|
|
|
#include "../../gfx/gfxutils.h"
|
|
|
|
#include "../fsutils.h"
|
|
|
|
#include <mem/heap.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <utils/sprintf.h>
|
|
|
|
#include "../../tegraexplorer/tconf.h"
|
|
|
|
#include "../../hid/hid.h"
|
2020-12-25 21:19:04 +00:00
|
|
|
#include <libs/fatfs/ff.h>
|
|
|
|
#include "../../utils/utils.h"
|
2020-12-28 01:29:58 +00:00
|
|
|
#include "../../keys/nca.h"
|
2020-12-28 13:51:59 +00:00
|
|
|
#include <storage/nx_sd.h>
|
[script] Make equivalent to tsV1
Fixed: functions in functions
Added functions: version, menu, pathCombine, pathEscFolder, fileMove, fileCopy, fileDel, mmcConnect, mmcMount, mkdir, dirRead, dirCopy, dirDel, mmcDump, mmcRestore
2021-01-04 00:55:58 +00:00
|
|
|
#include "../../storage/emummc.h"
|
2021-07-09 21:56:13 +01:00
|
|
|
#include "../../script/eval.h"
|
|
|
|
#include "../../script/parser.h"
|
|
|
|
#include "../../script/garbageCollector.h"
|
|
|
|
|
2020-12-24 23:20:30 +00:00
|
|
|
|
|
|
|
MenuEntry_t FileMenuEntries[] = {
|
2020-12-25 20:16:24 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "-- File menu --"},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT}, // For the file name and size
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_VIOLET) | SKIPBIT}, // For the file Attribs
|
|
|
|
{.optionUnion = HIDEBIT},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_WHITE), .name = "<- Back"},
|
2020-12-27 22:33:23 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "\nCopy to clipboard"},
|
2020-12-25 20:16:24 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Move to clipboard"},
|
2020-12-27 22:33:23 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Rename file\n"},
|
2020-12-25 20:16:24 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_RED), .name = "Delete file"},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_GREEN), .name = "View hex"},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Launch Payload"},
|
|
|
|
{.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "Launch Script"},
|
2020-12-24 23:20:30 +00:00
|
|
|
};
|
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
|
|
|
|
void UnimplementedException(char *path, FSEntry_t entry){
|
2020-12-24 23:20:30 +00:00
|
|
|
DrawError(newErrCode(TE_ERR_UNIMPLEMENTED));
|
2020-12-25 20:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int launch_payload(char *path);
|
|
|
|
|
|
|
|
void LaunchPayload(char *path, FSEntry_t entry){
|
|
|
|
launch_payload(CombinePaths(path, entry.name));
|
|
|
|
}
|
|
|
|
|
2020-12-25 21:19:04 +00:00
|
|
|
void CopyClipboard(char *path, FSEntry_t entry){
|
|
|
|
char *thing = CombinePaths(path, entry.name);
|
|
|
|
SetCopyParams(thing, CMODE_Copy);
|
|
|
|
free(thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MoveClipboard(char *path, FSEntry_t entry){
|
|
|
|
char *thing = CombinePaths(path, entry.name);
|
2020-12-26 00:05:33 +00:00
|
|
|
SetCopyParams(thing, CMODE_Move);
|
2020-12-25 21:19:04 +00:00
|
|
|
free(thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteFile(char *path, FSEntry_t entry){
|
2020-12-27 22:33:23 +00:00
|
|
|
gfx_con_setpos(384 + 16, 200 + 16 + 10 * 16);
|
2020-12-25 22:10:23 +00:00
|
|
|
SETCOLOR(COLOR_RED, COLOR_DARKGREY);
|
|
|
|
gfx_printf("Are you sure? ");
|
2021-01-11 20:22:24 +00:00
|
|
|
|
|
|
|
WaitFor(500);
|
2020-12-28 01:29:58 +00:00
|
|
|
if (!MakeYesNoHorzMenu(3, COLOR_DARKGREY))
|
2020-12-25 22:10:23 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-25 21:19:04 +00:00
|
|
|
char *thing = CombinePaths(path, entry.name);
|
|
|
|
int res = f_unlink(thing);
|
|
|
|
if (res)
|
|
|
|
DrawError(newErrCode(res));
|
|
|
|
free(thing);
|
|
|
|
}
|
|
|
|
|
2021-07-19 20:44:15 +01:00
|
|
|
void RunScriptString(char *str, u32 size){
|
|
|
|
gfx_clearscreen();
|
|
|
|
ParserRet_t ret = parseScript(str, size);
|
|
|
|
setStaticVars(&ret.staticVarHolder);
|
|
|
|
initRuntimeVars();
|
2021-07-23 00:10:03 +01:00
|
|
|
eval(ret.main.operations.data, ret.main.operations.count, 0);
|
2021-07-19 20:44:15 +01:00
|
|
|
exitRuntimeVars();
|
|
|
|
exitStaticVars(&ret.staticVarHolder);
|
|
|
|
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
|
|
|
vecFree(ret.staticVarHolder);
|
|
|
|
vecFree(ret.main.operations);
|
|
|
|
|
|
|
|
hidWait();
|
|
|
|
hidWait();
|
|
|
|
}
|
|
|
|
|
2020-12-28 13:51:59 +00:00
|
|
|
void RunScript(char *path, FSEntry_t entry){
|
|
|
|
char *thing = CombinePaths(path, entry.name);
|
|
|
|
u32 size;
|
|
|
|
char *script = sd_file_read(thing, &size);
|
|
|
|
free(thing);
|
|
|
|
if (!script)
|
|
|
|
return;
|
|
|
|
|
2021-07-09 21:56:13 +01:00
|
|
|
if (((entry.size >= 16 && entry.sizeDef == 1) || entry.sizeDef >= 2) && !TConf.minervaEnabled)
|
2021-01-04 15:57:47 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-28 13:51:59 +00:00
|
|
|
gfx_clearscreen();
|
2021-07-09 21:56:13 +01:00
|
|
|
/*
|
2020-12-28 13:51:59 +00:00
|
|
|
scriptCtx_t ctx = createScriptCtx();
|
2021-01-09 23:10:28 +00:00
|
|
|
ctx.script = runLexer(script, size);
|
2020-12-28 13:51:59 +00:00
|
|
|
free(script);
|
|
|
|
|
2021-01-01 17:30:51 +00:00
|
|
|
dictVectorAdd(&ctx.varDict, newDict(CpyStr("_CWD"), (newVar(StringType, 0, .stringType = path))));
|
[script] Make equivalent to tsV1
Fixed: functions in functions
Added functions: version, menu, pathCombine, pathEscFolder, fileMove, fileCopy, fileDel, mmcConnect, mmcMount, mkdir, dirRead, dirCopy, dirDel, mmcDump, mmcRestore
2021-01-04 00:55:58 +00:00
|
|
|
dictVectorAdd(&ctx.varDict, newDict(CpyStr("_EMU"), (newVar(IntType, 0, emu_cfg.enabled))));
|
2021-01-01 17:30:51 +00:00
|
|
|
|
2020-12-28 13:51:59 +00:00
|
|
|
printError(mainLoop(&ctx));
|
|
|
|
|
2021-01-04 15:57:47 +00:00
|
|
|
freeDictVector(&ctx.varDict);
|
2020-12-28 13:51:59 +00:00
|
|
|
lexarVectorClear(&ctx.script);
|
2021-07-09 21:56:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
gfx_printf("Parsing\n");
|
2021-07-18 22:51:27 +01:00
|
|
|
ParserRet_t ret = parseScript(script, size);
|
2021-07-09 21:56:13 +01:00
|
|
|
free(script);
|
|
|
|
gfx_printf("Init vars\n");
|
|
|
|
setStaticVars(&ret.staticVarHolder);
|
|
|
|
initRuntimeVars();
|
|
|
|
|
|
|
|
gfx_printf("start script\n");
|
|
|
|
Variable_t* res = eval(ret.main.operations.data, ret.main.operations.count, 1);
|
|
|
|
|
|
|
|
exitRuntimeVars();
|
|
|
|
exitStaticVars(&ret.staticVarHolder);
|
|
|
|
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
|
|
|
vecFree(ret.staticVarHolder);
|
|
|
|
vecFree(ret.main.operations);
|
|
|
|
|
|
|
|
hidWait();
|
|
|
|
hidWait();
|
|
|
|
hidWait();
|
2020-12-28 13:51:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 15:51:47 +00:00
|
|
|
void RenameFile(char *path, FSEntry_t entry){
|
|
|
|
gfx_clearscreen();
|
|
|
|
char *renameTo = ShowKeyboard(entry.name, false);
|
|
|
|
if (renameTo == NULL || !(*renameTo)) // smol memory leak but eh
|
|
|
|
return;
|
|
|
|
|
|
|
|
char *src = CombinePaths(path, entry.name);
|
|
|
|
char *dst = CombinePaths(path, renameTo);
|
|
|
|
|
|
|
|
int res = f_rename(src, dst);
|
|
|
|
if (res){
|
|
|
|
DrawError(newErrCode(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
free(src);
|
|
|
|
free(dst);
|
|
|
|
free(renameTo);
|
|
|
|
}
|
|
|
|
|
2020-12-29 16:12:58 +00:00
|
|
|
// This is from the original TE and it's bad but uhh i'm too lazy to fix it
|
|
|
|
void HexView(char *path, FSEntry_t entry){
|
|
|
|
char *filePath = CombinePaths(path, entry.name);
|
|
|
|
|
|
|
|
FIL in;
|
|
|
|
u8 *print;
|
|
|
|
u32 size;
|
|
|
|
QWORD offset = 0;
|
|
|
|
int res;
|
|
|
|
Input_t *input = hidRead();
|
|
|
|
|
|
|
|
while (input->buttons & (BtnPow | JoyB))
|
|
|
|
hidRead();
|
|
|
|
|
|
|
|
gfx_clearscreen();
|
2021-05-23 22:57:58 +01:00
|
|
|
print = calloc(2048, 1);
|
2020-12-29 16:12:58 +00:00
|
|
|
|
|
|
|
if ((res = f_open(&in, filePath, FA_READ | FA_OPEN_EXISTING))){
|
|
|
|
DrawError(newErrCode(res));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1){
|
|
|
|
f_lseek(&in, offset * 32);
|
|
|
|
|
|
|
|
if ((res = f_read(&in, print, 2048, &size))){
|
|
|
|
DrawError(newErrCode(res));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx_con_setpos(0, 31);
|
2021-05-23 22:57:58 +01:00
|
|
|
gfx_hexdump(offset * 32, print, ((size + 31) / 32) * 32);
|
2020-12-29 16:12:58 +00:00
|
|
|
|
|
|
|
input = hidRead();
|
|
|
|
|
|
|
|
if (!(input->buttons))
|
|
|
|
input = hidWait();
|
|
|
|
|
|
|
|
if (input->down && 2048 == size)
|
|
|
|
offset += 2;
|
|
|
|
if (input->up && offset > 0)
|
|
|
|
offset -= 2;
|
|
|
|
if (input->buttons & (BtnPow | JoyB))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
f_close(&in);
|
|
|
|
free(print);
|
|
|
|
free(filePath);
|
|
|
|
}
|
|
|
|
|
2020-12-29 00:05:33 +00:00
|
|
|
fileMenuPath FileMenuPaths[] = {
|
2020-12-25 21:19:04 +00:00
|
|
|
CopyClipboard,
|
|
|
|
MoveClipboard,
|
2020-12-29 15:51:47 +00:00
|
|
|
RenameFile,
|
2020-12-25 21:19:04 +00:00
|
|
|
DeleteFile,
|
2020-12-29 16:12:58 +00:00
|
|
|
HexView,
|
2020-12-25 20:16:24 +00:00
|
|
|
LaunchPayload,
|
2020-12-28 13:51:59 +00:00
|
|
|
RunScript
|
2020-12-25 20:16:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void FileMenu(char *path, FSEntry_t entry){
|
|
|
|
FileMenuEntries[1].name = entry.name;
|
2020-12-27 22:33:23 +00:00
|
|
|
FileMenuEntries[0].sizeUnion = entry.sizeUnion;
|
|
|
|
char attribs[16];
|
2020-12-25 20:16:24 +00:00
|
|
|
char *attribList = GetFileAttribs(entry);
|
2021-06-24 20:44:59 +01:00
|
|
|
s_printf(attribs, "Attribs:%s\n", attribList);
|
2020-12-25 20:16:24 +00:00
|
|
|
free(attribList);
|
|
|
|
FileMenuEntries[2].name = attribs;
|
|
|
|
|
2020-12-25 21:19:04 +00:00
|
|
|
FileMenuEntries[10].hide = !StrEndsWith(entry.name, ".bin");
|
|
|
|
FileMenuEntries[11].hide = !StrEndsWith(entry.name, ".te");
|
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
Vector_t ent = vecFromArray(FileMenuEntries, ARR_LEN(FileMenuEntries), sizeof(MenuEntry_t));
|
|
|
|
gfx_boxGrey(384, 200, 384 + 512, 200 + 320, 0x33);
|
|
|
|
gfx_con_setpos(384 + 16, 200 + 16);
|
|
|
|
int res = newMenu(&ent, 0, 30, 19, ENABLEB | ALWAYSREDRAW | USELIGHTGREY, ent.count);
|
|
|
|
|
|
|
|
if (res <= 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
FileMenuPaths[res - 5](path, entry);
|
2020-12-24 23:20:30 +00:00
|
|
|
}
|