2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_STORAGE_H
|
|
|
|
#define ENGINE_STORAGE_H
|
|
|
|
|
|
|
|
#include "kernel.h"
|
|
|
|
|
2022-11-05 13:13:28 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
2019-03-12 17:43:03 +00:00
|
|
|
enum
|
|
|
|
{
|
2021-09-13 08:06:34 +00:00
|
|
|
MAX_PATHS = 16
|
2019-03-12 17:43:03 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class IStorage : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("storage", 0)
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
2010-10-06 21:07:35 +00:00
|
|
|
TYPE_SAVE = 0,
|
2012-01-09 00:38:45 +00:00
|
|
|
TYPE_ALL = -1,
|
2017-07-12 18:15:00 +00:00
|
|
|
TYPE_ABSOLUTE = -2,
|
2022-11-06 09:32:26 +00:00
|
|
|
/**
|
|
|
|
* Translates to TYPE_SAVE if a path is relative
|
|
|
|
* and to TYPE_ABSOLUTE if a path is absolute.
|
2023-01-22 16:06:10 +00:00
|
|
|
* Only usable with OpenFile, ReadFile, ReadFileStr,
|
|
|
|
* GetCompletePath, FileExists and FolderExists.
|
2022-11-06 09:32:26 +00:00
|
|
|
*/
|
|
|
|
TYPE_SAVE_OR_ABSOLUTE = -3,
|
|
|
|
/**
|
|
|
|
* Translates to TYPE_ALL if a path is relative
|
|
|
|
* and to TYPE_ABSOLUTE if a path is absolute.
|
2023-01-22 16:06:10 +00:00
|
|
|
* Only usable with OpenFile, ReadFile, ReadFileStr,
|
|
|
|
* GetCompletePath, FileExists and FolderExists.
|
2022-11-06 09:32:26 +00:00
|
|
|
*/
|
|
|
|
TYPE_ALL_OR_ABSOLUTE = -4,
|
2012-01-09 00:38:45 +00:00
|
|
|
|
|
|
|
STORAGETYPE_BASIC = 0,
|
|
|
|
STORAGETYPE_SERVER,
|
|
|
|
STORAGETYPE_CLIENT,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-10-06 21:07:35 +00:00
|
|
|
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0;
|
2021-08-23 10:49:15 +00:00
|
|
|
virtual void ListDirectoryInfo(int Type, const char *pPath, FS_LISTDIR_CALLBACK_FILEINFO pfnCallback, void *pUser) = 0;
|
2022-06-13 16:28:13 +00:00
|
|
|
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = nullptr, int BufferSize = 0) = 0;
|
2023-01-22 16:06:10 +00:00
|
|
|
virtual bool FileExists(const char *pFilename, int Type) = 0;
|
|
|
|
virtual bool FolderExists(const char *pFilename, int Type) = 0;
|
2022-06-14 18:15:05 +00:00
|
|
|
virtual bool ReadFile(const char *pFilename, int Type, void **ppResult, unsigned *pResultLen) = 0;
|
|
|
|
virtual char *ReadFileStr(const char *pFilename, int Type) = 0;
|
2011-02-21 10:23:30 +00:00
|
|
|
virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize) = 0;
|
2022-11-05 13:13:28 +00:00
|
|
|
virtual size_t FindFiles(const char *pFilename, const char *pPath, int Type, std::set<std::string> *pEntries) = 0;
|
2010-10-06 21:07:35 +00:00
|
|
|
virtual bool RemoveFile(const char *pFilename, int Type) = 0;
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual bool RenameFile(const char *pOldFilename, const char *pNewFilename, int Type) = 0;
|
2010-10-16 16:33:54 +00:00
|
|
|
virtual bool CreateFolder(const char *pFoldername, int Type) = 0;
|
2012-01-08 12:14:02 +00:00
|
|
|
virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) = 0;
|
2015-03-14 19:01:18 +00:00
|
|
|
|
|
|
|
virtual bool RemoveBinaryFile(const char *pFilename) = 0;
|
2020-09-10 18:14:47 +00:00
|
|
|
virtual bool RenameBinaryFile(const char *pOldFilename, const char *pNewFilename) = 0;
|
|
|
|
virtual const char *GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
|
2023-01-02 14:22:27 +00:00
|
|
|
virtual const char *GetBinaryPathAbsolute(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
|
2017-08-30 11:59:42 +00:00
|
|
|
|
|
|
|
static void StripPathAndExtension(const char *pFilename, char *pBuffer, int BufferSize);
|
2021-12-20 14:00:21 +00:00
|
|
|
static const char *FormatTmpPath(char *aBuf, unsigned BufSize, const char *pPath);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2021-12-21 16:19:42 +00:00
|
|
|
extern IStorage *CreateStorage(int StorageType, int NumArgs, const char **ppArguments);
|
2015-08-21 21:02:50 +00:00
|
|
|
extern IStorage *CreateLocalStorage();
|
2021-04-21 11:13:29 +00:00
|
|
|
extern IStorage *CreateTempStorage(const char *pDirectory);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#endif
|