forked from DustinWatts/FreeTouchDeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStorage.h
87 lines (82 loc) · 3.43 KB
/
Storage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include "globals.hpp"
#include "UserConfig.h"
#include "FS.h"
namespace FreeTouchDeck
{
class FileSystem_t;
typedef size_t (*SizeCallback_t)();
typedef bool (*BeginCallback_t)();
typedef bool (*BooleanCallback_t)();
typedef bool (*CheckStatusCallback_t)();
typedef const char * (*StorageType_t)();
typedef fs::File (*OpenCallback_t)(const char *path, const char *mode);
typedef bool (*OperationCallback_t)(const char *path);
typedef bool (*FromToOperation_cb)(const char *pathFrom, const char *pathTo);
typedef bool (*OpenStringCallback_t)(const String &path, const char *mode);
typedef fs::File (*StringOpenCallback_t)(const String &path, const char *mode);
typedef bool (*StringOperationCallback_t)(const String &path);
typedef bool (*StringFromToOprationCallback_t)(const String &pathFrom, const String &pathTo);
class FileSystem_t
{
public:
SizeCallback_t totalBytes = NULL;
SizeCallback_t usedBytes = NULL;
fs::FS &fileSystem;
const char *Name;
StorageType_t StorageType;
BeginCallback_t Begin = NULL;
bool Initialized = false;
OpenCallback_t open;
BooleanCallback_t end;
OperationCallback_t exists;
OperationCallback_t remove;
FromToOperation_cb rename;
OperationCallback_t mkdir;
OperationCallback_t rmdir;
StringOpenCallback_t stopen;
StringOperationCallback_t stexists;
StringOperationCallback_t stremove;
StringFromToOprationCallback_t strename;
StringOperationCallback_t stmkdir;
StringOperationCallback_t strmdir;
CheckStatusCallback_t inserted;
bool External;
FileSystem_t(fs::FS&_fileSystem, const char * _Name, BeginCallback_t _Begin, SizeCallback_t _totalBytes, SizeCallback_t _usedBytes, StorageType_t _StorageType, OpenCallback_t _open,
OperationCallback_t _exists,
OperationCallback_t _remove,
FromToOperation_cb _rename,
OperationCallback_t _mkdir,
OperationCallback_t _rmdir,
StringOpenCallback_t _str_open,
StringOperationCallback_t _str_exists,
StringOperationCallback_t _str_remove,
StringFromToOprationCallback_t _str_rename,
StringOperationCallback_t _str_mkdir,
StringOperationCallback_t _str_rmdir, CheckStatusCallback_t _inserted, bool _external, BooleanCallback_t _end );
};
extern FileSystem_t *ftdfs;
inline bool isStorageInitialized() { return ftdfs && ftdfs->Initialized; }
void InitFileSystem();
bool InitializeStorage();
bool checkStatusHold();
/**
* @brief This function checks if a file exists and returns a boolean accordingly.
It then prints a debug message to the serial as wel as the tft.
*
* @param filename (const char *)
*
* @return boolean True if succeeded. False otherwise.
*
* @note Pass the filename including a leading /
*/
bool checkfile(const char *filename);
void ShowDir();
void ShowDir(FileSystem_t * targetFS);
size_t GetFileSize(const char * fileName, FileSystem_t * fileSystem);
bool ShowFileContent(const char * fileName, FileSystem_t * fileSystem);
bool CopyFile(const char *source, FileSystem_t *fromSystem,FileSystem_t *toSystem);
bool CopyFile(const char *source, const char *target, FileSystem_t *fromSystem, FileSystem_t *toSystem);
bool CopyFile(fs::File *source, const char *targetName, FileSystem_t *toSystem);
bool CopyFile(fs::File *source, FileSystem_t *toSystem);
};