[Save/Sync]
- Work on PMS.
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
using Barotrauma.LuaCs.Services.Processing;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public partial class PackageManagementService
|
||||
{
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.LuaCs.Data;
|
||||
|
||||
public partial interface IModConfigInfo : IAssembliesResourcesInfo,
|
||||
public interface IModConfigInfo : IAssembliesResourcesInfo,
|
||||
ILuaScriptsResourcesInfo, IConfigsResourcesInfo
|
||||
{
|
||||
// package info
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.LuaCs.Data;
|
||||
@@ -6,105 +7,132 @@ using FluentResults;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public partial class PackageManagementService : IPackageManagementService
|
||||
public sealed class PackageManagementService : IPackageManagementService
|
||||
{
|
||||
// svc
|
||||
private ILoggerService _logger;
|
||||
private IModConfigService _modConfigService;
|
||||
private ILuaScriptManagementService _luaScriptManagementService;
|
||||
private IPluginManagementService _pluginManagementService;
|
||||
// state
|
||||
private readonly ConcurrentDictionary<ContentPackage, IModConfigInfo> _loadedPackages = new();
|
||||
private readonly ConcurrentDictionary<ContentPackage, IModConfigInfo> _runningPackages = new();
|
||||
// control
|
||||
private readonly AsyncReaderWriterLock _operationsLock = new();
|
||||
|
||||
public PackageManagementService(ILoggerService logger, IModConfigService modConfigService, ILuaScriptManagementService luaScriptManagementService, IPluginManagementService pluginManagementService)
|
||||
{
|
||||
_logger = logger;
|
||||
_modConfigService = modConfigService;
|
||||
_luaScriptManagementService = luaScriptManagementService;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
using var lck = _operationsLock.AcquireWriterLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
if (!ModUtils.Threading.CheckIfClearAndSetBool(ref _isDisposed))
|
||||
return;
|
||||
|
||||
_logger.LogMessage($"{nameof(PackageManagementService)} is disposing");
|
||||
_luaScriptManagementService.Dispose();
|
||||
_pluginManagementService.Dispose();
|
||||
_modConfigService.Dispose();
|
||||
_logger.Dispose();
|
||||
|
||||
_logger = null;
|
||||
_luaScriptManagementService = null;
|
||||
_pluginManagementService = null;
|
||||
_modConfigService = null;
|
||||
_loadedPackages.Clear();
|
||||
_runningPackages.Clear();
|
||||
}
|
||||
|
||||
private int _isDisposed = 0;
|
||||
public bool IsDisposed
|
||||
{
|
||||
get => ModUtils.Threading.GetBool(ref _isDisposed);
|
||||
private set => ModUtils.Threading.SetBool(ref _isDisposed, value);
|
||||
set => ModUtils.Threading.SetBool(ref _isDisposed, value);
|
||||
}
|
||||
|
||||
|
||||
public FluentResults.Result Reset()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
using var lck = _operationsLock.AcquireWriterLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
if (IsDisposed)
|
||||
return FluentResults.Result.Fail($"{nameof(PackageManagementService)}failed to reset. Has already been disposed.");
|
||||
|
||||
var operationResult = new FluentResults.Result();
|
||||
CombineResultErrors(operationResult, UnsafeStopRunningPackagesInternal());
|
||||
CombineResultErrors(operationResult, UnsafeUnloadAllPackagesInternal());
|
||||
return operationResult;
|
||||
|
||||
void CombineResultErrors(FluentResults.Result result,
|
||||
ImmutableArray<(ContentPackage Package, FluentResults.Result OperationResult)> packRes)
|
||||
{
|
||||
if (packRes.IsDefaultOrEmpty)
|
||||
return;
|
||||
|
||||
foreach (var r in packRes)
|
||||
{
|
||||
if (r.OperationResult.IsSuccess)
|
||||
continue;
|
||||
_logger.LogResults(r.OperationResult);
|
||||
result.WithErrors(r.OperationResult.Errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImmutableArray<IConfigResourceInfo> Configs { get; }
|
||||
public ImmutableArray<ILuaScriptResourceInfo> LuaScripts { get; }
|
||||
public ImmutableArray<IAssemblyResourceInfo> Assemblies { get; }
|
||||
public async Task<FluentResults.Result> LoadPackageInfosAsync(ContentPackage package)
|
||||
public FluentResults.Result LoadPackageInfo(ContentPackage package)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<(ContentPackage, FluentResults.Result)>> LoadPackagesInfosAsync(IReadOnlyList<ContentPackage> packages)
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result LoadSuccessResult)> LoadPackagesInfo(IReadOnlyCollection<ContentPackage> packages)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IReadOnlyList<ContentPackage> GetAllLoadedPackages()
|
||||
private FluentResults.Result UnsafeLoadPackageInfoInternal(ContentPackage package)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsPackageLoaded(ContentPackage package)
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result ExecutionResult)> ExecuteLoadedPackages()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public ImmutableArray<T> FilterUnloadableResources<T>(IReadOnlyList<T> resources, bool enabledPackagesOnly = false) where T : IResourceInfo
|
||||
private ImmutableArray<(ContentPackage Package, FluentResults.Result StopExectionResult)> UnsafeStopRunningPackagesInternal()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result StopExecutionResult)> StopRunningPackages()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void DisposePackageInfos(ContentPackage package)
|
||||
private FluentResults.Result UnsafeUnloadPackageInternal(ContentPackage package)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void DisposePackagesInfos(IReadOnlyList<ContentPackage> packages)
|
||||
private ImmutableArray<(ContentPackage Package, FluentResults.Result UnloadSuccessResult)> UnsafeUnloadAllPackagesInternal()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public FluentResults.Result UnloadPackage(ContentPackage package)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result UnloadSuccessResult)> UnloadPackages(IReadOnlyCollection<ContentPackage> packages)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<IAssembliesResourcesInfo> GetAssembliesInfos(ContentPackage package, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<IConfigsResourcesInfo> GetConfigsInfos(ContentPackage package, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(ContentPackage package, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<IAssembliesResourcesInfo> GetAssembliesInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<IConfigsResourcesInfo> GetConfigsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Result<IAssembliesResourcesInfo>> GetAssembliesInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Result<IConfigsResourcesInfo>> GetConfigsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Result<ILuaScriptsResourcesInfo>> GetLuaScriptsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true)
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result UnloadSuccessResult)> UnloadAllPackages()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -9,50 +9,13 @@ using Barotrauma.LuaCs.Data;
|
||||
|
||||
namespace Barotrauma.LuaCs.Services;
|
||||
|
||||
public interface IPackageManagementService : IReusableService, IConfigsResourcesInfo, ILuaScriptsResourcesInfo, IAssembliesResourcesInfo
|
||||
public interface IPackageManagementService : IReusableService
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads and parses the provided <see cref="ContentPackage"/> for <see cref="IResourceInfo"/> supported by the current runtime environment.
|
||||
/// Will overwrite any existing package data.
|
||||
/// </summary>
|
||||
/// <param name="packages">Package to load.</param>
|
||||
/// <returns></returns>
|
||||
Task<FluentResults.Result> LoadPackageInfosAsync(ContentPackage package);
|
||||
/// <summary>
|
||||
/// Loads and parses the provided <see cref="ContentPackage"/> collection for <see cref="IResourceInfo"/> supported by the current runtime environment.
|
||||
/// Will overwrite any existing package data.
|
||||
/// </summary>
|
||||
/// <param name="packages">List of packages to load.</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<(ContentPackage, FluentResults.Result)>> LoadPackagesInfosAsync(IReadOnlyList<ContentPackage> packages);
|
||||
IReadOnlyList<ContentPackage> GetAllLoadedPackages();
|
||||
bool IsPackageLoaded(ContentPackage package);
|
||||
|
||||
/// <summary>
|
||||
/// Filters out resources not suitable for the current environment using the following criteria: <br/>
|
||||
/// - Platform (Operating System)<br/>
|
||||
/// - Target (Client|Server)<br/>
|
||||
/// - Null/Invalid<br/>
|
||||
/// - Dependency Package Registered in PMS<br/>
|
||||
/// </summary>
|
||||
/// <param name="resources"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
ImmutableArray<T> FilterUnloadableResources<T>(IReadOnlyList<T> resources, bool enabledPackagesOnly = false)
|
||||
where T : IResourceInfo;
|
||||
void DisposePackageInfos(ContentPackage package);
|
||||
void DisposePackagesInfos(IReadOnlyList<ContentPackage> packages);
|
||||
|
||||
// single
|
||||
FluentResults.Result<IAssembliesResourcesInfo> GetAssembliesInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
FluentResults.Result<IConfigsResourcesInfo> GetConfigsInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
FluentResults.Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(ContentPackage package, bool onlySupportedResources = true);
|
||||
// collection
|
||||
FluentResults.Result<IAssembliesResourcesInfo> GetAssembliesInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
FluentResults.Result<IConfigsResourcesInfo> GetConfigsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
FluentResults.Result<ILuaScriptsResourcesInfo> GetLuaScriptsInfos(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
|
||||
Task<FluentResults.Result<IAssembliesResourcesInfo>> GetAssembliesInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
Task<FluentResults.Result<IConfigsResourcesInfo>> GetConfigsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
Task<FluentResults.Result<ILuaScriptsResourcesInfo>> GetLuaScriptsInfosAsync(IReadOnlyList<ContentPackage> packages, bool onlySupportedResources = true);
|
||||
public FluentResults.Result LoadPackageInfo(ContentPackage package);
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result LoadSuccessResult)> LoadPackagesInfo(IReadOnlyCollection<ContentPackage> packages);
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result ExecutionResult)> ExecuteLoadedPackages();
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result StopExecutionResult)> StopRunningPackages();
|
||||
public FluentResults.Result UnloadPackage(ContentPackage package);
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result UnloadSuccessResult)> UnloadPackages(IReadOnlyCollection<ContentPackage> packages);
|
||||
public ImmutableArray<(ContentPackage Package, FluentResults.Result UnloadSuccessResult)> UnloadAllPackages();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user