1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 13:11:54 +00:00
TegraExplorer/source/fs/menus/explorer.c

89 lines
2.7 KiB
C
Raw Normal View History

#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"
#include "filemenu.h"
#include <string.h>
#include <mem/heap.h>
MenuEntry_t topEntries[] = {
{.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT},
{.optionUnion = COLORTORGB(COLOR_ORANGE), .name = "Back"},
2020-12-23 23:31:17 +00:00
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Clipboard -> Current folder"},
{.optionUnion = COLORTORGB(COLOR_GREY) | SKIPBIT, .name = "Current folder options"}
};
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;
}
void clearFileVector(Vector_t *v){
vecPDefArray(FSEntry_t*, entries, v);
for (int i = 0; i < v->count; i++)
free(entries[i].name);
free(v->data);
}
void FileExplorer(char *path){
2020-12-25 20:16:24 +00:00
char *storedPath = CpyStr(path);
int res = 0;
while (1){
gfx_clearscreen();
gfx_printf("Loading...\r");
//gfx_printf(" ");
Vector_t fileVec = ReadFolder(storedPath);
vecDefArray(FSEntry_t*, fsEntries, fileVec);
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));
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);
gfx_boxGrey(0, 16, 160, 31, 0x1B);
if (res >= fileVec.count + ARR_LEN(topEntries))
res = 0;
res = newMenu(&entries, res, 60, 42, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count);
2020-12-25 20:16:24 +00:00
char *oldPath = storedPath;
if (res < ARR_LEN(topEntries)) {
if (!strcmp(storedPath, path)){
clearFileVector(&fileVec);
return;
}
2020-12-25 20:16:24 +00:00
storedPath = EscapeFolder(oldPath);
free(oldPath);
res = 0;
}
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);
res = 0;
}
else {
2020-12-25 20:16:24 +00:00
FileMenu(storedPath, fsEntries[res - ARR_LEN(topEntries)]);
}
clearFileVector(&fileVec);
}
}