[Client] file functions now use FileSystem instead of Game functions
Updated accoding to momo5502's request.
This commit is contained in:
parent
49c2ccd700
commit
a2a303c3d0
@ -34,17 +34,14 @@ namespace Components
|
|||||||
mode = "write";
|
mode = "write";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fileHandle = 0;
|
|
||||||
if (mode == "write"s)
|
if (mode == "write"s)
|
||||||
{
|
{
|
||||||
fileHandle = Game::FS_FOpenFileWrite(path.data());
|
FileSystem::FileWriter(path).write(text);
|
||||||
}
|
}
|
||||||
else if (mode == "append"s)
|
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(<filepath>)
|
Script::AddFunction("fileRead", [](Game::scr_entref_t) // gsc: fileRead(<filepath>)
|
||||||
@ -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");
|
Game::Com_Printf(0, "^1fileRead: file not found!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* buffer = nullptr;
|
Game::Scr_AddString(FileSystem::FileReader(path).getBuffer().data());
|
||||||
Game::FS_ReadFile(path.data(), &buffer);
|
|
||||||
Game::Scr_AddString(buffer);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Script::AddFunction("fileExists", [](Game::scr_entref_t) // gsc: fileExists(<filepath>)
|
Script::AddFunction("fileExists", [](Game::scr_entref_t) // gsc: fileExists(<filepath>)
|
||||||
@ -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(<filepath>)
|
Script::AddFunction("fileRemove", [](Game::scr_entref_t) // gsc: fileRemove(<filepath>)
|
||||||
@ -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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user