- tweak: refactor funny

This commit is contained in:
2025-01-05 17:05:23 +03:00
parent 5b24f915a2
commit 8619e248fd
67 changed files with 485 additions and 492 deletions

View File

@@ -0,0 +1,30 @@
using Nebula.Shared.Models;
using Robust.LoaderApi;
namespace Nebula.Shared.FileApis;
public class HashApi : IFileApi
{
private readonly IFileApi _fileApi;
public Dictionary<string, RobustManifestItem> Manifest;
public HashApi(List<RobustManifestItem> manifest, IFileApi fileApi)
{
_fileApi = fileApi;
Manifest = new Dictionary<string, RobustManifestItem>();
foreach (var item in manifest) Manifest.TryAdd(item.Path, item);
}
public bool TryOpen(string path, out Stream? stream)
{
if (path[0] == '/') path = path.Substring(1);
if (Manifest.TryGetValue(path, out var a) && _fileApi.TryOpen(a.Hash, out stream))
return true;
stream = null;
return false;
}
public IEnumerable<string> AllFiles => Manifest.Keys;
}