Compare commits

...

5 Commits

Author SHA1 Message Date
Such Meme, Many Skill
b91c36d3fa Fastfs testing 2020-05-19 17:54:21 +02:00
Such Meme, Many Skill
a8e86c2de3 Don't forget to take results 2020-05-17 23:42:53 +02:00
Such Meme, Many Skill
6934e1422f Various improvements to scripting lang
- Errors will now be more precise, there are now 2 separate errors for a function lookup failure and a failure inside a function
- Errors will now show which line number they failed at, instead of the character offset
- Minus values are not considered errors anymore, however, printing them does not work well
- Gotos now make a @RETURN variable to make making functions easier
2020-05-15 20:17:31 +02:00
Such Meme, Many Skill
f49245e4ab Fix hidden copies messing with screen positions 2020-05-15 16:20:52 +02:00
Such Meme, Many Skill
9075f20854 Clean up bisfile extraction 2020-05-15 16:07:23 +02:00
13 changed files with 376 additions and 138 deletions

View File

@@ -42,8 +42,8 @@
#include "../../storage/sdmmc.h"
extern sdmmc_storage_t sd_storage;
#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
//#define EFSPRINTF(...)
//#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
#define EFSPRINTF(...)
/*--------------------------------------------------------------------------
@@ -4056,7 +4056,216 @@ FRESULT f_write (
LEAVE_FF(fs, FR_OK);
}
#ifdef FF_FASTFS
/*-----------------------------------------------------------------------*/
/* Fast Read Aligned Sized File Without a Cache */
/*-----------------------------------------------------------------------*/
#if FF_USE_FASTSEEK
FRESULT f_read_fast (
FIL* fp, /* Pointer to the file object */
const void* buff, /* Pointer to the data to be written */
UINT btr /* Number of bytes to read */
)
{
if (btr % 65536 != 0)
return f_read(fp, buff, btr, NULL);
FRESULT res;
FATFS *fs;
UINT csize_bytes;
DWORD clst;
UINT count = 0;
FSIZE_t work_sector = 0;
FSIZE_t sector_base = 0;
BYTE *wbuff = (BYTE*)buff;
// TODO support sector reading inside a cluster
res = validate(&fp->obj, &fs); /* Check validity of the file object */
if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) {
EFSPRINTF("FOV");
LEAVE_FF(fs, res); /* Check validity */
}
if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
FSIZE_t remain = fp->obj.objsize - fp->fptr;
if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */
csize_bytes = fs->csize * SS(fs);
if (!fp->fptr) { /* On the top of the file? */
clst = fp->obj.sclust; /* Follow from the origin */
} else {
if (fp->cltbl) clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
else { EFSPRINTF("CLTBL"); ABORT(fs, FR_CLTBL_NO_INIT); }
}
if (clst < 2) { EFSPRINTF("CCHK"); ABORT(fs, FR_INT_ERR); }
else if (clst == 0xFFFFFFFF) { EFSPRINTF("DSKC"); ABORT(fs, FR_DISK_ERR); }
fp->clust = clst; /* Set working cluster */
sector_base = clst2sect(fs, fp->clust);
count += fs->csize;
btr -= csize_bytes;
fp->fptr += csize_bytes;
while (btr) {
clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
if (clst < 2) { EFSPRINTF("CCHK2"); ABORT(fs, FR_INT_ERR); }
else if (clst == 0xFFFFFFFF) { EFSPRINTF("DSKC"); ABORT(fs, FR_DISK_ERR); }
fp->clust = clst;
work_sector = clst2sect(fs, fp->clust);
if ((work_sector - sector_base) == count) count += fs->csize;
else {
if (disk_read(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR);
wbuff += count * SS(fs);
sector_base = work_sector;
count = fs->csize;
}
fp->fptr += MIN(btr, csize_bytes);
btr -= MIN(btr, csize_bytes);
// TODO: what about if data is smaller than cluster?
// Must read-write back that cluster.
if (!btr) { /* Final cluster/sectors read. */
if (disk_read(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR);
}
}
LEAVE_FF(fs, FR_OK);
}
#endif
#endif
#ifdef FF_FASTFS
/*-----------------------------------------------------------------------*/
/* Fast Write Aligned Sized File Without a Cache */
/*-----------------------------------------------------------------------*/
#if FF_USE_FASTSEEK
FRESULT f_write_fast (
FIL* fp, /* Pointer to the file object */
const void* buff, /* Pointer to the data to be written */
UINT btw /* Number of bytes to write */
)
{
if (btw % 65536 != 0)
return f_write(fp, buff, btw, NULL);
FRESULT res;
FATFS *fs;
UINT csize_bytes;
DWORD clst;
UINT count = 0;
FSIZE_t work_sector = 0;
FSIZE_t sector_base = 0;
const BYTE *wbuff = (const BYTE*)buff;
// TODO support sector writing inside a cluster
res = validate(&fp->obj, &fs); /* Check validity of the file object */
if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) {
EFSPRINTF("FOV");
LEAVE_FF(fs, res); /* Check validity */
}
if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
/* Check fptr wrap-around (file size cannot reach 4 GiB at FAT volume) */
if ((!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) && (DWORD)(fp->fptr + btw) < (DWORD)fp->fptr) {
btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr);
}
csize_bytes = fs->csize * SS(fs);
if (!fp->fptr) { /* On the top of the file? */
clst = fp->obj.sclust; /* Follow from the origin */
} else {
if (fp->cltbl) clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
else { EFSPRINTF("CLTBL"); ABORT(fs, FR_CLTBL_NO_INIT); }
}
if (clst < 2) { EFSPRINTF("CCHK"); ABORT(fs, FR_INT_ERR); }
else if (clst == 0xFFFFFFFF) { EFSPRINTF("DERR"); ABORT(fs, FR_DISK_ERR); }
fp->clust = clst; /* Set working cluster */
sector_base = clst2sect(fs, fp->clust);
count += fs->csize;
btw -= csize_bytes;
fp->fptr += csize_bytes;
while (btw) {
clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
if (clst < 2) { EFSPRINTF("CCHK2"); ABORT(fs, FR_INT_ERR); }
else if (clst == 0xFFFFFFFF) { EFSPRINTF("DERR"); ABORT(fs, FR_DISK_ERR); }
fp->clust = clst;
work_sector = clst2sect(fs, fp->clust);
if ((work_sector - sector_base) == count) count += fs->csize;
else {
if (disk_write(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR);
wbuff += count * SS(fs);
sector_base = work_sector;
count = fs->csize;
}
fp->fptr += MIN(btw, csize_bytes);
btw -= MIN(btw, csize_bytes);
// what about if data is smaller than cluster?
// Probably must read-write back that cluster.
if (!btw) { /* Final cluster/sectors write. */
if (disk_write(fs->pdrv, wbuff, sector_base, count) != RES_OK) ABORT(fs, FR_DISK_ERR);
fp->flag &= (BYTE)~FA_DIRTY;
}
}
fp->flag |= FA_MODIFIED; /* Set file change flag */
LEAVE_FF(fs, FR_OK);
}
#endif
#endif
#ifdef FF_FASTFS
#if FF_USE_FASTSEEK
/*-----------------------------------------------------------------------*/
/* Seek File Read/Write Pointer */
/*-----------------------------------------------------------------------*/
DWORD *f_expand_cltbl (
FIL* fp, /* Pointer to the file object */
UINT tblsz, /* Size of table */
FSIZE_t ofs /* File pointer from top of file */
)
{
if (fp->flag & FA_WRITE) f_lseek(fp, ofs); /* Expand file if write is enabled */
if (!fp->cltbl) { /* Allocate memory for cluster link table */
fp->cltbl = (DWORD *)ff_memalloc(tblsz);
fp->cltbl[0] = tblsz;
}
if (f_lseek(fp, CREATE_LINKMAP)) { /* Create cluster link table */
ff_memfree(fp->cltbl);
fp->cltbl = NULL;
EFSPRINTF("CLTBLSZ");
return NULL;
}
f_lseek(fp, 0);
return fp->cltbl;
}
#endif
#endif
/*-----------------------------------------------------------------------*/
@@ -4169,6 +4378,13 @@ FRESULT f_close (
#endif
}
}
if (fp->cltbl != NULL){
ff_memfree(fp->cltbl);
fp->cltbl = NULL;
}
return res;
}

View File

@@ -246,7 +246,10 @@ typedef enum {
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
FR_INVALID_PARAMETER, /* (19) Given parameter is invalid */
#ifdef FF_FASTFS
FR_CLTBL_NO_INIT /* (20) The cluster table for fast seek/read/write was not created */
#endif
} FRESULT;
@@ -288,6 +291,11 @@ int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
#ifdef FF_FASTFS
FRESULT f_read_fast (FIL* fp, const void* buff, UINT btr); /* Fast read data from the file */
FRESULT f_write_fast (FIL* fp, const void* buff, UINT btw); /* Fast write data to the file */
DWORD *f_expand_cltbl (FIL* fp, UINT tblsz, FSIZE_t ofs); /* Expand file and populate cluster table */
#endif
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err)

View File

@@ -42,7 +42,13 @@
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
#define FF_FASTFS 1
#ifdef FF_FASTFS
#define FF_USE_FASTSEEK 1
#else
#define FF_USE_FASTSEEK 0
#endif
/* This option switches fast seek function. (0:Disable or 1:Enable) */
@@ -287,3 +293,5 @@
/*--- End of configuration options ---*/

View File

@@ -21,10 +21,11 @@ enum utils_err_codes_te_call {
ERR_EMMC_WRITE_FAILED,
ERR_FILE_TOO_BIG_FOR_DEST,
ERR_SD_EJECTED,
ERR_PARSE_FAIL,
ERR_SCRIPT_LOOKUP_FAIL,
ERR_CANNOT_COPY_FILE_TO_FS_PART,
ERR_NO_DESTINATION,
ERR_INI_PARSE_FAIL
ERR_INI_PARSE_FAIL,
ERR_IN_FUNC
};
extern const char *utils_err_codes_te[];

View File

@@ -50,10 +50,11 @@ const char *utils_err_codes_te[] = { // these start at 50
"EMMC WRITE FAILED",
"FILE TOO BIG FOR DEST",
"SD EJECTED",
"PARSING FAILED",
"FUNC LOOKUP FAIL",
"CANNOT COPY FILE TO FS PART",
"NO DESTINATION",
"INI PARSE FAIL"
"INI PARSE FAIL",
"ERR IN FUNC"
};
/*
const char *pkg2names[] = {

View File

@@ -191,7 +191,6 @@ int filemenu(menu_entry file){
break;
}
fsreader_readfolder(currentpath);
break;
case FILE_PAYLOAD:
launch_payload(fsutil_getnextloc(currentpath, file.name));
@@ -205,7 +204,6 @@ int filemenu(menu_entry file){
*/
runScript(fsutil_getnextloc(currentpath, file.name));
fsreader_readfolder(currentpath);
break;
case FILE_HEXVIEW:
viewbytes(fsutil_getnextloc(currentpath, file.name));
@@ -213,7 +211,6 @@ int filemenu(menu_entry file){
case FILE_DUMPBIS:
gfx_clearscreen();
extract_bis_file(fsutil_getnextloc(currentpath, file.name), currentpath);
fsreader_readfolder(currentpath);
hidWait();
break;
case FILE_SIGN:
@@ -231,5 +228,6 @@ int filemenu(menu_entry file){
return -1;
}
fsreader_readfolder(currentpath);
return 0;
}

View File

@@ -15,9 +15,8 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
FIL in, out;
FILINFO in_info;
u64 sizeRemaining, toCopy;
UINT temp1, temp2;
u8 *buff, toPrint = options & COPY_MODE_PRINT, toCancel = options & COPY_MODE_CANCEL;
u32 x, y, i = 11;
u32 x, y, i = 11, toSpeed;
int res;
gfx_con_getpos(&x, &y);
@@ -32,12 +31,12 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
return 1;
}
if (f_stat(locin, &in_info)){
if ((res = f_stat(locin, &in_info))){
gfx_errDisplay("copy", res, 3);
return 1;
}
if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){
if ((res = f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE))){
gfx_errDisplay("copy", res, 4);
return 1;
}
@@ -53,22 +52,20 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
sizeRemaining = f_size(&in);
const u64 totalsize = sizeRemaining;
DWORD *clmt_in = f_expand_cltbl(&in, BUFSIZE / 4, 0);
DWORD *clmt_out = f_expand_cltbl(&out, BUFSIZE / 4, totalsize);
while (sizeRemaining > 0){
toCopy = MIN(sizeRemaining, BUFSIZE);
if ((res = f_read(&in, buff, toCopy, &temp1))){
if ((res = f_read_fast(&in, buff, toCopy))){
gfx_errDisplay("copy", res, 5);
return 1;
break;
}
if ((res = f_write(&out, buff, toCopy, &temp2))){
if ((res = f_write_fast(&out, buff, toCopy))){
gfx_errDisplay("copy", res, 6);
return 1;
}
if (temp1 != temp2){
gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7);
return 1;
break;
}
sizeRemaining -= toCopy;
@@ -91,20 +88,19 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
}
}
RESETCOLOR;
gfx_con_setpos(x - 16, y);
if (toPrint){
RESETCOLOR;
gfx_con_setpos(x - 16, y);
}
f_close(&in);
f_close(&out);
free(buff);
if ((res = f_chmod(locout, in_info.fattrib, 0x3A))){
gfx_errDisplay("copy", res, 8);
return 1;
}
f_chmod(locout, in_info.fattrib, 0x3A);
f_stat(locin, &in_info); //somehow stops fatfs from being weird
return 0;
return res;
}
int fsact_del_recursive(char *path){

View File

@@ -13,25 +13,15 @@
#include "../utils/utils.h"
#include "fsactions.h"
u32 DecodeInt(u8* data) {
u32 out = 0;
for (int i = 0; i < 4; i++) {
out |= (data[i] << ((3 - i) * 8));
}
return out;
}
void copy_fil_size(FIL* in_src, FIL* out_src, int size_src){
u8* buff;
buff = calloc(16384, sizeof(u8));
buff = calloc(BUFSIZE, sizeof(u8));
int size = size_src;
int copysize;
while (size > 0){
copysize = MIN(16834, size);
copysize = MIN(BUFSIZE, size);
f_read(in_src, buff, copysize, NULL);
f_write(out_src, buff, copysize, NULL);
size -= copysize;
@@ -48,56 +38,50 @@ void gen_part(int size, FIL* in, char *path){
f_close(&out);
}
const char *filenames[] = {
"BOOT0.bin",
"BOOT1.bin",
"BCPKG2-1-Normal-Main",
"BCPKG2-3-SafeMode-Main",
"BCPKG2-2-Normal-Sub",
"BCPKG2-4-SafeMode-Sub"
};
int extract_bis_file(char *path, char *outfolder){
FIL in;
int res;
u8 version[0x10];
u8 args;
u8 temp[0x4];
u32 filesizes[4];
char *tempPath;
BisFile header;
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
gfx_errDisplay("extract_bis_file", res, 0);
return -1;
}
f_read(&in, version, 0x10, NULL);
f_read(&in, &args, 1, NULL);
f_read(&in, &header, sizeof(BisFile), NULL);
for (int i = 0; i < 4; i++)
header.sizes[i] = FLIPU32(header.sizes[i]);
gfx_printf("Version: %s\n\n", header.version);
// Loop to actually extract stuff
for (int i = 0; i < 4; i++){
f_read(&in, temp, 4, NULL);
filesizes[i] = DecodeInt(temp);
if (!(header.args & (BIT((7 - i)))))
continue;
gfx_printf("Extracting %s\n", filenames[i]);
gen_part(header.sizes[i], &in, fsutil_getnextloc(outfolder, filenames[i]));
}
gfx_printf("Version: %s\n\n", version);
// Loop to copy pkg2_1->2 and pkg2_3->4
for (int i = 4; i < 6; i++){
if (!(header.args & BIT((9 - i))))
continue;
if (args & BOOT0_ARG){
gfx_printf("\nExtracting BOOT0\n");
gen_part(filesizes[0], &in, fsutil_getnextloc(outfolder, "BOOT0.bin"));
}
if (args & BOOT1_ARG){
gfx_printf("Extracting BOOT1\n");
gen_part(filesizes[1], &in, fsutil_getnextloc(outfolder, "BOOT1.bin"));
}
if (args & BCPKG2_1_ARG){
utils_copystring(fsutil_getnextloc(outfolder, "BCPKG2-1-Normal-Main"), &tempPath);
gfx_printf("Extracting BCPKG2_1/2\n");
gen_part(filesizes[2], &in, tempPath);
fsact_copy(tempPath, fsutil_getnextloc(outfolder, "BCPKG2-2-Normal-Sub"), COPY_MODE_PRINT);
RESETCOLOR;
free(tempPath);
}
if (args & BCPKG2_3_ARG){
utils_copystring(fsutil_getnextloc(outfolder, "BCPKG2-3-SafeMode-Main"), &tempPath);
gfx_printf("Extracting BCPKG2_3/4\n");
gen_part(filesizes[3], &in, tempPath);
fsact_copy(tempPath, fsutil_getnextloc(outfolder, "BCPKG2-4-SafeMode-Sub"), COPY_MODE_PRINT);
utils_copystring(fsutil_getnextloc(outfolder, filenames[i - 2]), &tempPath);
gfx_printf("Copying %s\n", filenames[i]);
fsact_copy(tempPath, fsutil_getnextloc(outfolder, filenames[i]), COPY_MODE_PRINT);
RESETCOLOR;
free(tempPath);
}

View File

@@ -2,6 +2,14 @@
#include "../common/types.h"
#include "../../utils/types.h"
typedef struct {
u8 version[0x10];
u8 args;
u32 sizes[4];
} __attribute__((__packed__)) BisFile;
#define FLIPU32(in) ((in >> 24) & 0xFF) | ((in >> 8) & 0xFF00) | ((in << 8) & 0xFF0000) | ((in << 24) & 0xFF000000)
char *fsutil_getnextloc(const char *current, const char *add);
char *fsutil_getprevloc(char *current);
bool fsutil_checkfile(char* path);

View File

@@ -52,7 +52,7 @@ u32 gfx_errDisplay(const char *src_func, int err, int loc){
if (err < 15)
gfx_printf("Desc: %s\n", utils_err_codes[err]);
else if (err >= ERR_SAME_LOC && err <= ERR_INI_PARSE_FAIL)
else if (err >= ERR_SAME_LOC && err <= ERR_IN_FUNC)
gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]);
if (loc)

View File

@@ -74,14 +74,14 @@ int part_printf(){
if (argv[i][0] == '@'){
int toprintint;
if (parseIntInput(argv[i], &toprintint))
return -1;
return INFUNC_FAIL;
gfx_printf("%d", toprintint);
}
else {
char *toprintstring;
if (parseStringInput(argv[i], &toprintstring))
return -1;
return INFUNC_FAIL;
gfx_printf(toprintstring);
}
@@ -94,7 +94,7 @@ int part_printf(){
int part_print_int(){
int toprint;
if (parseIntInput(argv[0], &toprint))
return -1;
return INFUNC_FAIL;
SWAPCOLOR(currentcolor);
gfx_printf("%s: %d\n", argv[0], toprint);
@@ -107,7 +107,7 @@ int part_Wait(){
SWAPCOLOR(currentcolor);
if (parseIntInput(argv[0], &arg))
return -1;
return INFUNC_FAIL;
begintime = get_tmr_s();
@@ -122,9 +122,9 @@ int part_Wait(){
int part_Check(){
int left, right;
if (parseIntInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseIntInput(argv[2], &right))
return -1;
return INFUNC_FAIL;
if (!strcmp(argv[1], "=="))
return (left == right);
@@ -139,13 +139,13 @@ int part_Check(){
else if (!strcmp(argv[1], "<"))
return (left < right);
else
return -1;
return INFUNC_FAIL;
}
int part_if(){
int condition;
if (parseIntInput(argv[0], &condition))
return -1;
return INFUNC_FAIL;
getfollowingchar('{');
@@ -167,7 +167,7 @@ int part_if(){
int part_if_args(){
int condition;
if ((condition = part_Check()) < 0)
return -1;
return INFUNC_FAIL;
getfollowingchar('{');
@@ -180,9 +180,9 @@ int part_if_args(){
int part_Math(){
int left, right;
if (parseIntInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseIntInput(argv[2], &right))
return -1;
return INFUNC_FAIL;
switch (argv[1][0]){
case '+':
@@ -194,7 +194,7 @@ int part_Math(){
case '/':
return left / right;
}
return -1;
return INFUNC_FAIL;
}
int part_SetInt(){
@@ -206,9 +206,9 @@ int part_SetInt(){
int part_SetString(){
char *arg0;
if (parseStringInput(argv[0], &arg0))
return -1;
return INFUNC_FAIL;
if (argv[1][0] != '$')
return -1;
return INFUNC_FAIL;
str_str_add(argv[1], arg0);
return 0;
@@ -218,11 +218,11 @@ int part_SetStringIndex(){
int index;
char *out;
if (parseIntInput(argv[0], &index))
return -1;
return INFUNC_FAIL;
if (argv[1][0] != '$')
return -1;
return INFUNC_FAIL;
if (str_str_index(index, &out))
return -1;
return INFUNC_FAIL;
str_str_add(argv[1], out);
return 0;
@@ -231,7 +231,10 @@ int part_SetStringIndex(){
int part_goto(){
int target = 0;
if (parseIntInput(argv[0], &target))
return -1;
return INFUNC_FAIL;
str_int_add("@RETURN", (int)f_tell(&scriptin));
f_lseek(&scriptin, target);
return 0;
}
@@ -239,14 +242,14 @@ int part_goto(){
int part_invert(){
int arg;
if (parseIntInput(argv[0], &arg))
return -1;
return INFUNC_FAIL;
return (arg) ? 0 : 1;
}
int part_fs_exists(){
char *path;
if (parseStringInput(argv[0], &path))
return -1;
return INFUNC_FAIL;
return fsutil_checkfile(path);
}
@@ -260,7 +263,7 @@ int part_ConnectMMC(){
else if (!strcmp(arg, "EMUMMC"))
connect_mmc(EMUMMC);
else
return -1;
return INFUNC_FAIL;
return 0;
}
@@ -292,11 +295,11 @@ int part_Pause(){
int part_addstrings(){
char *combined, *left, *middle;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &middle))
return -1;
return INFUNC_FAIL;
if (argv[2][0] != '$')
return -1;
return INFUNC_FAIL;
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
sprintf(combined, "%s%s", left, middle);
@@ -309,7 +312,7 @@ int part_addstrings(){
int part_setColor(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
return INFUNC_FAIL;
if (!strcmp(arg, "RED"))
currentcolor = COLOR_RED;
@@ -326,7 +329,7 @@ int part_setColor(){
else if (!strcmp(arg, "WHITE"))
currentcolor = COLOR_WHITE;
else
return -1;
return INFUNC_FAIL;
return 0;
}
@@ -340,9 +343,9 @@ int part_fs_Move(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &right))
return -1;
return INFUNC_FAIL;
int res;
res = f_rename(left, right);
@@ -356,7 +359,7 @@ int part_fs_Delete(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
return INFUNC_FAIL;
int res;
res = f_unlink(arg);
@@ -370,7 +373,7 @@ int part_fs_DeleteRecursive(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
return INFUNC_FAIL;
return fsact_del_recursive(arg);
}
@@ -379,9 +382,9 @@ int part_fs_Copy(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &right))
return -1;
return INFUNC_FAIL;
return fsact_copy(left, right, COPY_MODE_PRINT);
}
@@ -390,9 +393,9 @@ int part_fs_CopyRecursive(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &right))
return -1;
return INFUNC_FAIL;
return fsact_copy_recursive(left, right);
}
@@ -401,7 +404,7 @@ int part_fs_MakeDir(){
char *arg;
if (parseStringInput(argv[0], &arg))
return -1;
return INFUNC_FAIL;
int res;
res = f_mkdir(arg);
@@ -418,10 +421,10 @@ int part_fs_OpenDir(){
char *path;
if (parseStringInput(argv[0], &path))
return -1;
return INFUNC_FAIL;
if (f_opendir(&dir, path))
return -1;
return INFUNC_FAIL;
isdirvalid = true;
str_int_add("@ISDIRVALID", isdirvalid);
@@ -440,7 +443,7 @@ int part_fs_CloseDir(){
int part_fs_ReadDir(){
if (!isdirvalid)
return -1;
return INFUNC_FAIL;
if (!f_readdir(&dir, &fno) && fno.fname[0]){
str_str_add("$FILENAME", fno.fname);
@@ -457,16 +460,16 @@ int part_setPrintPos(){
int left, right;
if (parseIntInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseIntInput(argv[1], &right))
return -1;
return INFUNC_FAIL;
if (left > 78)
return -1;
return INFUNC_FAIL;
if (right > 42)
return -1;
return INFUNC_FAIL;
gfx_con_setpos(left * 16, right * 16);
return 0;
@@ -476,9 +479,9 @@ int part_stringcompare(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &right))
return -1;
return INFUNC_FAIL;
return (strcmp(left, right)) ? 0 : 1;
}
@@ -486,11 +489,11 @@ int part_stringcompare(){
int part_fs_combinePath(){
char *combined, *left, *middle;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &middle))
return -1;
return INFUNC_FAIL;
if (argv[2][0] != '$')
return -1;
return INFUNC_FAIL;
combined = fsutil_getnextloc(left, middle);
@@ -503,9 +506,9 @@ int part_mmc_dumpPart(){
char *left, *right;
if (parseStringInput(argv[0], &left))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &right))
return -1;
return INFUNC_FAIL;
if (!strcmp(left, "BOOT")){
return emmcDumpBoot(right);
@@ -519,10 +522,10 @@ int part_mmc_restorePart(){
char *path;
if (parseStringInput(argv[0], &path))
return -1;
return INFUNC_FAIL;
if (currentlyMounted < 0)
return -1;
return INFUNC_FAIL;
return mmcFlashFile(path, currentlyMounted, false);
}
@@ -531,9 +534,9 @@ int part_fs_extractBisFile(){
char *path, *outfolder;
if (parseStringInput(argv[0], &path))
return -1;
return INFUNC_FAIL;
if (parseStringInput(argv[1], &outfolder))
return -1;
return INFUNC_FAIL;
return extract_bis_file(path, outfolder);
}
@@ -547,6 +550,8 @@ int part_getPos(){
return (int)f_tell(&scriptin);
}
str_fnc_struct functions[] = {
{"printf", part_printf, 255},
{"printInt", part_print_int, 1},
@@ -596,8 +601,8 @@ int run_function(char *func_name, int *out){
continue;
*out = functions[i].value();
return (*out < 0) ? -1 : 0;
return (*out == INFUNC_FAIL) ? -1 : 0;
}
}
return -1;
return -2;
}

View File

@@ -220,7 +220,16 @@ void mainparser(){
printerrors = true;
//gfx_printf("%s|%s|%d", funcbuff, argv[0], argc);
//btn_wait();
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin));
int lineNumber = 1;
u64 end = f_tell(&scriptin);
f_lseek(&scriptin, 0);
while (f_tell(&scriptin) < end && !f_eof(&scriptin)){
if (getnextchar() == '\n')
lineNumber++;
}
gfx_errDisplay((res == -1) ? funcbuff : "run_function", (res == -1) ? ERR_IN_FUNC : ERR_SCRIPT_LOOKUP_FAIL, lineNumber);
forceExit = true;
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
}
@@ -277,7 +286,9 @@ void runScript(char *path){
gfx_clearscreen();
utils_copystring(path, &path_local);
res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING);
DWORD *clmt_in = f_expand_cltbl(&scriptin, BUFSIZE / 4, 0);
if (res != FR_OK){
gfx_errDisplay("ParseScript", res, 1);
return;

View File

@@ -1,5 +1,7 @@
#pragma once
#define INFUNC_FAIL (int)0xC0000000
void runScript(char *path);
void skipbrackets();
void getfollowingchar(char end);