- Made Package loading conditional on resources being available.
- Made States registration use named parameters. - Changed IPluginManagementService interface to better suit expected return results.
This commit is contained in:
+30
-21
@@ -151,17 +151,28 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
try
|
||||
{
|
||||
var res = new FluentResults.Result();
|
||||
var configsTask = new Task<Task<FluentResults.Result>>(async Task<FluentResults.Result> () =>
|
||||
new FluentResults.Result()
|
||||
.WithReasons((await _configService.LoadConfigsAsync(config.Configs)).Reasons)
|
||||
.WithReasons((await _configService.LoadConfigsProfilesAsync(config.Configs)).Reasons));
|
||||
var luaScriptsTask = new Task<Task<FluentResults.Result>>(async () =>
|
||||
await _luaScriptManagementService.LoadScriptResourcesAsync(config.LuaScripts));
|
||||
var tasks = ImmutableArray.CreateBuilder<Task<Task<FluentResults.Result>>>();
|
||||
|
||||
if (!config.Configs.IsDefaultOrEmpty)
|
||||
{
|
||||
tasks.Add(Task.Factory.StartNew(async Task<FluentResults.Result> () =>
|
||||
new FluentResults.Result()
|
||||
.WithReasons((await _configService.LoadConfigsAsync(config.Configs)).Reasons)
|
||||
.WithReasons((await _configService.LoadConfigsProfilesAsync(config.Configs)).Reasons)));
|
||||
}
|
||||
|
||||
if (!config.LuaScripts.IsDefaultOrEmpty)
|
||||
{
|
||||
tasks.Add(Task.Factory.StartNew(async () =>
|
||||
await _luaScriptManagementService.LoadScriptResourcesAsync(config.LuaScripts)));
|
||||
}
|
||||
|
||||
if (tasks.Count == 0)
|
||||
{
|
||||
return FluentResults.Result.Ok();
|
||||
}
|
||||
|
||||
configsTask.Start();
|
||||
luaScriptsTask.Start();
|
||||
|
||||
var r = Task.WhenAll(configsTask, luaScriptsTask).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
var r = Task.WhenAll(tasks.ToArray()).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
foreach (var task in r)
|
||||
res.WithReasons(task.ConfigureAwait(false).GetAwaiter().GetResult().Reasons);
|
||||
@@ -180,7 +191,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
IService.CheckDisposed(this);
|
||||
|
||||
if (executionOrder.IsDefaultOrEmpty)
|
||||
{
|
||||
return FluentResults.Result.Fail($"{nameof(ExecuteLoadedPackages)}: No packages in the execution order list.");
|
||||
}
|
||||
|
||||
if (!_runningPackages.IsEmpty)
|
||||
{
|
||||
@@ -190,7 +203,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
}
|
||||
|
||||
if (_loadedPackages.IsEmpty)
|
||||
{
|
||||
return FluentResults.Result.Fail($"{nameof(ExecuteLoadedPackages)}: No packages loaded. Nothing to run!)");
|
||||
}
|
||||
|
||||
var result = new FluentResults.Result();
|
||||
|
||||
@@ -198,24 +213,16 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
var loadingOrderedPackages = _loadedPackages.OrderBy(pkg => executionOrder.IndexOf(pkg.Key))
|
||||
.ToImmutableArray();
|
||||
|
||||
//mod settings
|
||||
var settings = loadingOrderedPackages
|
||||
.SelectMany(pkg => pkg.Value.Configs.OrderBy(scr => scr.LoadPriority))
|
||||
.ToImmutableArray();
|
||||
if (!settings.IsDefaultOrEmpty)
|
||||
{
|
||||
result.WithReasons(_configService.LoadConfigsAsync(settings).ConfigureAwait(false).GetAwaiter()
|
||||
.GetResult().Reasons);
|
||||
result.WithReasons(_configService.LoadConfigsProfilesAsync(settings).ConfigureAwait(false)
|
||||
.GetAwaiter().GetResult().Reasons);
|
||||
}
|
||||
// NOTE: Config/Settings are instanced in LoadPackages()
|
||||
|
||||
//lua scripts
|
||||
var luaScripts = loadingOrderedPackages
|
||||
.SelectMany(pkg => pkg.Value.LuaScripts.OrderBy(scr => scr.LoadPriority))
|
||||
.ToImmutableArray();
|
||||
if (!luaScripts.IsDefaultOrEmpty)
|
||||
{
|
||||
result.WithReasons(_luaScriptManagementService.ExecuteLoadedScripts(luaScripts).Reasons);
|
||||
}
|
||||
|
||||
if (_runConfig.IsCsEnabled)
|
||||
{
|
||||
@@ -223,7 +230,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
||||
loadingOrderedPackages.SelectMany(pkg => pkg.Value.Assemblies.OrderBy(scr => scr.LoadPriority))
|
||||
.ToImmutableArray();
|
||||
if (!plugins.IsDefaultOrEmpty)
|
||||
{
|
||||
result.WithReasons(_pluginManagementService.LoadAssemblyResources(plugins).Reasons);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -13,6 +13,7 @@ using Barotrauma.LuaCs.Data;
|
||||
using Barotrauma.LuaCs.Events;
|
||||
using FluentResults;
|
||||
using FluentResults.LuaCs;
|
||||
using ImpromptuInterface.Build;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using OneOf;
|
||||
|
||||
@@ -21,14 +22,15 @@ namespace Barotrauma.LuaCs.Services;
|
||||
public class PluginManagementService : IPluginManagementService, IAssemblyManagementService
|
||||
{
|
||||
private readonly Func<IAssemblyLoaderService.LoaderInitData, IAssemblyLoaderService> _assemblyLoaderServiceFactory;
|
||||
private readonly ConcurrentDictionary<ContentPackage, (List<IAssemblyResourceInfo> ResourceInfos, IAssemblyLoaderService Loader)> _packageAssemblyResources;
|
||||
private readonly ConcurrentDictionary<ContentPackage, List<IDisposable>> _pluginInstances;
|
||||
private readonly ConcurrentDictionary<ContentPackage, (List<IAssemblyResourceInfo> ResourceInfos, IAssemblyLoaderService Loader)> _packageAssemblyResources = new();
|
||||
private readonly ConcurrentDictionary<ContentPackage, List<IDisposable>> _pluginInstances = new();
|
||||
private readonly Lazy<IEventService> _eventService;
|
||||
private readonly ConditionalWeakTable<IAssemblyLoaderService, ContentPackage> _unloadingAssemblyLoaders;
|
||||
private readonly ConditionalWeakTable<Assembly, ConcurrentDictionary<string, Type>> _assemblyTypesCache;
|
||||
private readonly ConditionalWeakTable<IAssemblyLoaderService, ContentPackage> _unloadingAssemblyLoaders = new();
|
||||
private readonly ConditionalWeakTable<Assembly, ConcurrentDictionary<string, Type>> _assemblyTypesCache = new();
|
||||
|
||||
public PluginManagementService(
|
||||
Func<IAssemblyLoaderService.LoaderInitData, IAssemblyLoaderService> assemblyLoaderServiceFactory,
|
||||
Func<IAssemblyLoaderService.LoaderInitData,
|
||||
IAssemblyLoaderService> assemblyLoaderServiceFactory,
|
||||
Lazy<IEventService> eventService)
|
||||
{
|
||||
_assemblyLoaderServiceFactory = assemblyLoaderServiceFactory;
|
||||
@@ -123,14 +125,20 @@ public class PluginManagementService : IPluginManagementService, IAssemblyManage
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result<ImmutableArray<IAssemblyResourceInfo>> LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource)
|
||||
public FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource)
|
||||
{
|
||||
#if DEBUG
|
||||
return FluentResults.Result.Fail($"{nameof(LoadAssemblyResources)}: Plugin loading not currently implemented.");
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ImmutableArray<Result<(Type, T)>> ActivateTypeInstances<T>(ImmutableArray<Type> types, bool serviceInjection = true,
|
||||
bool hostInstanceReference = false) where T : IDisposable
|
||||
{
|
||||
#if DEBUG
|
||||
return ImmutableArray<Result<(Type, T)>>.Empty;
|
||||
#endif
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public interface IPluginManagementService : IReusableService
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <returns>Success/Failure and list of failed resources, if any.</returns>
|
||||
FluentResults.Result<ImmutableArray<IAssemblyResourceInfo>> LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource);
|
||||
FluentResults.Result LoadAssemblyResources(ImmutableArray<IAssemblyResourceInfo> resource);
|
||||
|
||||
/// <summary>
|
||||
/// Creates instances of the given type and provides Property Injection and instance reference caching. Disposes of
|
||||
|
||||
Reference in New Issue
Block a user