1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-26 05:42:07 +00:00

Added file copying/moving/deleting

Also added sd failure messages

This probably needs a lot of cleanup
This commit is contained in:
Such Meme, Many Skill 2019-08-16 16:13:58 +02:00
parent b97969e112
commit d65eaedb14
10 changed files with 185 additions and 14 deletions

View file

@ -229,6 +229,9 @@ void gfx_putc(char c)
if (gfx_con.y > gfx_ctxt.height - 16)
gfx_con.y = 0;
}
else if (c == '\r'){
gfx_con.x = 0;
}
break;
case 8:
default:

View file

@ -191,7 +191,7 @@
#define FF_MIN_SS 512
#define FF_MAX_SS 512
#define FF_MAX_SS 4096
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
/ harddisk. But a larger value may be required for on-board flash memory and some

View file

@ -29,6 +29,7 @@
#include "utils/util.h"
#include "utils/btn.h"
#include "meme/main.h"
#include "meme/utils.h"
#include "keys/keys.h"
@ -152,6 +153,7 @@ extern void pivot_stack(u32 stack_top);
void ipl_main()
{
bool sd_mounted = false;
config_hw();
pivot_stack(IPL_STACK_TOP);
heap_init(IPL_HEAP_START);
@ -162,7 +164,8 @@ void ipl_main()
gfx_con_init();
display_backlight_pwm_init();
sd_mount();
meme_main();
sd_mounted = sd_mount();
meme_main(sd_mounted);
sd_unmount();
}

View file

@ -17,6 +17,45 @@ int _copystring(char *out, const char *in, int copynumb){
return ret;
}
int messagebox(char *message){
int ret = -1;
meme_clearscreen();
gfx_printf("%s", message);
u8 res = btn_wait();
if (res & BTN_POWER) ret = 0;
else ret = 1;
meme_clearscreen();
return ret;
}
int gfx_menulist(int ypos, char *list[], int length){
int i = 0;
int highlight = 1;
while(1){
gfx_con_setpos(0, ypos);
while(i < length){
if (i == highlight - 1) gfx_printf("%k%p%s%k%p\n", COLOR_DEFAULT, COLOR_WHITE, list[i], COLOR_WHITE, COLOR_DEFAULT);
else gfx_printf("%s\n", list[i]);
i++;
}
i = 0;
u8 res = btn_wait();
if (res & BTN_VOL_UP) highlight--;
else if (res & BTN_VOL_DOWN) highlight++;
else if (res & BTN_POWER) break;
if (highlight < 1) highlight = 1;
if (highlight > length) highlight = length;
}
return highlight;
}
void meme_clearscreen(){
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
gfx_box(0, 0, 719, 15, COLOR_WHITE);
gfx_printf("%k%pTegraExplorer, by SuchMemeManySkill\n%k%p", COLOR_DEFAULT, COLOR_WHITE, COLOR_WHITE, COLOR_DEFAULT);
}
void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits){
char temp[39];
int i = 0;
@ -25,6 +64,7 @@ void _printwithhighlight(int offset, int folderamount, char *items[], int highli
while(i < folderamount && i < 76){
ret = _copystring(temp, items[i + offset], 39);
if(i == highlight - 1) gfx_printf("\n%k%p%s%k%p", COLOR_DEFAULT, COLOR_WHITE, temp, COLOR_WHITE, COLOR_DEFAULT);
else if ((i == 0 || i == 1) && offset == 0) gfx_printf("%k\n%s%k", COLOR_ORANGE, temp, COLOR_WHITE);
else gfx_printf("\n%s", temp);
while(ret >= 0){

View file

@ -1,3 +1,6 @@
#pragma once
int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int folderamount);
void meme_clearscreen();
int gfx_menulist(int ypos, char *list[], int length);
int messagebox(char *message);

View file

@ -9,7 +9,7 @@
#include "../storage/sdmmc.h"
#include "graphics.h"
void meme_main(){
void meme_main(bool sdinit){
utils_gfx_init();
//static const u32 colors[7] = {COLOR_RED, COLOR_ORANGE, COLOR_YELLOW, COLOR_GREEN, COLOR_BLUE, COLOR_VIOLET, COLOR_DEFAULT};
//gfx_printf("%k%pTegraExplorer, made by SuchMemeManySkill \n%k%p", colors[6], colors[3], colors[3], colors[6]);
@ -22,12 +22,20 @@ void meme_main(){
*/
//f_rename("sd:/yeet.txt", "sd:/yote.txt");
char *itemsinfolder[500];
unsigned int muhbits[500];
if (sdinit){
sdexplorer(itemsinfolder, muhbits);
gfx_printf("%k\n\nExited main loop, vol+ to reboot to rcm\nvol- to reboot normally\npower to power off", COLOR_GREEN);
//write file and folder menu
//make clipboard and shit like that
//figure out time from keys.c
//figure out how to reboot to payloads https://github.com/CTCaer/hekate/blob/101c8bc1d0813da10016be771a9919c9e8112277/bootloader/main.c#L266
gfx_printf("%k\n\nExited main loop, vol+ to reboot to rcm\nvol- to reboot normally\npower to power off\n", COLOR_GREEN);
}
else gfx_printf("%k%pSD INIT FAILED\n\nvol+ to reboot to rcm\nvol- to reboot normally\npower to power off", COLOR_RED, COLOR_DEFAULT);
utils_waitforpower();
}

View file

@ -1,3 +1,3 @@
#pragma once
void meme_main();
void meme_main(bool sdinit);

View file

@ -8,26 +8,80 @@
#include "../storage/sdmmc.h"
#include "graphics.h"
int _openfilemenu(const char *path, char *clipboardpath){
meme_clearscreen();
FILINFO fno;
f_stat(path, &fno);
char *options[4];
int res = 0;
int mres = -1;
int ret = -1;
addchartoarray("Back", options, 0);
addchartoarray("Copy to clipboard", options, 1);
addchartoarray("Move to clipboard", options, 2);
addchartoarray("Delete file", options, 3);
gfx_printf("%kPath: %s%k\n\n", COLOR_GREEN, path, COLOR_WHITE);
int temp = (fno.fsize / 1024 / 1024);
gfx_printf("Size MB: %d", temp);
res = gfx_menulist(160, options, 4);
switch(res){
case 2:
ret = 0;
strcpy(clipboardpath, path);
break;
case 3:
ret = 1;
strcpy(clipboardpath, path);
break;
case 4:
mres = messagebox("Are you sure you want to delete this file?\nPower to confirm\nVOL to cancel");
if (mres == 0) f_unlink(path);
break;
default:
break;
}
meme_clearscreen();
return ret;
}
void sdexplorer(char *items[], unsigned int *muhbits){
int value = 1;
int copymode = -1;
int folderamount = 0;
char path[255] = "sd:/";
char clipboard[255] = "";
int temp = -1;
//static const u32 colors[8] = {COLOR_RED, COLOR_ORANGE, COLOR_YELLOW, COLOR_GREEN, COLOR_BLUE, COLOR_VIOLET, COLOR_DEFAULT, COLOR_WHITE};
while(1){
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
gfx_box(0, 0, 719, 15, COLOR_WHITE);
folderamount = readfolder(items, muhbits, path);
gfx_printf("%k%pTegraExplorer, made by SuchMeme %d\n%k%p", COLOR_DEFAULT, COLOR_WHITE, folderamount - 2, COLOR_WHITE, COLOR_DEFAULT);
gfx_printf("%k%pTegraExplorer, by SuchMemeManySkill %d\n%k%p", COLOR_DEFAULT, COLOR_WHITE, folderamount - 2, COLOR_WHITE, COLOR_DEFAULT);
value = fileexplorergui(items, muhbits, path, folderamount);
if (value == 1) {}
if (value == 1) {
if (copymode != -1){
copywithpath(clipboard, path, copymode);
copymode = -1;
}
}
else if (value == 2) {
if (strcmp("sd:/", path) == 0) break;
else removepartpath(path);
}
else {
if(muhbits[value - 1] & OPTION1) addpartpath(path, items[value - 1]);
else {
addpartpath(path, items[value - 1]);
temp = _openfilemenu(path, clipboard);
if (temp != -1) copymode = temp;
removepartpath(path);
}
}
}
}

View file

@ -37,7 +37,7 @@ void utils_waitforpower(){
power_off();
}
void _addchartoarray(char *add, char *items[], int spot){
void addchartoarray(char *add, char *items[], int spot){
size_t size = strlen(add) + 1;
items[spot] = (char*) malloc (size);
strlcpy(items[spot], add, size);
@ -46,23 +46,25 @@ void _addchartoarray(char *add, char *items[], int spot){
void _mallocandaddfolderbit(unsigned int *muhbits, int spot, bool value){
muhbits[spot] = (unsigned int) malloc (sizeof(int));
if (value) muhbits[spot] |= (OPTION1);
//ff.h line 368
}
int readfolder(char *items[], unsigned int *muhbits, const char *path){
DIR dir;
FILINFO fno;
int i = 2;
_addchartoarray(".", items, 0);
_addchartoarray("..", items, 1);
addchartoarray("Clipboard -> current folder", items, 0);
addchartoarray("Current folder -> One folder up", items, 1);
_mallocandaddfolderbit(muhbits, 0, true);
_mallocandaddfolderbit(muhbits, 1, true);
if (f_opendir(&dir, path)) {
gfx_printf("\nFailed to open %s", path);
return 0;
}
else {
while (!f_readdir(&dir, &fno) && fno.fname[0]){
_addchartoarray(fno.fname, items, i);
addchartoarray(fno.fname, items, i);
_mallocandaddfolderbit(muhbits, i, fno.fattrib & AM_DIR);
i++;
}
@ -70,3 +72,58 @@ int readfolder(char *items[], unsigned int *muhbits, const char *path){
f_closedir(&dir);
return i;
}
int copy(const char *src, const char *dst){
FIL in;
FIL out;
if (f_open(&in, src, FA_READ) != FR_OK){
//something has gone wrong
return 0;
}
if (f_open(&out, dst, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){
//something has gone wrong
return 0;
}
int BUFFSIZ = 32768;
u64 size = f_size(&in);
void *buff = malloc(BUFFSIZ);
int kbwritten = 0;
gfx_printf("%d\n", size);
while(size > BUFFSIZ){
int res1, res2;
res1 = f_read(&in, buff, BUFFSIZ, NULL);
res2 = f_write(&out, buff, BUFFSIZ, NULL);
kbwritten = kbwritten + BUFFSIZ;
gfx_printf("Written %d\r", kbwritten);
size = size - BUFFSIZ;
}
if(size != 0){
f_read(&in, buff, size, NULL);
f_write(&out, buff, size, NULL);
}
f_close(&in);
f_close(&out);
free(buff);
return 1;
}
int copywithpath(const char *src, const char *dstpath, int mode){
FILINFO fno;
f_stat(src, &fno);
char dst[255];
strcpy(dst, dstpath);
if (strcmp(dstpath, "sd:/") != 0) strcat(dst, "/");
strcat(dst, fno.fname);
int ret = -1;
if (mode == 0) ret = copy(src, dst);
if (mode == 1) f_rename(src, dst);
return ret;
}

View file

@ -10,3 +10,6 @@ void utils_waitforpower();
void removepartpath(char *path);
void addpartpath(char *path, char *add);
int readfolder(char *items[], unsigned int *muhbits, const char *path);
int copy(const char *src, const char *dst);
void addchartoarray(char *add, char *items[], int spot);
int copywithpath(const char *src, const char *dstpath, int mode);