Move various config manager APIs to internal.

This commit is contained in:
Pieter-Jan Briers
2020-12-04 11:15:09 +01:00
parent 6275768547
commit 953120aa76
8 changed files with 35 additions and 33 deletions

View File

@@ -38,7 +38,7 @@ namespace Robust.Client
{
internal sealed partial class GameController : IGameControllerInternal
{
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IConfigurationManagerInternal _configurationManager = default!;
[Dependency] private readonly IResourceCacheInternal _resourceCache = default!;
[Dependency] private readonly IRobustSerializer _serializer = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

View File

@@ -71,7 +71,7 @@ namespace Robust.Server
Buckets = Histogram.ExponentialBuckets(0.000_01, 2, 13)
});
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly IConfigurationManagerInternal _config = default!;
[Dependency] private readonly IComponentManager _components = default!;
[Dependency] private readonly IServerEntityManager _entities = default!;
[Dependency] private readonly ILogManager _log = default!;

View File

@@ -12,7 +12,7 @@ namespace Robust.Shared.Configuration
/// <summary>
/// Stores and manages global configuration variables.
/// </summary>
public class ConfigurationManager : IConfigurationManagerInternal
internal sealed class ConfigurationManager : IConfigurationManagerInternal
{
private const char TABLE_DELIMITER = '.';
private readonly Dictionary<string, ConfigVar> _configVars = new();
@@ -173,7 +173,7 @@ namespace Robust.Shared.Configuration
}
catch (Exception e)
{
Logger.WarningS("cfg", $"Cannot save the config file '{_configFile}'.\n {e.Message}");
Logger.WarningS("cfg", $"Cannot save the config file '{_configFile}'.\n {e}");
}
}

View File

@@ -10,17 +10,6 @@ namespace Robust.Shared.Interfaces.Configuration
/// </summary>
public interface IConfigurationManager
{
/// <summary>
/// Sets up the ConfigurationManager and loads a TOML configuration file.
/// </summary>
/// <param name="configFile">the full name of the config file.</param>
void LoadFromFile(string configFile);
/// <summary>
/// Specifies the location where the config file should be saved, without trying to load from it.
/// </summary>
void SetSaveFile(string configFile);
/// <summary>
/// Saves the configuration file to disk.
/// </summary>
@@ -66,7 +55,7 @@ namespace Robust.Shared.Interfaces.Configuration
/// <param name="name">The name of the CVar.</param>
/// <returns></returns>
T GetCVar<T>(string name);
T GetCVar<T>(CVarDef<T> def) where T : notnull;
/// <summary>
@@ -75,15 +64,10 @@ namespace Robust.Shared.Interfaces.Configuration
/// <param name="name">The name of the CVar</param>
Type GetCVarType(string name);
void OverrideConVars(IEnumerable<(string key, string value)> cVars);
void LoadCVarsFromAssembly(Assembly assembly);
void OnValueChanged<T>(CVarDef<T> cVar, Action<T> onValueChanged, bool invokeImmediately = false)
where T : notnull;
void OnValueChanged<T>(string name, Action<T> onValueChanged, bool invokeImmediately = false)
where T : notnull;
void Initialize(bool isServer);
}
}

View File

@@ -1,7 +1,25 @@
namespace Robust.Shared.Interfaces.Configuration
using System.Collections.Generic;
using System.Reflection;
namespace Robust.Shared.Interfaces.Configuration
{
internal interface IConfigurationManagerInternal : IConfigurationManager
{
void OverrideConVars(IEnumerable<(string key, string value)> cVars);
void LoadCVarsFromAssembly(Assembly assembly);
T GetSecureCVar<T>(string name);
void Initialize(bool isServer);
/// <summary>
/// Sets up the ConfigurationManager and loads a TOML configuration file.
/// </summary>
/// <param name="configFile">the full name of the config file.</param>
void LoadFromFile(string configFile);
/// <summary>
/// Specifies the location where the config file should be saved, without trying to load from it.
/// </summary>
void SetSaveFile(string configFile);
}
}

View File

@@ -343,11 +343,12 @@ namespace Robust.UnitTesting
IoCManager.Resolve<TestingModLoader>().Assemblies = _options.ContentAssemblies;
}
var cfg = IoCManager.Resolve<IConfigurationManagerInternal>();
if (_options != null)
{
_options.BeforeStart?.Invoke();
IoCManager.Resolve<IConfigurationManager>()
.OverrideConVars(_options.CVarOverrides.Select(p => (p.Key, p.Value)));
cfg.OverrideConVars(_options.CVarOverrides.Select(p => (p.Key, p.Value)));
if (_options.ExtraPrototypes != null)
{
@@ -356,8 +357,7 @@ namespace Robust.UnitTesting
}
}
IoCManager.Resolve<IConfigurationManager>()
.OverrideConVars(new []{("log.runtimelog", "false")});
cfg.OverrideConVars(new []{("log.runtimelog", "false")});
if (server.Start(() => new TestLogHandler("SERVER")))
{
@@ -438,7 +438,7 @@ namespace Robust.UnitTesting
if (_options != null)
{
_options.BeforeStart?.Invoke();
IoCManager.Resolve<IConfigurationManager>()
IoCManager.Resolve<IConfigurationManagerInternal>()
.OverrideConVars(_options.CVarOverrides.Select(p => (p.Key, p.Value)));
if (_options.ExtraPrototypes != null)

View File

@@ -54,7 +54,7 @@ namespace Robust.UnitTesting
foreach (var assembly in assemblies)
{
IoCManager.Resolve<IConfigurationManager>().LoadCVarsFromAssembly(assembly);
IoCManager.Resolve<IConfigurationManagerInternal>().LoadCVarsFromAssembly(assembly);
}
IoCManager.Resolve<IReflectionManager>().LoadAssemblies(assemblies);

View File

@@ -40,16 +40,16 @@ namespace Robust.UnitTesting.Shared.GameObjects
container.Register<IRobustMappedStringSerializer, RobustMappedStringSerializer>();
container.BuildGraph();
container.Resolve<IConfigurationManager>().Initialize(true);
container.Resolve<IConfigurationManager>().LoadCVarsFromAssembly(typeof(IConfigurationManager).Assembly);
var cfg = container.Resolve<IConfigurationManagerInternal>();
cfg.Initialize(true);
cfg.LoadCVarsFromAssembly(typeof(IConfigurationManager).Assembly);
container.Resolve<IReflectionManager>().LoadAssemblies(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Shared"));
IoCManager.InitThread(container);
IoCManager.Resolve<IConfigurationManager>()
.LoadCVarsFromAssembly(typeof(IConfigurationManager).Assembly); // Robust.Shared
cfg.LoadCVarsFromAssembly(typeof(IConfigurationManager).Assembly); // Robust.Shared
container.Resolve<INetManager>().Initialize(true);
var serializer = container.Resolve<IRobustSerializer>();