diff --git a/BizHawk.Client.Common/BinarySaveStates.cs b/BizHawk.Client.Common/BinarySaveStates.cs index 8bf3a327a7..17a19c6ff2 100644 --- a/BizHawk.Client.Common/BinarySaveStates.cs +++ b/BizHawk.Client.Common/BinarySaveStates.cs @@ -264,9 +264,9 @@ namespace BizHawk.Client.Common public BinaryStateSaver(string path, bool stateVersionTag = true) // stateVersionTag is a hack for reusing this for movie code { - _zip = new IonicZipWriter(path, Global.Config.SaveStateCompressionLevelNormal); + //_zip = new IonicZipWriter(path, Global.Config.SaveStateCompressionLevelNormal); //_zip = new SharpZipWriter(path, Global.Config.SaveStateCompressionLevelNormal); - //_zip = new SevenZipWriter(path, Global.Config.SaveStateCompressionLevelNormal); + _zip = new SevenZipWriter(path, Global.Config.SaveStateCompressionLevelNormal); if (stateVersionTag) { diff --git a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index 1e574701c8..4eea7aad6d 100644 --- a/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Windows.Forms; +using BizHawk.Common; using BizHawk.Client.Common; using BizHawk.Emulation.Common; using BizHawk.Client.EmuHawk.WinFormExtensions; @@ -431,6 +432,37 @@ namespace BizHawk.Client.EmuHawk } } + bool RunImportJobSingle(string basepath, string f, ref string errors) + { + try + { + var fi = new FileInfo(f); + if (!fi.Exists) return false; + + string target = Path.Combine(basepath, fi.Name); + if (new FileInfo(target).Exists) + { + //compare the files, if theyre the same. dont do anything + if (File.ReadAllBytes(target).SequenceEqual(File.ReadAllBytes(f))) + return false; + //hmm theyre different. import but rename it + string dir = Path.GetDirectoryName(target); + string ext = Path.GetExtension(target); + string name = Path.GetFileNameWithoutExtension(target); + name += " (variant)"; + target = Path.Combine(dir, name) + ext; + } + fi.CopyTo(target, false); + return true; + } + catch + { + if (errors != "") errors += "\n"; + errors += f; + return false; + } + } + void RunImportJob(IEnumerable files) { bool didSomething = false; @@ -438,29 +470,38 @@ namespace BizHawk.Client.EmuHawk string errors = ""; foreach(var f in files) { - try + using (var hf = new HawkFile(f)) { - var fi = new FileInfo(f); - if (!fi.Exists) continue; - string target = Path.Combine(basepath,fi.Name); - if(new FileInfo(target).Exists) + if (hf.IsArchive) { - //compare the files, if theyre the same. dont do anything - if(File.ReadAllBytes(target).SequenceEqual(File.ReadAllBytes(f))) - continue; - //hmm theyre different. import but rename it - string dir = Path.GetDirectoryName(target); - string ext = Path.GetExtension(target); - string name = Path.GetFileNameWithoutExtension(target); - name += " (variant)"; - target = Path.Combine(dir,name) + ext; + //blech. the worst extraction code in the universe. + string extractpath = System.IO.Path.GetTempFileName() + ".dir"; + DirectoryInfo di = null; + di = System.IO.Directory.CreateDirectory(extractpath); + + try + { + foreach (var ai in hf.ArchiveItems) + { + hf.BindArchiveMember(ai); + var stream = hf.GetStream(); + var ms = new MemoryStream(); + Util.CopyStream(hf.GetStream(), ms, stream.Length); + string outfile = ai.Name; + string myname = Path.GetFileName(outfile); + outfile = Path.Combine(extractpath, myname); + File.WriteAllBytes(outfile, ms.ToArray()); + hf.Unbind(); + didSomething |= RunImportJobSingle(basepath, outfile, ref errors); + } + } + finally + { + di.Delete(true); + } } - fi.CopyTo(target, false); - didSomething = true; - } - catch { - if (errors != "") errors += "\n"; - errors += f; + else + didSomething |= RunImportJobSingle(basepath, f, ref errors); } } diff --git a/BizHawk.Common/Util.cs b/BizHawk.Common/Util.cs index 0dc3f31839..6e787a859a 100644 --- a/BizHawk.Common/Util.cs +++ b/BizHawk.Common/Util.cs @@ -18,6 +18,20 @@ namespace BizHawk.Common HexConvPtr = (char*)HexConvHandle.AddrOfPinnedObject().ToPointer(); } + public static void CopyStream(Stream src, Stream dest, long len) + { + const int size = 0x2000; + byte[] buffer = new byte[size]; + while (len > 0) + { + long todo = len; + if (len > size) todo = size; + int n = src.Read(buffer, 0, (int)todo); + dest.Write(buffer, 0, n); + len -= n; + } + } + public static char* HexConvPtr { get; set; } public static bool IsPowerOfTwo(int x) diff --git a/BizHawk.Emulation.DiscSystem/Blobs/RiffMaster.cs b/BizHawk.Emulation.DiscSystem/Blobs/RiffMaster.cs index d6d4850498..5ab08e69be 100644 --- a/BizHawk.Emulation.DiscSystem/Blobs/RiffMaster.cs +++ b/BizHawk.Emulation.DiscSystem/Blobs/RiffMaster.cs @@ -2,6 +2,8 @@ using System.IO; using System.Collections.Generic; +using BizHawk.Common; + namespace BizHawk.Emulation.DiscSystem { /// @@ -70,23 +72,6 @@ namespace BizHawk.Emulation.DiscSystem public abstract RiffChunk Morph(); } - static class Util - { - public static void CopyStream(Stream src, Stream dest, long len) - { - const int size = 0x2000; - byte[] buffer = new byte[size]; - while (len > 0) - { - long todo = len; - if (len > size) todo = size; - int n = src.Read(buffer, 0, (int)todo); - dest.Write(buffer, 0, n); - len -= n; - } - } - } - public class RiffSubchunk : RiffChunk { public long Position;