[GSC] Add back fileremove (sandboxed!) (#509)

This commit is contained in:
Edo 2022-10-04 22:56:42 +01:00 committed by GitHub
parent 9ea52060f5
commit 6bca6f9df9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,6 +106,31 @@ namespace Components
Game::Scr_AddBool(FileSystem::FileReader(scriptData).exists());
});
Script::AddFunction("FileRemove", [] // gsc: FileRemove(<filepath>)
{
const auto* path = Game::Scr_GetString(0);
if (path == nullptr)
{
Game::Scr_ParamError(0, "^1FileRemove: filepath is not defined!\n");
return;
}
for (std::size_t i = 0; i < ARRAYSIZE(QueryStrings); ++i)
{
if (std::strstr(path, QueryStrings[i]) != nullptr)
{
Logger::Print("^1FileRemove: directory traversal is not allowed!\n");
return;
}
}
const auto p = "scriptdata" / std::filesystem::path(path);
const auto folder = p.parent_path().string();
const auto file = p.filename().string();
Game::Scr_AddInt(FileSystem::_DeleteFile(folder, file));
});
}
IO::IO()