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() {};
|
2016-11-20 08:09:07 -05:00
|
|
|
File(std::string file) : filePath(file) { this->read(); };
|
2016-09-19 16:52:00 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
bool exists() { return !this->buffer.empty(); };
|
|
|
|
std::string getName() { return this->filePath; };
|
|
|
|
std::string& getBuffer() { return this->buffer; };
|
2016-09-19 16:52:00 -04:00
|
|
|
|
|
|
|
private:
|
2016-11-20 08:09:07 -05:00
|
|
|
std::string filePath;
|
|
|
|
std::string buffer;
|
2016-09-19 16:52:00 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void read();
|
2016-09-19 16:52:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileReader
|
2015-12-23 21:26:46 -05:00
|
|
|
{
|
|
|
|
public:
|
2016-11-20 08:09:07 -05:00
|
|
|
FileReader() : size(-1), name(), handle(0) {};
|
2016-09-19 16:52:00 -04:00
|
|
|
FileReader(std::string file);
|
|
|
|
~FileReader();
|
2015-12-23 21:26:46 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
bool exists();
|
|
|
|
std::string getName();
|
|
|
|
std::string getBuffer();
|
|
|
|
int getSize();
|
|
|
|
bool read(void* buffer, size_t size);
|
|
|
|
void seek(int offset, int origin);
|
2015-12-23 21:26:46 -05:00
|
|
|
|
|
|
|
private:
|
2016-11-20 08:09:07 -05: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:
|
2016-11-20 08:09:07 -05:00
|
|
|
FileWriter(std::string file) : filePath(file), handle(0) { this->open(); };
|
|
|
|
~FileWriter() { this->close(); };
|
2016-01-10 06:25:31 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void write(std::string data);
|
2016-01-10 06:25:31 -05:00
|
|
|
|
|
|
|
private:
|
2016-11-20 08:09:07 -05:00
|
|
|
int handle;
|
|
|
|
std::string filePath;
|
2016-01-10 06:25:31 -05:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
void open();
|
|
|
|
void close();
|
2016-01-10 06:25:31 -05:00
|
|
|
};
|
|
|
|
|
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)
|
2016-11-20 08:09:07 -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
|
|
|
};
|
|
|
|
}
|