More explanatory naming for Manager Init (Attach) and Dispose (Detach).
Torch.Client uses the registry to discover Steam's installation directory.
This commit is contained in:
@@ -38,25 +38,25 @@ namespace Torch.API.Managers
|
|||||||
bool RemoveManager(IManager manager);
|
bool RemoveManager(IManager manager);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the dependency manager, and all its registered managers.
|
/// Sorts the dependency manager, then attaches all its registered managers in <see cref="AttachOrder" />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Init();
|
void Attach();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the dependency manager, and all its registered managers.
|
/// Detaches all registered managers in <see cref="DetachOrder"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Dispose();
|
void Detach();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The order that managers should be loaded in. (Dependencies, then dependents)
|
/// The order that managers should be attached in. (Dependencies, then dependents)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="InvalidOperationException">When trying to determine load order before this dependency manager is initialized</exception>
|
/// <exception cref="InvalidOperationException">When trying to determine load order before this dependency manager is initialized</exception>
|
||||||
IEnumerable<IManager> LoadOrder { get; }
|
IEnumerable<IManager> AttachOrder { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The order that managers should be unloaded in. (Dependents, then dependencies)
|
/// The order that managers should be detached in. (Dependents, then dependencies)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="InvalidOperationException">When trying to determine unload order before this dependency manager is initialized</exception>
|
/// <exception cref="InvalidOperationException">When trying to determine unload order before this dependency manager is initialized</exception>
|
||||||
IEnumerable<IManager> UnloadOrder { get; }
|
IEnumerable<IManager> DetachOrder { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,13 +12,13 @@ namespace Torch.API.Managers
|
|||||||
public interface IManager
|
public interface IManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the manager. Called once this manager's dependencies have been initialized.
|
/// Attaches the manager to the session. Called once this manager's dependencies have been attached.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Init();
|
void Attach();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the manager. Called before this manager's dependencies are disposed.
|
/// Detaches the manager from the session. Called before this manager's dependencies are detached.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Dispose();
|
void Detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,9 +31,6 @@ namespace Torch.Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly string[] _steamInstallDirectories = new[] {
|
|
||||||
@"C:\Program Files\Steam\", @"C:\Program Files (x86)\Steam\"
|
|
||||||
};
|
|
||||||
private const string _steamSpaceEngineersDirectory = @"steamapps\common\SpaceEngineers\";
|
private const string _steamSpaceEngineersDirectory = @"steamapps\common\SpaceEngineers\";
|
||||||
private const string _spaceEngineersVerifyFile = SpaceEngineersBinaries + @"\SpaceEngineers.exe";
|
private const string _spaceEngineersVerifyFile = SpaceEngineersBinaries + @"\SpaceEngineers.exe";
|
||||||
|
|
||||||
@@ -76,15 +73,18 @@ namespace Torch.Client
|
|||||||
private static void SetupSpaceEngInstallAlias()
|
private static void SetupSpaceEngInstallAlias()
|
||||||
{
|
{
|
||||||
string spaceEngineersDirectory = null;
|
string spaceEngineersDirectory = null;
|
||||||
foreach (string steamDir in _steamInstallDirectories)
|
|
||||||
|
// TODO look at Steam/config/Config.VDF? Has alternate directories.
|
||||||
|
var steamDir =
|
||||||
|
Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Valve\\Steam", "SteamPath", null) as string;
|
||||||
|
if (steamDir != null)
|
||||||
{
|
{
|
||||||
spaceEngineersDirectory = Path.Combine(steamDir, _steamSpaceEngineersDirectory);
|
spaceEngineersDirectory = Path.Combine(steamDir, _steamSpaceEngineersDirectory);
|
||||||
|
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
|
||||||
if (File.Exists(Path.Combine(spaceEngineersDirectory, _spaceEngineersVerifyFile)))
|
if (File.Exists(Path.Combine(spaceEngineersDirectory, _spaceEngineersVerifyFile)))
|
||||||
{
|
|
||||||
_log.Debug("Found Space Engineers in {0}", spaceEngineersDirectory);
|
_log.Debug("Found Space Engineers in {0}", spaceEngineersDirectory);
|
||||||
break;
|
else
|
||||||
}
|
_log.Debug("Couldn't find Space Engineers in {0}", spaceEngineersDirectory);
|
||||||
_log.Debug("Couldn't find Space Engineers in {0}", spaceEngineersDirectory);
|
|
||||||
}
|
}
|
||||||
if (spaceEngineersDirectory == null)
|
if (spaceEngineersDirectory == null)
|
||||||
{
|
{
|
||||||
@@ -149,7 +149,7 @@ namespace Torch.Client
|
|||||||
_log.Error("Unable to create junction link {0} => {1}", linkName, targetDir);
|
_log.Error("Unable to create junction link {0} => {1}", linkName, targetDir);
|
||||||
return cmd.ExitCode == 0;
|
return cmd.ExitCode == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
var ex = (Exception)e.ExceptionObject;
|
var ex = (Exception)e.ExceptionObject;
|
||||||
|
@@ -34,7 +34,7 @@ namespace Torch.Server.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Init()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
MyFileSystem.ExePath = Path.Combine(_filesystemManager.TorchDirectory, "DedicatedServer64");
|
MyFileSystem.ExePath = Path.Combine(_filesystemManager.TorchDirectory, "DedicatedServer64");
|
||||||
MyFileSystem.Init("Content", Torch.Config.InstancePath);
|
MyFileSystem.Init("Content", Torch.Config.InstancePath);
|
||||||
|
@@ -28,7 +28,7 @@ namespace Torch.Commands
|
|||||||
Prefix = prefix;
|
Prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
RegisterCommandModule(typeof(TorchCommands));
|
RegisterCommandModule(typeof(TorchCommands));
|
||||||
_chatManager.MessageRecieved += HandleCommand;
|
_chatManager.MessageRecieved += HandleCommand;
|
||||||
|
@@ -35,7 +35,7 @@ namespace Torch.Managers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -241,26 +241,26 @@ namespace Torch.Managers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the dependency manager, and all its registered managers.
|
/// Initializes the dependency manager, and all its registered managers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Init()
|
public void Attach()
|
||||||
{
|
{
|
||||||
if (_initialized)
|
if (_initialized)
|
||||||
throw new InvalidOperationException("Can't start the dependency manager more than once");
|
throw new InvalidOperationException("Can't start the dependency manager more than once");
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
Sort();
|
Sort();
|
||||||
foreach (ManagerInstance manager in _orderedManagers)
|
foreach (ManagerInstance manager in _orderedManagers)
|
||||||
manager.Instance.Init();
|
manager.Instance.Attach();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disposes the dependency manager, and all its registered managers.
|
/// Disposes the dependency manager, and all its registered managers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Detach()
|
||||||
{
|
{
|
||||||
if (!_initialized)
|
if (!_initialized)
|
||||||
throw new InvalidOperationException("Can't dispose an uninitialized dependency manager");
|
throw new InvalidOperationException("Can't dispose an uninitialized dependency manager");
|
||||||
for (int i = _orderedManagers.Count - 1; i >= 0; i--)
|
for (int i = _orderedManagers.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
_orderedManagers[i].Instance.Dispose();
|
_orderedManagers[i].Instance.Detach();
|
||||||
foreach (DependencyInfo field in _orderedManagers[i].Dependencies)
|
foreach (DependencyInfo field in _orderedManagers[i].Dependencies)
|
||||||
field.Field.SetValue(_orderedManagers[i].Instance, null);
|
field.Field.SetValue(_orderedManagers[i].Instance, null);
|
||||||
}
|
}
|
||||||
@@ -268,7 +268,7 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerable<IManager> LoadOrder
|
public IEnumerable<IManager> AttachOrder
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -280,7 +280,7 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerable<IManager> UnloadOrder
|
public IEnumerable<IManager> DetachOrder
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@@ -63,12 +63,12 @@ namespace Torch.Managers
|
|||||||
Torch = torchInstance;
|
Torch = torchInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Init()
|
public virtual void Attach()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Dispose()
|
public virtual void Detach()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -65,7 +65,7 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Init()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
Torch.SessionLoaded += OnSessionLoaded;
|
Torch.SessionLoaded += OnSessionLoaded;
|
||||||
_chatManager.MessageRecieved += Instance_MessageRecieved;
|
_chatManager.MessageRecieved += Instance_MessageRecieved;
|
||||||
|
@@ -63,7 +63,7 @@ namespace Torch.Managers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads the network intercept system
|
/// Loads the network intercept system
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Init()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
Torch.SessionLoaded += OnSessionLoaded;
|
Torch.SessionLoaded += OnSessionLoaded;
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ namespace Torch.Managers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unloads all plugins.
|
/// Unloads all plugins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose()
|
public override void Detach()
|
||||||
{
|
{
|
||||||
foreach (var plugin in Plugins)
|
foreach (var plugin in Plugins)
|
||||||
plugin.Dispose();
|
plugin.Dispose();
|
||||||
|
@@ -16,7 +16,7 @@ namespace Torch.Managers
|
|||||||
{
|
{
|
||||||
private MyScriptWhitelist _whitelist;
|
private MyScriptWhitelist _whitelist;
|
||||||
|
|
||||||
public void Init()
|
public void Attach()
|
||||||
{
|
{
|
||||||
_whitelist = MyScriptCompiler.Static.Whitelist;
|
_whitelist = MyScriptCompiler.Static.Whitelist;
|
||||||
MyScriptCompiler.Static.AddConditionalCompilationSymbols("TORCH");
|
MyScriptCompiler.Static.AddConditionalCompilationSymbols("TORCH");
|
||||||
@@ -41,7 +41,7 @@ namespace Torch.Managers
|
|||||||
Log.Info(whitelist);*/
|
Log.Info(whitelist);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Detach()
|
||||||
{
|
{
|
||||||
// TODO unregister whitelist patches
|
// TODO unregister whitelist patches
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ namespace Torch.Managers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles updating of the DS and Torch plugins.
|
/// Handles updating of the DS and Torch plugins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UpdateManager : Manager, IDisposable
|
public class UpdateManager : Manager
|
||||||
{
|
{
|
||||||
private Timer _updatePollTimer;
|
private Timer _updatePollTimer;
|
||||||
private GitHubClient _gitClient = new GitHubClient(new ProductHeaderValue("Torch"));
|
private GitHubClient _gitClient = new GitHubClient(new ProductHeaderValue("Torch"));
|
||||||
@@ -34,7 +34,7 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Init()
|
public override void Attach()
|
||||||
{
|
{
|
||||||
CheckAndUpdateTorch();
|
CheckAndUpdateTorch();
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ namespace Torch.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Dispose()
|
public override void Detach()
|
||||||
{
|
{
|
||||||
_updatePollTimer?.Dispose();
|
_updatePollTimer?.Dispose();
|
||||||
}
|
}
|
||||||
|
@@ -250,7 +250,7 @@ namespace Torch
|
|||||||
MySession.OnUnloading += OnSessionUnloading;
|
MySession.OnUnloading += OnSessionUnloading;
|
||||||
MySession.OnUnloaded += OnSessionUnloaded;
|
MySession.OnUnloaded += OnSessionUnloaded;
|
||||||
RegisterVRagePlugin();
|
RegisterVRagePlugin();
|
||||||
Managers.Init();
|
Managers.Attach();
|
||||||
_init = true;
|
_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +318,7 @@ namespace Torch
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
Managers.Dispose();
|
Managers.Detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
Reference in New Issue
Block a user