1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
3 | #ifndef ENGINE_STORAGE_H |
4 | #define ENGINE_STORAGE_H |
5 | |
6 | #include <base/hash.h> |
7 | #include <base/types.h> |
8 | |
9 | #include "kernel.h" |
10 | |
11 | #include <set> |
12 | #include <string> |
13 | |
14 | enum |
15 | { |
16 | MAX_PATHS = 16 |
17 | }; |
18 | |
19 | class IStorage : public IInterface |
20 | { |
21 | MACRO_INTERFACE("storage" ) |
22 | public: |
23 | enum |
24 | { |
25 | TYPE_SAVE = 0, |
26 | TYPE_ALL = -1, |
27 | TYPE_ABSOLUTE = -2, |
28 | /** |
29 | * Translates to TYPE_SAVE if a path is relative |
30 | * and to TYPE_ABSOLUTE if a path is absolute. |
31 | * Only usable with OpenFile, ReadFile, ReadFileStr, |
32 | * GetCompletePath, FileExists and FolderExists. |
33 | */ |
34 | TYPE_SAVE_OR_ABSOLUTE = -3, |
35 | /** |
36 | * Translates to TYPE_ALL if a path is relative |
37 | * and to TYPE_ABSOLUTE if a path is absolute. |
38 | * Only usable with OpenFile, ReadFile, ReadFileStr, |
39 | * GetCompletePath, FileExists and FolderExists. |
40 | */ |
41 | TYPE_ALL_OR_ABSOLUTE = -4, |
42 | |
43 | STORAGETYPE_BASIC = 0, |
44 | STORAGETYPE_SERVER, |
45 | STORAGETYPE_CLIENT, |
46 | }; |
47 | |
48 | virtual int NumPaths() const = 0; |
49 | |
50 | virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0; |
51 | virtual void ListDirectoryInfo(int Type, const char *pPath, FS_LISTDIR_CALLBACK_FILEINFO pfnCallback, void *pUser) = 0; |
52 | virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = nullptr, int BufferSize = 0) = 0; |
53 | virtual bool FileExists(const char *pFilename, int Type) = 0; |
54 | virtual bool FolderExists(const char *pFilename, int Type) = 0; |
55 | virtual bool ReadFile(const char *pFilename, int Type, void **ppResult, unsigned *pResultLen) = 0; |
56 | virtual char *ReadFileStr(const char *pFilename, int Type) = 0; |
57 | virtual bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc = nullptr) = 0; |
58 | virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize) = 0; |
59 | virtual size_t FindFiles(const char *pFilename, const char *pPath, int Type, std::set<std::string> *pEntries) = 0; |
60 | virtual bool RemoveFile(const char *pFilename, int Type) = 0; |
61 | virtual bool RemoveFolder(const char *pFilename, int Type) = 0; |
62 | virtual bool RenameFile(const char *pOldFilename, const char *pNewFilename, int Type) = 0; |
63 | virtual bool CreateFolder(const char *pFoldername, int Type) = 0; |
64 | virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) = 0; |
65 | |
66 | virtual bool RemoveBinaryFile(const char *pFilename) = 0; |
67 | virtual bool RenameBinaryFile(const char *pOldFilename, const char *pNewFilename) = 0; |
68 | virtual const char *GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0; |
69 | virtual const char *GetBinaryPathAbsolute(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0; |
70 | |
71 | static void StripPathAndExtension(const char *pFilename, char *pBuffer, int BufferSize); |
72 | static const char *FormatTmpPath(char *aBuf, unsigned BufSize, const char *pPath); |
73 | }; |
74 | |
75 | extern IStorage *CreateStorage(int StorageType, int NumArgs, const char **ppArguments); |
76 | extern IStorage *CreateLocalStorage(); |
77 | extern IStorage *CreateTempStorage(const char *pDirectory); |
78 | |
79 | #endif |
80 | |