Initial Commit
This commit is contained in:
148
TegraExplorer/source/fs/menus/explorer.c
Normal file
148
TegraExplorer/source/fs/menus/explorer.c
Normal file
@@ -0,0 +1,148 @@
|
||||
#include "explorer.h"
|
||||
#include "../../utils/vector.h"
|
||||
#include "../readers/folderReader.h"
|
||||
#include "../../gfx/menu.h"
|
||||
#include "../fsutils.h"
|
||||
#include "../../gfx/gfx.h"
|
||||
#include "../../gfx/gfxutils.h"
|
||||
#include "../../utils/utils.h"
|
||||
#include "filemenu.h"
|
||||
#include <string.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../../tegraexplorer/tconf.h"
|
||||
#include "../../err.h"
|
||||
#include "../fscopy.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../hid/hid.h"
|
||||
#include "foldermenu.h"
|
||||
|
||||
MenuEntry_t topEntries[] = {
|
||||
{.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT},
|
||||
{.optionUnion = COLORTORGB(COLOR_ORANGE)},
|
||||
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Current folder"},
|
||||
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Current folder options"}
|
||||
};
|
||||
|
||||
MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){
|
||||
MenuEntry_t out = {.name = entry.name, .sizeUnion = entry.sizeUnion};
|
||||
out.optionUnion = (entry.isDir) ? COLORTORGB(COLOR_WHITE) : COLORTORGB(COLOR_VIOLET);
|
||||
out.icon = (entry.isDir) ? 127 : 128;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FileExplorer(char *path){
|
||||
char *storedPath = CpyStr(path);
|
||||
int res = 0;
|
||||
|
||||
if (TConf.explorerCopyMode == CMODE_Move || TConf.explorerCopyMode == CMODE_MoveFolder)
|
||||
ResetCopyParams();
|
||||
|
||||
while (1){
|
||||
topEntries[2].optionUnion = (TConf.explorerCopyMode != CMODE_None) ? (COLORTORGB(COLOR_ORANGE)) : (COLORTORGB(COLOR_GREY) | SKIPBIT);
|
||||
topEntries[1].name = (!strcmp(storedPath, path)) ? "<- Exit explorer" : "<- Folder back";
|
||||
|
||||
gfx_clearscreen();
|
||||
gfx_printf("Loading...\r");
|
||||
|
||||
int readRes = 0;
|
||||
Vector_t fileVec = ReadFolder(storedPath, &readRes);
|
||||
if (readRes){
|
||||
clearFileVector(&fileVec);
|
||||
DrawError(newErrCode(readRes));
|
||||
return;
|
||||
}
|
||||
|
||||
vecDefArray(FSEntry_t*, fsEntries, fileVec);
|
||||
|
||||
topEntries[0].name = storedPath;
|
||||
Vector_t entries = newVec(sizeof(MenuEntry_t), fileVec.count + ARR_LEN(topEntries));
|
||||
entries.count = ARR_LEN(topEntries);
|
||||
memcpy(entries.data, topEntries, sizeof(MenuEntry_t) * ARR_LEN(topEntries));
|
||||
|
||||
for (int i = 0; i < fileVec.count; i++){
|
||||
MenuEntry_t a = MakeMenuOutFSEntry(fsEntries[i]);
|
||||
vecAddElem(&entries, a);
|
||||
}
|
||||
|
||||
gfx_con_setpos(144, 24);
|
||||
gfx_boxGrey(0, 16, 160, 31, 0x1B);
|
||||
|
||||
if (res >= fileVec.count + ARR_LEN(topEntries))
|
||||
res = 0;
|
||||
|
||||
res = newMenu(&entries, res, 60, 42, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count);
|
||||
vecFree(entries);
|
||||
|
||||
char *oldPath = storedPath;
|
||||
|
||||
if (res == 2){
|
||||
ErrCode_t err = {0};
|
||||
char *filename = CpyStr(strrchr(TConf.srcCopy, '/') + 1);
|
||||
char *dst = CombinePaths(storedPath, filename);
|
||||
|
||||
if (!strcmp(TConf.srcCopy, dst))
|
||||
err = newErrCode(TE_ERR_SAME_LOC);
|
||||
|
||||
if (!err.err && TConf.explorerCopyMode >= CMODE_CopyFolder){
|
||||
if (strstr(dst, TConf.srcCopy) != NULL)
|
||||
err = newErrCode(TE_ERR_PATH_IN_PATH);
|
||||
}
|
||||
|
||||
if (!err.err){
|
||||
if (TConf.explorerCopyMode == CMODE_Move || TConf.explorerCopyMode == CMODE_MoveFolder){
|
||||
if ((err.err = f_rename(TConf.srcCopy, dst)))
|
||||
err = newErrCode(err.err);
|
||||
}
|
||||
else if (TConf.explorerCopyMode == CMODE_Copy) {
|
||||
gfx_clearscreen();
|
||||
RESETCOLOR;
|
||||
gfx_printf("Hold vol+/- to cancel\nCopying %s... ", filename);
|
||||
err = FileCopy(TConf.srcCopy, dst, COPY_MODE_CANCEL | COPY_MODE_PRINT);
|
||||
}
|
||||
else {
|
||||
gfx_clearscreen();
|
||||
RESETCOLOR;
|
||||
gfx_printf("\nCopying folder... ");
|
||||
err = FolderCopy(TConf.srcCopy, storedPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DrawError(err);
|
||||
free(dst);
|
||||
free(filename);
|
||||
ResetCopyParams();
|
||||
}
|
||||
else if (res == 3){
|
||||
if (FolderMenu(storedPath)){
|
||||
storedPath = EscapeFolder(oldPath);
|
||||
free(oldPath);
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
else if (res < ARR_LEN(topEntries)) {
|
||||
if (!strcmp(storedPath, path)){
|
||||
clearFileVector(&fileVec);
|
||||
free(storedPath);
|
||||
return;
|
||||
}
|
||||
|
||||
storedPath = EscapeFolder(oldPath);
|
||||
free(oldPath);
|
||||
res = 0;
|
||||
}
|
||||
else if (fsEntries[res - ARR_LEN(topEntries)].isDir) {
|
||||
storedPath = CombinePaths(storedPath, fsEntries[res - ARR_LEN(topEntries)].name);
|
||||
free(oldPath);
|
||||
res = 0;
|
||||
}
|
||||
else {
|
||||
FileMenu(storedPath, fsEntries[res - ARR_LEN(topEntries)]);
|
||||
}
|
||||
|
||||
clearFileVector(&fileVec);
|
||||
}
|
||||
}
|
||||
7
TegraExplorer/source/fs/menus/explorer.h
Normal file
7
TegraExplorer/source/fs/menus/explorer.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "../../utils/vector.h"
|
||||
#include "../../gfx/menu.h"
|
||||
#include "../fstypes.h"
|
||||
|
||||
void FileExplorer(char *path);
|
||||
MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry);
|
||||
216
TegraExplorer/source/fs/menus/filemenu.c
Normal file
216
TegraExplorer/source/fs/menus/filemenu.c
Normal file
@@ -0,0 +1,216 @@
|
||||
#include "filemenu.h"
|
||||
#include "../../err.h"
|
||||
#include "../../gfx/menu.h"
|
||||
#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"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../utils/utils.h"
|
||||
#include "../../keys/nca.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../../storage/emummc.h"
|
||||
#include "../../script/eval.h"
|
||||
#include "../../script/parser.h"
|
||||
#include "../../script/garbageCollector.h"
|
||||
|
||||
|
||||
MenuEntry_t FileMenuEntries[] = {
|
||||
{.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"},
|
||||
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "\nCopy to clipboard"},
|
||||
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Move to clipboard"},
|
||||
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Rename file\n"},
|
||||
{.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"},
|
||||
};
|
||||
|
||||
|
||||
void UnimplementedException(char *path, FSEntry_t entry){
|
||||
DrawError(newErrCode(TE_ERR_UNIMPLEMENTED));
|
||||
}
|
||||
|
||||
extern int launch_payload(char *path);
|
||||
|
||||
void LaunchPayload(char *path, FSEntry_t entry){
|
||||
launch_payload(CombinePaths(path, entry.name));
|
||||
}
|
||||
|
||||
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);
|
||||
SetCopyParams(thing, CMODE_Move);
|
||||
free(thing);
|
||||
}
|
||||
|
||||
void DeleteFile(char *path, FSEntry_t entry){
|
||||
gfx_con_setpos(384 + 16, 200 + 16 + 10 * 16);
|
||||
SETCOLOR(COLOR_RED, COLOR_DARKGREY);
|
||||
gfx_printf("Are you sure? ");
|
||||
|
||||
WaitFor(500);
|
||||
if (!MakeYesNoHorzMenu(3, COLOR_DARKGREY))
|
||||
return;
|
||||
|
||||
char *thing = CombinePaths(path, entry.name);
|
||||
int res = f_unlink(thing);
|
||||
if (res)
|
||||
DrawError(newErrCode(res));
|
||||
free(thing);
|
||||
}
|
||||
|
||||
void RunScriptString(char *str, u32 size){
|
||||
TConf.scriptCWD = "sd:/";
|
||||
gfx_clearscreen();
|
||||
ParserRet_t ret = parseScript(str, size);
|
||||
setStaticVars(&ret.staticVarHolder);
|
||||
initRuntimeVars();
|
||||
eval(ret.main.operations.data, ret.main.operations.count, 0);
|
||||
exitRuntimeVars();
|
||||
exitStaticVars(&ret.staticVarHolder);
|
||||
exitFunction(ret.main.operations.data, ret.main.operations.count);
|
||||
vecFree(ret.staticVarHolder);
|
||||
vecFree(ret.main.operations);
|
||||
}
|
||||
|
||||
void RunScript(char *path, FSEntry_t entry){
|
||||
char *thing = CombinePaths(path, entry.name);
|
||||
u32 size;
|
||||
char *script = sd_file_read(thing, &size);
|
||||
free(thing);
|
||||
TConf.scriptCWD = path;
|
||||
|
||||
if (!script)
|
||||
return;
|
||||
|
||||
if (((entry.size >= 16 && entry.sizeDef == 1) || entry.sizeDef >= 2) && !TConf.minervaEnabled)
|
||||
return;
|
||||
|
||||
gfx_clearscreen();
|
||||
|
||||
ParserRet_t ret = parseScript(script, size);
|
||||
free(script);
|
||||
setStaticVars(&ret.staticVarHolder);
|
||||
initRuntimeVars();
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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();
|
||||
print = calloc(2048, 1);
|
||||
|
||||
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);
|
||||
gfx_hexdump(offset * 32, print, ((size + 31) / 32) * 32);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
fileMenuPath FileMenuPaths[] = {
|
||||
CopyClipboard,
|
||||
MoveClipboard,
|
||||
RenameFile,
|
||||
DeleteFile,
|
||||
HexView,
|
||||
LaunchPayload,
|
||||
RunScript
|
||||
};
|
||||
|
||||
void FileMenu(char *path, FSEntry_t entry){
|
||||
FileMenuEntries[1].name = entry.name;
|
||||
FileMenuEntries[0].sizeUnion = entry.sizeUnion;
|
||||
char attribs[16];
|
||||
char *attribList = GetFileAttribs(entry);
|
||||
s_printf(attribs, "Attribs:%s\n", attribList);
|
||||
free(attribList);
|
||||
FileMenuEntries[2].name = attribs;
|
||||
|
||||
FileMenuEntries[10].hide = !StrEndsWith(entry.name, ".bin");
|
||||
FileMenuEntries[11].hide = !StrEndsWith(entry.name, ".te");
|
||||
|
||||
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);
|
||||
}
|
||||
8
TegraExplorer/source/fs/menus/filemenu.h
Normal file
8
TegraExplorer/source/fs/menus/filemenu.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "../fstypes.h"
|
||||
|
||||
typedef void (*fileMenuPath)(char *path, FSEntry_t entry);
|
||||
|
||||
void FileMenu(char *path, FSEntry_t entry);
|
||||
void RunScript(char *path, FSEntry_t entry);
|
||||
void RunScriptString(char *str, u32 size);
|
||||
134
TegraExplorer/source/fs/menus/foldermenu.c
Normal file
134
TegraExplorer/source/fs/menus/foldermenu.c
Normal file
@@ -0,0 +1,134 @@
|
||||
#include "foldermenu.h"
|
||||
#include "../../err.h"
|
||||
#include "../../gfx/menu.h"
|
||||
#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"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../utils/utils.h"
|
||||
#include "../../keys/nca.h"
|
||||
#include <storage/nx_sd.h>
|
||||
#include "../fscopy.h"
|
||||
|
||||
MenuEntry_t FolderMenuEntries[] = {
|
||||
{.optionUnion = COLORTORGB(COLOR_WHITE) | SKIPBIT, .name = "-- Folder 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"},
|
||||
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "\nCopy to clipboard"},
|
||||
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Move to clipboard"},
|
||||
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Rename current folder\n"},
|
||||
{.optionUnion = COLORTORGB(COLOR_RED), .name = "Delete current folder"},
|
||||
{.optionUnion = COLORTORGB(COLOR_GREEN), .name = "\nCreate folder"}
|
||||
};
|
||||
|
||||
int UnimplementedFolderException(const char *path){
|
||||
DrawError(newErrCode(TE_ERR_UNIMPLEMENTED));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FolderCopyClipboard(const char *path){
|
||||
SetCopyParams(path, CMODE_CopyFolder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FolderMoveClipboard(const char *path){
|
||||
SetCopyParams(path, CMODE_MoveFolder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DeleteFolder(const char *path){
|
||||
gfx_con_setpos(384 + 16, 200 + 16 + 10 * 16);
|
||||
SETCOLOR(COLOR_RED, COLOR_DARKGREY);
|
||||
gfx_printf("Are you sure? ");
|
||||
|
||||
WaitFor(1000);
|
||||
if (MakeYesNoHorzMenu(3, COLOR_DARKGREY)){
|
||||
gfx_clearscreen();
|
||||
SETCOLOR(COLOR_RED, COLOR_DEFAULT);
|
||||
gfx_printf("\nDeleting... ");
|
||||
ErrCode_t err = FolderDelete(path);
|
||||
if (err.err){
|
||||
DrawError(err);
|
||||
}
|
||||
else return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RenameFolder(const char *path){
|
||||
char *prev = EscapeFolder(path);
|
||||
gfx_clearscreen();
|
||||
|
||||
char *renameTo = ShowKeyboard(strrchr(path, '/') + 1, false);
|
||||
if (renameTo == NULL || !(*renameTo)) // smol memory leak but eh
|
||||
return 0;
|
||||
|
||||
char *dst = CombinePaths(prev, renameTo);
|
||||
|
||||
int res = f_rename(path, dst);
|
||||
if (res){
|
||||
DrawError(newErrCode(res));
|
||||
}
|
||||
|
||||
free(prev);
|
||||
free(dst);
|
||||
free(renameTo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CreateFolder(const char *path){
|
||||
gfx_clearscreen();
|
||||
|
||||
char *create = ShowKeyboard("New Folder", true);
|
||||
if (create == NULL || !(*create)) // smol memory leak but eh
|
||||
return 0;
|
||||
|
||||
char *dst = CombinePaths(path, create);
|
||||
f_mkdir(dst);
|
||||
|
||||
free(dst);
|
||||
free(create);
|
||||
return 0;
|
||||
}
|
||||
|
||||
folderMenuPath FolderMenuPaths[] = {
|
||||
FolderCopyClipboard,
|
||||
FolderMoveClipboard,
|
||||
RenameFolder,
|
||||
DeleteFolder,
|
||||
CreateFolder
|
||||
};
|
||||
|
||||
int FolderMenu(const char *path){
|
||||
FSEntry_t file = GetFileInfo(path);
|
||||
FolderMenuEntries[1].name = file.name;
|
||||
|
||||
char attribs[16];
|
||||
char *attribList = GetFileAttribs(file);
|
||||
s_printf(attribs, "Attribs:%s\n", attribList);
|
||||
free(attribList);
|
||||
FolderMenuEntries[2].name = attribs;
|
||||
|
||||
// If root, disable all options other than create folder!
|
||||
int isRoot = !strcmp(file.name, "Root");
|
||||
FolderMenuEntries[2].hide = isRoot;
|
||||
for (int i = 5; i <= 8; i++)
|
||||
FolderMenuEntries[i].hide = isRoot;
|
||||
|
||||
|
||||
Vector_t ent = vecFromArray(FolderMenuEntries, ARR_LEN(FolderMenuEntries), 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 0;
|
||||
|
||||
return FolderMenuPaths[res - 5](path);
|
||||
}
|
||||
4
TegraExplorer/source/fs/menus/foldermenu.h
Normal file
4
TegraExplorer/source/fs/menus/foldermenu.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
typedef int (*folderMenuPath)(const char *path);
|
||||
int FolderMenu(const char *path);
|
||||
Reference in New Issue
Block a user