2015-12-23 21:26:46 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class FileSystem : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-09-19 16:52:00 -04:00
|
|
|
class File
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
File() {};
|
|
|
|
File(std::string file) : FilePath(file) { this->Read(); };
|
|
|
|
|
|
|
|
bool Exists() { return !this->Buffer.empty(); };
|
|
|
|
std::string GetName() { return this->FilePath; };
|
|
|
|
std::string& GetBuffer() { return this->Buffer; };
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string FilePath;
|
|
|
|
std::string Buffer;
|
|
|
|
|
|
|
|
void Read();
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileReader
|
2015-12-23 21:26:46 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-09-19 16:52:00 -04:00
|
|
|
FileReader() : Size(-1), Name(), Handle(0) {};
|
|
|
|
FileReader(std::string file);
|
|
|
|
~FileReader();
|
2015-12-23 21:26:46 -05:00
|
|
|
|
2016-09-14 17:01:53 -04:00
|
|
|
bool Exists();
|
|
|
|
std::string GetName();
|
|
|
|
std::string GetBuffer();
|
2016-11-12 06:51:34 -05:00
|
|
|
int GetSize();
|
2016-09-14 17:01:53 -04:00
|
|
|
bool Read(void* buffer, size_t size);
|
|
|
|
void Seek(int offset, int origin);
|
2015-12-23 21:26:46 -05:00
|
|
|
|
|
|
|
private:
|
2016-09-14 17:01:53 -04:00
|
|
|
int Handle;
|
|
|
|
int Size;
|
|
|
|
std::string Name;
|
2015-12-23 21:26:46 -05:00
|
|
|
};
|
|
|
|
|
2016-01-10 06:25:31 -05:00
|
|
|
class FileWriter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileWriter(std::string file) : FilePath(file), Handle(0) { this->Open(); };
|
|
|
|
~FileWriter() { this->Close(); };
|
|
|
|
|
|
|
|
void Write(std::string data);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int Handle;
|
|
|
|
std::string FilePath;
|
|
|
|
|
|
|
|
void Open();
|
|
|
|
void Close();
|
|
|
|
};
|
|
|
|
|
2016-08-15 10:40:30 -04:00
|
|
|
FileSystem();
|
2016-11-12 06:51:34 -05:00
|
|
|
~FileSystem();
|
2016-08-15 10:40:30 -04:00
|
|
|
|
2016-09-16 05:04:28 -04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2015-12-23 21:26:46 -05:00
|
|
|
const char* GetName() { return "FileSystem"; };
|
2016-08-15 10:40:30 -04:00
|
|
|
#endif
|
2016-01-02 12:28:47 -05:00
|
|
|
|
2016-01-10 06:25:31 -05:00
|
|
|
static std::vector<std::string> GetFileList(std::string path, std::string extension);
|
2016-04-04 11:18:57 -04:00
|
|
|
static std::vector<std::string> GetSysFileList(std::string path, std::string extension, bool folders = false);
|
2016-01-10 06:25:31 -05:00
|
|
|
static void DeleteFile(std::string folder, std::string file);
|
|
|
|
|
2016-01-02 12:28:47 -05:00
|
|
|
private:
|
2016-11-13 05:58:23 -05:00
|
|
|
static std::mutex Mutex;
|
2016-11-12 06:51:34 -05:00
|
|
|
static Utils::Memory::Allocator MemAllocator;
|
|
|
|
|
2016-11-13 05:58:23 -05:00
|
|
|
static int ReadFile(const char* path, char** buffer);
|
2016-11-13 09:04:34 -05:00
|
|
|
static char* AllocateFile(int size);
|
2016-11-12 06:51:34 -05:00
|
|
|
static void FreeFile(void* buffer);
|
2016-06-06 07:00:48 -04:00
|
|
|
|
|
|
|
static void RegisterFolder(const char* folder);
|
|
|
|
|
|
|
|
static void RegisterFolders();
|
|
|
|
static void StartupStub();
|
2016-01-02 12:28:47 -05:00
|
|
|
static int ExecIsFSStub(const char* execFilename);
|
2015-12-23 21:26:46 -05:00
|
|
|
};
|
|
|
|
}
|