11#nullable enable
22
3- using System ;
43using System . Collections . Generic ;
54using System . Diagnostics ;
6- using System . Security . Cryptography ;
75using System . IO ;
86using System . Linq ;
97
10- using BizHawk . Common . BufferExtensions ;
8+ using BizHawk . Common ;
119using BizHawk . Common . CollectionExtensions ;
10+ using BizHawk . Common . IOExtensions ;
1211using BizHawk . Emulation . Common ;
1312
1413namespace BizHawk . Client . Common
@@ -20,9 +19,7 @@ public sealed class FirmwareManager
2019 public static ( byte [ ] Patched , string ActualHash ) PerformPatchInMemory ( byte [ ] @base , in FirmwarePatchOption patchOption )
2120 {
2221 var patched = patchOption . Patches . Aggregate ( seed : @base , ( a , fpd ) => fpd . ApplyToMutating ( a ) ) ;
23- using var sha1 = SHA1 . Create ( ) ;
24- sha1 . ComputeHash ( patched ) ;
25- return ( patched , sha1 . Hash . BytesToHexString ( ) ) ;
22+ return ( patched , SHA1Checksum . ComputeDigestHex ( patched ) ) ;
2623 }
2724
2825 public static ( string FilePath , int FileSize , FirmwareFile FF ) PerformPatchOnDisk ( string baseFilename , in FirmwarePatchOption patchOption , PathEntryCollection pathEntries )
@@ -95,26 +92,16 @@ public static (string FilePath, int FileSize, FirmwareFile FF) PerformPatchOnDis
9592 return resolved . FilePath ;
9693 }
9794
98- private sealed class RealFirmwareReader : IDisposable
95+ private sealed class RealFirmwareReader
9996 {
10097 private readonly Dictionary < string , RealFirmwareFile > _dict = new ( ) ;
10198
102- private SHA1 ? _sha1 = SHA1 . Create ( ) ;
103-
10499 public IReadOnlyDictionary < string , RealFirmwareFile > Dict => _dict ;
105100
106- public void Dispose ( )
107- {
108- _sha1 ? . Dispose ( ) ;
109- _sha1 = null ;
110- }
111-
112101 public RealFirmwareFile Read ( FileInfo fi )
113102 {
114- if ( _sha1 == null ) throw new ObjectDisposedException ( nameof ( RealFirmwareReader ) ) ;
115103 using var fs = fi . OpenRead ( ) ;
116- _sha1 ! . ComputeHash ( fs ) ;
117- var hash = _sha1 . Hash . BytesToHexString ( ) ;
104+ var hash = SHA1Checksum . ComputeDigestHex ( fs . ReadAllBytes ( ) ) ;
118105 return _dict ! [ hash ] = new RealFirmwareFile ( fi , hash ) ;
119106 }
120107 }
@@ -133,7 +120,7 @@ public bool CanFileBeImported(string f)
133120 if ( ! _firmwareSizes . Contains ( fi . Length ) ) return false ;
134121
135122 // check the hash
136- using var reader = new RealFirmwareReader ( ) ;
123+ var reader = new RealFirmwareReader ( ) ;
137124 reader . Read ( fi ) ;
138125 var hash = reader . Dict . Values . First ( ) . Hash ;
139126 return FirmwareDatabase . FirmwareFiles . Any ( a => a . Hash == hash ) ;
@@ -146,7 +133,7 @@ public bool CanFileBeImported(string f)
146133
147134 public void DoScanAndResolve ( PathEntryCollection pathEntries , IDictionary < string , string > userSpecifications )
148135 {
149- using var reader = new RealFirmwareReader ( ) ;
136+ var reader = new RealFirmwareReader ( ) ;
150137
151138 // build a list of files under the global firmwares path, and build a hash for each of them (as ResolutionInfo) while we're at it
152139 var todo = new Queue < DirectoryInfo > ( new [ ] { new DirectoryInfo ( pathEntries . AbsolutePathFor ( pathEntries . FirmwaresPathFragment , null ) ) } ) ;
0 commit comments