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:
YoshiRulz 2025-05-31 07:48:10 +10:00
parent fe1b973132
commit f0daba69be
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 12 additions and 5 deletions

View File

@ -8,14 +8,17 @@ namespace BizHawk.Client.Common
public class FrameworkZipWriter : IZipWriter
{
private ZipArchive _archive;
private FileStream _fs;
private Zstd _zstd;
private readonly CompressionLevel _level;
private readonly int _zstdCompressionLevel;
public FrameworkZipWriter(string path, int compressionLevel)
{
_archive = new ZipArchive(new FileStream(path, FileMode.Create, FileAccess.Write),
ZipArchiveMode.Create, false);
_fs = new(path, FileMode.Create, FileAccess.Write);
_archive = new(_fs, ZipArchiveMode.Create, leaveOpen: true);
if (compressionLevel == 0)
_level = CompressionLevel.NoCompression;
else if (compressionLevel < 5)
@ -53,7 +56,9 @@ namespace BizHawk.Client.Common
_archive.Dispose();
_archive = null;
}
_fs?.Flush(flushToDisk: true);
_fs?.Dispose();
_fs = null;
if (_zstd != null)
{
_zstd.Dispose();

View File

@ -2096,8 +2096,10 @@ namespace BizHawk.Client.EmuHawk
if (saveram == null)
return true;
using (var writer = new BinaryWriter(new FileStream(newPath, FileMode.Create, FileAccess.Write)))
writer.Write(saveram, 0, saveram.Length);
FileStream fs = new(newPath, FileMode.Create, FileAccess.Write);
using (BinaryWriter writer = new(fs)) writer.Write(saveram);
fs.Flush(flushToDisk: true);
fs.Dispose();
if (file.Exists)
{