add infrastructure to use alternate zipping libraries in savestate. use DotNetZip for some speedupzzzzzzzzzzzz

This commit is contained in:
goyuken 2014-10-09 23:39:13 +00:00
parent 070050fd34
commit a09c488f5b
6 changed files with 120 additions and 26 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
//using Ionic.Zip;
namespace BizHawk.Client.Common
{
@ -27,17 +28,8 @@ namespace BizHawk.Client.Common
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> WriteNames;
@ -104,7 +96,6 @@ namespace BizHawk.Client.Common
if (!_isDisposed)
{
_isDisposed = true;
if (disposing)
{
_zip.Close();
@ -251,7 +242,7 @@ namespace BizHawk.Client.Common
public class BinaryStateSaver : IDisposable
{
private readonly ZipOutputStream _zip;
private readonly IZipWriter _zip;
private bool _isDisposed;
private static void WriteVersion(Stream s)
@ -267,12 +258,8 @@ namespace BizHawk.Client.Common
/// <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
{
_zip = new ZipOutputStream(s)
{
IsStreamOwner = false,
UseZip64 = UseZip64.Off
};
_zip.SetLevel(Global.Config.SaveStateCompressionLevelNormal);
_zip = new IonicZipWriter(s, Global.Config.SaveStateCompressionLevelNormal);
//_zip = new SharpZipWriter(s, Global.Config.SaveStateCompressionLevelNormal);
if (stateVersionTag)
{
@ -283,13 +270,7 @@ namespace BizHawk.Client.Common
public void PutLump(BinaryStateLump lump, Action<Stream> callback)
{
var name = BinaryStateFileNames.GetWriteName(lump);
var e = new ZipEntry(name);
if (Global.Config.SaveStateCompressionLevelNormal == 0)
e.CompressionMethod = CompressionMethod.Stored;
else e.CompressionMethod = CompressionMethod.Deflated;
_zip.PutNextEntry(e);
callback(_zip);
_zip.CloseEntry();
_zip.WriteItem(name, callback);
}
public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
@ -326,7 +307,7 @@ namespace BizHawk.Client.Common
if (disposing)
{
_zip.Close();
_zip.Dispose();
}
}
}

View File

@ -39,6 +39,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\References\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="LuaInterface">
<HintPath>..\References\LuaInterface.dll</HintPath>
</Reference>
@ -114,7 +117,9 @@
<Compile Include="inputAdapters\InputAdapterExtensions.cs" />
<Compile Include="inputAdapters\InputAdapters.cs" />
<Compile Include="inputAdapters\InputManager.cs" />
<Compile Include="IonicZipWriter.cs" />
<Compile Include="IPS.cs" />
<Compile Include="IZipWriter.cs" />
<Compile Include="KeyTurbo.cs" />
<Compile Include="lua\EmuLuaLibrary.Bit.cs" />
<Compile Include="lua\EmuLuaLibrary.Emu.cs" />
@ -185,6 +190,7 @@
<Compile Include="SaveSlotManager.cs" />
<Compile Include="SavestateManager.cs" />
<Compile Include="SevenZipSharpArchiveHandler.cs" />
<Compile Include="SharpZipWriter.cs" />
<Compile Include="SystemInfo.cs" />
<Compile Include="tools\Cheat.cs" />
<Compile Include="tools\CheatList.cs" />

View File

@ -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);
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}
}

BIN
References/Ionic.Zip.dll Normal file

Binary file not shown.