2019-12-01 16:10:01 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2019-11-21 15:02:45 +00:00
|
|
|
#include "../gfx/gfx.h"
|
|
|
|
#include "te.h"
|
|
|
|
#include "../utils/btn.h"
|
2019-12-01 00:49:36 +00:00
|
|
|
#include "../utils/util.h"
|
2019-11-21 15:02:45 +00:00
|
|
|
#include "gfx.h"
|
2019-12-01 00:49:36 +00:00
|
|
|
#include "fs.h"
|
2019-12-01 16:10:01 +00:00
|
|
|
#include "../mem/minerva.h"
|
2019-12-01 00:49:36 +00:00
|
|
|
|
|
|
|
const char fixedoptions[3][50] = {
|
|
|
|
"Folder -> previous folder",
|
|
|
|
"Clipboard -> Current folder",
|
|
|
|
"Folder options"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char sizevalues[4][3] = {
|
|
|
|
" B",
|
|
|
|
"KB",
|
|
|
|
"MB",
|
|
|
|
"GB"
|
|
|
|
};
|
2019-11-21 15:02:45 +00:00
|
|
|
|
|
|
|
void clearscreen(){
|
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
|
|
|
gfx_con_setpos(0, 0);
|
|
|
|
gfx_printf("%k%KTegraexplorer%k%K\n", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2019-11-21 16:34:47 +00:00
|
|
|
int message(char* message, u32 color){
|
2019-11-21 15:02:45 +00:00
|
|
|
clearscreen();
|
|
|
|
gfx_printf("%k%s%k", color, message, COLOR_DEFAULT);
|
|
|
|
return btn_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
int makemenu(menu_item menu[], int menuamount){
|
|
|
|
int currentpos = 1, i, res;
|
|
|
|
clearscreen();
|
|
|
|
|
|
|
|
while (1){
|
|
|
|
gfx_con_setpos(0, 31);
|
2019-11-21 16:34:47 +00:00
|
|
|
|
|
|
|
if (currentpos == 1){
|
2019-11-21 19:54:18 +00:00
|
|
|
while (currentpos < menuamount && menu[currentpos - 1].property < 1)
|
2019-11-21 16:34:47 +00:00
|
|
|
currentpos++;
|
|
|
|
}
|
|
|
|
if (currentpos == menuamount){
|
2019-11-21 19:54:18 +00:00
|
|
|
while (currentpos > 1 && menu[currentpos - 1].property < 1)
|
2019-11-21 16:34:47 +00:00
|
|
|
currentpos--;
|
|
|
|
}
|
|
|
|
|
2019-11-21 15:02:45 +00:00
|
|
|
for (i = 0; i < menuamount; i++){
|
2019-11-21 16:34:47 +00:00
|
|
|
if (menu[i].property < 0)
|
2019-11-21 15:02:45 +00:00
|
|
|
continue;
|
|
|
|
if (i == currentpos - 1)
|
|
|
|
gfx_printf("%k%K%s%K\n", COLOR_DEFAULT, COLOR_WHITE, menu[i].name, COLOR_DEFAULT);
|
|
|
|
else
|
|
|
|
gfx_printf("%k%s\n", menu[i].color, menu[i].name);
|
|
|
|
}
|
|
|
|
gfx_printf("\n%k%s", COLOR_WHITE, menuamount);
|
|
|
|
|
|
|
|
res = btn_wait();
|
|
|
|
|
2019-11-21 16:34:47 +00:00
|
|
|
if (res & BTN_VOL_UP && currentpos > 1){
|
2019-11-21 15:02:45 +00:00
|
|
|
currentpos--;
|
2019-11-21 19:54:18 +00:00
|
|
|
while(menu[currentpos - 1].property < 1 && currentpos > 1)
|
2019-11-21 16:34:47 +00:00
|
|
|
currentpos--;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (res & BTN_VOL_DOWN && currentpos < menuamount){
|
2019-11-21 15:02:45 +00:00
|
|
|
currentpos++;
|
2019-11-21 19:54:18 +00:00
|
|
|
while(menu[currentpos - 1].property < 1 && currentpos < menuamount)
|
2019-11-21 16:34:47 +00:00
|
|
|
currentpos++;
|
|
|
|
}
|
|
|
|
|
2019-11-21 15:02:45 +00:00
|
|
|
else if (res & BTN_POWER)
|
|
|
|
return menu[currentpos - 1].internal_function;
|
|
|
|
}
|
2019-12-01 00:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void printfsentry(fs_entry file, bool highlight){
|
|
|
|
int size = 0;
|
2019-12-01 16:10:01 +00:00
|
|
|
char *display;
|
|
|
|
|
|
|
|
display = (char*) malloc (38);
|
|
|
|
memset(display + 37, '\0', 1);
|
|
|
|
|
|
|
|
if (strlen(file.name) > 37){
|
|
|
|
strlcpy(display, file.name, 37);
|
|
|
|
memset(display + 34, '.', 3);
|
|
|
|
}
|
|
|
|
else // make option to clear the screen gracefully line by line
|
|
|
|
strcpy(display, file.name);
|
2019-12-01 00:49:36 +00:00
|
|
|
|
|
|
|
if (highlight)
|
|
|
|
gfx_printf("%K%k", COLOR_WHITE, COLOR_DEFAULT);
|
|
|
|
else
|
|
|
|
gfx_printf("%K%k", COLOR_DEFAULT, COLOR_WHITE);
|
|
|
|
|
|
|
|
if (file.property & ISDIR)
|
2019-12-01 16:10:01 +00:00
|
|
|
gfx_printf("%s\n", display);
|
2019-12-01 00:49:36 +00:00
|
|
|
else {
|
|
|
|
for (size = 4; size < 8; size++)
|
|
|
|
if ((file.property & (1 << size)))
|
|
|
|
break;
|
|
|
|
|
2019-12-01 16:10:01 +00:00
|
|
|
gfx_printf("%k%s%K\a%d\e%s", COLOR_VIOLET, display, COLOR_DEFAULT, file.size, sizevalues[size - 4]);
|
2019-12-01 00:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int makefilemenu(fs_entry *files, int amount, char *path){
|
|
|
|
int currentpos = 1, i, res = 0, offset = 0, quickoffset = 300;
|
2019-12-01 16:10:01 +00:00
|
|
|
u32 timer;
|
2019-12-01 00:49:36 +00:00
|
|
|
clearscreen();
|
|
|
|
gfx_con_setpos(544, 0);
|
|
|
|
gfx_printf("%K%k%d / 500\n%K%k%s%k\n\n", COLOR_WHITE, COLOR_DEFAULT, amount, COLOR_DEFAULT, COLOR_GREEN, path, COLOR_DEFAULT);
|
|
|
|
while (1){
|
|
|
|
gfx_con_setpos(0, 47);
|
2019-12-01 16:10:01 +00:00
|
|
|
timer = get_tmr_ms();
|
|
|
|
for (i = -3 + offset; i < amount && i < 30 + offset; i++){
|
2019-12-01 00:49:36 +00:00
|
|
|
if (i < 0){
|
|
|
|
if (i == currentpos - 1)
|
|
|
|
gfx_printf("%k%K%s%K\n", COLOR_ORANGE, COLOR_WHITE, fixedoptions[i + 3], COLOR_DEFAULT);
|
|
|
|
else
|
2019-12-01 16:10:01 +00:00
|
|
|
gfx_printf("%k%K%s\n", COLOR_ORANGE, COLOR_DEFAULT, fixedoptions[i + 3]);
|
2019-12-01 00:49:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
printfsentry(files[i], (i == currentpos - 1));
|
|
|
|
}
|
|
|
|
|
2019-12-01 16:10:01 +00:00
|
|
|
gfx_printf("\n%k%K %s %s\nTime taken: %dms", COLOR_BLUE, COLOR_DEFAULT, (offset + 30 < amount) ? "v" : " ", (offset > 0) ? "^" : " ", get_tmr_ms() - timer);
|
|
|
|
|
2019-12-01 00:49:36 +00:00
|
|
|
if (quickoffset == 300)
|
|
|
|
res = btn_wait();
|
|
|
|
else {
|
|
|
|
msleep(quickoffset);
|
|
|
|
res = btn_read();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res == 0)
|
|
|
|
quickoffset = 300;
|
2019-12-01 16:10:01 +00:00
|
|
|
else if (quickoffset > 46)
|
|
|
|
quickoffset -= 45;
|
2019-12-01 00:49:36 +00:00
|
|
|
|
2019-12-01 16:10:01 +00:00
|
|
|
if ((res & BTN_VOL_UP) && currentpos > -2){
|
2019-12-01 00:49:36 +00:00
|
|
|
currentpos--;
|
2019-12-01 16:10:01 +00:00
|
|
|
if (offset != 0 && currentpos < offset - 2){
|
|
|
|
offset--;
|
|
|
|
gfx_box(0, 47, 719, 576, COLOR_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((res & BTN_VOL_DOWN) && currentpos < amount){
|
2019-12-01 00:49:36 +00:00
|
|
|
currentpos++;
|
2019-12-01 16:10:01 +00:00
|
|
|
if (currentpos - offset > 30){
|
|
|
|
offset++;
|
|
|
|
gfx_box(0, 47, 719, 576, COLOR_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
2019-12-01 00:49:36 +00:00
|
|
|
if (res & BTN_POWER)
|
|
|
|
return currentpos;
|
|
|
|
}
|
2019-12-01 16:10:01 +00:00
|
|
|
minerva_periodic_training();
|
2019-11-21 15:02:45 +00:00
|
|
|
}
|