mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-12-25 19:06:02 +00:00
Add file copy/move
This commit is contained in:
parent
a74a8814e1
commit
ab5c5e799e
12 changed files with 138 additions and 43 deletions
|
@ -23,6 +23,7 @@ const char *TEErrors[] = {
|
|||
[TE_EXCEPTION_UNDEFINED - 1] = "E Undefined",
|
||||
[TE_EXCEPTION_PREF_ABORT - 1] = "E Pref abort",
|
||||
[TE_EXCEPTION_DATA_ABORT - 1] = "E Data abort",
|
||||
[TE_ERR_SAME_LOC - 1] = "Same copy location",
|
||||
};
|
||||
|
||||
const char *GetErrStr(u32 err){
|
||||
|
@ -39,6 +40,9 @@ const char *GetErrStr(u32 err){
|
|||
#define leny 240
|
||||
|
||||
void DrawError(ErrCode_t err){
|
||||
if (err.err == 0)
|
||||
return;
|
||||
|
||||
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);
|
||||
|
|
|
@ -12,7 +12,8 @@ enum {
|
|||
TE_EXCEPTION_RESET,
|
||||
TE_EXCEPTION_UNDEFINED,
|
||||
TE_EXCEPTION_PREF_ABORT,
|
||||
TE_EXCEPTION_DATA_ABORT
|
||||
TE_EXCEPTION_DATA_ABORT,
|
||||
TE_ERR_SAME_LOC
|
||||
};
|
||||
|
||||
#define newErrCode(err) (ErrCode_t) {err, __LINE__, __FILE__}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#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;
|
||||
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))){
|
||||
return newErrCode(res);
|
||||
}
|
||||
|
||||
if ((res = f_write(&out, buff, toCopy, NULL))){
|
||||
return newErrCode(res);
|
||||
}
|
||||
|
||||
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 newErrCode(0);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include <utils/types.h>
|
||||
#include "../err.h"
|
||||
|
||||
#define COPY_MODE_CANCEL BIT(0)
|
||||
#define COPY_MODE_PRINT BIT(1)
|
||||
|
||||
ErrCode_t FileCopy(const char *locin, const char *locout, u8 options);
|
|
@ -17,7 +17,7 @@ char *CombinePaths(const char *current, const char *add){
|
|||
return ret;
|
||||
}
|
||||
|
||||
char *EscapeFolder(char *current){
|
||||
char *EscapeFolder(const char *current){
|
||||
char *ret;
|
||||
char *temp;
|
||||
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
#include "fstypes.h"
|
||||
|
||||
u64 GetFileSize(char *path);
|
||||
char *EscapeFolder(char *current);
|
||||
char *EscapeFolder(const char *current);
|
||||
char *CombinePaths(const char *current, const char *add);
|
||||
char *GetFileAttribs(FSEntry_t entry);
|
|
@ -10,6 +10,10 @@
|
|||
#include <string.h>
|
||||
#include <mem/heap.h>
|
||||
#include "../../tegraexplorer/tconf.h"
|
||||
#include "../../err.h"
|
||||
#include "../fscopy.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include "../../hid/hid.h"
|
||||
|
||||
MenuEntry_t topEntries[] = {
|
||||
{.optionUnion = COLORTORGB(COLOR_GREEN) | SKIPBIT},
|
||||
|
@ -39,7 +43,7 @@ void FileExplorer(char *path){
|
|||
int res = 0;
|
||||
|
||||
while (1){
|
||||
topEntries[2].optionUnion = COLORTORGB(((TConf.explorerCopyMode != CMODE_None) ? COLOR_ORANGE : COLOR_GREY)) | SKIPBIT;
|
||||
topEntries[2].optionUnion = (TConf.explorerCopyMode != CMODE_None) ? (COLORTORGB(COLOR_ORANGE)) : (COLORTORGB(COLOR_GREY) | SKIPBIT);
|
||||
|
||||
gfx_clearscreen();
|
||||
gfx_printf("Loading...\r");
|
||||
|
@ -67,7 +71,32 @@ void FileExplorer(char *path){
|
|||
|
||||
char *oldPath = storedPath;
|
||||
|
||||
if (res < ARR_LEN(topEntries)) {
|
||||
if (res == 2){
|
||||
ErrCode_t res;
|
||||
char *filename = CpyStr(strrchr(TConf.srcCopy, '/') + 1);
|
||||
char *dst = CombinePaths(storedPath, filename);
|
||||
|
||||
if (!strcmp(TConf.srcCopy, dst))
|
||||
res = newErrCode(TE_ERR_SAME_LOC);
|
||||
else {
|
||||
if (TConf.explorerCopyMode == CMODE_Move){
|
||||
if ((res.err = f_rename(TConf.srcCopy, dst)))
|
||||
res = newErrCode(res.err);
|
||||
}
|
||||
else {
|
||||
gfx_clearscreen();
|
||||
RESETCOLOR;
|
||||
gfx_printf("Hold vol+/- to cancel\nCopying %s... ", filename);
|
||||
res = FileCopy(TConf.srcCopy, dst, COPY_MODE_CANCEL | COPY_MODE_PRINT);
|
||||
}
|
||||
}
|
||||
|
||||
DrawError(res);
|
||||
free(dst);
|
||||
free(filename);
|
||||
ResetCopyParams();
|
||||
}
|
||||
else if (res < ARR_LEN(topEntries)) {
|
||||
if (!strcmp(storedPath, path)){
|
||||
clearFileVector(&fileVec);
|
||||
return;
|
||||
|
|
|
@ -46,7 +46,7 @@ void CopyClipboard(char *path, FSEntry_t entry){
|
|||
|
||||
void MoveClipboard(char *path, FSEntry_t entry){
|
||||
char *thing = CombinePaths(path, entry.name);
|
||||
SetCopyParams(thing, CMODE_Copy);
|
||||
SetCopyParams(thing, CMODE_Move);
|
||||
free(thing);
|
||||
}
|
||||
|
||||
|
@ -56,33 +56,6 @@ MenuEntry_t DeleteEntries[] = {
|
|||
};
|
||||
|
||||
void DeleteFile(char *path, FSEntry_t entry){
|
||||
/*
|
||||
u8 left = 0;
|
||||
|
||||
while (1){
|
||||
gfx_con_setpos(384 + 16, 200 + 16 + 9 * 16);
|
||||
SETCOLOR(COLOR_RED, COLOR_DARKGREY);
|
||||
gfx_printf("Are you sure? ");
|
||||
|
||||
(left) ? SETCOLOR(COLOR_DARKGREY, COLOR_RED) : SETCOLOR(COLOR_RED, COLOR_DARKGREY);
|
||||
gfx_printf("Yes");
|
||||
RESETCOLOR;
|
||||
gfx_printf(" ");
|
||||
(!left) ? SETCOLOR(COLOR_DARKGREY, COLOR_YELLOW) : SETCOLOR(COLOR_YELLOW, COLOR_DARKGREY);
|
||||
gfx_printf("No");
|
||||
|
||||
Input_t *input = hidWait();
|
||||
|
||||
if (input->a && left)
|
||||
break;
|
||||
else if (input->right)
|
||||
left = 0;
|
||||
else if (input->left)
|
||||
left = 1;
|
||||
else if (input->a || input->b)
|
||||
return;
|
||||
}
|
||||
*/
|
||||
gfx_con_setpos(384 + 16, 200 + 16 + 8 * 16);
|
||||
SETCOLOR(COLOR_RED, COLOR_DARKGREY);
|
||||
gfx_printf("Are you sure? ");
|
||||
|
|
|
@ -194,8 +194,8 @@ static inline void _show_errors()
|
|||
{
|
||||
gfx_clearscreen();
|
||||
WPRINTFARGS("LR %08X", *excp_lr);
|
||||
u16 exception = TE_EXCEPTION_RESET;
|
||||
/*
|
||||
u32 exception = 0;
|
||||
|
||||
switch (*excp_type)
|
||||
{
|
||||
case EXCP_TYPE_RESET:
|
||||
|
@ -210,7 +210,7 @@ static inline void _show_errors()
|
|||
case EXCP_TYPE_DABRT:
|
||||
exception = TE_EXCEPTION_DATA_ABORT;
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
// Clear the exception.
|
||||
*excp_enabled = 0;
|
||||
|
@ -242,7 +242,7 @@ void ipl_main()
|
|||
h_cfg.errors |= !sd_mount() ? ERR_SD_BOOT_EN : 0;
|
||||
|
||||
TConf.minervaEnabled = !minerva_init();
|
||||
TConf.FSBuffSize = (TConf.minervaEnabled) ? 0x400000 : 0x10000;
|
||||
TConf.FSBuffSize = (TConf.minervaEnabled) ? 0x800000 : 0x10000;
|
||||
|
||||
// Train DRAM and switch to max frequency.
|
||||
if (TConf.minervaEnabled) //!TODO: Add Tegra210B01 support to minerva.
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#include "tconf.h"
|
||||
#include <mem/heap.h>
|
||||
#include "../utils/utils.h"
|
||||
TConf_t TConf = {0};
|
||||
|
||||
void ResetCopyParams(){
|
||||
TConf.heldExplorerCopyLoc = LOC_None;
|
||||
if (TConf.srcCopy != NULL)
|
||||
free(TConf.srcCopy);
|
||||
FREE(TConf.srcCopy);
|
||||
TConf.explorerCopyMode = CMODE_None;
|
||||
}
|
||||
|
||||
void SetCopyParams(char *path, u8 mode){
|
||||
void SetCopyParams(const char *path, u8 mode){
|
||||
ResetCopyParams();
|
||||
TConf.heldExplorerCopyLoc = TConf.curExplorerLoc;
|
||||
TConf.explorerCopyMode = mode;
|
||||
TConf.srcCopy = path;
|
||||
TConf.srcCopy = CpyStr(path);
|
||||
}
|
|
@ -39,4 +39,4 @@ typedef struct {
|
|||
extern TConf_t TConf;
|
||||
|
||||
void ResetCopyParams();
|
||||
void SetCopyParams(char *path, u8 mode);
|
||||
void SetCopyParams(const char *path, u8 mode);
|
|
@ -3,4 +3,6 @@
|
|||
|
||||
char *CpyStr(const char* in);
|
||||
void MaskIn(char *mod, u32 bitstream, char mask);
|
||||
bool StrEndsWith(char *begin, char *end);
|
||||
bool StrEndsWith(char *begin, char *end);
|
||||
|
||||
#define FREE(x) free(x); x = NULL;
|
Loading…
Reference in a new issue