HexEditor "File on Disk" fixes (squashed PR #3998)

* Fix keeping rom domain selected

* Turn unnecessary field into local

* Handle `null` return from `GetRomBytes()`

* Simplify `GetRomBytes()`

* Add try-catch around opening rom file
This commit is contained in:
kalimag 2024-08-21 07:59:39 +02:00 committed by GitHub
parent b9cd4a93cc
commit 4e85a71d53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 24 deletions

View File

@ -10,7 +10,6 @@ using System.Windows.Forms;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
using BizHawk.Common.IOExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.Properties; using BizHawk.Client.EmuHawk.Properties;
@ -110,7 +109,6 @@ namespace BizHawk.Client.EmuHawk
private string _findStr = ""; private string _findStr = "";
private bool _mouseIsDown; private bool _mouseIsDown;
private byte[] _rom;
private MemoryDomain _romDomain; private MemoryDomain _romDomain;
private HexFind _hexFind; private HexFind _hexFind;
private string _lastRom = ""; private string _lastRom = "";
@ -231,25 +229,27 @@ namespace BizHawk.Client.EmuHawk
public override void Restart() public override void Restart()
{ {
_romDomain = null;
if (Emulator.SystemId is not VSystemID.Raw.Arcade) if (Emulator.SystemId is not VSystemID.Raw.Arcade)
{ {
_rom = GetRomBytes(); var rom = GetRomBytes();
_romDomain = new MemoryDomainByteArray(ROM_DOMAIN_NAME, MemoryDomain.Endian.Little, _rom, writable: true, wordSize: 1); if (rom is not null)
if (_domain.Name == _romDomain.Name)
{ {
_domain = _romDomain; _romDomain = new MemoryDomainByteArray(ROM_DOMAIN_NAME, MemoryDomain.Endian.Little, rom, writable: true, wordSize: 1);
} }
} }
if (_domain.Name == ROM_DOMAIN_NAME && _romDomain is not null)
{
_domain = _romDomain;
}
else else
{ {
_romDomain = null; _domain = MemoryDomains.Any(x => x.Name == _domain.Name)
? MemoryDomains[_domain.Name]
: MemoryDomains.MainMemory;
} }
_domain = MemoryDomains.Any(x => x.Name == _domain.Name)
? MemoryDomains[_domain.Name]
: MemoryDomains.MainMemory;
BigEndian = _domain.EndianType == MemoryDomain.Endian.Big; BigEndian = _domain.EndianType == MemoryDomain.Endian.Big;
_maxRow = _domain.Size / 2; _maxRow = _domain.Size / 2;
@ -456,24 +456,25 @@ namespace BizHawk.Client.EmuHawk
{ {
var path = MainForm.CurrentlyOpenRomArgs.OpenAdvanced.SimplePath; var path = MainForm.CurrentlyOpenRomArgs.OpenAdvanced.SimplePath;
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{
return new byte[] { 0xFF };
}
using var file = new HawkFile(path);
if (!file.Exists)
{ {
return null; return null;
} }
if (file.IsArchive) try
{ {
var stream = file.GetStream(); using var file = new HawkFile(path);
return stream.ReadAllBytes(); if (file.Exists)
{
return file.ReadAllBytes();
}
}
catch (Exception ex)
{
using var exceptionBox = new ExceptionBox(ex);
this.ShowDialogWithTempMute(exceptionBox);
} }
return File.ReadAllBytes(path); return null;
} }
private static int GetNumDigits(long i) private static int GetNumDigits(long i)