1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 11:56:42 +00:00

Add file options menu

This commit is contained in:
Such Meme, Many Skill 2019-12-01 20:31:17 +01:00
parent 3abb52c962
commit 65f38ba459
4 changed files with 89 additions and 15 deletions

View file

@ -231,6 +231,8 @@ void gfx_putc(char c)
gfx_con.x = 672;
else if (c == '\a')
gfx_con.x = 608;
else if (c == '\r')
gfx_con.x = 0;
break;
case 8:

View file

@ -7,10 +7,26 @@
#include "../utils/sprintf.h"
#include "../utils/btn.h"
#include "../gfx/gfx.h"
#include "../utils/util.h"
fs_entry fileobjects[500];
char rootpath[10] = "";
char currentpath[255] = "";
char clipboard[255] = "";
u8 clipboardhelper = 0;
extern const char sizevalues[4][3];
extern int launch_payload(char *path);
menu_item explfilemenu[8] = {
{"-- File Menu --", COLOR_BLUE, -1, 0},
{"FILE", COLOR_GREEN, -1, 0},
{"\nSIZE", COLOR_VIOLET, -1, 0},
{"\n\n\nBack", COLOR_WHITE, -1, 1},
{"\nCopy to clipboard", COLOR_BLUE, COPY, 1},
{"Move to clipboard", COLOR_BLUE, MOVE, 1},
{"\nDelete file", COLOR_RED, DELETE, 1},
{"\nLaunch Payload", COLOR_ORANGE, PAYLOAD, 1}
};
char *getnextloc(char *current, char *add){
char *ret;
@ -108,7 +124,8 @@ int readfolder(const char *path){
}
void filemenu(const char *startpath){
int amount, res;
int amount, res, tempint;
char temp[100];
strcpy(rootpath, startpath);
strcpy(currentpath, startpath);
amount = readfolder(currentpath);
@ -136,6 +153,42 @@ void filemenu(const char *startpath){
strcpy(currentpath, getnextloc(currentpath, fileobjects[res - 1].name));
amount = readfolder(currentpath);
}
else {
strlcpy(explfilemenu[1].name, fileobjects[res - 1].name, 43);
for (tempint = 4; tempint < 8; tempint++)
if ((fileobjects[res - 1].property & (1 << tempint)))
break;
sprintf(temp, "\nSize: %d %s", fileobjects[res - 1].size, sizevalues[tempint - 4]);
strcpy(explfilemenu[2].name, temp);
if (strstr(fileobjects[res - 1].name, ".bin") != NULL)
explfilemenu[7].property = 1;
else
explfilemenu[7].property = -1;
res = makemenu(explfilemenu, 8);
switch (res){
case COPY:
case MOVE:
strcpy(clipboard, getnextloc(currentpath, fileobjects[res - 1].name));
break;
case DELETE:
msleep(100);
sprintf(temp, "Do you want to delete:\n%s\n\nPress Power to confirm\nPress Vol+/- to cancel", fileobjects[res - 1].name);
res = message(temp, COLOR_RED);
if (res & BTN_POWER){
f_unlink(getnextloc(currentpath, fileobjects[res - 1].name));
amount = readfolder(currentpath);
}
break;
case PAYLOAD:
launch_payload(getnextloc(currentpath, fileobjects[res - 1].name));
break;
}
}
}
}
}

View file

@ -24,6 +24,13 @@ typedef struct _fs_entry {
u8 property;
} fs_entry;
enum filemenuoptions {
COPY = 1,
MOVE,
DELETE,
PAYLOAD
};
int readfolder(const char *path);
void filemenu();
bool checkfile(char* path);

View file

@ -10,9 +10,9 @@
#include "../mem/minerva.h"
const char fixedoptions[3][50] = {
"Folder -> previous folder",
"Clipboard -> Current folder",
"Folder options"
"Folder -> previous folder ",
"Clipboard -> Current folder ",
"Folder options "
};
const char sizevalues[4][3] = {
@ -80,9 +80,10 @@ int makemenu(menu_item menu[], int menuamount){
}
}
void printfsentry(fs_entry file, bool highlight){
void printfsentry(fs_entry file, bool highlight, bool refresh){
int size = 0;
char *display;
int length;
display = (char*) malloc (38);
memset(display + 37, '\0', 1);
@ -91,7 +92,7 @@ void printfsentry(fs_entry file, bool highlight){
strlcpy(display, file.name, 37);
memset(display + 34, '.', 3);
}
else // make option to clear the screen gracefully line by line
else
strcpy(display, file.name);
if (highlight)
@ -106,21 +107,32 @@ void printfsentry(fs_entry file, bool highlight){
if ((file.property & (1 << size)))
break;
gfx_printf("%k%s%K\a%d\e%s", COLOR_VIOLET, display, COLOR_DEFAULT, file.size, sizevalues[size - 4]);
gfx_printf("%k%s%K", COLOR_VIOLET, display, COLOR_DEFAULT);
}
if (refresh){
length = strlen(display);
for (int i = 0; i < (42 - length); i++)
gfx_printf(" ");
}
if (!(file.property & ISDIR))
gfx_printf("\a%d\e%s", file.size, sizevalues[size - 4]);
free(display);
}
int makefilemenu(fs_entry *files, int amount, char *path){
int currentpos = 1, i, res = 0, offset = 0, quickoffset = 300;
int currentpos = -2, i, res = 0, offset = 0, quickoffset = 300;
u32 timer;
bool refresh = false;
clearscreen();
gfx_con_setpos(544, 0);
gfx_printf("%K%k%d / 500\n%K%k%s%k\n\n", COLOR_WHITE, COLOR_DEFAULT, amount, COLOR_DEFAULT, COLOR_GREEN, path, COLOR_DEFAULT);
while (1){
gfx_con_setpos(0, 47);
timer = get_tmr_ms();
for (i = -3 + offset; i < amount && i < 30 + offset; i++){
for (i = -3 + offset; i < amount && i < 60 + offset; i++){
if (i < 0){
if (i == currentpos - 1)
gfx_printf("%k%K%s%K\n", COLOR_ORANGE, COLOR_WHITE, fixedoptions[i + 3], COLOR_DEFAULT);
@ -128,10 +140,10 @@ int makefilemenu(fs_entry *files, int amount, char *path){
gfx_printf("%k%K%s\n", COLOR_ORANGE, COLOR_DEFAULT, fixedoptions[i + 3]);
}
else
printfsentry(files[i], (i == currentpos - 1));
printfsentry(files[i], (i == currentpos - 1), refresh);
}
gfx_printf("\n%k%K %s %s\nTime taken: %dms", COLOR_BLUE, COLOR_DEFAULT, (offset + 30 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
refresh = false;
gfx_printf("\n%k%K %s %s\n\nTime taken for screen draw: %dms ", COLOR_BLUE, COLOR_DEFAULT, (offset + 60 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
if (quickoffset == 300)
res = btn_wait();
@ -149,14 +161,14 @@ int makefilemenu(fs_entry *files, int amount, char *path){
currentpos--;
if (offset != 0 && currentpos < offset - 2){
offset--;
gfx_box(0, 47, 719, 576, COLOR_DEFAULT);
refresh = true;
}
}
if ((res & BTN_VOL_DOWN) && currentpos < amount){
currentpos++;
if (currentpos - offset > 30){
if (currentpos - offset > 60){
offset++;
gfx_box(0, 47, 719, 576, COLOR_DEFAULT);
refresh = true;
}
}
if (res & BTN_POWER)