Warn at runtime if a lowercase/invalid hash is added to FWDB (resolves #3916)
left the existing unit test untouched
This commit is contained in:
parent
ae1692f2e1
commit
0122dec099
|
@ -39,13 +39,16 @@ namespace BizHawk.Emulation.Common
|
|||
string desc,
|
||||
string additionalInfo = "",
|
||||
bool isBad = false)
|
||||
=> filesByHash[hash] = new(
|
||||
hash: hash,
|
||||
size: size,
|
||||
recommendedName: recommendedName,
|
||||
desc: desc,
|
||||
additionalInfo: additionalInfo,
|
||||
isBad: isBad);
|
||||
{
|
||||
FirmwareFile ff = new(
|
||||
hash: hash,
|
||||
size: size,
|
||||
recommendedName: recommendedName,
|
||||
desc: desc,
|
||||
additionalInfo: additionalInfo,
|
||||
isBad: isBad);
|
||||
return filesByHash[ff.Hash/*may have been reformatted*/] = ff;
|
||||
}
|
||||
|
||||
void Option(string systemId, string id, in FirmwareFile ff, FirmwareOptionStatus status = FirmwareOptionStatus.Acceptable)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace BizHawk.Emulation.Common
|
||||
{
|
||||
public readonly struct FirmwareFile
|
||||
{
|
||||
internal static void CheckChecksumStrIsHex(ref string digest)
|
||||
{
|
||||
static bool IsAllowedCharacter(char c)
|
||||
=> c is (>= '0' and <= '9') or (>= 'A' and <= 'F'); //TODO SearchValues?
|
||||
if (digest.All(IsAllowedCharacter)) return;
|
||||
if (!digest.IsHex()) throw new ArgumentOutOfRangeException(paramName: nameof(digest), actualValue: digest, message: "malformed checksum digest: must match /[0-9A-F]+/ (no lowercase please)");
|
||||
// but if it is hex, let's be lenient
|
||||
Console.Write("interpreting as hex checksum digest and uppercasing (please fix in source): ");
|
||||
Console.WriteLine(digest);
|
||||
digest = digest.ToUpperInvariant();
|
||||
}
|
||||
|
||||
public readonly string Description;
|
||||
|
||||
public readonly string Hash;
|
||||
|
@ -22,6 +39,7 @@ namespace BizHawk.Emulation.Common
|
|||
string additionalInfo = "",
|
||||
bool isBad = false)
|
||||
{
|
||||
CheckChecksumStrIsHex(ref hash);
|
||||
Description = desc;
|
||||
Hash = hash;
|
||||
Info = additionalInfo;
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public FirmwareOption(FirmwareID id, string hash, long size, FirmwareOptionStatus status)
|
||||
{
|
||||
FirmwareFile.CheckChecksumStrIsHex(ref hash);
|
||||
Hash = hash;
|
||||
ID = id;
|
||||
Size = size;
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public FirmwarePatchOption(string baseHash, IReadOnlyList<FirmwarePatchData> patches, string targetHash)
|
||||
{
|
||||
FirmwareFile.CheckChecksumStrIsHex(ref baseHash);
|
||||
FirmwareFile.CheckChecksumStrIsHex(ref targetHash);
|
||||
BaseHash = baseHash;
|
||||
Patches = patches;
|
||||
TargetHash = targetHash;
|
||||
|
|
Loading…
Reference in New Issue