2020-12-23 16:39:22 +00:00
|
|
|
#include <mem/heap.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "fsutils.h"
|
|
|
|
#include "../utils/utils.h"
|
|
|
|
#include <utils/sprintf.h>
|
|
|
|
#include <libs/fatfs/ff.h>
|
2020-12-24 23:20:30 +00:00
|
|
|
#include "readers/folderReader.h"
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
char *CombinePaths(const char *current, const char *add){
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
size_t size = strlen(current) + strlen(add) + 2;
|
|
|
|
ret = (char*) malloc (size);
|
|
|
|
|
2021-06-24 20:44:59 +01:00
|
|
|
s_printf(ret, (current[strlen(current) - 1] == '/') ? "%s%s" : "%s/%s", current, add);
|
2020-12-23 16:39:22 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-26 00:05:33 +00:00
|
|
|
char *EscapeFolder(const char *current){
|
2020-12-23 16:39:22 +00:00
|
|
|
char *ret;
|
|
|
|
char *temp;
|
|
|
|
|
|
|
|
ret = CpyStr(current);
|
|
|
|
temp = strrchr(ret, '/');
|
|
|
|
|
|
|
|
if (*(temp - 1) == ':')
|
|
|
|
temp++;
|
|
|
|
|
|
|
|
*temp = '\0';
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-29 00:05:33 +00:00
|
|
|
FSEntry_t GetFileInfo(const char *path){
|
2020-12-23 16:39:22 +00:00
|
|
|
FILINFO fno;
|
|
|
|
f_stat(path, &fno);
|
2020-12-29 00:05:33 +00:00
|
|
|
FSEntry_t entry = {.optionUnion = fno.fattrib, .name = strrchr(path, '/') + 1};
|
|
|
|
if (!(*entry.name))
|
|
|
|
entry.name = "Root";
|
|
|
|
return entry;
|
2020-12-24 23:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *GetFileAttribs(FSEntry_t entry){
|
|
|
|
char *ret = CpyStr("RHSVDA");
|
|
|
|
MaskIn(ret, entry.optionUnion, '-');
|
|
|
|
return ret;
|
2020-12-28 01:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 22:11:57 +01:00
|
|
|
// Returns 1 if a file exists, 0 if it does not
|
2020-12-31 11:55:26 +00:00
|
|
|
bool FileExists(const char* path){
|
2020-12-28 01:29:58 +00:00
|
|
|
FRESULT fr;
|
|
|
|
FILINFO fno;
|
|
|
|
|
|
|
|
fr = f_stat(path, &fno);
|
|
|
|
|
|
|
|
return !(fr & FR_NO_FILE);
|
|
|
|
}
|