ToolManager: Added tool dependency injection on tool restart and load.
This commit is contained in:
parent
99506df596
commit
b65bf1b5ae
|
@ -36,6 +36,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = Get<T>();
|
var result = Get<T>();
|
||||||
|
|
||||||
|
UpdateDependencies(result);
|
||||||
|
result.Restart();
|
||||||
|
|
||||||
result.Show();
|
result.Show();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -68,6 +72,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return attribute.Dependencies;
|
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>
|
/// <summary>
|
||||||
/// Determines whether a tool is available, considering its dependencies
|
/// Determines whether a tool is available, considering its dependencies
|
||||||
/// and the services provided by the emulator core.
|
/// and the services provided by the emulator core.
|
||||||
|
@ -181,7 +198,26 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Global.CheatList.NewList(GenerateDefaultCheatFilename(), autosave: true);
|
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>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue