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:
parent
b9cd4a93cc
commit
4e85a71d53
|
@ -10,7 +10,6 @@ using System.Windows.Forms;
|
|||
using BizHawk.Common;
|
||||
using BizHawk.Common.NumberExtensions;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Client.EmuHawk.Properties;
|
||||
|
@ -110,7 +109,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private string _findStr = "";
|
||||
private bool _mouseIsDown;
|
||||
private byte[] _rom;
|
||||
private MemoryDomain _romDomain;
|
||||
private HexFind _hexFind;
|
||||
private string _lastRom = "";
|
||||
|
@ -231,24 +229,26 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public override void Restart()
|
||||
{
|
||||
_romDomain = null;
|
||||
if (Emulator.SystemId is not VSystemID.Raw.Arcade)
|
||||
{
|
||||
_rom = GetRomBytes();
|
||||
_romDomain = new MemoryDomainByteArray(ROM_DOMAIN_NAME, MemoryDomain.Endian.Little, _rom, writable: true, wordSize: 1);
|
||||
|
||||
if (_domain.Name == _romDomain.Name)
|
||||
var rom = GetRomBytes();
|
||||
if (rom is not null)
|
||||
{
|
||||
_domain = _romDomain;
|
||||
_romDomain = new MemoryDomainByteArray(ROM_DOMAIN_NAME, MemoryDomain.Endian.Little, rom, writable: true, wordSize: 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (_domain.Name == ROM_DOMAIN_NAME && _romDomain is not null)
|
||||
{
|
||||
_romDomain = null;
|
||||
_domain = _romDomain;
|
||||
}
|
||||
else
|
||||
{
|
||||
_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;
|
||||
|
||||
|
@ -456,24 +456,25 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var path = MainForm.CurrentlyOpenRomArgs.OpenAdvanced.SimplePath;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return new byte[] { 0xFF };
|
||||
}
|
||||
|
||||
using var file = new HawkFile(path);
|
||||
|
||||
if (!file.Exists)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (file.IsArchive)
|
||||
try
|
||||
{
|
||||
var stream = file.GetStream();
|
||||
return stream.ReadAllBytes();
|
||||
using var file = new HawkFile(path);
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue