Compare commits
5 Commits
2.0.2
...
Fastfs_Tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b91c36d3fa | ||
|
|
a8e86c2de3 | ||
|
|
6934e1422f | ||
|
|
f49245e4ab | ||
|
|
9075f20854 |
@@ -42,8 +42,8 @@
|
|||||||
#include "../../storage/sdmmc.h"
|
#include "../../storage/sdmmc.h"
|
||||||
extern sdmmc_storage_t sd_storage;
|
extern sdmmc_storage_t sd_storage;
|
||||||
|
|
||||||
#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
|
//#define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
|
||||||
//#define EFSPRINTF(...)
|
#define EFSPRINTF(...)
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -4056,7 +4056,216 @@ FRESULT f_write (
|
|||||||
LEAVE_FF(fs, FR_OK);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fp->cltbl != NULL){
|
||||||
|
ff_memfree(fp->cltbl);
|
||||||
|
fp->cltbl = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -246,7 +246,10 @@ typedef enum {
|
|||||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
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_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_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;
|
} 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_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 */
|
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 */
|
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_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||||
#define f_error(fp) ((fp)->err)
|
#define f_error(fp) ((fp)->err)
|
||||||
|
|||||||
@@ -42,7 +42,13 @@
|
|||||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
/* 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
|
#define FF_USE_FASTSEEK 0
|
||||||
|
#endif
|
||||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||||
|
|
||||||
|
|
||||||
@@ -287,3 +293,5 @@
|
|||||||
|
|
||||||
|
|
||||||
/*--- End of configuration options ---*/
|
/*--- End of configuration options ---*/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ enum utils_err_codes_te_call {
|
|||||||
ERR_EMMC_WRITE_FAILED,
|
ERR_EMMC_WRITE_FAILED,
|
||||||
ERR_FILE_TOO_BIG_FOR_DEST,
|
ERR_FILE_TOO_BIG_FOR_DEST,
|
||||||
ERR_SD_EJECTED,
|
ERR_SD_EJECTED,
|
||||||
ERR_PARSE_FAIL,
|
ERR_SCRIPT_LOOKUP_FAIL,
|
||||||
ERR_CANNOT_COPY_FILE_TO_FS_PART,
|
ERR_CANNOT_COPY_FILE_TO_FS_PART,
|
||||||
ERR_NO_DESTINATION,
|
ERR_NO_DESTINATION,
|
||||||
ERR_INI_PARSE_FAIL
|
ERR_INI_PARSE_FAIL,
|
||||||
|
ERR_IN_FUNC
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const char *utils_err_codes_te[];
|
extern const char *utils_err_codes_te[];
|
||||||
|
|||||||
@@ -50,10 +50,11 @@ const char *utils_err_codes_te[] = { // these start at 50
|
|||||||
"EMMC WRITE FAILED",
|
"EMMC WRITE FAILED",
|
||||||
"FILE TOO BIG FOR DEST",
|
"FILE TOO BIG FOR DEST",
|
||||||
"SD EJECTED",
|
"SD EJECTED",
|
||||||
"PARSING FAILED",
|
"FUNC LOOKUP FAIL",
|
||||||
"CANNOT COPY FILE TO FS PART",
|
"CANNOT COPY FILE TO FS PART",
|
||||||
"NO DESTINATION",
|
"NO DESTINATION",
|
||||||
"INI PARSE FAIL"
|
"INI PARSE FAIL",
|
||||||
|
"ERR IN FUNC"
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
const char *pkg2names[] = {
|
const char *pkg2names[] = {
|
||||||
|
|||||||
@@ -191,7 +191,6 @@ int filemenu(menu_entry file){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fsreader_readfolder(currentpath);
|
|
||||||
break;
|
break;
|
||||||
case FILE_PAYLOAD:
|
case FILE_PAYLOAD:
|
||||||
launch_payload(fsutil_getnextloc(currentpath, file.name));
|
launch_payload(fsutil_getnextloc(currentpath, file.name));
|
||||||
@@ -205,7 +204,6 @@ int filemenu(menu_entry file){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
runScript(fsutil_getnextloc(currentpath, file.name));
|
runScript(fsutil_getnextloc(currentpath, file.name));
|
||||||
fsreader_readfolder(currentpath);
|
|
||||||
break;
|
break;
|
||||||
case FILE_HEXVIEW:
|
case FILE_HEXVIEW:
|
||||||
viewbytes(fsutil_getnextloc(currentpath, file.name));
|
viewbytes(fsutil_getnextloc(currentpath, file.name));
|
||||||
@@ -213,7 +211,6 @@ int filemenu(menu_entry file){
|
|||||||
case FILE_DUMPBIS:
|
case FILE_DUMPBIS:
|
||||||
gfx_clearscreen();
|
gfx_clearscreen();
|
||||||
extract_bis_file(fsutil_getnextloc(currentpath, file.name), currentpath);
|
extract_bis_file(fsutil_getnextloc(currentpath, file.name), currentpath);
|
||||||
fsreader_readfolder(currentpath);
|
|
||||||
hidWait();
|
hidWait();
|
||||||
break;
|
break;
|
||||||
case FILE_SIGN:
|
case FILE_SIGN:
|
||||||
@@ -231,5 +228,6 @@ int filemenu(menu_entry file){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fsreader_readfolder(currentpath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
|
|||||||
FIL in, out;
|
FIL in, out;
|
||||||
FILINFO in_info;
|
FILINFO in_info;
|
||||||
u64 sizeRemaining, toCopy;
|
u64 sizeRemaining, toCopy;
|
||||||
UINT temp1, temp2;
|
|
||||||
u8 *buff, toPrint = options & COPY_MODE_PRINT, toCancel = options & COPY_MODE_CANCEL;
|
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;
|
int res;
|
||||||
|
|
||||||
gfx_con_getpos(&x, &y);
|
gfx_con_getpos(&x, &y);
|
||||||
@@ -32,12 +31,12 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f_stat(locin, &in_info)){
|
if ((res = f_stat(locin, &in_info))){
|
||||||
gfx_errDisplay("copy", res, 3);
|
gfx_errDisplay("copy", res, 3);
|
||||||
return 1;
|
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);
|
gfx_errDisplay("copy", res, 4);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -53,22 +52,20 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
|
|||||||
sizeRemaining = f_size(&in);
|
sizeRemaining = f_size(&in);
|
||||||
const u64 totalsize = sizeRemaining;
|
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){
|
while (sizeRemaining > 0){
|
||||||
toCopy = MIN(sizeRemaining, BUFSIZE);
|
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);
|
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);
|
gfx_errDisplay("copy", res, 6);
|
||||||
return 1;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (temp1 != temp2){
|
|
||||||
gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sizeRemaining -= toCopy;
|
sizeRemaining -= toCopy;
|
||||||
@@ -91,20 +88,19 @@ int fsact_copy(const char *locin, const char *locout, u8 options){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RESETCOLOR;
|
if (toPrint){
|
||||||
gfx_con_setpos(x - 16, y);
|
RESETCOLOR;
|
||||||
|
gfx_con_setpos(x - 16, y);
|
||||||
|
}
|
||||||
|
|
||||||
f_close(&in);
|
f_close(&in);
|
||||||
f_close(&out);
|
f_close(&out);
|
||||||
free(buff);
|
free(buff);
|
||||||
|
|
||||||
if ((res = f_chmod(locout, in_info.fattrib, 0x3A))){
|
f_chmod(locout, in_info.fattrib, 0x3A);
|
||||||
gfx_errDisplay("copy", res, 8);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
f_stat(locin, &in_info); //somehow stops fatfs from being weird
|
f_stat(locin, &in_info); //somehow stops fatfs from being weird
|
||||||
return 0;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsact_del_recursive(char *path){
|
int fsact_del_recursive(char *path){
|
||||||
|
|||||||
@@ -13,25 +13,15 @@
|
|||||||
#include "../utils/utils.h"
|
#include "../utils/utils.h"
|
||||||
#include "fsactions.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){
|
void copy_fil_size(FIL* in_src, FIL* out_src, int size_src){
|
||||||
u8* buff;
|
u8* buff;
|
||||||
buff = calloc(16384, sizeof(u8));
|
buff = calloc(BUFSIZE, sizeof(u8));
|
||||||
|
|
||||||
int size = size_src;
|
int size = size_src;
|
||||||
int copysize;
|
int copysize;
|
||||||
|
|
||||||
while (size > 0){
|
while (size > 0){
|
||||||
copysize = MIN(16834, size);
|
copysize = MIN(BUFSIZE, size);
|
||||||
f_read(in_src, buff, copysize, NULL);
|
f_read(in_src, buff, copysize, NULL);
|
||||||
f_write(out_src, buff, copysize, NULL);
|
f_write(out_src, buff, copysize, NULL);
|
||||||
size -= copysize;
|
size -= copysize;
|
||||||
@@ -48,56 +38,50 @@ void gen_part(int size, FIL* in, char *path){
|
|||||||
f_close(&out);
|
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){
|
int extract_bis_file(char *path, char *outfolder){
|
||||||
FIL in;
|
FIL in;
|
||||||
int res;
|
int res;
|
||||||
u8 version[0x10];
|
|
||||||
u8 args;
|
|
||||||
u8 temp[0x4];
|
|
||||||
u32 filesizes[4];
|
|
||||||
char *tempPath;
|
char *tempPath;
|
||||||
|
BisFile header;
|
||||||
|
|
||||||
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
|
if ((res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING))){
|
||||||
gfx_errDisplay("extract_bis_file", res, 0);
|
gfx_errDisplay("extract_bis_file", res, 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
f_read(&in, version, 0x10, NULL);
|
f_read(&in, &header, sizeof(BisFile), NULL);
|
||||||
f_read(&in, &args, 1, NULL);
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++){
|
|
||||||
f_read(&in, temp, 4, NULL);
|
|
||||||
filesizes[i] = DecodeInt(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx_printf("Version: %s\n\n", version);
|
|
||||||
|
|
||||||
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){
|
for (int i = 0; i < 4; i++)
|
||||||
utils_copystring(fsutil_getnextloc(outfolder, "BCPKG2-3-SafeMode-Main"), &tempPath);
|
header.sizes[i] = FLIPU32(header.sizes[i]);
|
||||||
gfx_printf("Extracting BCPKG2_3/4\n");
|
|
||||||
|
|
||||||
gen_part(filesizes[3], &in, tempPath);
|
gfx_printf("Version: %s\n\n", header.version);
|
||||||
fsact_copy(tempPath, fsutil_getnextloc(outfolder, "BCPKG2-4-SafeMode-Sub"), COPY_MODE_PRINT);
|
|
||||||
|
// Loop to actually extract stuff
|
||||||
|
for (int i = 0; i < 4; i++){
|
||||||
|
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]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop to copy pkg2_1->2 and pkg2_3->4
|
||||||
|
for (int i = 4; i < 6; i++){
|
||||||
|
if (!(header.args & BIT((9 - i))))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
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;
|
RESETCOLOR;
|
||||||
free(tempPath);
|
free(tempPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
#include "../common/types.h"
|
#include "../common/types.h"
|
||||||
#include "../../utils/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_getnextloc(const char *current, const char *add);
|
||||||
char *fsutil_getprevloc(char *current);
|
char *fsutil_getprevloc(char *current);
|
||||||
bool fsutil_checkfile(char* path);
|
bool fsutil_checkfile(char* path);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ u32 gfx_errDisplay(const char *src_func, int err, int loc){
|
|||||||
|
|
||||||
if (err < 15)
|
if (err < 15)
|
||||||
gfx_printf("Desc: %s\n", utils_err_codes[err]);
|
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]);
|
gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]);
|
||||||
|
|
||||||
if (loc)
|
if (loc)
|
||||||
|
|||||||
@@ -74,14 +74,14 @@ int part_printf(){
|
|||||||
if (argv[i][0] == '@'){
|
if (argv[i][0] == '@'){
|
||||||
int toprintint;
|
int toprintint;
|
||||||
if (parseIntInput(argv[i], &toprintint))
|
if (parseIntInput(argv[i], &toprintint))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
gfx_printf("%d", toprintint);
|
gfx_printf("%d", toprintint);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *toprintstring;
|
char *toprintstring;
|
||||||
if (parseStringInput(argv[i], &toprintstring))
|
if (parseStringInput(argv[i], &toprintstring))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
gfx_printf(toprintstring);
|
gfx_printf(toprintstring);
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ int part_printf(){
|
|||||||
int part_print_int(){
|
int part_print_int(){
|
||||||
int toprint;
|
int toprint;
|
||||||
if (parseIntInput(argv[0], &toprint))
|
if (parseIntInput(argv[0], &toprint))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
SWAPCOLOR(currentcolor);
|
SWAPCOLOR(currentcolor);
|
||||||
gfx_printf("%s: %d\n", argv[0], toprint);
|
gfx_printf("%s: %d\n", argv[0], toprint);
|
||||||
@@ -107,7 +107,7 @@ int part_Wait(){
|
|||||||
SWAPCOLOR(currentcolor);
|
SWAPCOLOR(currentcolor);
|
||||||
|
|
||||||
if (parseIntInput(argv[0], &arg))
|
if (parseIntInput(argv[0], &arg))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
begintime = get_tmr_s();
|
begintime = get_tmr_s();
|
||||||
|
|
||||||
@@ -122,9 +122,9 @@ int part_Wait(){
|
|||||||
int part_Check(){
|
int part_Check(){
|
||||||
int left, right;
|
int left, right;
|
||||||
if (parseIntInput(argv[0], &left))
|
if (parseIntInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseIntInput(argv[2], &right))
|
if (parseIntInput(argv[2], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (!strcmp(argv[1], "=="))
|
if (!strcmp(argv[1], "=="))
|
||||||
return (left == right);
|
return (left == right);
|
||||||
@@ -139,13 +139,13 @@ int part_Check(){
|
|||||||
else if (!strcmp(argv[1], "<"))
|
else if (!strcmp(argv[1], "<"))
|
||||||
return (left < right);
|
return (left < right);
|
||||||
else
|
else
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int part_if(){
|
int part_if(){
|
||||||
int condition;
|
int condition;
|
||||||
if (parseIntInput(argv[0], &condition))
|
if (parseIntInput(argv[0], &condition))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
getfollowingchar('{');
|
getfollowingchar('{');
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ int part_if(){
|
|||||||
int part_if_args(){
|
int part_if_args(){
|
||||||
int condition;
|
int condition;
|
||||||
if ((condition = part_Check()) < 0)
|
if ((condition = part_Check()) < 0)
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
getfollowingchar('{');
|
getfollowingchar('{');
|
||||||
|
|
||||||
@@ -180,9 +180,9 @@ int part_if_args(){
|
|||||||
int part_Math(){
|
int part_Math(){
|
||||||
int left, right;
|
int left, right;
|
||||||
if (parseIntInput(argv[0], &left))
|
if (parseIntInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseIntInput(argv[2], &right))
|
if (parseIntInput(argv[2], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
switch (argv[1][0]){
|
switch (argv[1][0]){
|
||||||
case '+':
|
case '+':
|
||||||
@@ -194,7 +194,7 @@ int part_Math(){
|
|||||||
case '/':
|
case '/':
|
||||||
return left / right;
|
return left / right;
|
||||||
}
|
}
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int part_SetInt(){
|
int part_SetInt(){
|
||||||
@@ -206,9 +206,9 @@ int part_SetInt(){
|
|||||||
int part_SetString(){
|
int part_SetString(){
|
||||||
char *arg0;
|
char *arg0;
|
||||||
if (parseStringInput(argv[0], &arg0))
|
if (parseStringInput(argv[0], &arg0))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (argv[1][0] != '$')
|
if (argv[1][0] != '$')
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
str_str_add(argv[1], arg0);
|
str_str_add(argv[1], arg0);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -218,11 +218,11 @@ int part_SetStringIndex(){
|
|||||||
int index;
|
int index;
|
||||||
char *out;
|
char *out;
|
||||||
if (parseIntInput(argv[0], &index))
|
if (parseIntInput(argv[0], &index))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (argv[1][0] != '$')
|
if (argv[1][0] != '$')
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (str_str_index(index, &out))
|
if (str_str_index(index, &out))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
str_str_add(argv[1], out);
|
str_str_add(argv[1], out);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -231,7 +231,10 @@ int part_SetStringIndex(){
|
|||||||
int part_goto(){
|
int part_goto(){
|
||||||
int target = 0;
|
int target = 0;
|
||||||
if (parseIntInput(argv[0], &target))
|
if (parseIntInput(argv[0], &target))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
|
str_int_add("@RETURN", (int)f_tell(&scriptin));
|
||||||
|
|
||||||
f_lseek(&scriptin, target);
|
f_lseek(&scriptin, target);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -239,14 +242,14 @@ int part_goto(){
|
|||||||
int part_invert(){
|
int part_invert(){
|
||||||
int arg;
|
int arg;
|
||||||
if (parseIntInput(argv[0], &arg))
|
if (parseIntInput(argv[0], &arg))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
return (arg) ? 0 : 1;
|
return (arg) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int part_fs_exists(){
|
int part_fs_exists(){
|
||||||
char *path;
|
char *path;
|
||||||
if (parseStringInput(argv[0], &path))
|
if (parseStringInput(argv[0], &path))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return fsutil_checkfile(path);
|
return fsutil_checkfile(path);
|
||||||
}
|
}
|
||||||
@@ -260,7 +263,7 @@ int part_ConnectMMC(){
|
|||||||
else if (!strcmp(arg, "EMUMMC"))
|
else if (!strcmp(arg, "EMUMMC"))
|
||||||
connect_mmc(EMUMMC);
|
connect_mmc(EMUMMC);
|
||||||
else
|
else
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -292,11 +295,11 @@ int part_Pause(){
|
|||||||
int part_addstrings(){
|
int part_addstrings(){
|
||||||
char *combined, *left, *middle;
|
char *combined, *left, *middle;
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &middle))
|
if (parseStringInput(argv[1], &middle))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (argv[2][0] != '$')
|
if (argv[2][0] != '$')
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
|
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
|
||||||
sprintf(combined, "%s%s", left, middle);
|
sprintf(combined, "%s%s", left, middle);
|
||||||
@@ -309,7 +312,7 @@ int part_addstrings(){
|
|||||||
int part_setColor(){
|
int part_setColor(){
|
||||||
char *arg;
|
char *arg;
|
||||||
if (parseStringInput(argv[0], &arg))
|
if (parseStringInput(argv[0], &arg))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (!strcmp(arg, "RED"))
|
if (!strcmp(arg, "RED"))
|
||||||
currentcolor = COLOR_RED;
|
currentcolor = COLOR_RED;
|
||||||
@@ -326,7 +329,7 @@ int part_setColor(){
|
|||||||
else if (!strcmp(arg, "WHITE"))
|
else if (!strcmp(arg, "WHITE"))
|
||||||
currentcolor = COLOR_WHITE;
|
currentcolor = COLOR_WHITE;
|
||||||
else
|
else
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -340,9 +343,9 @@ int part_fs_Move(){
|
|||||||
char *left, *right;
|
char *left, *right;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &right))
|
if (parseStringInput(argv[1], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
res = f_rename(left, right);
|
res = f_rename(left, right);
|
||||||
@@ -356,7 +359,7 @@ int part_fs_Delete(){
|
|||||||
char *arg;
|
char *arg;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &arg))
|
if (parseStringInput(argv[0], &arg))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
res = f_unlink(arg);
|
res = f_unlink(arg);
|
||||||
@@ -370,7 +373,7 @@ int part_fs_DeleteRecursive(){
|
|||||||
char *arg;
|
char *arg;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &arg))
|
if (parseStringInput(argv[0], &arg))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return fsact_del_recursive(arg);
|
return fsact_del_recursive(arg);
|
||||||
}
|
}
|
||||||
@@ -379,9 +382,9 @@ int part_fs_Copy(){
|
|||||||
char *left, *right;
|
char *left, *right;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &right))
|
if (parseStringInput(argv[1], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return fsact_copy(left, right, COPY_MODE_PRINT);
|
return fsact_copy(left, right, COPY_MODE_PRINT);
|
||||||
}
|
}
|
||||||
@@ -390,9 +393,9 @@ int part_fs_CopyRecursive(){
|
|||||||
char *left, *right;
|
char *left, *right;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &right))
|
if (parseStringInput(argv[1], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return fsact_copy_recursive(left, right);
|
return fsact_copy_recursive(left, right);
|
||||||
}
|
}
|
||||||
@@ -401,7 +404,7 @@ int part_fs_MakeDir(){
|
|||||||
char *arg;
|
char *arg;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &arg))
|
if (parseStringInput(argv[0], &arg))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
res = f_mkdir(arg);
|
res = f_mkdir(arg);
|
||||||
@@ -418,10 +421,10 @@ int part_fs_OpenDir(){
|
|||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &path))
|
if (parseStringInput(argv[0], &path))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (f_opendir(&dir, path))
|
if (f_opendir(&dir, path))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
isdirvalid = true;
|
isdirvalid = true;
|
||||||
str_int_add("@ISDIRVALID", isdirvalid);
|
str_int_add("@ISDIRVALID", isdirvalid);
|
||||||
@@ -440,7 +443,7 @@ int part_fs_CloseDir(){
|
|||||||
|
|
||||||
int part_fs_ReadDir(){
|
int part_fs_ReadDir(){
|
||||||
if (!isdirvalid)
|
if (!isdirvalid)
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (!f_readdir(&dir, &fno) && fno.fname[0]){
|
if (!f_readdir(&dir, &fno) && fno.fname[0]){
|
||||||
str_str_add("$FILENAME", fno.fname);
|
str_str_add("$FILENAME", fno.fname);
|
||||||
@@ -457,16 +460,16 @@ int part_setPrintPos(){
|
|||||||
int left, right;
|
int left, right;
|
||||||
|
|
||||||
if (parseIntInput(argv[0], &left))
|
if (parseIntInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (parseIntInput(argv[1], &right))
|
if (parseIntInput(argv[1], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (left > 78)
|
if (left > 78)
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (right > 42)
|
if (right > 42)
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
gfx_con_setpos(left * 16, right * 16);
|
gfx_con_setpos(left * 16, right * 16);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -476,9 +479,9 @@ int part_stringcompare(){
|
|||||||
char *left, *right;
|
char *left, *right;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &right))
|
if (parseStringInput(argv[1], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return (strcmp(left, right)) ? 0 : 1;
|
return (strcmp(left, right)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
@@ -486,11 +489,11 @@ int part_stringcompare(){
|
|||||||
int part_fs_combinePath(){
|
int part_fs_combinePath(){
|
||||||
char *combined, *left, *middle;
|
char *combined, *left, *middle;
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &middle))
|
if (parseStringInput(argv[1], &middle))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (argv[2][0] != '$')
|
if (argv[2][0] != '$')
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
combined = fsutil_getnextloc(left, middle);
|
combined = fsutil_getnextloc(left, middle);
|
||||||
|
|
||||||
@@ -503,9 +506,9 @@ int part_mmc_dumpPart(){
|
|||||||
char *left, *right;
|
char *left, *right;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &left))
|
if (parseStringInput(argv[0], &left))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &right))
|
if (parseStringInput(argv[1], &right))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (!strcmp(left, "BOOT")){
|
if (!strcmp(left, "BOOT")){
|
||||||
return emmcDumpBoot(right);
|
return emmcDumpBoot(right);
|
||||||
@@ -519,10 +522,10 @@ int part_mmc_restorePart(){
|
|||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &path))
|
if (parseStringInput(argv[0], &path))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
if (currentlyMounted < 0)
|
if (currentlyMounted < 0)
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return mmcFlashFile(path, currentlyMounted, false);
|
return mmcFlashFile(path, currentlyMounted, false);
|
||||||
}
|
}
|
||||||
@@ -531,9 +534,9 @@ int part_fs_extractBisFile(){
|
|||||||
char *path, *outfolder;
|
char *path, *outfolder;
|
||||||
|
|
||||||
if (parseStringInput(argv[0], &path))
|
if (parseStringInput(argv[0], &path))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
if (parseStringInput(argv[1], &outfolder))
|
if (parseStringInput(argv[1], &outfolder))
|
||||||
return -1;
|
return INFUNC_FAIL;
|
||||||
|
|
||||||
return extract_bis_file(path, outfolder);
|
return extract_bis_file(path, outfolder);
|
||||||
}
|
}
|
||||||
@@ -547,6 +550,8 @@ int part_getPos(){
|
|||||||
return (int)f_tell(&scriptin);
|
return (int)f_tell(&scriptin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
str_fnc_struct functions[] = {
|
str_fnc_struct functions[] = {
|
||||||
{"printf", part_printf, 255},
|
{"printf", part_printf, 255},
|
||||||
{"printInt", part_print_int, 1},
|
{"printInt", part_print_int, 1},
|
||||||
@@ -596,8 +601,8 @@ int run_function(char *func_name, int *out){
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
*out = functions[i].value();
|
*out = functions[i].value();
|
||||||
return (*out < 0) ? -1 : 0;
|
return (*out == INFUNC_FAIL) ? -1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -2;
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,16 @@ void mainparser(){
|
|||||||
printerrors = true;
|
printerrors = true;
|
||||||
//gfx_printf("%s|%s|%d", funcbuff, argv[0], argc);
|
//gfx_printf("%s|%s|%d", funcbuff, argv[0], argc);
|
||||||
//btn_wait();
|
//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;
|
forceExit = true;
|
||||||
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
|
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
|
||||||
}
|
}
|
||||||
@@ -277,7 +286,9 @@ void runScript(char *path){
|
|||||||
gfx_clearscreen();
|
gfx_clearscreen();
|
||||||
utils_copystring(path, &path_local);
|
utils_copystring(path, &path_local);
|
||||||
|
|
||||||
|
|
||||||
res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING);
|
res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING);
|
||||||
|
DWORD *clmt_in = f_expand_cltbl(&scriptin, BUFSIZE / 4, 0);
|
||||||
if (res != FR_OK){
|
if (res != FR_OK){
|
||||||
gfx_errDisplay("ParseScript", res, 1);
|
gfx_errDisplay("ParseScript", res, 1);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define INFUNC_FAIL (int)0xC0000000
|
||||||
|
|
||||||
void runScript(char *path);
|
void runScript(char *path);
|
||||||
void skipbrackets();
|
void skipbrackets();
|
||||||
void getfollowingchar(char end);
|
void getfollowingchar(char end);
|
||||||
Reference in New Issue
Block a user