[Filesystem] Cleanup
This commit is contained in:
parent
49ed76807b
commit
7b1b135e3f
@ -15,8 +15,11 @@ namespace Components
|
|||||||
int handle;
|
int handle;
|
||||||
const auto len = Game::FS_FOpenFileReadForThread(filePath.data(), &handle, thread);
|
const auto len = Game::FS_FOpenFileReadForThread(filePath.data(), &handle, thread);
|
||||||
|
|
||||||
if (handle)
|
if (!handle)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto* buf = AllocateFile(len + 1);
|
auto* buf = AllocateFile(len + 1);
|
||||||
|
|
||||||
[[maybe_unused]] auto bytesRead = Game::FS_Read(buf, len, handle);
|
[[maybe_unused]] auto bytesRead = Game::FS_Read(buf, len, handle);
|
||||||
@ -30,7 +33,6 @@ namespace Components
|
|||||||
this->buffer.append(buf, len);
|
this->buffer.append(buf, len);
|
||||||
FreeFile(buf);
|
FreeFile(buf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void FileSystem::RawFile::read()
|
void FileSystem::RawFile::read()
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ namespace Components
|
|||||||
class AbstractFile
|
class AbstractFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~AbstractFile() {};
|
virtual ~AbstractFile() = default;
|
||||||
|
|
||||||
virtual bool exists() = 0;
|
virtual bool exists() = 0;
|
||||||
virtual std::string getName() = 0;
|
virtual std::string getName() = 0;
|
||||||
@ -19,12 +19,12 @@ namespace Components
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
File() = default;
|
File() = default;
|
||||||
File(std::string file) : filePath{std::move(file)} { this->read(); };
|
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, Game::FsThread thread) : filePath{std::move(file)} { this->read(thread); }
|
||||||
|
|
||||||
bool exists() override { return !this->buffer.empty(); };
|
bool exists() override { return !this->buffer.empty(); }
|
||||||
std::string getName() override { return this->filePath; };
|
std::string getName() override { return this->filePath; }
|
||||||
std::string& getBuffer() override { return this->buffer; };
|
std::string& getBuffer() override { return this->buffer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
@ -36,12 +36,12 @@ namespace Components
|
|||||||
class RawFile : public AbstractFile
|
class RawFile : public AbstractFile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RawFile() {};
|
RawFile() = default;
|
||||||
RawFile(const std::string& file) : filePath(file) { this->read(); };
|
RawFile(std::string file) : filePath(std::move(file)) { this->read(); }
|
||||||
|
|
||||||
bool exists() override { return !this->buffer.empty(); };
|
bool exists() override { return !this->buffer.empty(); }
|
||||||
std::string getName() override { return this->filePath; };
|
std::string getName() override { return this->filePath; }
|
||||||
std::string& getBuffer() override { return this->buffer; };
|
std::string& getBuffer() override { return this->buffer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
@ -53,7 +53,7 @@ namespace Components
|
|||||||
class FileReader
|
class FileReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileReader() : handle(0), size(-1), name() {};
|
FileReader() : handle(0), size(-1), name() {}
|
||||||
FileReader(const std::string& file);
|
FileReader(const std::string& file);
|
||||||
~FileReader();
|
~FileReader();
|
||||||
|
|
||||||
@ -73,8 +73,8 @@ namespace Components
|
|||||||
class FileWriter
|
class FileWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileWriter(const std::string& file, bool append = false) : handle(0), filePath(file) { this->open(append); };
|
FileWriter(std::string file, bool append = false) : handle(0), filePath(std::move(file)) { this->open(append); }
|
||||||
~FileWriter() { this->close(); };
|
~FileWriter() { this->close(); }
|
||||||
|
|
||||||
void write(const std::string& data);
|
void write(const std::string& data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user