add infrastructure to use alternate zipping libraries in savestate. use DotNetZip for some speedupzzzzzzzzzzzz
This commit is contained in:
parent
070050fd34
commit
a09c488f5b
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
//using Ionic.Zip;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
|
@ -27,17 +28,8 @@ namespace BizHawk.Client.Common
|
||||||
Markers
|
Markers
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BinaryStateFileNames
|
public static class BinaryStateFileNames
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
public const string Versiontag = "BizState 1.0";
|
|
||||||
public const string Corestate = "Core";
|
|
||||||
public const string Framebuffer = "Framebuffer";
|
|
||||||
public const string Input = "Input Log";
|
|
||||||
public const string CorestateText = "CoreText";
|
|
||||||
public const string Movieheader = "Header";
|
|
||||||
*/
|
|
||||||
|
|
||||||
private static readonly Dictionary<BinaryStateLump, string> ReadNames;
|
private static readonly Dictionary<BinaryStateLump, string> ReadNames;
|
||||||
private static readonly Dictionary<BinaryStateLump, string> WriteNames;
|
private static readonly Dictionary<BinaryStateLump, string> WriteNames;
|
||||||
|
|
||||||
|
@ -104,7 +96,6 @@ namespace BizHawk.Client.Common
|
||||||
if (!_isDisposed)
|
if (!_isDisposed)
|
||||||
{
|
{
|
||||||
_isDisposed = true;
|
_isDisposed = true;
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
_zip.Close();
|
_zip.Close();
|
||||||
|
@ -251,7 +242,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public class BinaryStateSaver : IDisposable
|
public class BinaryStateSaver : IDisposable
|
||||||
{
|
{
|
||||||
private readonly ZipOutputStream _zip;
|
private readonly IZipWriter _zip;
|
||||||
private bool _isDisposed;
|
private bool _isDisposed;
|
||||||
|
|
||||||
private static void WriteVersion(Stream s)
|
private static void WriteVersion(Stream s)
|
||||||
|
@ -267,12 +258,8 @@ namespace BizHawk.Client.Common
|
||||||
/// <param name="s">not closed when finished!</param>
|
/// <param name="s">not closed when finished!</param>
|
||||||
public BinaryStateSaver(Stream s, bool stateVersionTag = true) // stateVersionTag is a hack for reusing this for movie code
|
public BinaryStateSaver(Stream s, bool stateVersionTag = true) // stateVersionTag is a hack for reusing this for movie code
|
||||||
{
|
{
|
||||||
_zip = new ZipOutputStream(s)
|
_zip = new IonicZipWriter(s, Global.Config.SaveStateCompressionLevelNormal);
|
||||||
{
|
//_zip = new SharpZipWriter(s, Global.Config.SaveStateCompressionLevelNormal);
|
||||||
IsStreamOwner = false,
|
|
||||||
UseZip64 = UseZip64.Off
|
|
||||||
};
|
|
||||||
_zip.SetLevel(Global.Config.SaveStateCompressionLevelNormal);
|
|
||||||
|
|
||||||
if (stateVersionTag)
|
if (stateVersionTag)
|
||||||
{
|
{
|
||||||
|
@ -283,13 +270,7 @@ namespace BizHawk.Client.Common
|
||||||
public void PutLump(BinaryStateLump lump, Action<Stream> callback)
|
public void PutLump(BinaryStateLump lump, Action<Stream> callback)
|
||||||
{
|
{
|
||||||
var name = BinaryStateFileNames.GetWriteName(lump);
|
var name = BinaryStateFileNames.GetWriteName(lump);
|
||||||
var e = new ZipEntry(name);
|
_zip.WriteItem(name, callback);
|
||||||
if (Global.Config.SaveStateCompressionLevelNormal == 0)
|
|
||||||
e.CompressionMethod = CompressionMethod.Stored;
|
|
||||||
else e.CompressionMethod = CompressionMethod.Deflated;
|
|
||||||
_zip.PutNextEntry(e);
|
|
||||||
callback(_zip);
|
|
||||||
_zip.CloseEntry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
|
public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
|
||||||
|
@ -326,7 +307,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
_zip.Close();
|
_zip.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\References\ICSharpCode.SharpZipLib.dll</HintPath>
|
<HintPath>..\References\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Ionic.Zip">
|
||||||
|
<HintPath>..\References\Ionic.Zip.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="LuaInterface">
|
<Reference Include="LuaInterface">
|
||||||
<HintPath>..\References\LuaInterface.dll</HintPath>
|
<HintPath>..\References\LuaInterface.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -114,7 +117,9 @@
|
||||||
<Compile Include="inputAdapters\InputAdapterExtensions.cs" />
|
<Compile Include="inputAdapters\InputAdapterExtensions.cs" />
|
||||||
<Compile Include="inputAdapters\InputAdapters.cs" />
|
<Compile Include="inputAdapters\InputAdapters.cs" />
|
||||||
<Compile Include="inputAdapters\InputManager.cs" />
|
<Compile Include="inputAdapters\InputManager.cs" />
|
||||||
|
<Compile Include="IonicZipWriter.cs" />
|
||||||
<Compile Include="IPS.cs" />
|
<Compile Include="IPS.cs" />
|
||||||
|
<Compile Include="IZipWriter.cs" />
|
||||||
<Compile Include="KeyTurbo.cs" />
|
<Compile Include="KeyTurbo.cs" />
|
||||||
<Compile Include="lua\EmuLuaLibrary.Bit.cs" />
|
<Compile Include="lua\EmuLuaLibrary.Bit.cs" />
|
||||||
<Compile Include="lua\EmuLuaLibrary.Emu.cs" />
|
<Compile Include="lua\EmuLuaLibrary.Emu.cs" />
|
||||||
|
@ -185,6 +190,7 @@
|
||||||
<Compile Include="SaveSlotManager.cs" />
|
<Compile Include="SaveSlotManager.cs" />
|
||||||
<Compile Include="SavestateManager.cs" />
|
<Compile Include="SavestateManager.cs" />
|
||||||
<Compile Include="SevenZipSharpArchiveHandler.cs" />
|
<Compile Include="SevenZipSharpArchiveHandler.cs" />
|
||||||
|
<Compile Include="SharpZipWriter.cs" />
|
||||||
<Compile Include="SystemInfo.cs" />
|
<Compile Include="SystemInfo.cs" />
|
||||||
<Compile Include="tools\Cheat.cs" />
|
<Compile Include="tools\Cheat.cs" />
|
||||||
<Compile Include="tools\CheatList.cs" />
|
<Compile Include="tools\CheatList.cs" />
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace BizHawk.Client.Common
|
||||||
|
{
|
||||||
|
interface IZipWriter : IDisposable
|
||||||
|
{
|
||||||
|
void WriteItem(string name, Action<Stream> callback);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using Ionic.Zip;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace BizHawk.Client.Common
|
||||||
|
{
|
||||||
|
public class IonicZipWriter : IZipWriter
|
||||||
|
{
|
||||||
|
private ZipOutputStream z;
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
public IonicZipWriter(Stream s, int compressionlevel)
|
||||||
|
{
|
||||||
|
level = compressionlevel;
|
||||||
|
z = new ZipOutputStream(s, true)
|
||||||
|
{
|
||||||
|
EnableZip64 = Zip64Option.Never,
|
||||||
|
CompressionLevel = (Ionic.Zlib.CompressionLevel)level
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteItem(string name, Action<Stream> callback)
|
||||||
|
{
|
||||||
|
var e = z.PutNextEntry(name);
|
||||||
|
if (level == 0)
|
||||||
|
e.CompressionMethod = CompressionMethod.None;
|
||||||
|
else
|
||||||
|
e.CompressionMethod = CompressionMethod.Deflate;
|
||||||
|
callback(z);
|
||||||
|
// there is no CloseEntry() call
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (z != null)
|
||||||
|
{
|
||||||
|
z.Dispose();
|
||||||
|
z = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace BizHawk.Client.Common
|
||||||
|
{
|
||||||
|
public class SharpZipWriter : IZipWriter
|
||||||
|
{
|
||||||
|
private ZipOutputStream z;
|
||||||
|
private int level;
|
||||||
|
|
||||||
|
public SharpZipWriter(Stream s, int compressionlevel)
|
||||||
|
{
|
||||||
|
level = compressionlevel;
|
||||||
|
z = new ZipOutputStream(s)
|
||||||
|
{
|
||||||
|
IsStreamOwner = false,
|
||||||
|
UseZip64 = UseZip64.Off
|
||||||
|
};
|
||||||
|
z.SetLevel(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteItem(string name, Action<Stream> callback)
|
||||||
|
{
|
||||||
|
var e = new ZipEntry(name);
|
||||||
|
if (level == 0)
|
||||||
|
e.CompressionMethod = CompressionMethod.Stored;
|
||||||
|
else
|
||||||
|
e.CompressionMethod = CompressionMethod.Deflated;
|
||||||
|
z.PutNextEntry(e);
|
||||||
|
callback(z);
|
||||||
|
z.CloseEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (z != null)
|
||||||
|
{
|
||||||
|
z.Dispose();
|
||||||
|
z = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue