- tweak: Change content hold think
This commit is contained in:
@@ -75,5 +75,5 @@ public sealed class FileApi : IReadWriteFileApi
|
||||
return File.Exists(fullPath);
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllFiles => Directory.EnumerateFiles(RootPath, "*.*", SearchOption.AllDirectories);
|
||||
public IEnumerable<string> AllFiles => Directory.EnumerateFiles(RootPath, "*.*", SearchOption.AllDirectories).Select(p=>p.Replace(RootPath,"").Substring(1));
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
using Nebula.Shared.Models;
|
||||
using Robust.LoaderApi;
|
||||
|
||||
@@ -6,26 +9,59 @@ namespace Nebula.Shared.FileApis;
|
||||
|
||||
public class HashApi : IFileApi
|
||||
{
|
||||
private readonly IFileApi _fileApi;
|
||||
public Dictionary<string, RobustManifestItem> Manifest;
|
||||
private readonly IReadWriteFileApi _fileApi;
|
||||
private readonly Dictionary<string, RobustManifestItem> _manifest;
|
||||
public IReadOnlyDictionary<string, RobustManifestItem> Manifest => _manifest;
|
||||
|
||||
public HashApi(List<RobustManifestItem> manifest, IFileApi fileApi)
|
||||
public HashApi(List<RobustManifestItem> manifest, IReadWriteFileApi fileApi)
|
||||
{
|
||||
_fileApi = fileApi;
|
||||
Manifest = new Dictionary<string, RobustManifestItem>();
|
||||
foreach (var item in manifest) Manifest.TryAdd(item.Path, item);
|
||||
_manifest = new Dictionary<string, RobustManifestItem>();
|
||||
foreach (var item in manifest) _manifest.TryAdd(item.Path, item);
|
||||
}
|
||||
|
||||
public bool TryOpen(string path,[NotNullWhen(true)] out Stream? stream)
|
||||
{
|
||||
if (path[0] == '/') path = path.Substring(1);
|
||||
|
||||
if (Manifest.TryGetValue(path, out var a) && _fileApi.TryOpen(a.Hash, out stream))
|
||||
if (_manifest.TryGetValue(path, out var a) && _fileApi.TryOpen(GetManifestPath(a), out stream))
|
||||
return true;
|
||||
|
||||
stream = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllFiles => Manifest.Keys;
|
||||
public bool TryOpen(RobustManifestItem item ,[NotNullWhen(true)] out Stream? stream){
|
||||
if(_fileApi.TryOpen(GetManifestPath(item), out stream))
|
||||
return true;
|
||||
|
||||
stream = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryOpenByHash(string hash ,[NotNullWhen(true)] out Stream? stream){
|
||||
if(_fileApi.TryOpen(GetManifestPath(hash), out stream))
|
||||
return true;
|
||||
|
||||
stream = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Save(RobustManifestItem item, Stream stream){
|
||||
return _fileApi.Save(GetManifestPath(item), stream);
|
||||
}
|
||||
|
||||
public bool Has(RobustManifestItem item){
|
||||
return _fileApi.Has(GetManifestPath(item));
|
||||
}
|
||||
|
||||
private string GetManifestPath(RobustManifestItem item){
|
||||
return GetManifestPath(item.Hash);
|
||||
}
|
||||
|
||||
public static string GetManifestPath(string hash){
|
||||
return hash[0].ToString() + hash[1].ToString() + '/' + hash;
|
||||
}
|
||||
|
||||
public IEnumerable<string> AllFiles => _manifest.Keys;
|
||||
}
|
||||
Reference in New Issue
Block a user