Improved copy-overwrite handling

This commit is contained in:
d0k3 2016-03-02 17:32:19 +01:00
parent df82754a6a
commit f574549cdb

View File

@ -114,7 +114,7 @@ bool FileCreate(const char* path, u8* data, u32 size) {
return (bytes_written == size); return (bytes_written == size);
} }
bool PathCopyWorker(char* dest, char* orig) { bool PathCopyWorker(char* dest, char* orig, bool overwrite) {
FILINFO fno = {.lfname = NULL}; FILINFO fno = {.lfname = NULL};
bool ret = false; bool ret = false;
@ -138,11 +138,12 @@ bool PathCopyWorker(char* dest, char* orig) {
} }
// check if destination exists // check if destination exists
if (f_stat(dest, NULL) == FR_OK) { if (!overwrite && (f_stat(dest, NULL) == FR_OK)) {
char namestr[40]; char namestr[36 + 1];
TruncateString(namestr, dest, 36, 8); TruncateString(namestr, dest, 36, 8);
if (!ShowPrompt(true, "Destination already exists:\n%s\nOverwrite existing file(s)?", namestr)) if (!ShowPrompt(true, "Destination already exists:\n%s\nOverwrite existing file(s)?", namestr))
return false; return false;
overwrite = true;
} }
// the copy process takes place here // the copy process takes place here
@ -169,7 +170,7 @@ bool PathCopyWorker(char* dest, char* orig) {
if (fno.fname[0] == 0) { if (fno.fname[0] == 0) {
ret = true; ret = true;
break; break;
} else if (!PathCopyWorker(dest, orig)) { } else if (!PathCopyWorker(dest, orig, overwrite)) {
break; break;
} }
} }
@ -222,7 +223,7 @@ bool PathCopy(const char* destdir, const char* orig) {
if (!CheckWritePermissions(destdir)) return false; if (!CheckWritePermissions(destdir)) return false;
strncpy(fdpath, destdir, 255); strncpy(fdpath, destdir, 255);
strncpy(fopath, orig, 255); strncpy(fopath, orig, 255);
return PathCopyWorker(fdpath, fopath); return PathCopyWorker(fdpath, fopath, false);
} }
bool PathDeleteWorker(char* fpath) { bool PathDeleteWorker(char* fpath) {