From f9cf371cf9b389f44e0ad817ae56aa91af0a61ed Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Sat, 2 May 2020 17:31:00 +0200 Subject: [PATCH] i have no brain and i must rename --- source/tegraexplorer/common/common.h | 4 ++- source/tegraexplorer/common/structs.c | 4 ++- source/tegraexplorer/fs/filemenu.c | 10 +++++- source/tegraexplorer/fs/foldermenu.c | 51 +++++++++++++++++++++++++-- source/tegraexplorer/fs/fsmenu.c | 2 +- source/tegraexplorer/utils/utils.c | 14 +++++--- 6 files changed, 74 insertions(+), 11 deletions(-) diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index bb706b7..4bca51c 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -94,7 +94,9 @@ extern menu_entry fs_menu_file[]; enum fs_menu_folder_return { DIR_EXITFOLDER = 2, DIR_COPYFOLDER, - DIR_DELETEFOLDER + DIR_DELETEFOLDER, + DIR_RENAME, + DIR_CREATE }; extern menu_entry fs_menu_folder[]; diff --git a/source/tegraexplorer/common/structs.c b/source/tegraexplorer/common/structs.c index bbf78e6..2db40d7 100644 --- a/source/tegraexplorer/common/structs.c +++ b/source/tegraexplorer/common/structs.c @@ -61,7 +61,9 @@ menu_entry fs_menu_folder[] = { {"\nBack", COLOR_WHITE, ISMENU}, {"Return to main menu\n", COLOR_BLUE, ISMENU}, {"Copy to clipboard", COLOR_VIOLET, ISMENU}, - {"Delete folder", COLOR_RED, ISMENU} + {"Delete folder", COLOR_RED, ISMENU}, + {"Rename folder", COLOR_BLUE, ISMENU}, + {"Create folder", COLOR_BLUE, ISMENU} }; menu_entry fs_menu_startdir[] = { diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index ac2d3e3..198b7c9 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -171,9 +171,17 @@ int filemenu(menu_entry file){ break; utils_copystring(fsutil_getnextloc(currentpath, file.name), &curPath); - f_rename(curPath, fsutil_getnextloc(currentpath, name)); + + temp = f_rename(curPath, fsutil_getnextloc(currentpath, name)); + free(curPath); free(name); + + if (temp){ + gfx_errDisplay("fileMenu", temp, 0); + break; + } + fsreader_readfolder(currentpath); break; case FILE_PAYLOAD: diff --git a/source/tegraexplorer/fs/foldermenu.c b/source/tegraexplorer/fs/foldermenu.c index 0ef97e0..45a53c6 100644 --- a/source/tegraexplorer/fs/foldermenu.c +++ b/source/tegraexplorer/fs/foldermenu.c @@ -9,6 +9,7 @@ #include "fsactions.h" #include "fsutils.h" #include "../../utils/sprintf.h" +#include "../utils/utils.h" extern char *currentpath; extern char *clipboard; @@ -39,6 +40,7 @@ void copyfolder(char *in, char *out){ int foldermenu(){ int res; + char *name; FILINFO attribs; if (fs_menu_folder[0].name != NULL) @@ -50,6 +52,7 @@ int foldermenu(){ SETBIT(fs_menu_folder[3].property, ISHIDE, (*(currentpath + res - 1) == '/')); SETBIT(fs_menu_folder[4].property, ISHIDE, (*(currentpath + res - 1) == '/')); + SETBIT(fs_menu_folder[5].property, ISHIDE, (*(currentpath + res - 1) == '/')); if (f_stat(currentpath, &attribs)) SETBIT(fs_menu_folder[0].property, ISHIDE, 1); @@ -62,7 +65,7 @@ int foldermenu(){ (attribs.fattrib & AM_ARC) ? 'A' : '-'); } - res = menu_make(fs_menu_folder, 5, currentpath); + res = menu_make(fs_menu_folder, 7, currentpath); switch (res){ case DIR_EXITFOLDER: @@ -73,8 +76,7 @@ int foldermenu(){ break; case DIR_DELETEFOLDER: gfx_clearscreen(); - gfx_printf("Do you want to delete this folder?\nThe entire folder, with all subcontents\n will be deleted!!!\n\nPress vol+/- to cancel\n"); - if (gfx_makewaitmenu("Press power to contine...", 3)){ + if (gfx_defaultWaitMenu("Do you want to delete this folder?\nThe entire folder, with all subcontents will be deleted!!!", 4)){ gfx_clearscreen(); gfx_printf("\nDeleting folder, please wait...\n"); @@ -84,6 +86,49 @@ int foldermenu(){ fsreader_readfolder(currentpath); } break; + case DIR_RENAME:; + char *prevLoc, *dirName; + + dirName = strrchr(currentpath, '/') + 1; + + gfx_clearscreen(); + gfx_printf("Renaming %s...\n\n", dirName); + name = utils_InputText(dirName, 32); + if (name == NULL) + break; + + utils_copystring(fsutil_getprevloc(currentpath), &prevLoc); + res = f_rename(currentpath, fsutil_getnextloc(prevLoc, name)); + + free(prevLoc); + free(name); + + if (res){ + gfx_errDisplay("folderMenu", res, 1); + break; + } + + fsreader_writecurpath(fsutil_getprevloc(currentpath)); + fsreader_readfolder(currentpath); + + break; + case DIR_CREATE:; + gfx_clearscreen(); + gfx_printf("Give a name for your new folder\n\n"); + name = utils_InputText("New Folder", 32); + if (name == NULL) + break; + + res = f_mkdir(fsutil_getnextloc(currentpath, name)); + free(name); + + if (res){ + gfx_errDisplay("folderMenu", res, 1); + break; + } + + fsreader_readfolder(currentpath); + break; } return 0; diff --git a/source/tegraexplorer/fs/fsmenu.c b/source/tegraexplorer/fs/fsmenu.c index b59350f..22d00a7 100644 --- a/source/tegraexplorer/fs/fsmenu.c +++ b/source/tegraexplorer/fs/fsmenu.c @@ -55,7 +55,7 @@ void fileexplorer(const char *startpath, int type){ break; case FILEMENU_CURFOLDER: - if (foldermenu()) + if (foldermenu() < 0) return; break; case -1: diff --git a/source/tegraexplorer/utils/utils.c b/source/tegraexplorer/utils/utils.c index d0c746c..1ec981a 100644 --- a/source/tegraexplorer/utils/utils.c +++ b/source/tegraexplorer/utils/utils.c @@ -98,11 +98,17 @@ char *utils_InputText(char *start, int maxLen){ if (input->buttons & (KEY_A | KEY_B)) break; - if (input->buttons & (KEY_LDOWN | KEY_RDOWN) && buff[currentPos] < 126) - buff[currentPos]++; + if (input->buttons & (KEY_LDOWN | KEY_RDOWN) && buff[currentPos] < 126){ + temp = ++buff[currentPos]; + while (temp == '\\' || temp == '/' || temp == ':' || temp == '*' || temp == '?' || temp == '"' || temp == '<' || temp == '>' || temp == '|') + temp = ++buff[currentPos]; + } - if (input->buttons & (KEY_LUP | KEY_RUP) && buff[currentPos] > 32) - buff[currentPos]--; + if (input->buttons & (KEY_LUP | KEY_RUP) && buff[currentPos] > 32){ + temp = --buff[currentPos]; + while (temp == '\\' || temp == '/' || temp == ':' || temp == '*' || temp == '?' || temp == '"' || temp == '<' || temp == '>' || temp == '|') + temp = --buff[currentPos]; + } if (input->Lleft && currentPos > 0) currentPos--;