diff --git a/source/gfx/gfx.c b/source/gfx/gfx.c index 96f9bfe..665a7d2 100644 --- a/source/gfx/gfx.c +++ b/source/gfx/gfx.c @@ -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: diff --git a/source/libs/fatfs/ffconf.h b/source/libs/fatfs/ffconf.h index ca13b33..a086f13 100644 --- a/source/libs/fatfs/ffconf.h +++ b/source/libs/fatfs/ffconf.h @@ -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 diff --git a/source/main.c b/source/main.c index 8706339..d7e8972 100644 --- a/source/main.c +++ b/source/main.c @@ -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(); } diff --git a/source/meme/graphics.c b/source/meme/graphics.c index bc51391..0f00f57 100644 --- a/source/meme/graphics.c +++ b/source/meme/graphics.c @@ -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){ diff --git a/source/meme/graphics.h b/source/meme/graphics.h index 4779ebc..6e86aa2 100644 --- a/source/meme/graphics.h +++ b/source/meme/graphics.h @@ -1,3 +1,6 @@ #pragma once -int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int folderamount); \ No newline at end of file +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); \ No newline at end of file diff --git a/source/meme/main.c b/source/meme/main.c index 4795c02..9765fcb 100644 --- a/source/meme/main.c +++ b/source/meme/main.c @@ -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(); } \ No newline at end of file diff --git a/source/meme/main.h b/source/meme/main.h index 146c2ed..1bdb733 100644 --- a/source/meme/main.h +++ b/source/meme/main.h @@ -1,3 +1,3 @@ #pragma once -void meme_main(); \ No newline at end of file +void meme_main(bool sdinit); \ No newline at end of file diff --git a/source/meme/mainfunctions.c b/source/meme/mainfunctions.c index 4ed8338..75ddd8c 100644 --- a/source/meme/mainfunctions.c +++ b/source/meme/mainfunctions.c @@ -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); + } } } } \ No newline at end of file diff --git a/source/meme/utils.c b/source/meme/utils.c index c6b07b0..559b5b9 100644 --- a/source/meme/utils.c +++ b/source/meme/utils.c @@ -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,27 +46,84 @@ 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++; } } 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; } \ No newline at end of file diff --git a/source/meme/utils.h b/source/meme/utils.h index 67c9e5b..fe0cf40 100644 --- a/source/meme/utils.h +++ b/source/meme/utils.h @@ -9,4 +9,7 @@ void utils_gfx_init(); void utils_waitforpower(); void removepartpath(char *path); void addpartpath(char *path, char *add); -int readfolder(char *items[], unsigned int *muhbits, const char *path); \ No newline at end of file +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); \ No newline at end of file