- SafeStorageService glow up.

- ILuaScriptLoader now inherits the ISafeStorageValidation interface.
 - LuaScriptLoader now uses the SafeStorageService.
This commit is contained in:
MapleWheels
2026-01-15 08:13:23 -05:00
committed by Maplewheels
parent 055a508901
commit 3ddaceb5ac
5 changed files with 261 additions and 179 deletions
@@ -2,7 +2,9 @@
namespace Barotrauma.LuaCs.Services.Safe;
public interface ISafeStorageService : IStorageService
public interface ISafeStorageService : IStorageService, ISafeStorageValidation { }
public interface ISafeStorageValidation
{
/// <summary>
/// Checks the given file path to see if it can be read. This includes any permissions, whitelists and OS checks.
@@ -16,26 +18,33 @@ public interface ISafeStorageService : IStorageService
/// <summary>
/// Adds the given path to the specified whitelists.
/// </summary>
/// <param name="path">Either the fully-qualified or local reference path to the given file.</param>
/// <param name="readOnly"></param>
/// <param name="path">The path to the file, exactly as it will be passed to the Try(Load|Save) methods in <see cref="StorageService"/>.</param>
/// <param name="readOnly">Whether to add it to the read whitelist only, or Read+Write whitelists.</param>
void AddFileToWhitelist(string path, bool readOnly = true);
/// <summary>
/// Removes the given path from all whitelists (Read|Write).
/// Adds the given collection of file paths to whitelists (Read|+Write)
/// </summary>
/// <param name="paths">The paths to the files, formatted exactly as it will be passed to the Try(Load|Save) methods in <see cref="StorageService"/>.</param>
/// <param name="readOnly">Whether to add it to the read whitelist only, or Read+Write whitelists.</param>
void AddFilesToWhitelist(ImmutableArray<string> paths, bool readOnly = true);
/// <summary>
/// Removes the given path from all whitelists (Read|+Write).
/// </summary>
/// <param name="path"></param>
void RemoveFileFromAllWhitelists(string path);
/// <summary>
/// Sets the whitelist filtering for read-only file permissions for the instance.
/// Sets the whitelist filtering for read-only file permissions for the instance. Overwrites previous list.
/// </summary>
/// <param name="filePaths">List of absolute file paths allowed.</param>
/// <param name="filePaths">List of file paths allowed, as will be passed to the <see cref="StorageService"/> Try(Load|Save) methods.</param>
FluentResults.Result SetReadOnlyWhitelist(ImmutableArray<string> filePaths);
/// <summary>
/// Sets the whitelist filtering for read & write file permissions for the instance.
/// Sets the whitelist filtering for read & write file permissions for the instance. Overwrites previous lists.
/// </summary>
/// <param name="filePaths">List of absolute file paths allowed.</param>
/// <param name="filePaths">List of file paths allowed, as will be passed to the <see cref="StorageService"/> Try(Load|Save) methods.</param>
FluentResults.Result SetReadWriteWhitelist(ImmutableArray<string> filePaths);
/// <summary>