mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 20:06:43 +00:00
Added file copying/moving/deleting
Also added sd failure messages This probably needs a lot of cleanup
This commit is contained in:
parent
b97969e112
commit
d65eaedb14
10 changed files with 185 additions and 14 deletions
|
@ -229,6 +229,9 @@ void gfx_putc(char c)
|
||||||
if (gfx_con.y > gfx_ctxt.height - 16)
|
if (gfx_con.y > gfx_ctxt.height - 16)
|
||||||
gfx_con.y = 0;
|
gfx_con.y = 0;
|
||||||
}
|
}
|
||||||
|
else if (c == '\r'){
|
||||||
|
gfx_con.x = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -191,7 +191,7 @@
|
||||||
|
|
||||||
|
|
||||||
#define FF_MIN_SS 512
|
#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,
|
/* 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
|
/ 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
|
/ harddisk. But a larger value may be required for on-board flash memory and some
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "utils/util.h"
|
#include "utils/util.h"
|
||||||
#include "utils/btn.h"
|
#include "utils/btn.h"
|
||||||
#include "meme/main.h"
|
#include "meme/main.h"
|
||||||
|
#include "meme/utils.h"
|
||||||
|
|
||||||
#include "keys/keys.h"
|
#include "keys/keys.h"
|
||||||
|
|
||||||
|
@ -152,6 +153,7 @@ extern void pivot_stack(u32 stack_top);
|
||||||
|
|
||||||
void ipl_main()
|
void ipl_main()
|
||||||
{
|
{
|
||||||
|
bool sd_mounted = false;
|
||||||
config_hw();
|
config_hw();
|
||||||
pivot_stack(IPL_STACK_TOP);
|
pivot_stack(IPL_STACK_TOP);
|
||||||
heap_init(IPL_HEAP_START);
|
heap_init(IPL_HEAP_START);
|
||||||
|
@ -162,7 +164,8 @@ void ipl_main()
|
||||||
gfx_con_init();
|
gfx_con_init();
|
||||||
display_backlight_pwm_init();
|
display_backlight_pwm_init();
|
||||||
|
|
||||||
sd_mount();
|
|
||||||
meme_main();
|
sd_mounted = sd_mount();
|
||||||
|
meme_main(sd_mounted);
|
||||||
sd_unmount();
|
sd_unmount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,45 @@ int _copystring(char *out, const char *in, int copynumb){
|
||||||
return ret;
|
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){
|
void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits){
|
||||||
char temp[39];
|
char temp[39];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -25,6 +64,7 @@ void _printwithhighlight(int offset, int folderamount, char *items[], int highli
|
||||||
while(i < folderamount && i < 76){
|
while(i < folderamount && i < 76){
|
||||||
ret = _copystring(temp, items[i + offset], 39);
|
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);
|
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);
|
else gfx_printf("\n%s", temp);
|
||||||
|
|
||||||
while(ret >= 0){
|
while(ret >= 0){
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int folderamount);
|
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);
|
|
@ -9,7 +9,7 @@
|
||||||
#include "../storage/sdmmc.h"
|
#include "../storage/sdmmc.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
void meme_main(){
|
void meme_main(bool sdinit){
|
||||||
utils_gfx_init();
|
utils_gfx_init();
|
||||||
//static const u32 colors[7] = {COLOR_RED, COLOR_ORANGE, COLOR_YELLOW, COLOR_GREEN, COLOR_BLUE, COLOR_VIOLET, COLOR_DEFAULT};
|
//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]);
|
//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");
|
//f_rename("sd:/yeet.txt", "sd:/yote.txt");
|
||||||
|
|
||||||
|
|
||||||
char *itemsinfolder[500];
|
char *itemsinfolder[500];
|
||||||
unsigned int muhbits[500];
|
unsigned int muhbits[500];
|
||||||
|
|
||||||
|
if (sdinit){
|
||||||
sdexplorer(itemsinfolder, muhbits);
|
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();
|
utils_waitforpower();
|
||||||
}
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void meme_main();
|
void meme_main(bool sdinit);
|
|
@ -8,26 +8,80 @@
|
||||||
#include "../storage/sdmmc.h"
|
#include "../storage/sdmmc.h"
|
||||||
#include "graphics.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){
|
void sdexplorer(char *items[], unsigned int *muhbits){
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
int copymode = -1;
|
||||||
int folderamount = 0;
|
int folderamount = 0;
|
||||||
char path[255] = "sd:/";
|
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};
|
//static const u32 colors[8] = {COLOR_RED, COLOR_ORANGE, COLOR_YELLOW, COLOR_GREEN, COLOR_BLUE, COLOR_VIOLET, COLOR_DEFAULT, COLOR_WHITE};
|
||||||
while(1){
|
while(1){
|
||||||
gfx_clear_grey(0x1B);
|
gfx_clear_grey(0x1B);
|
||||||
gfx_con_setpos(0, 0);
|
gfx_con_setpos(0, 0);
|
||||||
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
gfx_box(0, 0, 719, 15, COLOR_WHITE);
|
||||||
folderamount = readfolder(items, muhbits, path);
|
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);
|
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) {
|
else if (value == 2) {
|
||||||
if (strcmp("sd:/", path) == 0) break;
|
if (strcmp("sd:/", path) == 0) break;
|
||||||
else removepartpath(path);
|
else removepartpath(path);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(muhbits[value - 1] & OPTION1) addpartpath(path, items[value - 1]);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ void utils_waitforpower(){
|
||||||
power_off();
|
power_off();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addchartoarray(char *add, char *items[], int spot){
|
void addchartoarray(char *add, char *items[], int spot){
|
||||||
size_t size = strlen(add) + 1;
|
size_t size = strlen(add) + 1;
|
||||||
items[spot] = (char*) malloc (size);
|
items[spot] = (char*) malloc (size);
|
||||||
strlcpy(items[spot], add, 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){
|
void _mallocandaddfolderbit(unsigned int *muhbits, int spot, bool value){
|
||||||
muhbits[spot] = (unsigned int) malloc (sizeof(int));
|
muhbits[spot] = (unsigned int) malloc (sizeof(int));
|
||||||
if (value) muhbits[spot] |= (OPTION1);
|
if (value) muhbits[spot] |= (OPTION1);
|
||||||
|
//ff.h line 368
|
||||||
}
|
}
|
||||||
|
|
||||||
int readfolder(char *items[], unsigned int *muhbits, const char *path){
|
int readfolder(char *items[], unsigned int *muhbits, const char *path){
|
||||||
DIR dir;
|
DIR dir;
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
int i = 2;
|
int i = 2;
|
||||||
_addchartoarray(".", items, 0);
|
addchartoarray("Clipboard -> current folder", items, 0);
|
||||||
_addchartoarray("..", items, 1);
|
addchartoarray("Current folder -> One folder up", items, 1);
|
||||||
_mallocandaddfolderbit(muhbits, 0, true);
|
_mallocandaddfolderbit(muhbits, 0, true);
|
||||||
_mallocandaddfolderbit(muhbits, 1, true);
|
_mallocandaddfolderbit(muhbits, 1, true);
|
||||||
|
|
||||||
if (f_opendir(&dir, path)) {
|
if (f_opendir(&dir, path)) {
|
||||||
gfx_printf("\nFailed to open %s", path);
|
gfx_printf("\nFailed to open %s", path);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
while (!f_readdir(&dir, &fno) && fno.fname[0]){
|
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);
|
_mallocandaddfolderbit(muhbits, i, fno.fattrib & AM_DIR);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -70,3 +72,58 @@ int readfolder(char *items[], unsigned int *muhbits, const char *path){
|
||||||
f_closedir(&dir);
|
f_closedir(&dir);
|
||||||
return i;
|
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;
|
||||||
|
}
|
|
@ -10,3 +10,6 @@ void utils_waitforpower();
|
||||||
void removepartpath(char *path);
|
void removepartpath(char *path);
|
||||||
void addpartpath(char *path, char *add);
|
void addpartpath(char *path, char *add);
|
||||||
int readfolder(char *items[], unsigned int *muhbits, const char *path);
|
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);
|
Loading…
Reference in a new issue