firmware importer now supports archives
This commit is contained in:
parent
2f374d9199
commit
5cf5894329
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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<string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Emulation.DiscSystem
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue