- tweak: View autogenerator

This commit is contained in:
2025-07-02 21:32:51 +03:00
parent 9e95d68c4a
commit 517fadaab8
57 changed files with 316 additions and 286 deletions

View File

@@ -13,10 +13,24 @@ public partial class ContentService
{
public readonly IReadWriteFileApi ContentFileApi = fileService.CreateFileApi("content");
public readonly IReadWriteFileApi ManifestFileApi = fileService.CreateFileApi("manifest");
public bool CheckManifestExist(RobustManifestItem item)
public void SetServerHash(string address, string hash)
{
return ContentFileApi.Has(item.Hash);
var dict = varService.GetConfigValue(CurrentConVar.ServerManifestHash)!;
if (dict.TryGetValue(address, out var oldHash))
{
if(oldHash == hash) return;
ManifestFileApi.Remove(oldHash);
}
dict[address] = hash;
varService.SetConfigValue(CurrentConVar.ServerManifestHash, dict);
}
public HashApi CreateHashApi(List<RobustManifestItem> manifestItems)
{
return new HashApi(manifestItems, ContentFileApi);
}
public async Task<HashApi> EnsureItems(ManifestReader manifestReader, Uri downloadUri,
@@ -34,7 +48,7 @@ public partial class ContentService
allItems.Add(item.Value);
}
var hashApi = new HashApi(allItems, ContentFileApi);
var hashApi = CreateHashApi(allItems);
items = allItems.Where(a=> !hashApi.Has(a)).ToList();
@@ -54,6 +68,8 @@ public partial class ContentService
_logger.Log("Loading manifest from: " + info.Hash);
return await EnsureItems(new ManifestReader(stream), info.DownloadUri, loadingHandler, cancellationToken);
}
SetServerHash(info.ManifestUri.ToString(), info.Hash);
_logger.Log("Fetching manifest from: " + info.ManifestUri);

View File

@@ -9,7 +9,7 @@ public partial class ContentService
{
_logger.Log("Checking migration...");
var migrationList = ContentFileApi.AllFiles.Where(f => !f.Contains("\\")).ToList();
var migrationList = ContentFileApi.AllFiles.Where(f => !f.Contains('\\')).ToList();
if(migrationList.Count == 0) return false;
_logger.Log($"Found {migrationList.Count} migration files. Starting migration...");

View File

@@ -1,5 +1,4 @@
using System.Data;
using Nebula.Shared.Models;
using Nebula.Shared.Models;
using Nebula.Shared.Services.Logging;
namespace Nebula.Shared.Services;
@@ -28,4 +27,10 @@ public partial class ContentService(
return info;
}
public void RemoveAllContent(ILoadingHandler loadingHandler, CancellationToken cancellationToken)
{
fileService.RemoveAllFiles("content", loadingHandler, cancellationToken);
fileService.RemoveAllFiles("manifest", loadingHandler, cancellationToken);
}
}

View File

@@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
using Nebula.Shared.FileApis;
using Nebula.Shared.FileApis.Interfaces;
using Nebula.Shared.Models;
using Nebula.Shared.Services.Logging;
using Robust.LoaderApi;
namespace Nebula.Shared.Services;
@@ -13,11 +14,11 @@ public class FileService
public static readonly string RootPath = Path.Join(Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData), "Datum");
private readonly DebugService _debugService;
private readonly ILogger _logger;
public FileService(DebugService debugService)
{
_debugService = debugService;
_logger = debugService.GetLogger(this);
if(!Directory.Exists(RootPath))
Directory.CreateDirectory(RootPath);
@@ -25,6 +26,7 @@ public class FileService
public IReadWriteFileApi CreateFileApi(string path)
{
_logger.Debug($"Creating file api for {path}");
return new FileApi(Path.Join(RootPath, path));
}
@@ -32,6 +34,7 @@ public class FileService
{
path = Path.Combine(Path.GetTempPath(), "tempThink"+Path.GetRandomFileName());
Directory.CreateDirectory(path);
_logger.Debug($"Ensuring temp directory for {path}");
return new FileApi(path);
}
@@ -53,6 +56,38 @@ public class FileService
throw;
}
}
public void RemoveAllFiles(string fileApiName,ILoadingHandler loadingHandler, CancellationToken cancellationToken)
{
_logger.Debug($"Deleting files from {fileApiName}");
var path = Path.Combine(RootPath, fileApiName);
var di = new DirectoryInfo(path);
var files = di.GetFiles();
var dirs = di.GetDirectories();
loadingHandler.AppendJob(files.Length);
loadingHandler.AppendJob(dirs.Length);
if(cancellationToken.IsCancellationRequested)
return;
foreach (var file in files)
{
if(cancellationToken.IsCancellationRequested)
return;
file.Delete();
loadingHandler.AppendResolvedJob();
}
foreach (var dir in dirs)
{
if(cancellationToken.IsCancellationRequested)
return;
dir.Delete(true);
loadingHandler.AppendResolvedJob();
}
}
}
public sealed class ConsoleLoadingHandler : ILoadingHandler