1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-12-29 04:46:01 +00:00
TegraExplorer/source/tegraexplorer/fs/filemenu.c

210 lines
6 KiB
C
Raw Normal View History

2020-03-18 22:58:32 +00:00
#include <string.h>
#include "entrymenu.h"
#include "../common/common.h"
#include "../../libs/fatfs/ff.h"
#include "../../gfx/gfx.h"
#include "fsutils.h"
#include "fsactions.h"
#include "../utils/utils.h"
#include "../gfx/gfxutils.h"
#include "../../mem/heap.h"
#include "fsreader.h"
#include "../gfx/menu.h"
#include "../common/types.h"
#include "../../utils/sprintf.h"
2020-03-31 13:24:34 +01:00
#include "../script/parser.h"
2020-03-19 15:11:18 +00:00
#include "../emmc/emmcoperations.h"
#include "../../hid/hid.h"
2020-03-18 22:58:32 +00:00
extern char *currentpath;
extern char *clipboard;
extern u8 clipboardhelper;
extern int launch_payload(char *path);
int delfile(const char *path, const char *filename){
gfx_clearscreen();
SWAPCOLOR(COLOR_ORANGE);
gfx_printf("Are you sure you want to delete:\n%s\n\nPress B to cancel\n", filename);
if (gfx_makewaitmenu("Press A to delete", 3)){
2020-03-18 22:58:32 +00:00
f_unlink(path);
fsreader_readfolder(currentpath);
return 0;
}
else
return -1;
}
void viewbytes(char *path){
FIL in;
2020-05-02 15:40:40 +01:00
u8 *print;
2020-03-18 22:58:32 +00:00
u32 size;
QWORD offset = 0;
int res;
Inputs *input = hidRead();
while (input->buttons & (KEY_POW | KEY_B));
2020-03-18 22:58:32 +00:00
gfx_clearscreen();
2020-05-02 15:40:40 +01:00
print = malloc (1024);
2020-03-18 22:58:32 +00:00
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
gfx_errDisplay("viewbytes", res, 1);
return;
}
while (1){
f_lseek(&in, offset * 16);
2020-05-02 15:40:40 +01:00
if ((res = f_read(&in, print, 1024 * sizeof(u8), &size))){
2020-03-18 22:58:32 +00:00
gfx_errDisplay("viewbytes", res, 2);
return;
}
gfx_con_setpos(0, 31);
gfx_hexdump(offset * 16, print, size * sizeof(u8));
input = hidRead();
2020-03-18 22:58:32 +00:00
if (!(input->buttons))
input = hidWait();
2020-03-18 22:58:32 +00:00
if (input->Ldown && 1024 * sizeof(u8) == size)
2020-03-18 22:58:32 +00:00
offset++;
if (input->Lup && offset > 0)
2020-03-18 22:58:32 +00:00
offset--;
if (input->buttons & (KEY_POW | KEY_B))
2020-03-18 22:58:32 +00:00
break;
}
f_close(&in);
2020-05-02 15:40:40 +01:00
free(print);
2020-03-18 22:58:32 +00:00
}
void copyfile(const char *src_in, const char *outfolder){
char *in, *out, *filename;
int res;
gfx_clearscreen();
utils_copystring(src_in, &in);
utils_copystring(strrchr(in, '/') + 1, &filename);
utils_copystring(fsutil_getnextloc(outfolder, filename), &out);
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", filename);
if (!strcmp(in, out)){
gfx_errDisplay("gfxcopy", ERR_SAME_LOC, 1);
return;
}
if (clipboardhelper & OPERATIONMOVE){
if ((res = f_rename(in, out))){
gfx_errDisplay("gfxcopy", res, 2);
return;
}
}
else if (clipboardhelper & OPERATIONCOPY) {
if (fsact_copy(in, out, COPY_MODE_CANCEL | COPY_MODE_PRINT))
return;
}
else {
gfx_errDisplay("gfxcopy", ERR_EMPTY_CLIPBOARD, 3);
return;
}
free(in);
free(out);
free(filename);
fsreader_readfolder(currentpath);
}
int filemenu(menu_entry file){
int temp;
FILINFO attribs;
for (int i = 0; i < 3; i++)
if (fs_menu_file[i].name != NULL)
free(fs_menu_file[i].name);
utils_copystring(file.name, &fs_menu_file[0].name);
fs_menu_file[1].name = malloc(16);
fs_menu_file[2].name = malloc(16);
for (temp = 4; temp < 8; temp++)
if ((file.property & (1 << temp)))
break;
sprintf(fs_menu_file[1].name, "\nSize: %d %s", file.storage, gfx_file_size_names[temp - 4]);
if (f_stat(fsutil_getnextloc(currentpath, file.name), &attribs))
SETBIT(fs_menu_file[2].property, ISHIDE, 1);
else {
SETBIT(fs_menu_file[2].property, ISHIDE, 0);
sprintf(fs_menu_file[2].name, "Attribs: %c%c%c%c",
(attribs.fattrib & AM_RDO) ? 'R' : '-',
(attribs.fattrib & AM_SYS) ? 'S' : '-',
(attribs.fattrib & AM_HID) ? 'H' : '-',
(attribs.fattrib & AM_ARC) ? 'A' : '-');
}
2020-05-02 15:40:40 +01:00
SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.property & ISKB) && strstr(file.name, ".rom") == NULL);
SETBIT(fs_menu_file[9].property, ISHIDE, strstr(file.name, ".te") == NULL);
SETBIT(fs_menu_file[11].property, ISHIDE, strstr(file.name, ".bis") == NULL);
2020-03-18 22:58:32 +00:00
2020-05-02 15:40:40 +01:00
temp = menu_make(fs_menu_file, 12, "-- File Menu --");
2020-03-18 22:58:32 +00:00
switch (temp){
case FILE_COPY:
fsreader_writeclipboard(fsutil_getnextloc(currentpath, file.name), OPERATIONCOPY);
break;
case FILE_MOVE:
fsreader_writeclipboard(fsutil_getnextloc(currentpath, file.name), OPERATIONMOVE);
break;
case FILE_DELETE:
delfile(fsutil_getnextloc(currentpath, file.name), file.name);
break;
2020-05-02 15:40:40 +01:00
case FILE_RENAME:;
char *name, *curPath;
gfx_clearscreen();
gfx_printf("Renaming %s...\n\n", file.name);
name = utils_InputText(file.name, 32);
if (name == NULL)
break;
utils_copystring(fsutil_getnextloc(currentpath, file.name), &curPath);
2020-05-02 16:31:00 +01:00
temp = f_rename(curPath, fsutil_getnextloc(currentpath, name));
2020-05-02 15:40:40 +01:00
free(curPath);
free(name);
2020-05-02 16:31:00 +01:00
if (temp){
gfx_errDisplay("fileMenu", temp, 0);
break;
}
2020-05-02 15:40:40 +01:00
fsreader_readfolder(currentpath);
break;
2020-03-18 22:58:32 +00:00
case FILE_PAYLOAD:
launch_payload(fsutil_getnextloc(currentpath, file.name));
break;
case FILE_SCRIPT:
2020-03-30 19:15:07 +01:00
//ParseScript(fsutil_getnextloc(currentpath, file.name));
2020-04-01 15:48:36 +01:00
runScript(fsutil_getnextloc(currentpath, file.name));
2020-04-01 12:57:25 +01:00
fsreader_readfolder(currentpath);
2020-03-18 22:58:32 +00:00
break;
case FILE_HEXVIEW:
viewbytes(fsutil_getnextloc(currentpath, file.name));
break;
case FILE_DUMPBIS:
2020-03-19 15:11:18 +00:00
gfx_clearscreen();
extract_bis_file(fsutil_getnextloc(currentpath, file.name), currentpath);
fsreader_readfolder(currentpath);
hidWait();
2020-03-18 22:58:32 +00:00
break;
case -1:
return -1;
2020-03-18 22:58:32 +00:00
}
return 0;
}