DDraceNetwork Docs
storage.h
Go to the documentation of this file.
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
14enum
15{
16 MAX_PATHS = 16
17};
18
19class IStorage : public IInterface
20{
21 MACRO_INTERFACE("storage")
22public:
23 enum
24 {
42
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 RetrieveTimes(const char *pFilename, int Type, time_t *pCreated, time_t *pModified) = 0;
58 virtual bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc = nullptr) = 0;
59 virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize) = 0;
60 virtual size_t FindFiles(const char *pFilename, const char *pPath, int Type, std::set<std::string> *pEntries) = 0;
61 virtual bool RemoveFile(const char *pFilename, int Type) = 0;
62 virtual bool RemoveFolder(const char *pFilename, int Type) = 0;
63 virtual bool RenameFile(const char *pOldFilename, const char *pNewFilename, int Type) = 0;
64 virtual bool CreateFolder(const char *pFoldername, int Type) = 0;
65 virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize) = 0;
66
67 virtual bool RemoveBinaryFile(const char *pFilename) = 0;
68 virtual bool RenameBinaryFile(const char *pOldFilename, const char *pNewFilename) = 0;
69 virtual const char *GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
70 virtual const char *GetBinaryPathAbsolute(const char *pFilename, char *pBuffer, unsigned BufferSize) = 0;
71
72 static void StripPathAndExtension(const char *pFilename, char *pBuffer, int BufferSize);
73 static const char *FormatTmpPath(char *aBuf, unsigned BufSize, const char *pPath);
74};
75
76extern IStorage *CreateStorage(int StorageType, int NumArgs, const char **ppArguments);
78extern IStorage *CreateTempStorage(const char *pDirectory);
79
80#endif
Definition: kernel.h:10
Definition: storage.h:20
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser)=0
virtual const char * GetBinaryPath(const char *pFilename, char *pBuffer, unsigned BufferSize)=0
virtual bool FolderExists(const char *pFilename, int Type)=0
virtual bool RenameBinaryFile(const char *pOldFilename, const char *pNewFilename)=0
virtual const char * GetBinaryPathAbsolute(const char *pFilename, char *pBuffer, unsigned BufferSize)=0
virtual char * ReadFileStr(const char *pFilename, int Type)=0
virtual bool RenameFile(const char *pOldFilename, const char *pNewFilename, int Type)=0
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer=nullptr, int BufferSize=0)=0
virtual bool FileExists(const char *pFilename, int Type)=0
static void StripPathAndExtension(const char *pFilename, char *pBuffer, int BufferSize)
Definition: storage.cpp:885
static const char * FormatTmpPath(char *aBuf, unsigned BufSize, const char *pPath)
Definition: storage.cpp:907
virtual bool RemoveFolder(const char *pFilename, int Type)=0
virtual bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc=nullptr)=0
virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize)=0
virtual bool CreateFolder(const char *pFoldername, int Type)=0
virtual bool RetrieveTimes(const char *pFilename, int Type, time_t *pCreated, time_t *pModified)=0
virtual bool ReadFile(const char *pFilename, int Type, void **ppResult, unsigned *pResultLen)=0
virtual bool RemoveFile(const char *pFilename, int Type)=0
virtual void GetCompletePath(int Type, const char *pDir, char *pBuffer, unsigned BufferSize)=0
virtual int NumPaths() const =0
virtual size_t FindFiles(const char *pFilename, const char *pPath, int Type, std::set< std::string > *pEntries)=0
virtual void ListDirectoryInfo(int Type, const char *pPath, FS_LISTDIR_CALLBACK_FILEINFO pfnCallback, void *pUser)=0
virtual bool RemoveBinaryFile(const char *pFilename)=0
@ TYPE_ABSOLUTE
Definition: storage.h:27
@ STORAGETYPE_CLIENT
Definition: storage.h:45
@ TYPE_ALL_OR_ABSOLUTE
Definition: storage.h:41
@ STORAGETYPE_BASIC
Definition: storage.h:43
@ TYPE_ALL
Definition: storage.h:26
@ TYPE_SAVE_OR_ABSOLUTE
Definition: storage.h:34
@ STORAGETYPE_SERVER
Definition: storage.h:44
@ TYPE_SAVE
Definition: storage.h:25
#define MACRO_INTERFACE(Name)
Definition: kernel.h:25
void * IOHANDLE
Definition: logger.h:11
IStorage * CreateTempStorage(const char *pDirectory)
Definition: storage.cpp:932
IStorage * CreateStorage(int StorageType, int NumArgs, const char **ppArguments)
Definition: storage.cpp:913
IStorage * CreateLocalStorage()
Definition: storage.cpp:918
@ MAX_PATHS
Definition: storage.h:16
Definition: hash.h:15
int(* FS_LISTDIR_CALLBACK_FILEINFO)(const CFsFileInfo *info, int is_dir, int dir_type, void *user)
Definition: types.h:29
int(* FS_LISTDIR_CALLBACK)(const char *name, int is_dir, int dir_type, void *user)
Definition: types.h:20