Tools - add a SupportedSystems attribute to ToolAttributes, if specified by a tool, the IsAvailable and Load Calls will check that the current system id is in the list
This commit is contained in:
parent
1ba166af19
commit
0630be922b
|
@ -1,16 +1,19 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class ToolAttributes : Attribute
|
||||
{
|
||||
public ToolAttributes(bool released)
|
||||
public ToolAttributes(bool released, string[] supportedSystems)
|
||||
{
|
||||
Released = released;
|
||||
SupportedSystems = supportedSystems;
|
||||
}
|
||||
|
||||
public bool Released { get; private set; }
|
||||
|
||||
public IEnumerable<string> SupportedSystems { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ using BizHawk.Emulation.Common;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[ToolAttributes(released: false)]
|
||||
[ToolAttributes(released: false, supportedSystems: null)]
|
||||
public partial class AutoHawk : Form, IToolFormAutoConfig
|
||||
{
|
||||
public AutoHawk()
|
||||
|
|
|
@ -13,7 +13,6 @@ using BizHawk.Client.Common;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[ToolAttributes(released: true)]
|
||||
public partial class GenericDebugger : Form, IToolFormAutoConfig, IControlMainform
|
||||
{
|
||||
public GenericDebugger()
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
this.MaximizeBox = false;
|
||||
this.Name = "GameShark";
|
||||
this.Text = "GameShark Converter";
|
||||
this.Load += new System.EventHandler(this.GameShark_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
|
|
@ -8,16 +8,13 @@ using System.Globalization;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[ToolAttributes(released: true, supportedSystems: new[] { "GB" })]
|
||||
public partial class GameShark : Form, IToolForm, IToolFormAutoConfig
|
||||
{
|
||||
//We are using Memory Domains, so we NEED this.
|
||||
[RequiredService]
|
||||
private IMemoryDomains MemoryDomains { get; set; }
|
||||
//Since this is only using GameBoy at the moment, we do this.
|
||||
//TODO:
|
||||
//Expand this so that this tool supports ALL cores that are capable of using GameShark/CodeBreaker/Action Replay/Game Genie
|
||||
[RequiredService]
|
||||
private Gameboy GB { get; set; }
|
||||
|
||||
public GameShark()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -100,5 +97,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
txtCheat.Clear();
|
||||
txtDescription.Clear();
|
||||
}
|
||||
|
||||
private void GameShark_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,10 +43,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
public IToolForm Load(Type toolType, bool focus = true)
|
||||
{
|
||||
if (!typeof(IToolForm).IsAssignableFrom(toolType))
|
||||
throw new ArgumentException(String.Format("Type {0} does not implement IToolForm.", toolType.Name));
|
||||
{
|
||||
throw new ArgumentException(string.Format("Type {0} does not implement IToolForm.", toolType.Name));
|
||||
}
|
||||
|
||||
if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, toolType))
|
||||
if (!IsAvailable(toolType))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var existingTool = _tools.FirstOrDefault(x => toolType.IsAssignableFrom(x.GetType()));
|
||||
|
||||
|
@ -63,6 +67,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
existingTool.Show();
|
||||
existingTool.Focus();
|
||||
}
|
||||
|
||||
return existingTool;
|
||||
}
|
||||
}
|
||||
|
@ -580,7 +585,37 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public bool IsAvailable(Type t)
|
||||
{
|
||||
return ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t);
|
||||
if (!ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var tool = Assembly
|
||||
.GetAssembly(typeof(IToolForm))
|
||||
.GetTypes()
|
||||
.FirstOrDefault(type => type == t);
|
||||
|
||||
if (tool == null) // This isn't a tool, must not be available
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var attr = tool.GetCustomAttributes(false)
|
||||
.OfType<ToolAttributes>()
|
||||
.FirstOrDefault();
|
||||
|
||||
if (attr == null) // If no attributes there is no supported systems documented so assume all
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If no supported systems mentioned assume all
|
||||
if (attr.SupportedSystems != null && attr.SupportedSystems.Any())
|
||||
{
|
||||
return attr.SupportedSystems.Contains(Global.Emulator.SystemId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Eventually we want a single game genie tool, then this mess goes away
|
||||
|
|
Loading…
Reference in New Issue