2024-12-22 16:38:47 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2024-12-22 21:38:19 +03:00
|
|
|
|
using Nebula.Launcher.Models;
|
2024-12-22 16:38:47 +03:00
|
|
|
|
using Nebula.Launcher.Utils;
|
|
|
|
|
|
using Robust.LoaderApi;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Nebula.Launcher.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;
|
|
|
|
|
|
}
|