simplify Stream.ReadAllBytes extension and use it more
This commit is contained in:
parent
31c7f59e86
commit
f1e11dfc36
|
@ -5,6 +5,7 @@ using System.IO.Compression;
|
|||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores;
|
||||
|
@ -497,9 +498,7 @@ namespace BizHawk.Client.Common
|
|||
// TODO: Why does the PSF loader need CbDeflater provided? Surely this is a matter internal to it.
|
||||
static byte[] CbDeflater(Stream instream, int size)
|
||||
{
|
||||
var ret = new MemoryStream();
|
||||
new GZipStream(instream, CompressionMode.Decompress).CopyTo(ret);
|
||||
return ret.ToArray();
|
||||
return new GZipStream(instream, CompressionMode.Decompress).ReadAllBytes();
|
||||
}
|
||||
var psf = new PSF();
|
||||
psf.Load(path, CbDeflater);
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.CollectionExtensions;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -67,17 +68,16 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
get
|
||||
{
|
||||
var (f, data) = GetStateClosestToFrame(frame);
|
||||
var (f, dataStream) = GetStateClosestToFrame(frame);
|
||||
if (f != frame)
|
||||
{
|
||||
data.Dispose();
|
||||
dataStream.Dispose();
|
||||
return NonState;
|
||||
}
|
||||
|
||||
var ms = new MemoryStream();
|
||||
data.CopyTo(ms);
|
||||
data.Dispose();
|
||||
return ms.ToArray();
|
||||
var data = dataStream.ReadAllBytes();
|
||||
dataStream.Dispose();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,10 +286,8 @@ namespace BizHawk.Client.Common
|
|||
return;
|
||||
}
|
||||
|
||||
var ms = new MemoryStream();
|
||||
using var s = state.GetReadStream();
|
||||
s.CopyTo(ms);
|
||||
_reserved.Add(state.Frame, ms.ToArray());
|
||||
_reserved.Add(state.Frame, s.ReadAllBytes());
|
||||
AddStateCache(state.Frame);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ using System.Windows.Forms;
|
|||
using BizHawk.Common;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Common.CollectionExtensions;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
// notes: eventually, we intend to have a "firmware acquisition interface" exposed to the emulator cores.
|
||||
|
@ -656,13 +657,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
foreach (var ai in hf.ArchiveItems)
|
||||
{
|
||||
hf.BindArchiveMember(ai);
|
||||
var stream = hf.GetStream();
|
||||
var ms = new MemoryStream();
|
||||
Util.CopyStream(hf.GetStream(), ms, stream.Length);
|
||||
string outfile = ai.Name;
|
||||
string myname = Path.GetFileName(outfile);
|
||||
outfile = Path.Combine(extractPath, myname);
|
||||
File.WriteAllBytes(outfile, ms.ToArray());
|
||||
File.WriteAllBytes(outfile, hf.GetStream().ReadAllBytes());
|
||||
hf.Unbind();
|
||||
|
||||
if (_cbAllowImport.Checked || Manager.CanFileBeImported(outfile))
|
||||
|
|
|
@ -11,17 +11,8 @@ namespace BizHawk.Common.IOExtensions
|
|||
|
||||
public static byte[] ReadAllBytes(this Stream stream)
|
||||
{
|
||||
const int BUFF_SIZE = 4096;
|
||||
var buffer = new byte[BUFF_SIZE];
|
||||
|
||||
int bytesRead;
|
||||
var inStream = new BufferedStream(stream);
|
||||
var outStream = new MemoryStream();
|
||||
|
||||
while ((bytesRead = inStream.Read(buffer, 0, BUFF_SIZE)) > 0)
|
||||
{
|
||||
outStream.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
stream.CopyTo(outStream);
|
||||
|
||||
return outStream.ToArray();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue