- tweak: View autogenerator
This commit is contained in:
@@ -28,6 +28,8 @@ public static class CurrentConVar
|
||||
ConVarBuilder.Build<Dictionary<string, EngineVersionInfo>>("engine.manifest.backup");
|
||||
public static readonly ConVar<ModulesInfo> ModuleManifestBackup =
|
||||
ConVarBuilder.Build<ModulesInfo>("module.manifest.backup");
|
||||
public static readonly ConVar<Dictionary<string, string>> ServerManifestHash =
|
||||
ConVarBuilder.Build<Dictionary<string, string>>("server.manifest.hash",[]);
|
||||
|
||||
public static readonly ConVar<Dictionary<string,string>> DotnetUrl = ConVarBuilder.Build<Dictionary<string,string>>("dotnet.url",
|
||||
new(){
|
||||
|
||||
@@ -55,6 +55,11 @@ public class HashApi : IFileApi
|
||||
return _fileApi.Has(GetManifestPath(item));
|
||||
}
|
||||
|
||||
public bool Remove(RobustManifestItem item)
|
||||
{
|
||||
return _fileApi.Remove(GetManifestPath(item));
|
||||
}
|
||||
|
||||
private string GetManifestPath(RobustManifestItem item){
|
||||
return GetManifestPath(item.Hash);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public sealed record ServerInfo(
|
||||
[property: JsonPropertyName("auth")] AuthInfo Auth,
|
||||
[property: JsonPropertyName("build")] BuildInfo Build,
|
||||
[property: JsonPropertyName("desc")] string Desc,
|
||||
[property: JsonPropertyName("links")] List<ServerLink> Links);
|
||||
[property: JsonPropertyName("links")] List<ServerLink>? Links);
|
||||
|
||||
public sealed record EngineVersionInfo(
|
||||
[property: JsonPropertyName("insecure")]
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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...");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -94,8 +94,16 @@ public class ManifestReader : StreamReader
|
||||
{
|
||||
var line = ReadLine();
|
||||
if (line == null) return null;
|
||||
var splited = line.Split(" ");
|
||||
return new RobustManifestItem(splited[0], line.Substring(splited[0].Length + 1), CurrentId++);
|
||||
|
||||
var firstSpaceIndex = line.IndexOf(' ');
|
||||
if (firstSpaceIndex == -1)
|
||||
return new RobustManifestItem(line, string.Empty, CurrentId++);
|
||||
|
||||
var span = line.AsSpan();
|
||||
var firstPart = span.Slice(0, firstSpaceIndex);
|
||||
var secondPart = span.Slice(firstSpaceIndex + 1);
|
||||
|
||||
return new RobustManifestItem(firstPart.ToString(), secondPart.ToString(), CurrentId++);
|
||||
}
|
||||
|
||||
public bool TryReadItem([NotNullWhen(true)] out RobustManifestItem? item)
|
||||
|
||||
8
Nebula.Shared/ViewHelper/ViewModelRegisterAttribute.cs
Normal file
8
Nebula.Shared/ViewHelper/ViewModelRegisterAttribute.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Nebula.Shared.ViewHelper;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ViewModelRegisterAttribute(Type? type = null, bool isSingleton = true) : Attribute
|
||||
{
|
||||
public Type? Type { get; } = type;
|
||||
public bool IsSingleton { get; } = isSingleton;
|
||||
}
|
||||
Reference in New Issue
Block a user