properly dispose of IDisposables in core savestate code, and a few other places
This commit is contained in:
parent
f944cd65a7
commit
fef746dffa
|
@ -34,7 +34,7 @@ namespace BizHawk.Common.IOExtensions
|
|||
|
||||
public static string ReadStringUtf8NullTerminated(this BinaryReader br)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using var ms = new MemoryStream();
|
||||
for (;;)
|
||||
{
|
||||
var b = br.ReadByte();
|
||||
|
|
|
@ -147,10 +147,8 @@ namespace BizHawk.Common
|
|||
/// </summary>
|
||||
public static bool ExistsAt(string path)
|
||||
{
|
||||
using (var file = new HawkFile(path))
|
||||
{
|
||||
return file.Exists;
|
||||
}
|
||||
using var file = new HawkFile(path);
|
||||
return file.Exists;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -158,20 +156,16 @@ namespace BizHawk.Common
|
|||
/// </summary>
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
using (var file = new HawkFile(path))
|
||||
using var file = new HawkFile(path);
|
||||
if (!file.Exists)
|
||||
{
|
||||
if (!file.Exists)
|
||||
{
|
||||
throw new FileNotFoundException(path);
|
||||
}
|
||||
|
||||
using (Stream stream = file.GetStream())
|
||||
{
|
||||
var ms = new MemoryStream((int)stream.Length);
|
||||
stream.CopyTo(ms);
|
||||
return ms.GetBuffer();
|
||||
}
|
||||
throw new FileNotFoundException(path);
|
||||
}
|
||||
|
||||
using Stream stream = file.GetStream();
|
||||
using var ms = new MemoryStream((int)stream.Length);
|
||||
stream.CopyTo(ms);
|
||||
return ms.GetBuffer();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -7,10 +7,7 @@ namespace BizHawk.Emulation.Cores.Calculators
|
|||
{
|
||||
public partial class TI83 : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
@ -34,8 +31,8 @@ namespace BizHawk.Emulation.Cores.Calculators
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
|
|
@ -10,13 +10,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
/// </summary>
|
||||
public partial class AmstradCPC : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
SyncState(new Serializer(writer));
|
||||
}
|
||||
|
@ -38,8 +34,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
|
|
@ -31,13 +31,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
private void SyncState(Serializer ser)
|
||||
|
|
|
@ -10,12 +10,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
/// </summary>
|
||||
public partial class ZXSpectrum : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
SyncState(new Serializer(writer));
|
||||
}
|
||||
|
@ -37,8 +34,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
|
|
@ -7,10 +7,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
{
|
||||
public partial class Atari2600 : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
@ -34,8 +31,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
|
|
@ -74,8 +74,8 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream(_savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream(_savebuff2, true);
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
if (ms.Position != _savebuff2.Length)
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
|
|||
byte[] realfile = null;
|
||||
|
||||
{
|
||||
var ms = new MemoryStream(file, false);
|
||||
var br = new BinaryReader(ms);
|
||||
using var ms = new MemoryStream(file, false);
|
||||
using var br = new BinaryReader(ms);
|
||||
string header = Encoding.ASCII.GetString(br.ReadBytes(4));
|
||||
int p0 = br.ReadUInt16();
|
||||
int p1 = br.ReadUInt16();
|
||||
|
|
|
@ -7,10 +7,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
{
|
||||
public partial class ColecoVision : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
@ -34,8 +31,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
@ -46,7 +43,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
|
|||
byte[] core = null;
|
||||
if (ser.IsWriter)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using var ms = new MemoryStream();
|
||||
ms.Close();
|
||||
core = ms.ToArray();
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
|
|||
byte[] core = null;
|
||||
if (ser.IsWriter)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using var ms = new MemoryStream();
|
||||
ms.Close();
|
||||
core = ms.ToArray();
|
||||
}
|
||||
|
|
|
@ -84,8 +84,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
public byte[] SaveStateBinary()
|
||||
{
|
||||
StartSaveStateBinaryInternal();
|
||||
var ms = new MemoryStream(_savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream(_savebuff2, true);
|
||||
using var bw = new BinaryWriter(ms);
|
||||
FinishSaveStateBinaryInternal(bw);
|
||||
bw.Flush();
|
||||
ms.Close();
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
@ -43,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
|
|||
byte[] core = null;
|
||||
if (ser.IsWriter)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using var ms = new MemoryStream();
|
||||
ms.Close();
|
||||
core = ms.ToArray();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
|||
{
|
||||
public partial class N64 : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred { get { return true; } }
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
// these functions are all exact copy paste from gambatte.
|
||||
// if something's wrong here, it's probably wrong there too
|
||||
|
@ -82,8 +82,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
|
|||
SaveStateBinaryPrivateBuff = new byte[lenwant];
|
||||
}
|
||||
|
||||
var ms = new MemoryStream(SaveStateBinaryPrivateBuff);
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream(SaveStateBinaryPrivateBuff);
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
|
||||
|
|
|
@ -658,7 +658,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
//create the board's rom and vrom
|
||||
if (iNesHeaderInfo != null)
|
||||
{
|
||||
var ms = new MemoryStream(file, false);
|
||||
using var ms = new MemoryStream(file, false);
|
||||
ms.Seek(16, SeekOrigin.Begin); // ines header
|
||||
//pluck the necessary bytes out of the file
|
||||
if (iNesHeaderInfo.trainer_size != 0)
|
||||
|
|
|
@ -48,8 +48,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
|
|
@ -3,15 +3,11 @@
|
|||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
||||
{
|
||||
public partial class SMS : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
@ -35,8 +31,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryWriter bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
return ms.ToArray();
|
||||
|
@ -47,13 +43,13 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
|
|||
byte[] core = null;
|
||||
if (ser.IsWriter)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
using var ms = new MemoryStream();
|
||||
ms.Close();
|
||||
core = ms.ToArray();
|
||||
}
|
||||
Cpu.SyncState(ser);
|
||||
|
||||
ser.BeginSection(nameof(SMS));
|
||||
ser.BeginSection(nameof(SMS));
|
||||
Vdp.SyncState(ser);
|
||||
PSG.SyncState(ser);
|
||||
ser.Sync("RAM", ref SystemRam, false);
|
||||
|
|
|
@ -8,10 +8,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
|||
{
|
||||
public partial class GPGX : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
@ -59,8 +56,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
ms.Close();
|
||||
|
|
|
@ -1181,8 +1181,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
|
|||
public byte[] SaveStateBinary()
|
||||
{
|
||||
//this are objectionable shenanigans, but theyre required to get the extra info in the stream. we need a better approach.
|
||||
var ms = new MemoryStream(savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream(savebuff2, true);
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
if (ms.Position != savebuff2.Length)
|
||||
|
@ -1191,10 +1191,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
|
|||
return savebuff2;
|
||||
}
|
||||
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.WonderSwan
|
|||
savebuff2 = new byte[savebuff.Length + 13];
|
||||
}
|
||||
|
||||
JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented };
|
||||
JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
class TextStateData
|
||||
|
@ -88,8 +88,8 @@ namespace BizHawk.Emulation.Cores.WonderSwan
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream(savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream(savebuff2, true);
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
if (ms.Position != savebuff2.Length)
|
||||
|
@ -98,9 +98,6 @@ namespace BizHawk.Emulation.Cores.WonderSwan
|
|||
return savebuff2;
|
||||
}
|
||||
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -303,8 +303,8 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var bw = new BinaryWriter(ms);
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
ms.Close();
|
||||
|
|
Loading…
Reference in New Issue