cleanups in CoreFeatureAnalysis

This commit is contained in:
adelikat 2019-12-21 08:57:31 -06:00
parent 7149b0ef65
commit 442ec14c76
1 changed files with 21 additions and 38 deletions

View File

@ -7,7 +7,6 @@ using System.Reflection;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -18,7 +17,6 @@ namespace BizHawk.Client.EmuHawk
private class CoreInfo private class CoreInfo
{ {
public string CoreName { get; set; } public string CoreName { get; set; }
public string TypeName { get; set; }
public bool Released { get; set; } public bool Released { get; set; }
public Dictionary<string, ServiceInfo> Services { get; set; } public Dictionary<string, ServiceInfo> Services { get; set; }
public List<string> NotApplicableTypes { get; set; } public List<string> NotApplicableTypes { get; set; }
@ -26,7 +24,6 @@ namespace BizHawk.Client.EmuHawk
public CoreInfo() { } public CoreInfo() { }
public CoreInfo(IEmulator emu) public CoreInfo(IEmulator emu)
{ {
TypeName = emu.GetType().ToString();
CoreName = emu.Attributes().CoreName; CoreName = emu.Attributes().CoreName;
Released = emu.Attributes().Released; Released = emu.Attributes().Released;
Services = new Dictionary<string, ServiceInfo>(); Services = new Dictionary<string, ServiceInfo>();
@ -37,12 +34,12 @@ namespace BizHawk.Client.EmuHawk
Services.Add(si.TypeName, si); Services.Add(si.TypeName, si);
} }
var notapplicableAttr = ((ServiceNotApplicableAttribute)Attribute var notApplicableAttribute = ((ServiceNotApplicableAttribute)Attribute
.GetCustomAttribute(emu.GetType(), typeof(ServiceNotApplicableAttribute))); .GetCustomAttribute(emu.GetType(), typeof(ServiceNotApplicableAttribute)));
if (notapplicableAttr != null) if (notApplicableAttribute != null)
{ {
NotApplicableTypes = notapplicableAttr.NotApplicableTypes NotApplicableTypes = notApplicableAttribute.NotApplicableTypes
.Select(x => x.ToString()) .Select(x => x.ToString())
.ToList(); .ToList();
} }
@ -60,23 +57,19 @@ namespace BizHawk.Client.EmuHawk
public List<FunctionInfo> Functions { get; set; } public List<FunctionInfo> Functions { get; set; }
public ServiceInfo() { } public ServiceInfo() { }
public ServiceInfo(Type servicetype, object service) public ServiceInfo(Type serviceType, object service)
{ {
if (servicetype.IsGenericType) TypeName = serviceType.IsGenericType
{ ? serviceType.GetGenericTypeDefinition().ToString()
TypeName = servicetype.GetGenericTypeDefinition().ToString(); : serviceType.ToString();
}
else
{
TypeName = servicetype.ToString();
}
Functions = new List<FunctionInfo>(); Functions = new List<FunctionInfo>();
IEnumerable<MethodInfo> methods = servicetype.GetMethods(); // .Concat(servicetype.GetProperties().Select(p => p.GetGetMethod())); IEnumerable<MethodInfo> methods = serviceType.GetMethods();
if (servicetype.IsInterface) if (serviceType.IsInterface)
{ {
var map = service.GetType().GetInterfaceMap(servicetype); var map = service.GetType().GetInterfaceMap(serviceType);
// project interface methods to actual implementations // project interface methods to actual implementations
methods = methods.Select( methods = methods.Select(
m => map.TargetMethods[Array.IndexOf(map.InterfaceMethods, m)]); m => map.TargetMethods[Array.IndexOf(map.InterfaceMethods, m)]);
@ -115,8 +108,9 @@ namespace BizHawk.Client.EmuHawk
#endregion #endregion
// ReSharper disable once UnusedAutoPropertyAccessor.Local
[RequiredService] [RequiredService]
IEmulator emu { get; set; } IEmulator Emulator { get; set; }
public CoreFeatureAnalysis() public CoreFeatureAnalysis()
{ {
@ -124,11 +118,6 @@ namespace BizHawk.Client.EmuHawk
KnownCores = new Dictionary<string, CoreInfo>(); KnownCores = new Dictionary<string, CoreInfo>();
} }
private void OkBtn_Click(object sender, EventArgs e)
{
Close();
}
public void NewUpdate(ToolFormUpdateType type) { } public void NewUpdate(ToolFormUpdateType type) { }
private TreeNode CreateCoreTree(CoreInfo ci) private TreeNode CreateCoreTree(CoreInfo ci)
@ -167,13 +156,13 @@ namespace BizHawk.Client.EmuHawk
} }
var knownServies = Assembly.GetAssembly(typeof(IEmulator)) var knownServices = Assembly.GetAssembly(typeof(IEmulator))
.GetTypes() .GetTypes()
.Where(t => typeof(IEmulatorService).IsAssignableFrom(t)) .Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
.Where(t => t != typeof(IEmulatorService)) .Where(t => t != typeof(IEmulatorService))
.Where(t => t.IsInterface); .Where(t => t.IsInterface);
var additionalServices = knownServies var additionalServices = knownServices
.Where(t => !ci.Services.ContainsKey(t.ToString())) .Where(t => !ci.Services.ContainsKey(t.ToString()))
.Where(t => !ci.NotApplicableTypes.Contains(t.ToString())) .Where(t => !ci.NotApplicableTypes.Contains(t.ToString()))
.Where(t => !typeof(ISpecializedEmulatorService).IsAssignableFrom(t)); // We don't want to show these as unimplemented, they aren't expected services .Where(t => !typeof(ISpecializedEmulatorService).IsAssignableFrom(t)); // We don't want to show these as unimplemented, they aren't expected services
@ -215,7 +204,7 @@ namespace BizHawk.Client.EmuHawk
CoreTree.ImageList.Images.Add("Bad", Properties.Resources.ExclamationRed); CoreTree.ImageList.Images.Add("Bad", Properties.Resources.ExclamationRed);
CoreTree.ImageList.Images.Add("Unknown", Properties.Resources.RetroQuestion); CoreTree.ImageList.Images.Add("Unknown", Properties.Resources.RetroQuestion);
var possiblecoretypes = var possibleCoreTypes =
Assembly Assembly
.Load("BizHawk.Emulation.Cores") .Load("BizHawk.Emulation.Cores")
.GetTypes() .GetTypes()
@ -229,7 +218,7 @@ namespace BizHawk.Client.EmuHawk
.ThenBy(t => t.CoreAttributes.CoreName) .ThenBy(t => t.CoreAttributes.CoreName)
.ToList(); .ToList();
toolStripStatusLabel1.Text = $"Total: {possiblecoretypes.Count} Released: {KnownCores.Values.Count(c => c.Released)} Profiled: {KnownCores.Count}"; toolStripStatusLabel1.Text = $"Total: {possibleCoreTypes.Count} Released: {KnownCores.Values.Count(c => c.Released)} Profiled: {KnownCores.Count}";
CoreTree.Nodes.Clear(); CoreTree.Nodes.Clear();
CoreTree.BeginUpdate(); CoreTree.BeginUpdate();
@ -245,7 +234,7 @@ namespace BizHawk.Client.EmuHawk
CoreTree.Nodes.Add(coreNode); CoreTree.Nodes.Add(coreNode);
} }
foreach (var t in possiblecoretypes) foreach (var t in possibleCoreTypes)
{ {
if (!KnownCores.ContainsKey(t.CoreAttributes.CoreName)) if (!KnownCores.ContainsKey(t.CoreAttributes.CoreName))
{ {
@ -277,22 +266,16 @@ namespace BizHawk.Client.EmuHawk
public void Restart() public void Restart()
{ {
var ci = new CoreInfo(emu); var ci = new CoreInfo(Emulator);
KnownCores[ci.CoreName] = ci; KnownCores[ci.CoreName] = ci;
DoCurrentCoreTree(ci); DoCurrentCoreTree(ci);
DoAllCoresTree(ci); DoAllCoresTree(ci);
} }
public bool AskSaveChanges() public bool AskSaveChanges() => true;
{
return true;
}
public bool UpdateBefore public bool UpdateBefore => false;
{
get { return false; }
}
#endregion #endregion
} }