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

Add renaming option

This commit is contained in:
Such Meme, Many Skill 2020-05-02 16:40:40 +02:00
parent 0bf3b35582
commit b273b1e5ab
6 changed files with 125 additions and 10 deletions

View file

@ -81,6 +81,7 @@ extern menu_entry utils_mmcChoice[];
enum fs_menu_file_return {
FILE_COPY = 4,
FILE_MOVE,
FILE_RENAME,
FILE_DELETE,
FILE_PAYLOAD,
FILE_SCRIPT,

View file

@ -48,6 +48,7 @@ menu_entry fs_menu_file[] = {
{"\n\n\nBack", COLOR_WHITE, ISMENU},
{"\nCopy to clipboard", COLOR_BLUE, ISMENU},
{"Move to clipboard", COLOR_BLUE, ISMENU},
{"Rename file", COLOR_BLUE, ISMENU},
{"\nDelete file\n", COLOR_RED, ISMENU},
{"Launch Payload", COLOR_ORANGE, ISMENU},
{"Launch Script", COLOR_YELLOW, ISMENU},

View file

@ -36,7 +36,7 @@ int delfile(const char *path, const char *filename){
void viewbytes(char *path){
FIL in;
u8 print[1024];
u8 *print;
u32 size;
QWORD offset = 0;
int res;
@ -45,6 +45,7 @@ void viewbytes(char *path){
while (input->buttons & (KEY_POW | KEY_B));
gfx_clearscreen();
print = malloc (1024);
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
gfx_errDisplay("viewbytes", res, 1);
@ -54,7 +55,7 @@ void viewbytes(char *path){
while (1){
f_lseek(&in, offset * 16);
if ((res = f_read(&in, &print, 1024 * sizeof(u8), &size))){
if ((res = f_read(&in, print, 1024 * sizeof(u8), &size))){
gfx_errDisplay("viewbytes", res, 2);
return;
}
@ -75,6 +76,7 @@ void viewbytes(char *path){
break;
}
f_close(&in);
free(print);
}
void copyfile(const char *src_in, const char *outfolder){
@ -145,12 +147,11 @@ int filemenu(menu_entry file){
(attribs.fattrib & AM_ARC) ? 'A' : '-');
}
SETBIT(fs_menu_file[7].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.property & ISKB) && strstr(file.name, ".rom") == NULL);
SETBIT(fs_menu_file[8].property, ISHIDE, strstr(file.name, ".te") == NULL);
SETBIT(fs_menu_file[10].property, ISHIDE, strstr(file.name, ".bis") == NULL);
temp = menu_make(fs_menu_file, 11, "-- File Menu --");
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);
temp = menu_make(fs_menu_file, 12, "-- File Menu --");
switch (temp){
case FILE_COPY:
fsreader_writeclipboard(fsutil_getnextloc(currentpath, file.name), OPERATIONCOPY);
@ -161,6 +162,20 @@ int filemenu(menu_entry file){
case FILE_DELETE:
delfile(fsutil_getnextloc(currentpath, file.name), file.name);
break;
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);
f_rename(curPath, fsutil_getnextloc(currentpath, name));
free(curPath);
free(name);
fsreader_readfolder(currentpath);
break;
case FILE_PAYLOAD:
launch_payload(fsutil_getnextloc(currentpath, file.name));
break;

View file

@ -201,7 +201,7 @@ int menu_make(menu_entry *entries, int amount, char *toptext){
if (refresh)
gfx_drawScrollBar(minscreen, maxscreen, amount);
while ((input = hidRead())->buttons & (KEY_B | KEY_A));
while (hidRead()->buttons & (KEY_B | KEY_A));
input->buttons = 0;
while (!(input->buttons & (KEY_A | KEY_LDOWN | KEY_LUP | KEY_B | KEY_RUP | KEY_RDOWN))){

View file

@ -4,6 +4,8 @@
#include "../gfx/menu.h"
#include "../../storage/emummc.h"
#include "../../mem/heap.h"
#include "../gfx/gfxutils.h"
#include "../../hid/hid.h"
/*
#include "../../utils/util.h"
#include "../../utils/sprintf.h"
@ -35,4 +37,99 @@ void utils_takeScreenshot(){
f_mkdir(basepath);
path = fsutil_getnextloc(basepath, name);
}
*/
*/
char *utils_InputText(char *start, int maxLen){
int offset = -1, currentPos = 0, len;
char temp;
Inputs *input = hidRead();
u32 x, y;
gfx_printf("Add characters by pressing X\nRemove characters by pressing Y\nJoysticks for movement\nB to cancel, A to accept\n\n");
gfx_con_getpos(&x, &y);
if (strlen(start) > maxLen)
return NULL;
char *buff;
buff = calloc(maxLen + 1, sizeof(char));
strcpy(buff, start);
while (1){
offset = -1;
gfx_con_setpos(x, y);
for (int i = 0; i < 3; i++){
if (offset != 0){
SWAPCOLOR(0xFF666666);
gfx_con.fntsz = 8;
}
else {
SWAPCOLOR(COLOR_WHITE);
gfx_con.fntsz = 16;
}
for (int x = 0; x < strlen(buff); x++){
if (offset == 0 && x == currentPos){
gfx_printf("%k%c%k", COLOR_GREEN, buff[x], COLOR_WHITE);
}
else {
temp = buff[x] + offset;
if (!(temp >= 32 && temp <= 126))
temp = ' ';
gfx_putc(temp);
}
if (offset != 0)
gfx_puts(" ");
else
gfx_putc(' ');
}
gfx_putc('\n');
offset++;
}
if (input->buttons & (KEY_RDOWN | KEY_RUP))
hidRead();
else
hidWait();
len = strlen(buff);
if (input->buttons & (KEY_A | KEY_B))
break;
if (input->buttons & (KEY_LDOWN | KEY_RDOWN) && buff[currentPos] < 126)
buff[currentPos]++;
if (input->buttons & (KEY_LUP | KEY_RUP) && buff[currentPos] > 32)
buff[currentPos]--;
if (input->Lleft && currentPos > 0)
currentPos--;
if (input->Lright && currentPos < len - 1)
currentPos++;
if (input->x && maxLen > len){
buff[len] = '.';
buff[len + 1] = '\0';
}
if (input->y && len > 1){
buff[len - 1] = '\0';
if (currentPos == len - 1){
currentPos--;
}
gfx_boxGrey(0, y, 1279, y + 48, 0x1B);
}
}
gfx_con.fntsz = 16;
if (input->b){
free(buff);
return NULL;
}
return buff;
}

View file

@ -1,4 +1,5 @@
#pragma once
int utils_mmcMenu();
void utils_copystring(const char *in, char **out);
void utils_copystring(const char *in, char **out);
char *utils_InputText(char *start, int maxLen);