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

Add folder navigating!

This commit is contained in:
Such Meme, Many Skill 2019-08-15 22:16:48 +02:00
parent 82a941bb13
commit a190a07016
9 changed files with 172 additions and 27 deletions

View file

@ -10,12 +10,12 @@ include $(DEVKITARM)/base_rules
IPL_LOAD_ADDR := 0x40003000
LPVERSION_MAJOR := 1
LPVERSION_MINOR := 3
LPVERSION_MINOR := 0
LPVERSION_BUGFX := 0
################################################################################
TARGET := Lockpick_RCM
TARGET := TegraExplorer
BUILDDIR := build
OUTPUTDIR := output
SOURCEDIR = source

View file

@ -164,4 +164,5 @@ void ipl_main()
sd_mount();
meme_main();
sd_unmount();
}

84
source/meme/graphics.c Normal file
View file

@ -0,0 +1,84 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "../gfx/di.h"
#include "../gfx/gfx.h"
#include "../utils/btn.h"
#include "../utils/util.h"
#include "graphics.h"
#include "utils.h"
int _copystring(char *out, const char *in, int copynumb){
strncpy(out, in, copynumb - 1);
int strlength = strlen(in);
if (strlength > copynumb + 1) strlength = copynumb;
memset(out + strlength, '\0', 1);
int ret = copynumb - strlength;
return ret;
}
void _printwithhighlight(int offset, int folderamount, char *items[], int highlight, unsigned int *muhbits){
char temp[39];
int i = 0;
int ret = 0;
gfx_con_setpos(0, 32);
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_GREEN, temp, COLOR_GREEN, COLOR_DEFAULT);
else gfx_printf("\n%s", temp);
while(ret >= 0){
gfx_printf(" ");
ret = ret - 1;
}
gfx_con.x = 720 - (16 * 6);
if (muhbits[i + offset] & OPTION1) gfx_printf("DIR");
else gfx_printf("FILE");
i++;
}
}
int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int folderamount){
bool change = true;
int select = 1;
int sleepvalue = 300;
int offset = 0;
char temp[43];
gfx_con_setpos(0, 16);
_copystring(temp, path, 43);
gfx_printf("%k%s\n%k", COLOR_ORANGE, temp, COLOR_GREEN);
while(1){
if (change){
_printwithhighlight(offset, folderamount, items, select, muhbits);
change = false;
msleep(sleepvalue);
}
u8 res = btn_read();
if (res & BTN_VOL_UP){
select = select - 1, change = true;
sleepvalue = sleepvalue - 75;
}
else if (res & BTN_VOL_DOWN){
select++, change = true;
sleepvalue = sleepvalue - 75;
}
else {
sleepvalue = 300;
}
if (res & BTN_POWER) break;
if (select < 1){
select = 1;
if (offset > 0) offset = offset - 1;
}
if (select > folderamount) select = folderamount;
if (select > 76){
select = 76;
if (76 + offset < folderamount) offset++;
}
if (sleepvalue < 30) sleepvalue = 30;
}
int ret = select + offset;
return ret;
}

3
source/meme/graphics.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
int fileexplorergui(char *items[], unsigned int *muhbits, const char path[], int folderamount);

View file

@ -4,37 +4,30 @@
#include "../utils/btn.h"
#include "utils.h"
#include "main.h"
#include "mainfunctions.h"
#include "../libs/fatfs/ff.h"
#include "../storage/sdmmc.h"
#include "graphics.h"
void meme_main(){
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%pHello World!\n%k%pHi denn i think i did it\n%p%kAnother test\n", colors[1], colors[0], colors[2], colors[5], colors[6], colors[3]);
//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]);
/*
sdmmc_storage_t storage;
sdmmc_t sdmmc;
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4);
sdmmc_storage_set_mmc_partition(&storage, 1);
*/
//f_rename("sd:/yeet.txt", "sd:/yote.txt");
char *itemsinfolder[250];
unsigned int muhbits[250];
int folderamount = 0;
char path[100] = "sd:/";
char *itemsinfolder[500];
unsigned int muhbits[500];
folderamount = readfolder(itemsinfolder, muhbits, path);
sdexplorer(itemsinfolder, muhbits);
int i = 0;
gfx_printf("%d", folderamount);
while(i < folderamount){
gfx_printf("\n%s", itemsinfolder[i]);
if (muhbits[i] & OPTION1) gfx_printf(" <DIR>");
else gfx_printf(" <FILE>");
i++;
}
gfx_printf("\n\nExited main loop, vol+ to reboot to rcm\nvol- to reboot normally\npower to power off");
utils_waitforpower();
}

View file

@ -0,0 +1,33 @@
#include <string.h>
#include "../gfx/di.h"
#include "../gfx/gfx.h"
#include "../utils/btn.h"
#include "utils.h"
#include "mainfunctions.h"
#include "../libs/fatfs/ff.h"
#include "../storage/sdmmc.h"
#include "graphics.h"
void sdexplorer(char *items[], unsigned int *muhbits){
int value = 1;
int folderamount = 0;
char path[255] = "sd:/";
static const u32 colors[7] = {COLOR_RED, COLOR_ORANGE, COLOR_YELLOW, COLOR_GREEN, COLOR_BLUE, COLOR_VIOLET, COLOR_DEFAULT};
while(1){
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
gfx_box(0, 0, 719, 15, COLOR_GREEN);
folderamount = readfolder(items, muhbits, path);
gfx_printf("%k%pTegraExplorer, made by SuchMeme %d\n%k%p", colors[6], colors[3], folderamount - 2, colors[3], colors[6]);
value = fileexplorergui(items, muhbits, path, folderamount);
if (value == 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]);
}
}
}

View file

@ -0,0 +1,3 @@
#pragma once
void sdexplorer(char *items[], unsigned int *muhbits);

View file

@ -15,6 +15,18 @@ void utils_gfx_init(){
gfx_con_setpos(0, 0);
}
void removepartpath(char *path){
char *ret;
ret = strrchr(path, '/');
memset(ret, '\0', 1);
if (strcmp(path, "sd:") == 0) strcpy(path, "sd:/");
}
void addpartpath(char *path, char *add){
if (strcmp(path, "sd:/") != 0) strcat(path, "/");
strcat(path, add);
}
void utils_waitforpower(){
u32 btn = btn_wait();
if (btn & BTN_VOL_UP)
@ -25,22 +37,36 @@ void utils_waitforpower(){
power_off();
}
int readfolder(char *items[], unsigned int *muhbits, const char path[]){
void _addchartoarray(char *add, char *items[], int spot){
size_t size = strlen(add) + 1;
items[spot] = (char*) malloc (size);
strlcpy(items[spot], add, size);
}
void _mallocandaddfolderbit(unsigned int *muhbits, int spot, bool value){
muhbits[spot] = (unsigned int) malloc (sizeof(int));
if (value) muhbits[spot] |= (OPTION1);
}
int readfolder(char *items[], unsigned int *muhbits, const char *path){
DIR dir;
FILINFO fno;
int i = 0;
int i = 2;
_addchartoarray(".", items, 0);
_addchartoarray("..", items, 1);
_mallocandaddfolderbit(muhbits, 0, true);
_mallocandaddfolderbit(muhbits, 1, true);
if (f_opendir(&dir, path)) {
gfx_printf("\nFailed to open %s", path);
}
else{
else {
while (!f_readdir(&dir, &fno) && fno.fname[0]){
size_t size = strlen(fno.fname) + 1;
items[i] = (char*) malloc (size);
strlcpy(items[i], fno.fname, size);
if (fno.fattrib & AM_DIR) muhbits[i] |= (OPTION1);
_addchartoarray(fno.fname, items, i);
_mallocandaddfolderbit(muhbits, i, fno.fattrib & AM_DIR);
i++;
}
}
f_closedir(&dir);
return i;
}

View file

@ -7,4 +7,6 @@
void utils_gfx_init();
void utils_waitforpower();
int readfolder(char *items[], unsigned int *muhbits, const char path[]);
void removepartpath(char *path);
void addpartpath(char *path, char *add);
int readfolder(char *items[], unsigned int *muhbits, const char *path);