1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-26 22:02:08 +00:00
TegraExplorer/source/fs/fscopy.c

81 lines
1.9 KiB
C
Raw Normal View History

2020-12-26 00:05:33 +00:00
#include "fscopy.h"
#include <libs/fatfs/ff.h>
#include <utils/btn.h>
#include "../tegraexplorer/tconf.h"
#include "../gfx/gfx.h"
#include <mem/heap.h>
#include <string.h>
#include "../gfx/gfxutils.h"
ErrCode_t FileCopy(const char *locin, const char *locout, u8 options){
FIL in, out;
FILINFO in_info;
u64 sizeRemaining, toCopy;
u8 *buff;
u32 x, y;
ErrCode_t err = newErrCode(0);
2020-12-26 00:05:33 +00:00
int res = 0;
gfx_con_getpos(&x, &y);
if (!strcmp(locin, locout)){
return newErrCode(TE_ERR_SAME_LOC);
}
if ((res = f_open(&in, locin, FA_READ | FA_OPEN_EXISTING))){
return newErrCode(res);
}
if ((res = f_stat(locin, &in_info))){
return newErrCode(res);
}
if ((res = f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE))){
return newErrCode(res);
}
if (options & COPY_MODE_PRINT){
gfx_printf("[ ]");
x += 16;
gfx_con_setpos(x, y);
}
buff = malloc(TConf.FSBuffSize);
sizeRemaining = f_size(&in);
const u64 totalsize = sizeRemaining;
while (sizeRemaining > 0){
toCopy = MIN(sizeRemaining, TConf.FSBuffSize);
if ((res = f_read(&in, buff, toCopy, NULL))){
err = newErrCode(res);
break;
2020-12-26 00:05:33 +00:00
}
if ((res = f_write(&out, buff, toCopy, NULL))){
err = newErrCode(res);
break;
2020-12-26 00:05:33 +00:00
}
sizeRemaining -= toCopy;
if (options & COPY_MODE_PRINT){
gfx_printf("%3d%%", (u32)(((totalsize - sizeRemaining) * 100) / totalsize));
gfx_con_setpos(x, y);
}
if (options & COPY_MODE_CANCEL && btn_read() & (BTN_VOL_DOWN | BTN_VOL_UP)){
f_unlink(locout);
break;
}
}
f_close(&in);
f_close(&out);
free(buff);
f_chmod(locout, in_info.fattrib, 0x3A);
//f_stat(locin, &in_info); //somehow stops fatfs from being weird
return err;
2020-12-26 00:05:33 +00:00
}