Don't dispose hawkfile stream after ReadAllBytes(), fix ReadAllBytes callsites to do disposal properly

This commit is contained in:
CasualPokePlayer 2025-01-10 15:00:49 -08:00
parent 4aa334244e
commit a30c0efb78
6 changed files with 6 additions and 6 deletions

View File

@ -835,7 +835,7 @@ namespace BizHawk.Client.Common
var ext = file.Extension;
var gi = Disc.IsValidExtension(ext)
? MakeGameFromDisc(InstantiateDiscFor(path), ext: ext, name: Path.GetFileNameWithoutExtension(file.Name))
: new RomGame(new(file.CanonicalFullPath)).GameInfo; // need to re-open???
: new RomGame(file).GameInfo;
Game.Name = $"{gi.Name} [{Game.Name/* core name */}]";
}
}

View File

@ -95,7 +95,7 @@ namespace BizHawk.Client.Common
using var rom = new HawkFile(result);
if (rom.IsArchive) rom.BindFirst();
var romData = (ReadOnlySpan<byte>) rom.ReadAllBytes();
var romData = new ReadOnlySpan<byte>(rom.ReadAllBytes());
int headerBytes = romData.Length % 1024; // assume that all roms have sizes divisible by 1024, and any rest is header
romData = romData[headerBytes..];
if (matchesMovieHash(romData))

View File

@ -478,7 +478,7 @@ namespace BizHawk.Client.EmuHawk
// to always be copied to the global firmware directory
if (hf.IsArchive)
{
var ac = new ArchiveChooser(new HawkFile(filePath));
using var ac = new ArchiveChooser(hf);
if (!ac.ShowDialog(this).IsOk()) return;
var insideFile = hf.BindArchiveMember(ac.SelectedMemberIndex);

View File

@ -97,7 +97,7 @@ namespace BizHawk.Client.EmuHawk
{
if (PalettePath.Text.Length > 0)
{
var palette = new HawkFile(PalettePath.Text);
using var palette = new HawkFile(PalettePath.Text);
if (palette.Exists)
{

View File

@ -87,7 +87,7 @@ namespace BizHawk.Client.EmuHawk
filter: FilesystemFilterSet.Palettes,
initDir: _config.PathEntries.PalettesAbsolutePathFor(VSystemID.Raw.NES));
if (result is null) return;
HawkFile palette = new(result);
using HawkFile palette = new(result);
if (palette.Exists)
{

View File

@ -94,7 +94,7 @@ namespace BizHawk.Client.EmuHawk
return;
}
using ArchiveChooser ac = new(new(hawkPath)); //TODO can we pass hf here instead of instantiating a new HawkFile?
using ArchiveChooser ac = new(hf);
if (!this.ShowDialogAsChild(ac).IsOk()
|| ac.SelectedMemberIndex < 0 || hf.ArchiveItems.Count <= ac.SelectedMemberIndex)
{