2020-12-23 16:39:22 +00:00
|
|
|
#include "explorer.h"
|
|
|
|
#include "../../utils/vector.h"
|
|
|
|
#include "../readers/folderReader.h"
|
|
|
|
#include "../../gfx/menu.h"
|
|
|
|
#include "../fsutils.h"
|
|
|
|
#include "../../gfx/gfx.h"
|
|
|
|
#include "../../gfx/gfxutils.h"
|
|
|
|
#include "../../utils/utils.h"
|
2020-12-24 23:20:30 +00:00
|
|
|
#include "filemenu.h"
|
2020-12-23 16:39:22 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <mem/heap.h>
|
2020-12-25 21:19:04 +00:00
|
|
|
#include "../../tegraexplorer/tconf.h"
|
2020-12-26 00:05:33 +00:00
|
|
|
#include "../../err.h"
|
|
|
|
#include "../fscopy.h"
|
|
|
|
#include <libs/fatfs/ff.h>
|
|
|
|
#include "../../hid/hid.h"
|
2020-12-29 00:05:33 +00:00
|
|
|
#include "foldermenu.h"
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
MenuEntry_t topEntries[] = {
|
2020-12-24 16:06:21 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT},
|
2020-12-27 22:33:23 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_ORANGE)},
|
2020-12-23 23:31:17 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Current folder"},
|
2020-12-29 00:05:33 +00:00
|
|
|
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Current folder options"}
|
2020-12-23 16:39:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){
|
|
|
|
MenuEntry_t out = {.name = entry.name, .sizeUnion = entry.sizeUnion};
|
|
|
|
out.optionUnion = (entry.isDir) ? COLORTORGB(COLOR_WHITE) : COLORTORGB(COLOR_VIOLET);
|
|
|
|
out.icon = (entry.isDir) ? 127 : 128;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2020-12-28 01:29:58 +00:00
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
void FileExplorer(char *path){
|
2020-12-25 20:16:24 +00:00
|
|
|
char *storedPath = CpyStr(path);
|
2020-12-23 16:39:22 +00:00
|
|
|
int res = 0;
|
|
|
|
|
2020-12-29 00:05:33 +00:00
|
|
|
if (TConf.explorerCopyMode == CMODE_Move || TConf.explorerCopyMode == CMODE_MoveFolder)
|
|
|
|
ResetCopyParams();
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
while (1){
|
2020-12-26 00:05:33 +00:00
|
|
|
topEntries[2].optionUnion = (TConf.explorerCopyMode != CMODE_None) ? (COLORTORGB(COLOR_ORANGE)) : (COLORTORGB(COLOR_GREY) | SKIPBIT);
|
2020-12-27 22:33:23 +00:00
|
|
|
topEntries[1].name = (!strcmp(storedPath, path)) ? "<- Exit explorer" : "<- Folder back";
|
2020-12-25 21:19:04 +00:00
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
gfx_clearscreen();
|
|
|
|
gfx_printf("Loading...\r");
|
2020-12-28 01:29:58 +00:00
|
|
|
|
|
|
|
int readRes = 0;
|
|
|
|
Vector_t fileVec = ReadFolder(storedPath, &readRes);
|
|
|
|
if (readRes){
|
|
|
|
clearFileVector(&fileVec);
|
|
|
|
DrawError(newErrCode(readRes));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-23 16:39:22 +00:00
|
|
|
vecDefArray(FSEntry_t*, fsEntries, fileVec);
|
|
|
|
|
2020-12-24 16:06:21 +00:00
|
|
|
topEntries[0].name = storedPath;
|
|
|
|
Vector_t entries = newVec(sizeof(MenuEntry_t), fileVec.count + ARR_LEN(topEntries));
|
|
|
|
entries.count = ARR_LEN(topEntries);
|
|
|
|
memcpy(entries.data, topEntries, sizeof(MenuEntry_t) * ARR_LEN(topEntries));
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < fileVec.count; i++){
|
|
|
|
MenuEntry_t a = MakeMenuOutFSEntry(fsEntries[i]);
|
|
|
|
vecAddElem(&entries, a);
|
|
|
|
}
|
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
gfx_con_setpos(144, 24);
|
2020-12-24 16:06:21 +00:00
|
|
|
gfx_boxGrey(0, 16, 160, 31, 0x1B);
|
2020-12-24 23:20:30 +00:00
|
|
|
|
|
|
|
if (res >= fileVec.count + ARR_LEN(topEntries))
|
|
|
|
res = 0;
|
|
|
|
|
2020-12-24 16:06:21 +00:00
|
|
|
res = newMenu(&entries, res, 60, 42, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count);
|
2021-07-17 22:26:37 +01:00
|
|
|
vecFree(entries);
|
2020-12-23 16:39:22 +00:00
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
char *oldPath = storedPath;
|
|
|
|
|
2020-12-26 00:05:33 +00:00
|
|
|
if (res == 2){
|
2020-12-29 00:05:33 +00:00
|
|
|
ErrCode_t err = {0};
|
2020-12-26 00:05:33 +00:00
|
|
|
char *filename = CpyStr(strrchr(TConf.srcCopy, '/') + 1);
|
|
|
|
char *dst = CombinePaths(storedPath, filename);
|
|
|
|
|
|
|
|
if (!strcmp(TConf.srcCopy, dst))
|
2020-12-29 00:05:33 +00:00
|
|
|
err = newErrCode(TE_ERR_SAME_LOC);
|
|
|
|
|
|
|
|
if (!err.err && TConf.explorerCopyMode >= CMODE_CopyFolder){
|
|
|
|
if (strstr(dst, TConf.srcCopy) != NULL)
|
|
|
|
err = newErrCode(TE_ERR_PATH_IN_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err.err){
|
|
|
|
if (TConf.explorerCopyMode == CMODE_Move || TConf.explorerCopyMode == CMODE_MoveFolder){
|
|
|
|
if ((err.err = f_rename(TConf.srcCopy, dst)))
|
|
|
|
err = newErrCode(err.err);
|
2020-12-26 00:05:33 +00:00
|
|
|
}
|
2020-12-29 00:05:33 +00:00
|
|
|
else if (TConf.explorerCopyMode == CMODE_Copy) {
|
2020-12-26 00:05:33 +00:00
|
|
|
gfx_clearscreen();
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_printf("Hold vol+/- to cancel\nCopying %s... ", filename);
|
2020-12-29 00:05:33 +00:00
|
|
|
err = FileCopy(TConf.srcCopy, dst, COPY_MODE_CANCEL | COPY_MODE_PRINT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gfx_clearscreen();
|
|
|
|
RESETCOLOR;
|
|
|
|
gfx_printf("\nCopying folder... ");
|
|
|
|
err = FolderCopy(TConf.srcCopy, storedPath);
|
2020-12-26 00:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 00:05:33 +00:00
|
|
|
|
2020-12-26 00:05:33 +00:00
|
|
|
|
2020-12-29 00:05:33 +00:00
|
|
|
DrawError(err);
|
2020-12-26 00:05:33 +00:00
|
|
|
free(dst);
|
|
|
|
free(filename);
|
|
|
|
ResetCopyParams();
|
|
|
|
}
|
2020-12-29 00:05:33 +00:00
|
|
|
else if (res == 3){
|
|
|
|
if (FolderMenu(storedPath)){
|
|
|
|
storedPath = EscapeFolder(oldPath);
|
|
|
|
free(oldPath);
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-12-26 00:05:33 +00:00
|
|
|
else if (res < ARR_LEN(topEntries)) {
|
2020-12-23 16:39:22 +00:00
|
|
|
if (!strcmp(storedPath, path)){
|
|
|
|
clearFileVector(&fileVec);
|
2021-07-17 22:26:37 +01:00
|
|
|
free(storedPath);
|
2020-12-23 16:39:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-25 20:16:24 +00:00
|
|
|
storedPath = EscapeFolder(oldPath);
|
|
|
|
free(oldPath);
|
2020-12-24 23:20:30 +00:00
|
|
|
res = 0;
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
2020-12-24 16:06:21 +00:00
|
|
|
else if (fsEntries[res - ARR_LEN(topEntries)].isDir) {
|
2020-12-25 20:16:24 +00:00
|
|
|
storedPath = CombinePaths(storedPath, fsEntries[res - ARR_LEN(topEntries)].name);
|
|
|
|
free(oldPath);
|
2020-12-24 23:20:30 +00:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else {
|
2020-12-25 20:16:24 +00:00
|
|
|
FileMenu(storedPath, fsEntries[res - ARR_LEN(topEntries)]);
|
2020-12-23 16:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clearFileVector(&fileVec);
|
|
|
|
}
|
|
|
|
}
|