1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-09 13:41:45 +00:00

Add basic file copying + add file delete wait timer

This commit is contained in:
Such Meme, Many Skill 2019-12-10 22:46:34 +01:00
parent fd74812d2b
commit e837e2e6ed
4 changed files with 101 additions and 22 deletions

View file

@ -49,9 +49,10 @@
---------------------------------------------------------------------------*/ ---------------------------------------------------------------------------*/
PARTITION VolToPart[2] = { PARTITION VolToPart[] = {
{0, 1}, {0, 1},
{1, 1} {1, 1},
{1, 2}
}; };
#if FF_DEFINED != 86604 /* Revision ID */ #if FF_DEFINED != 86604 /* Revision ID */

View file

@ -163,12 +163,12 @@
/ Drive/Volume Configurations / Drive/Volume Configurations
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#define FF_VOLUMES 2 #define FF_VOLUMES 3
/* Number of volumes (logical drives) to be used. (1-10) */ /* Number of volumes (logical drives) to be used. (1-10) */
#define FF_STR_VOLUME_ID 1 #define FF_STR_VOLUME_ID 1
#define FF_VOLUME_STRS "sd", "emmc" #define FF_VOLUME_STRS "sd", "system", "user"
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive

View file

@ -1,5 +1,5 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include "../mem/heap.h"
#include "gfx.h" #include "gfx.h"
#include "fs.h" #include "fs.h"
#include "../utils/types.h" #include "../utils/types.h"
@ -40,19 +40,20 @@ void writecurpath(const char *in){
strcpy(currentpath, in); strcpy(currentpath, in);
} }
void writeclipboard(const char *in, bool operation, bool folder){ void writeclipboard(const char *in, bool move, bool folder){
if (clipboard != NULL) if (clipboard != NULL)
free(clipboard); free(clipboard);
clipboardhelper = 0; clipboardhelper = 0;
if (operation) if (move)
clipboardhelper |= (OPERATION); clipboardhelper |= (OPERATIONMOVE);
else
clipboardhelper |= (OPERATIONCOPY);
if (folder) if (folder)
clipboardhelper |= (ISDIR); clipboardhelper |= (ISDIR);
size_t len = strlen(in) + 1; size_t len = strlen(in) + 1;
clipboard = (char*) malloc (len); clipboard = (char*) malloc (len);
strcpy(clipboard, in); strcpy(clipboard, in);
@ -145,11 +146,14 @@ void viewbytes(char *path){
f_close(&in); f_close(&in);
} }
int copyfile(const char *locin, const char *locout, bool print){ int copy(const char *locin, const char *locout, bool print){
FIL in, out; FIL in, out;
u64 sizeoffile, sizecopied = 0; u64 sizeoffile, sizecopied = 0, totalsize;
UINT temp1, temp2; UINT temp1, temp2;
u8 *buff; u8 *buff;
unsigned int x, y, i = 0;
gfx_con_getpos(&x, &y);
if (!strcmp(locin, locout)){ if (!strcmp(locin, locout)){
return 3; return 3;
@ -165,11 +169,12 @@ int copyfile(const char *locin, const char *locout, bool print){
buff = malloc (BUFSIZE); buff = malloc (BUFSIZE);
sizeoffile = f_size(&in); sizeoffile = f_size(&in);
totalsize = sizeoffile;
while (sizeoffile > BUFSIZE){ while (sizeoffile > 0){
if (f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1)) if (f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))
return 3; return 3;
if (f_write(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2)) if (f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))
return 4; return 4;
if (temp1 != temp2) if (temp1 != temp2)
@ -177,6 +182,18 @@ int copyfile(const char *locin, const char *locout, bool print){
sizeoffile -= temp1; sizeoffile -= temp1;
sizecopied += temp1; sizecopied += temp1;
if (print && 10 > i++){
gfx_printf("%k[%d%%/100%%]%k", COLOR_GREEN, ((sizecopied * 100) / totalsize) ,COLOR_WHITE);
gfx_con_setpos(x, y);
i = 0;
if (btn_read() & BTN_VOL_DOWN){
f_unlink(locout);
break;
}
}
} }
f_close(&in); f_close(&in);
@ -186,6 +203,43 @@ int copyfile(const char *locin, const char *locout, bool print){
return 0; return 0;
} }
void copyfile(const char *path, const char *outfolder){
char *filename = strrchr(path, '/');
char *outstring;
size_t outstringsize = strlen(filename) + strlen(outfolder) + 2;
int res;
clearscreen();
outstring = (char*) malloc (outstringsize);
if (strcmp(rootpath, outfolder))
sprintf(outstring, "%s/%s", outfolder, filename + 1);
else
sprintf(outstring, "%s%s", outfolder, filename + 1);
gfx_printf("Note:\nTo stop the transfer hold Vol-\n\n%s\nProgress: ", outstring);
if (clipboardhelper & OPERATIONMOVE){
f_rename(path, outstring);
}
else if (clipboardhelper & OPERATIONCOPY) {
res = copy(path, outstring, true);
if (res){
gfx_printf("\n\n%kSomething went wrong while copying!\n\nErrcode: %d%k", COLOR_RED, res, COLOR_WHITE);
btn_wait();
}
}
else {
message("\nClipboard is empty!", COLOR_RED);
}
free (outstring);
clipboardhelper = 0;
}
u64 getfilesize(char *path){ u64 getfilesize(char *path){
FILINFO fno; FILINFO fno;
f_stat(path, &fno); f_stat(path, &fno);
@ -246,6 +300,33 @@ int readfolder(const char *path){
return folderamount; return folderamount;
} }
int delfile(const char *path, const char *filename){
clearscreen();
int res;
int amount = -1;
u32 start = get_tmr_s();
gfx_printf("Are you sure you want to delete:\n%s\n\nPress vol+/- to cancel\n", filename);
while(1){
res = btn_read();
if (res & BTN_VOL_UP || res & BTN_VOL_DOWN)
break;
if (start + 3 > get_tmr_s()){
gfx_printf("\r<Wait %d seconds>", 3 + start - get_tmr_s());
}
else if (res & BTN_POWER){
f_unlink(path);
amount = readfolder(currentpath);
break;
}
else {
gfx_printf("\r%kPress power to delete%k", COLOR_RED, COLOR_WHITE);
}
}
return amount;
}
void filemenu(const char *startpath){ void filemenu(const char *startpath){
int amount, res, tempint; int amount, res, tempint;
char temp[100]; char temp[100];
@ -265,7 +346,8 @@ void filemenu(const char *startpath){
} }
} }
if (res == -1){ if (res == -1){
break; copyfile(clipboard, currentpath);
amount = readfolder(currentpath);
} }
if (res == 0) if (res == 0)
@ -301,13 +383,8 @@ void filemenu(const char *startpath){
writeclipboard(getnextloc(currentpath, fileobjects[res - 1].name), true, false); writeclipboard(getnextloc(currentpath, fileobjects[res - 1].name), true, false);
break; break;
case DELETE: case DELETE:
msleep(100); if ((tempint = delfile(getnextloc(currentpath, fileobjects[res - 1].name), fileobjects[res - 1].name)) != -1)
sprintf(temp, "Do you want to delete:\n%s\n\nPress Power to confirm\nPress Vol+/- to cancel", fileobjects[res - 1].name); amount = tempint;
tempint = message(temp, COLOR_RED);
if (tempint & BTN_POWER){
f_unlink(getnextloc(currentpath, fileobjects[res - 1].name));
amount = readfolder(currentpath);
}
break; break;
case PAYLOAD: case PAYLOAD:
launch_payload(getnextloc(currentpath, fileobjects[res - 1].name)); launch_payload(getnextloc(currentpath, fileobjects[res - 1].name));

View file

@ -9,7 +9,8 @@
#define ISKB (1 << 5) #define ISKB (1 << 5)
#define ISB (1 << 4) #define ISB (1 << 4)
#define OPERATION (1 << 1) #define OPERATIONCOPY (1 << 1)
#define OPERATIONMOVE (1 << 2)
#define BUFSIZE 32768 #define BUFSIZE 32768