Add exceptions, start file menu

This commit is contained in:
SuchMemeManySkill
2020-12-25 21:16:24 +01:00
parent 1a931b0256
commit 9588ffb89a
13 changed files with 215 additions and 46 deletions

View File

@@ -34,7 +34,7 @@ void clearFileVector(Vector_t *v){
}
void FileExplorer(char *path){
char *storedPath = path;
char *storedPath = CpyStr(path);
int res = 0;
while (1){
@@ -54,7 +54,7 @@ void FileExplorer(char *path){
vecAddElem(&entries, a);
}
gfx_con_setpos(144, 16);
gfx_con_setpos(144, 24);
gfx_boxGrey(0, 16, 160, 31, 0x1B);
if (res >= fileVec.count + ARR_LEN(topEntries))
@@ -62,25 +62,25 @@ void FileExplorer(char *path){
res = newMenu(&entries, res, 60, 42, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count);
char *oldPath = storedPath;
if (res < ARR_LEN(topEntries)) {
if (!strcmp(storedPath, path)){
clearFileVector(&fileVec);
return;
}
char *copy = CpyStr(storedPath);
storedPath = EscapeFolder(copy);
free(copy);
storedPath = EscapeFolder(oldPath);
free(oldPath);
res = 0;
}
else if (fsEntries[res - ARR_LEN(topEntries)].isDir) {
char *copy = CpyStr(storedPath);
storedPath = CombinePaths(copy, fsEntries[res - ARR_LEN(topEntries)].name);
free(copy);
storedPath = CombinePaths(storedPath, fsEntries[res - ARR_LEN(topEntries)].name);
free(oldPath);
res = 0;
}
else {
FileMenu(fsEntries[res - ARR_LEN(topEntries)]);
FileMenu(storedPath, fsEntries[res - ARR_LEN(topEntries)]);
}

View File

@@ -1,11 +1,67 @@
#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"
MenuEntry_t FileMenuEntries[] = {
// Still have to think up the options
{.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 = "Copy to clipboard"},
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Move to clipboard"},
{.optionUnion = COLORTORGB(COLOR_BLUE), .name = "Rename file"},
{.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 FileMenu(FSEntry_t entry){
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));
}
menuPaths FileMenuPaths[] = {
UnimplementedException,
UnimplementedException,
UnimplementedException,
UnimplementedException,
UnimplementedException,
LaunchPayload,
UnimplementedException
};
void FileMenu(char *path, FSEntry_t entry){
FileMenuEntries[1].name = entry.name;
FileMenuEntries[1].sizeUnion = entry.sizeUnion;
char attribs[15];
char *attribList = GetFileAttribs(entry);
sprintf(attribs, "Attribs:%s", attribList);
free(attribList);
FileMenuEntries[2].name = attribs;
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);
}

View File

@@ -1,4 +1,6 @@
#pragma once
#include "../fstypes.h"
void FileMenu(FSEntry_t entry);
typedef void (*fileMenuPath)(char *path, FSEntry_t entry);
void FileMenu(char *path, FSEntry_t entry);