External tools no longer crash on loading new ROM
This commit is contained in:
parent
c76d850687
commit
bc4330a9d1
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using BizHawk.Common.ReflectionExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.ApiHawk;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
||||
{
|
||||
public static class ApiManager
|
||||
{
|
||||
private static ApiContainer container;
|
||||
private static void Register(IEmulatorServiceProvider serviceProvider)
|
||||
{
|
||||
// Register external apis
|
||||
var apis = Assembly
|
||||
.Load("BizHawk.Client.ApiHawk")
|
||||
.GetTypes()
|
||||
.Where(t => typeof(IExternalApi).IsAssignableFrom(t))
|
||||
.Where(t => t.IsSealed)
|
||||
.Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
|
||||
.ToList();
|
||||
|
||||
apis.AddRange(
|
||||
Assembly
|
||||
.GetAssembly(typeof(ApiContainer))
|
||||
.GetTypes()
|
||||
.Where(t => typeof(IExternalApi).IsAssignableFrom(t))
|
||||
.Where(t => t.IsSealed)
|
||||
.Where(t => ServiceInjector.IsAvailable(serviceProvider, t)));
|
||||
|
||||
foreach (var api in apis)
|
||||
{
|
||||
var instance = (IExternalApi)Activator.CreateInstance(api);
|
||||
ServiceInjector.UpdateServices(serviceProvider, instance);
|
||||
Libraries.Add(api, instance);
|
||||
}
|
||||
container = new ApiContainer(Libraries);
|
||||
GlobalWin.ApiProvider = new BasicApiProvider(container);
|
||||
}
|
||||
private static readonly Dictionary<Type, IExternalApi> Libraries = new Dictionary<Type, IExternalApi>();
|
||||
public static void Restart(IEmulatorServiceProvider newServiceProvider)
|
||||
{
|
||||
Libraries.Clear();
|
||||
Register(newServiceProvider);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -664,7 +664,7 @@
|
|||
<Compile Include="Api\Libraries\GuiApi.cs" />
|
||||
<Compile Include="Api\Libraries\InputApi.cs" />
|
||||
<Compile Include="Api\Libraries\SaveStateAPI.cs" />
|
||||
<Compile Include="Api\Libraries\PluginLibrary.cs" />
|
||||
<Compile Include="Api\ApiManager.cs" />
|
||||
<Compile Include="Api\Libraries\CommApi.cs" />
|
||||
<!--<Compile Include="Input\GamePad.cs" Condition=" '$(OS)' == 'Windows_NT' " />-->
|
||||
<Compile Include="Input\GamePad.cs" />
|
||||
|
|
|
@ -3793,8 +3793,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
GlobalWin.Tools.Restart();
|
||||
ApiManager.Restart(Emulator.ServiceProvider);
|
||||
GlobalWin.Tools.Restart();
|
||||
|
||||
if (Global.Config.LoadCheatFileByGame)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue