Check FWIDs in database at runtime

see e119bdda3
This commit is contained in:
James Groom 2023-11-09 08:51:29 +10:00 committed by GitHub
parent 282417c9af
commit e9468cb0c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -47,8 +47,6 @@ namespace BizHawk.Emulation.Common
additionalInfo: additionalInfo,
isBad: isBad);
// make sure id doesn't have a space, it is stored in the (space delimited) movie header!
void Option(string systemId, string id, in FirmwareFile ff, FirmwareOptionStatus status = FirmwareOptionStatus.Acceptable)
{
var option = new FirmwareOption(new(systemId, id), ff.Hash, ff.Size, ff.IsBad ? FirmwareOptionStatus.Bad : status);

View File

@ -1,3 +1,6 @@
using System;
using System.Linq;
namespace BizHawk.Emulation.Common
{
public readonly struct FirmwareID
@ -16,6 +19,11 @@ namespace BizHawk.Emulation.Common
public FirmwareID(string system, string firmware)
{
static bool IsAllowedCharacter(char c)
=> c is '-' or (>= '0' and <= '9') or (>= 'A' and <= 'Z') or '_' or (>= 'a' and <= 'z');
const string ERR_MSG_INVALID_CHAR = "FWIDs must match /[-0-9A-Z_a-z]+/";
if (!system.All(IsAllowedCharacter)) throw new ArgumentOutOfRangeException(paramName: system, actualValue: system, message: ERR_MSG_INVALID_CHAR);
if (!firmware.All(IsAllowedCharacter)) throw new ArgumentOutOfRangeException(paramName: firmware, actualValue: firmware, message: ERR_MSG_INVALID_CHAR);
System = system;
Firmware = firmware;
}