Add fw dumping

- also fatfs is stupid
- also close files properly on a failed copy
- also check for errors during folder readouts
- also make sure holding vol- doesn't dump the keys anyway
This commit is contained in:
suchmememanyskill
2020-12-28 02:29:58 +01:00
parent 859ad2cc4c
commit 513bd804b1
18 changed files with 222 additions and 29 deletions

View File

@@ -13,6 +13,7 @@ ErrCode_t FileCopy(const char *locin, const char *locout, u8 options){
u64 sizeRemaining, toCopy;
u8 *buff;
u32 x, y;
ErrCode_t err = newErrCode(0);
int res = 0;
gfx_con_getpos(&x, &y);
@@ -47,11 +48,13 @@ ErrCode_t FileCopy(const char *locin, const char *locout, u8 options){
toCopy = MIN(sizeRemaining, TConf.FSBuffSize);
if ((res = f_read(&in, buff, toCopy, NULL))){
return newErrCode(res);
err = newErrCode(res);
break;
}
if ((res = f_write(&out, buff, toCopy, NULL))){
return newErrCode(res);
err = newErrCode(res);
break;
}
sizeRemaining -= toCopy;
@@ -74,5 +77,5 @@ ErrCode_t FileCopy(const char *locin, const char *locout, u8 options){
f_chmod(locout, in_info.fattrib, 0x3A);
//f_stat(locin, &in_info); //somehow stops fatfs from being weird
return newErrCode(0);
return err;
}

View File

@@ -42,4 +42,13 @@ char *GetFileAttribs(FSEntry_t entry){
char *ret = CpyStr("RHSVDA");
MaskIn(ret, entry.optionUnion, '-');
return ret;
}
}
bool FileExists(char* path){
FRESULT fr;
FILINFO fno;
fr = f_stat(path, &fno);
return !(fr & FR_NO_FILE);
}

View File

@@ -5,4 +5,5 @@
u64 GetFileSize(char *path);
char *EscapeFolder(const char *current);
char *CombinePaths(const char *current, const char *add);
char *GetFileAttribs(FSEntry_t entry);
char *GetFileAttribs(FSEntry_t entry);
bool FileExists(char* path);

View File

@@ -30,13 +30,7 @@ MenuEntry_t MakeMenuOutFSEntry(FSEntry_t entry){
return out;
}
void clearFileVector(Vector_t *v){
vecPDefArray(FSEntry_t*, entries, v);
for (int i = 0; i < v->count; i++)
free(entries[i].name);
free(v->data);
}
void FileExplorer(char *path){
char *storedPath = CpyStr(path);
@@ -48,8 +42,15 @@ void FileExplorer(char *path){
gfx_clearscreen();
gfx_printf("Loading...\r");
//gfx_printf(" ");
Vector_t fileVec = ReadFolder(storedPath);
int readRes = 0;
Vector_t fileVec = ReadFolder(storedPath, &readRes);
if (readRes){
clearFileVector(&fileVec);
DrawError(newErrCode(readRes));
return;
}
vecDefArray(FSEntry_t*, fsEntries, fileVec);
topEntries[0].name = storedPath;

View File

@@ -10,6 +10,7 @@
#include "../../hid/hid.h"
#include <libs/fatfs/ff.h>
#include "../../utils/utils.h"
#include "../../keys/nca.h"
MenuEntry_t FileMenuEntries[] = {
// Still have to think up the options
@@ -50,17 +51,12 @@ void MoveClipboard(char *path, FSEntry_t entry){
free(thing);
}
MenuEntry_t DeleteEntries[] = {
{.optionUnion = COLORTORGB(COLOR_YELLOW), .name = "No"},
{.R = 255, .name = "Yes"}
};
void DeleteFile(char *path, FSEntry_t entry){
gfx_con_setpos(384 + 16, 200 + 16 + 10 * 16);
SETCOLOR(COLOR_RED, COLOR_DARKGREY);
gfx_printf("Are you sure? ");
if (!MakeHorizontalMenu(DeleteEntries, 2, 3, COLOR_DARKGREY))
if (!MakeYesNoHorzMenu(3, COLOR_DARKGREY))
return;
char *thing = CombinePaths(path, entry.name);

View File

@@ -1,19 +1,27 @@
#include "folderReader.h"
#include <libs/fatfs/ff.h>
#include "../../utils/utils.h"
#include <mem/heap.h>
Vector_t /* of type FSEntry_t */ ReadFolder(char *path){
void clearFileVector(Vector_t *v){
vecPDefArray(FSEntry_t*, entries, v);
for (int i = 0; i < v->count; i++)
free(entries[i].name);
free(v->data);
}
Vector_t /* of type FSEntry_t */ ReadFolder(char *path, int *res){
Vector_t out = newVec(sizeof(FSEntry_t), 16); // we may want to prealloc with the same size as the folder
DIR dir;
FILINFO fno;
int res;
if ((res = f_opendir(&dir, path))){
if ((*res = f_opendir(&dir, path))){
// Err!
return out;
}
while (!f_readdir(&dir, &fno) && fno.fname[0]) {
while (!(*res = f_readdir(&dir, &fno)) && fno.fname[0]) {
FSEntry_t newEntry = {.optionUnion = fno.fattrib, .name = CpyStr(fno.fname)};
if (!newEntry.isDir){

View File

@@ -3,4 +3,5 @@
#include "../../utils/vector.h"
#include "../fstypes.h"
Vector_t /* of type FSEntry_t */ ReadFolder(char *path);
void clearFileVector(Vector_t *v);
Vector_t /* of type FSEntry_t */ ReadFolder(char *path, int *res);