diff --git a/src/Components/Modules/FileSystem.cpp b/src/Components/Modules/FileSystem.cpp index d8b61308..00408819 100644 --- a/src/Components/Modules/FileSystem.cpp +++ b/src/Components/Modules/FileSystem.cpp @@ -15,21 +15,23 @@ namespace Components int handle; const auto len = Game::FS_FOpenFileReadForThread(filePath.data(), &handle, thread); - if (handle) + if (!handle) { - auto* buf = AllocateFile(len + 1); - - [[maybe_unused]] auto bytesRead = Game::FS_Read(buf, len, handle); - - assert(bytesRead == len); - - buf[len] = '\0'; - - Game::FS_FCloseFile(handle); - - this->buffer.append(buf, len); - FreeFile(buf); + return; } + + auto* buf = AllocateFile(len + 1); + + [[maybe_unused]] auto bytesRead = Game::FS_Read(buf, len, handle); + + assert(bytesRead == len); + + buf[len] = '\0'; + + Game::FS_FCloseFile(handle); + + this->buffer.append(buf, len); + FreeFile(buf); } void FileSystem::RawFile::read() diff --git a/src/Components/Modules/FileSystem.hpp b/src/Components/Modules/FileSystem.hpp index aca27f7a..542e68e7 100644 --- a/src/Components/Modules/FileSystem.hpp +++ b/src/Components/Modules/FileSystem.hpp @@ -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);