Merge pull request #422 from diamante0018/cleanup-filesystem
[Filesystem] Cleanup
This commit is contained in:
commit
d79b3710a4
@ -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()
|
||||
@ -200,7 +202,7 @@ namespace Components
|
||||
return fileList;
|
||||
}
|
||||
|
||||
bool FileSystem::DeleteFile(const std::string& folder, const std::string& file)
|
||||
bool FileSystem::_DeleteFile(const std::string& folder, const std::string& file)
|
||||
{
|
||||
char path[MAX_PATH] = { 0 };
|
||||
Game::FS_BuildPathToFile(Dvar::Var("fs_basepath").get<const char*>(), reinterpret_cast<char*>(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast<char**>(&path));
|
||||
|
@ -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);
|
||||
|
||||
@ -92,7 +92,7 @@ namespace Components
|
||||
static std::filesystem::path GetAppdataPath();
|
||||
static std::vector<std::string> GetFileList(const std::string& path, const std::string& extension);
|
||||
static std::vector<std::string> GetSysFileList(const std::string& path, const std::string& extension, bool folders = false);
|
||||
static bool DeleteFile(const std::string& folder, const std::string& file);
|
||||
static bool _DeleteFile(const std::string& folder, const std::string& file);
|
||||
|
||||
private:
|
||||
static std::mutex Mutex;
|
||||
|
@ -226,8 +226,8 @@ namespace Components
|
||||
|
||||
Logger::Print("Deleting demo {}...\n", info.name);
|
||||
|
||||
FileSystem::DeleteFile("demos", info.name + ".dm_13");
|
||||
FileSystem::DeleteFile("demos", info.name + ".dm_13.json");
|
||||
FileSystem::_DeleteFile("demos", info.name + ".dm_13");
|
||||
FileSystem::_DeleteFile("demos", info.name + ".dm_13.json");
|
||||
|
||||
// Reset our ui_demo_* dvars here, because the theater menu needs it.
|
||||
Dvar::Var("ui_demo_mapname").set("");
|
||||
@ -310,8 +310,8 @@ namespace Components
|
||||
for (int i = 0; i < numDel; ++i)
|
||||
{
|
||||
Logger::Print("Deleting old demo {}\n", files[i]);
|
||||
FileSystem::DeleteFile("demos", files[i].data());
|
||||
FileSystem::DeleteFile("demos", Utils::String::VA("%s.json", files[i].data()));
|
||||
FileSystem::_DeleteFile("demos", files[i].data());
|
||||
FileSystem::_DeleteFile("demos", Utils::String::VA("%s.json", files[i].data()));
|
||||
}
|
||||
|
||||
Command::Execute(Utils::String::VA("record auto_%lld", time(nullptr)), true);
|
||||
|
@ -40,7 +40,7 @@ namespace Components
|
||||
assert(dvar);
|
||||
assert(parsedValue);
|
||||
|
||||
Game::Dvar_SetFromStringFromSource(dvar, parsedValue, Game::DvarSetSource::DVAR_SOURCE_INTERNAL);
|
||||
Game::Dvar_SetFromStringFromSource(dvar, parsedValue, Game::DVAR_SOURCE_INTERNAL);
|
||||
Logger::Print("Overriding '{}' from '{}'\n", dvar->name, filename);
|
||||
|
||||
// Successfully found and tried to apply the string value to the dvar
|
||||
|
Loading…
Reference in New Issue
Block a user