Convert RealFirmwareFile to readonly struct

This commit is contained in:
YoshiRulz 2021-02-12 16:15:57 +10:00
parent 3a3cb0c30b
commit 2f18c74840
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 14 additions and 7 deletions

View File

@ -58,15 +58,14 @@ namespace BizHawk.Client.Common
public RealFirmwareFile Read(FileInfo fi) public RealFirmwareFile Read(FileInfo fi)
{ {
var rff = new RealFirmwareFile { FileInfo = fi };
using (var fs = fi.OpenRead()) using (var fs = fi.OpenRead())
{ {
_sha1.ComputeHash(fs); _sha1.ComputeHash(fs);
} }
rff.Hash = _sha1.Hash.BytesToHexString(); var hash = _sha1.Hash.BytesToHexString();
Dict[rff.Hash] = rff; var rff = new RealFirmwareFile(fi, hash);
Dict[hash] = rff;
return rff; return rff;
} }

View File

@ -1,12 +1,20 @@
#nullable enable
using System.IO; using System.IO;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
/// <summary>represents a file found on disk in the user's firmware directory matching a file in our database</summary> /// <summary>represents a file found on disk in the user's firmware directory matching a file in our database</summary>
public sealed class RealFirmwareFile public readonly struct RealFirmwareFile
{ {
public FileInfo FileInfo { get; set; } public readonly FileInfo FileInfo;
public string Hash { get; set; } public readonly string Hash;
public RealFirmwareFile(FileInfo fileInfo, string hash)
{
FileInfo = fileInfo;
Hash = hash;
}
} }
} }