Call `FileStream.Flush` for SaveRAM and movies (resolves #3419)
...and anything else which uses `FrameworkZipWriter`/`ZipStateSaver`, which I think is just savestates
This commit is contained in:
parent
fe1b973132
commit
f0daba69be
|
@ -8,14 +8,17 @@ namespace BizHawk.Client.Common
|
||||||
public class FrameworkZipWriter : IZipWriter
|
public class FrameworkZipWriter : IZipWriter
|
||||||
{
|
{
|
||||||
private ZipArchive _archive;
|
private ZipArchive _archive;
|
||||||
|
|
||||||
|
private FileStream _fs;
|
||||||
|
|
||||||
private Zstd _zstd;
|
private Zstd _zstd;
|
||||||
private readonly CompressionLevel _level;
|
private readonly CompressionLevel _level;
|
||||||
private readonly int _zstdCompressionLevel;
|
private readonly int _zstdCompressionLevel;
|
||||||
|
|
||||||
public FrameworkZipWriter(string path, int compressionLevel)
|
public FrameworkZipWriter(string path, int compressionLevel)
|
||||||
{
|
{
|
||||||
_archive = new ZipArchive(new FileStream(path, FileMode.Create, FileAccess.Write),
|
_fs = new(path, FileMode.Create, FileAccess.Write);
|
||||||
ZipArchiveMode.Create, false);
|
_archive = new(_fs, ZipArchiveMode.Create, leaveOpen: true);
|
||||||
if (compressionLevel == 0)
|
if (compressionLevel == 0)
|
||||||
_level = CompressionLevel.NoCompression;
|
_level = CompressionLevel.NoCompression;
|
||||||
else if (compressionLevel < 5)
|
else if (compressionLevel < 5)
|
||||||
|
@ -53,7 +56,9 @@ namespace BizHawk.Client.Common
|
||||||
_archive.Dispose();
|
_archive.Dispose();
|
||||||
_archive = null;
|
_archive = null;
|
||||||
}
|
}
|
||||||
|
_fs?.Flush(flushToDisk: true);
|
||||||
|
_fs?.Dispose();
|
||||||
|
_fs = null;
|
||||||
if (_zstd != null)
|
if (_zstd != null)
|
||||||
{
|
{
|
||||||
_zstd.Dispose();
|
_zstd.Dispose();
|
||||||
|
|
|
@ -2096,8 +2096,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (saveram == null)
|
if (saveram == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
using (var writer = new BinaryWriter(new FileStream(newPath, FileMode.Create, FileAccess.Write)))
|
FileStream fs = new(newPath, FileMode.Create, FileAccess.Write);
|
||||||
writer.Write(saveram, 0, saveram.Length);
|
using (BinaryWriter writer = new(fs)) writer.Write(saveram);
|
||||||
|
fs.Flush(flushToDisk: true);
|
||||||
|
fs.Dispose();
|
||||||
|
|
||||||
if (file.Exists)
|
if (file.Exists)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue