From a2a303c3d0500c1f0bde8250ae375fd747e8b6e4 Mon Sep 17 00:00:00 2001 From: Joelrau Date: Wed, 2 Sep 2020 13:14:38 +0300 Subject: [PATCH] [Client] file functions now use FileSystem instead of Game functions Updated accoding to momo5502's request. --- src/Components/Modules/Client.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Components/Modules/Client.cpp b/src/Components/Modules/Client.cpp index e46c4047..496a57b1 100644 --- a/src/Components/Modules/Client.cpp +++ b/src/Components/Modules/Client.cpp @@ -34,17 +34,14 @@ namespace Components mode = "write"; } - auto fileHandle = 0; if (mode == "write"s) { - fileHandle = Game::FS_FOpenFileWrite(path.data()); + FileSystem::FileWriter(path).write(text); } else if (mode == "append"s) { - fileHandle = Game::FS_FOpenFileAppend(path.data()); + FileSystem::FileWriter(path, true).write(text); } - Game::FS_Write(text, strlen(text), fileHandle); - Game::FS_FCloseFile(fileHandle); }); Script::AddFunction("fileRead", [](Game::scr_entref_t) // gsc: fileRead() @@ -67,15 +64,13 @@ namespace Components } } - if (Game::FS_FileExists(path.data()) == false) + if (!FileSystem::FileReader(path).exists()) { Game::Com_Printf(0, "^1fileRead: file not found!\n"); return; } - char* buffer = nullptr; - Game::FS_ReadFile(path.data(), &buffer); - Game::Scr_AddString(buffer); + Game::Scr_AddString(FileSystem::FileReader(path).getBuffer().data()); }); Script::AddFunction("fileExists", [](Game::scr_entref_t) // gsc: fileExists() @@ -98,7 +93,7 @@ namespace Components } } - Game::Scr_AddInt(Game::FS_FileExists(path.data())); + Game::Scr_AddInt(FileSystem::FileReader(path).exists()); }); Script::AddFunction("fileRemove", [](Game::scr_entref_t) // gsc: fileRemove() @@ -121,7 +116,10 @@ namespace Components } } - Game::Scr_AddInt(Game::FS_Remove(path.data())); + auto p = std::filesystem::path(path); + std::string folder = p.parent_path().string(); + std::string file = p.filename().string(); + Game::Scr_AddInt(FileSystem::DeleteFile(folder, file)); }); }