ToolManager: Added tool dependency injection on tool restart and load.

This commit is contained in:
scepheo 2014-12-13 22:32:08 +00:00
parent 99506df596
commit b65bf1b5ae
1 changed files with 37 additions and 1 deletions

View File

@ -36,6 +36,10 @@ namespace BizHawk.Client.EmuHawk
}
var result = Get<T>();
UpdateDependencies(result);
result.Restart();
result.Show();
return result;
}
@ -68,6 +72,19 @@ namespace BizHawk.Client.EmuHawk
return attribute.Dependencies;
}
/// <summary>
/// Feeds the tool its required services.
/// </summary>
private void UpdateDependencies(IToolForm tool)
{
var serviceSet = new Dictionary<Type, object>();
foreach (var service in GetDependencies(tool.GetType()))
serviceSet[service] = Global.Emulator.ServiceProvider.GetService(service);
tool.EmulatorServices = serviceSet;
}
/// <summary>
/// Determines whether a tool is available, considering its dependencies
/// and the services provided by the emulator core.
@ -181,7 +198,26 @@ namespace BizHawk.Client.EmuHawk
Global.CheatList.NewList(GenerateDefaultCheatFilename(), autosave: true);
}
_tools.ForEach(x => x.Restart());
var unavailable = new List<IToolForm>();
foreach (var tool in _tools)
{
if (IsAvailable(tool.GetType()))
{
UpdateDependencies(tool);
tool.Restart();
}
else
{
unavailable.Add(tool);
}
}
foreach (var tool in unavailable)
{
tool.Close();
_tools.Remove(tool);
}
}
/// <summary>