EmuHawk: ToolManager.IsAvailable<T> (#1294)

This commit is contained in:
Asnivor 2018-09-10 20:08:44 +01:00 committed by feos
parent c012f56e45
commit 8a10ba6372
3 changed files with 30 additions and 8 deletions

View File

@ -6,14 +6,17 @@ namespace BizHawk.Client.EmuHawk
[AttributeUsage(AttributeTargets.Class)]
public class ToolAttribute : Attribute
{
public ToolAttribute(bool released, string[] supportedSystems)
public ToolAttribute(bool released, string[] supportedSystems, string[] unsupportedCores = null)
{
Released = released;
SupportedSystems = supportedSystems;
UnsupportedCores = unsupportedCores;
}
public bool Released { get; private set; }
public IEnumerable<string> SupportedSystems { get; private set; }
public IEnumerable<string> UnsupportedCores { get; private set; }
}
}

View File

@ -20,7 +20,8 @@ namespace BizHawk.Client.EmuHawk
//Verify all wording in the error reports
[Tool(released: true, supportedSystems: new[] { "GB", "GBA", "GEN", "N64", "NES", "PSX", "SAT", "SMS", "SNES" })]
[Tool(released: true, supportedSystems: new[] { "GB", "GBA", "GEN", "N64", "NES", "PSX", "SAT", "SMS", "SNES" },
unsupportedCores: new[] { "Snes9x" })]
public partial class GameShark : Form, IToolForm, IToolFormAutoConfig
{
#region " Game Genie Dictionary "

View File

@ -10,6 +10,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Client.EmuHawk.CoreExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -743,13 +744,30 @@ namespace BizHawk.Client.EmuHawk
.OfType<ToolAttribute>()
.FirstOrDefault();
// If no supported systems mentioned assume all
if (attr?.SupportedSystems != null && attr.SupportedSystems.Any())
// start with the assumption that if no supported systems are mentioned and no unsupported cores are mentioned
// then this is available for all
bool supported = true;
if (attr?.SupportedSystems != null && attr.SupportedSystems.Any())
{
return attr.SupportedSystems.Contains(Global.Emulator.SystemId);
}
// supported systems are available
supported = attr.SupportedSystems.Contains(Global.Emulator.SystemId);
return true;
if (supported)
{
// check for a core not supported override
if (attr.UnsupportedCores.Contains(Global.Emulator.DisplayName()))
supported = false;
}
}
else if (attr?.UnsupportedCores != null && attr.UnsupportedCores.Any())
{
// no supported system specified, but unsupported cores are
if (attr.UnsupportedCores.Contains(Global.Emulator.DisplayName()))
supported = false;
}
return supported;
}
// Note: Referencing these properties creates an instance of the tool and persists it. They should be referenced by type if this is not desired
@ -973,7 +991,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadGameGenieEc()
{
if (GlobalWin.Tools.IsAvailable<GameShark>())
{
{
GlobalWin.Tools.Load<GameShark>();
}
}