diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index f590441378..3d095e4c17 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -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 ReadNames; private static readonly Dictionary 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 /// not closed when finished! 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 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 callback) @@ -326,7 +307,7 @@ namespace BizHawk.Client.Common if (disposing) { - _zip.Close(); + _zip.Dispose(); } } } diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index 21f5f4518b..85265a57d7 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -39,6 +39,9 @@ False ..\References\ICSharpCode.SharpZipLib.dll + + ..\References\Ionic.Zip.dll + ..\References\LuaInterface.dll @@ -114,7 +117,9 @@ + + @@ -185,6 +190,7 @@ + diff --git a/BizHawk.Client.Common/IZipWriter.cs b/BizHawk.Client.Common/IZipWriter.cs new file mode 100644 index 0000000000..919de6c469 --- /dev/null +++ b/BizHawk.Client.Common/IZipWriter.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 callback); + } +} diff --git a/BizHawk.Client.Common/IonicZipWriter.cs b/BizHawk.Client.Common/IonicZipWriter.cs new file mode 100644 index 0000000000..0450656134 --- /dev/null +++ b/BizHawk.Client.Common/IonicZipWriter.cs @@ -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 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; + } + } + } +} diff --git a/BizHawk.Client.Common/SharpZipWriter.cs b/BizHawk.Client.Common/SharpZipWriter.cs new file mode 100644 index 0000000000..5277cd4ffc --- /dev/null +++ b/BizHawk.Client.Common/SharpZipWriter.cs @@ -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 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; + } + } + } +} diff --git a/References/Ionic.Zip.dll b/References/Ionic.Zip.dll new file mode 100644 index 0000000000..95fa928855 Binary files /dev/null and b/References/Ionic.Zip.dll differ