[Filesystem] Cleanup

This commit is contained in:
Diavolo 2022-08-11 12:31:19 +02:00
parent 49ed76807b
commit 7b1b135e3f
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
2 changed files with 29 additions and 27 deletions

View File

@ -15,8 +15,11 @@ namespace Components
int handle;
const auto len = Game::FS_FOpenFileReadForThread(filePath.data(), &handle, thread);
if (handle)
if (!handle)
{
return;
}
auto* buf = AllocateFile(len + 1);
[[maybe_unused]] auto bytesRead = Game::FS_Read(buf, len, handle);
@ -30,7 +33,6 @@ namespace Components
this->buffer.append(buf, len);
FreeFile(buf);
}
}
void FileSystem::RawFile::read()
{

View File

@ -8,7 +8,7 @@ namespace Components
class AbstractFile
{
public:
virtual ~AbstractFile() {};
virtual ~AbstractFile() = default;
virtual bool exists() = 0;
virtual std::string getName() = 0;
@ -19,12 +19,12 @@ namespace Components
{
public:
File() = default;
File(std::string file) : filePath{std::move(file)} { this->read(); };
File(std::string file, Game::FsThread thread) : filePath{std::move(file)} { this->read(thread); };
File(std::string file) : filePath{std::move(file)} { this->read(); }
File(std::string file, Game::FsThread thread) : filePath{std::move(file)} { this->read(thread); }
bool exists() override { return !this->buffer.empty(); };
std::string getName() override { return this->filePath; };
std::string& getBuffer() override { return this->buffer; };
bool exists() override { return !this->buffer.empty(); }
std::string getName() override { return this->filePath; }
std::string& getBuffer() override { return this->buffer; }
private:
std::string filePath;
@ -36,12 +36,12 @@ namespace Components
class RawFile : public AbstractFile
{
public:
RawFile() {};
RawFile(const std::string& file) : filePath(file) { this->read(); };
RawFile() = default;
RawFile(std::string file) : filePath(std::move(file)) { this->read(); }
bool exists() override { return !this->buffer.empty(); };
std::string getName() override { return this->filePath; };
std::string& getBuffer() override { return this->buffer; };
bool exists() override { return !this->buffer.empty(); }
std::string getName() override { return this->filePath; }
std::string& getBuffer() override { return this->buffer; }
private:
std::string filePath;
@ -53,7 +53,7 @@ namespace Components
class FileReader
{
public:
FileReader() : handle(0), size(-1), name() {};
FileReader() : handle(0), size(-1), name() {}
FileReader(const std::string& file);
~FileReader();
@ -73,8 +73,8 @@ namespace Components
class FileWriter
{
public:
FileWriter(const std::string& file, bool append = false) : handle(0), filePath(file) { this->open(append); };
~FileWriter() { this->close(); };
FileWriter(std::string file, bool append = false) : handle(0), filePath(std::move(file)) { this->open(append); }
~FileWriter() { this->close(); }
void write(const std::string& data);