From 9c47d118439aa98851de5d8829c5604f77314c50 Mon Sep 17 00:00:00 2001 From: SuchMemeManySkill Date: Fri, 25 Dec 2020 22:19:04 +0100 Subject: [PATCH] Add some options to FileMenu !Warning, there is no confirmation yet on deletions --- source/fs/menus/explorer.c | 4 +++- source/fs/menus/filemenu.c | 31 ++++++++++++++++++++++++++++--- source/utils/utils.c | 9 +++++++++ source/utils/utils.h | 3 ++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/source/fs/menus/explorer.c b/source/fs/menus/explorer.c index 9c82993..85447c3 100644 --- a/source/fs/menus/explorer.c +++ b/source/fs/menus/explorer.c @@ -9,6 +9,7 @@ #include "filemenu.h" #include #include +#include "../../tegraexplorer/tconf.h" MenuEntry_t topEntries[] = { {.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT}, @@ -38,6 +39,8 @@ void FileExplorer(char *path){ int res = 0; while (1){ + topEntries[2].optionUnion = COLORTORGB(((TConf.explorerCopyMode != CMODE_None) ? COLOR_ORANGE : COLOR_GREY)) | SKIPBIT; + gfx_clearscreen(); gfx_printf("Loading...\r"); //gfx_printf(" "); @@ -83,7 +86,6 @@ void FileExplorer(char *path){ FileMenu(storedPath, fsEntries[res - ARR_LEN(topEntries)]); } - clearFileVector(&fileVec); } } \ No newline at end of file diff --git a/source/fs/menus/filemenu.c b/source/fs/menus/filemenu.c index c49457c..d0a5296 100644 --- a/source/fs/menus/filemenu.c +++ b/source/fs/menus/filemenu.c @@ -8,6 +8,8 @@ #include #include "../../tegraexplorer/tconf.h" #include "../../hid/hid.h" +#include +#include "../../utils/utils.h" MenuEntry_t FileMenuEntries[] = { // Still have to think up the options @@ -36,11 +38,31 @@ 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_Copy); + free(thing); +} + +void DeleteFile(char *path, FSEntry_t entry){ + char *thing = CombinePaths(path, entry.name); + int res = f_unlink(thing); + if (res) + DrawError(newErrCode(res)); + free(thing); +} + menuPaths FileMenuPaths[] = { + CopyClipboard, + MoveClipboard, UnimplementedException, - UnimplementedException, - UnimplementedException, - UnimplementedException, + DeleteFile, UnimplementedException, LaunchPayload, UnimplementedException @@ -55,6 +77,9 @@ void FileMenu(char *path, FSEntry_t entry){ 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); diff --git a/source/utils/utils.c b/source/utils/utils.c index 1427626..752ba7d 100644 --- a/source/utils/utils.c +++ b/source/utils/utils.c @@ -20,4 +20,13 @@ void MaskIn(char *mod, u32 bitstream, char mask){ bitstream >>= 1; mod++; } +} + +// non-zero is yes, zero is no +bool StrEndsWith(char *begin, char *end){ + begin = strrchr(begin, *end); + if (begin != NULL) + return !strcmp(begin, end); + + return 0; } \ No newline at end of file diff --git a/source/utils/utils.h b/source/utils/utils.h index 2f91525..a903bc3 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -2,4 +2,5 @@ #include char *CpyStr(const char* in); -void MaskIn(char *mod, u32 bitstream, char mask); \ No newline at end of file +void MaskIn(char *mod, u32 bitstream, char mask); +bool StrEndsWith(char *begin, char *end); \ No newline at end of file