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

Add errors

and prepare for file menu more
and fix that you can't go left right when going up down
This commit is contained in:
SuchMemeManySkill 2020-12-25 00:20:30 +01:00
parent b97bab3661
commit 1a931b0256
16 changed files with 167 additions and 30 deletions

53
source/err.c Normal file
View file

@ -0,0 +1,53 @@
#include "err.h"
#include "gfx/gfx.h"
#include "hid/hid.h"
#include "gfx/gfxutils.h"
const char *fatfsErrors[] = {
"I/O ERROR",
"NO DISK",
"NOT READY",
"NO FILE",
"NO PATH",
"PATH INVALID",
"ACCESS DENIED",
"ACCESS DENIED",
"INVALID PTR",
"PROTECTED",
"INVALID DRIVE",
"NO MEM",
"NO FAT",
"MKFS ABORT"
};
const char *TEErrors[] = {
"Unimplemented"
};
const char *GetErrStr(u32 err){
--err; // obv error codes cannot be 0
if (err >= 0 && err < ARRAY_SIZE(fatfsErrors))
return fatfsErrors[err];
if (err >= 20 && err < ARRAY_SIZE(TEErrors) + 20)
return TEErrors[err - 20];
return "(Unknown)";
}
#define lx 256
#define ly 240
#define lenx 768
#define leny 240
void DrawError(ErrCode_t err){
SETCOLOR(COLOR_ORANGE, COLOR_DARKGREY);
gfx_box(lx, ly, lx + lenx, ly + leny, COLOR_ORANGE);
gfx_boxGrey(lx + 16, ly + 16, lx + lenx - 16, ly + leny - 16, 0x33);
gfx_con_setpos(lx + ((lenx - 17 * 16) / 2), ly + 32);
gfx_printf("An error occured!\n\n%bErr : %d\nLine: %d\nFile: %s\nDesc: %s%b", lx + 48, err.err, err.loc, err.file, GetErrStr(err.err), 0);
gfx_con_setpos(lx + ((lenx - 19 * 16) / 2), ly + leny - 48);
gfx_printf("Press A to continue");
hidWaitMask((JoyA | JoyB));
}

15
source/err.h Normal file
View file

@ -0,0 +1,15 @@
#pragma once
#include <utils/types.h>
typedef struct {
u16 err;
u16 loc;
char* file;
} ErrCode_t;
enum {
TE_ERR_UNIMPLEMENTED = 21,
};
#define newErrCode(err) (ErrCode_t) {err, __LINE__, __FILE__}
void DrawError(ErrCode_t err);

25
source/fs/fstypes.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include <utils/types.h>
typedef struct {
char *name;
union {
struct {
u8 readOnly:1;
u8 hidden:1;
u8 system:1;
u8 volume:1;
u8 isDir:1;
u8 archive:1;
};
u8 optionUnion;
};
union {
struct {
u16 size:12;
u16 showSize:1;
u16 sizeDef:3;
};
u16 sizeUnion;
};
} FSEntry_t;

View file

@ -4,6 +4,7 @@
#include "../utils/utils.h"
#include <utils/sprintf.h>
#include <libs/fatfs/ff.h>
#include "readers/folderReader.h"
char *CombinePaths(const char *current, const char *add){
char *ret;
@ -35,4 +36,10 @@ u64 GetFileSize(char *path){
FILINFO fno;
f_stat(path, &fno);
return fno.fsize;
}
char *GetFileAttribs(FSEntry_t entry){
char *ret = CpyStr("RHSVDA");
MaskIn(ret, entry.optionUnion, '-');
return ret;
}

View file

@ -1,6 +1,8 @@
#pragma once
#include <utils/types.h>
#include "fstypes.h"
u64 GetFileSize(char *path);
char *EscapeFolder(char *current);
char *CombinePaths(const char *current, const char *add);
char *CombinePaths(const char *current, const char *add);
char *GetFileAttribs(FSEntry_t entry);

View file

@ -6,6 +6,7 @@
#include "../../gfx/gfx.h"
#include "../../gfx/gfxutils.h"
#include "../../utils/utils.h"
#include "filemenu.h"
#include <string.h>
#include <mem/heap.h>
@ -55,6 +56,10 @@ void FileExplorer(char *path){
gfx_con_setpos(144, 16);
gfx_boxGrey(0, 16, 160, 31, 0x1B);
if (res >= fileVec.count + ARR_LEN(topEntries))
res = 0;
res = newMenu(&entries, res, 60, 42, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count);
if (res < ARR_LEN(topEntries)) {
@ -66,14 +71,19 @@ void FileExplorer(char *path){
char *copy = CpyStr(storedPath);
storedPath = EscapeFolder(copy);
free(copy);
res = 0;
}
else if (fsEntries[res - ARR_LEN(topEntries)].isDir) {
char *copy = CpyStr(storedPath);
storedPath = CombinePaths(copy, fsEntries[res - ARR_LEN(topEntries)].name);
free(copy);
res = 0;
}
else {
FileMenu(fsEntries[res - ARR_LEN(topEntries)]);
}
res = 0;
clearFileVector(&fileVec);
}
}

View file

@ -0,0 +1,11 @@
#include "filemenu.h"
#include "../../err.h"
#include "../../gfx/menu.h"
MenuEntry_t FileMenuEntries[] = {
// Still have to think up the options
};
void FileMenu(FSEntry_t entry){
DrawError(newErrCode(TE_ERR_UNIMPLEMENTED));
}

View file

@ -0,0 +1,4 @@
#pragma once
#include "../fstypes.h"
void FileMenu(FSEntry_t entry);

View file

@ -14,7 +14,8 @@ Vector_t /* of type FSEntry_t */ ReadFolder(char *path){
}
while (!f_readdir(&dir, &fno) && fno.fname[0]) {
FSEntry_t newEntry = {.isDir = (fno.fattrib & AM_DIR) ? 1 : 0, .name = CpyStr(fno.fname)};
FSEntry_t newEntry = {.optionUnion = fno.fattrib, .name = CpyStr(fno.fname)};
if (!newEntry.isDir){
u64 total = fno.fsize;
u8 type = 0;
@ -33,5 +34,7 @@ Vector_t /* of type FSEntry_t */ ReadFolder(char *path){
vecAddElem(&out, newEntry);
}
f_closedir(&dir);
return out;
}

View file

@ -1,23 +1,6 @@
#pragma once
#include <utils/types.h>
#include "../../utils/vector.h"
typedef struct {
char *name;
union {
struct {
u8 isDir:1;
};
u8 optionUnion;
};
union {
struct {
u16 size:12;
u16 showSize:1;
u16 sizeDef:3;
};
u16 sizeUnion;
};
} FSEntry_t;
#include "../fstypes.h"
Vector_t /* of type FSEntry_t */ ReadFolder(char *path);

View file

@ -123,6 +123,8 @@ static const u8 _gfx_font[] = {
0x00, 0x0E, 0x12, 0x22, 0x22, 0x22, 0x3E, 0x00, // Char 128 (file)
};
u32 YLeftConfig = YLEFT;
void gfx_clear_grey(u8 color)
{
memset(gfx_ctxt.fb, color, gfx_ctxt.width * gfx_ctxt.height * 4);
@ -240,13 +242,13 @@ void gfx_putc(char c)
gfx_con.y -= 16;
if (gfx_con.y < 16){
gfx_con.y = YLEFT;
gfx_con.y = YLeftConfig;
gfx_con.x += 16;
}
}
else if (c == '\n')
{
gfx_con.y = YLEFT;
gfx_con.y = YLeftConfig;
gfx_con.x += 16;
if (gfx_con.x > gfx_ctxt.width - 16)
gfx_con.x = 0;
@ -256,7 +258,7 @@ void gfx_putc(char c)
else if (c == '\a')
gfx_con.y = 639;
else if (c == '\r')
gfx_con.y = YLEFT;
gfx_con.y = YLeftConfig;
break;
case 8:
@ -282,14 +284,14 @@ void gfx_putc(char c)
gfx_con.y -= 8;
if (gfx_con.y < 8){
gfx_con.y = YLEFT;
gfx_con.y = YLeftConfig;
gfx_con.x += 8;
}
}
else if (c == '\n')
{
gfx_con.y = YLEFT;
gfx_con.y = YLeftConfig;
gfx_con.x += 8;
if (gfx_con.x > gfx_ctxt.width - 8)
gfx_con.x = 0;
@ -299,7 +301,7 @@ void gfx_putc(char c)
else if (c == '\a')
gfx_con.y = 639;
else if (c == '\r')
gfx_con.y = YLEFT;
gfx_con.y = YLeftConfig;
break;
}
@ -449,6 +451,11 @@ void gfx_vprintf(const char *fmt, va_list ap)
gfx_con.bgcol = va_arg(ap, u32);
gfx_con.fillbg = 1;
break;
case 'b':;
u32 b = YLEFT - va_arg(ap, u32);
gfx_con.y = b;
YLeftConfig = gfx_con.y;
break;
case '%':
gfx_putc('%');
break;

View file

@ -4,6 +4,7 @@
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_DEFAULT 0xFF1B1B1B
#define COLOR_GREY 0xFF888888
#define COLOR_DARKGREY 0xFF333333
#define COLORTORGB(color) (color & 0x00FFFFFF)
#define SETCOLOR(fg, bg) gfx_con_setcol(fg, 1, bg)

View file

@ -129,7 +129,7 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 op
else if (input->b && options & ENABLEB)
return 0;
else if (input->down || input->rDown || input->right){ //Rdown should probs not trigger a page change. Same for RUp
u32 temp = (input->right) ? screenLenY : 1;
u32 temp = (input->right && !(input->down || input->rDown)) ? screenLenY : 1;
if (vec->count > selected + temp){
selected += temp;
@ -141,7 +141,7 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 op
}
}
else if (input->up || input->rUp || input->left){
u32 temp = (input->left) ? screenLenY : 1;
u32 temp = (input->left && !(input->up || input->rUp)) ? screenLenY : 1;
if (selected >= temp){
selected -= temp;
break;

View file

@ -47,6 +47,7 @@
#include "gfx/gfxutils.h"
#include "tegraexplorer/mainmenu.h"
#include "tegraexplorer/tconf.h"
#include "err.h"
hekate_config h_cfg;
@ -209,6 +210,7 @@ void ipl_main()
//u32 res = newMenu(&a, 0, 40, 5, testAdd, NULL);
//gfx_clearscreen();
//DrawError(newErrCode(1));
EnterMainMenu();

View file

@ -1,5 +1,6 @@
#include "utils.h"
#include <string.h>
#include <utils/types.h>
#include <mem/heap.h>
char *CpyStr(const char* in){
@ -8,4 +9,15 @@ char *CpyStr(const char* in){
out[len] = 0;
memcpy(out, in, len);
return out;
}
void MaskIn(char *mod, u32 bitstream, char mask){
u32 len = strlen(mod);
for (int i = 0; i < len; i++){
if (bitstream & 1)
*mod = mask;
bitstream >>= 1;
mod++;
}
}

View file

@ -1,3 +1,5 @@
#pragma once
#include <utils/types.h>
char *CpyStr(const char* in);
char *CpyStr(const char* in);
void MaskIn(char *mod, u32 bitstream, char mask);