This commit is contained in:
nattthebear 2015-06-30 23:28:26 -04:00
parent de98e0ed66
commit a0f3931257
1 changed files with 8 additions and 13 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Zip;
//using Ionic.Zip; //using Ionic.Zip;
@ -135,25 +136,19 @@ namespace BizHawk.Client.Common
} }
} }
private static byte[] zipheader = new byte[] { 0x50, 0x4b, 0x03, 0x04 };
public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false) public static BinaryStateLoader LoadAndDetect(string filename, bool isMovieLoad = false)
{ {
var ret = new BinaryStateLoader(); var ret = new BinaryStateLoader();
// PORTABLE TODO - SKIP THIS.. FOR NOW using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
// check whether its an archive before we try opening it
bool isArchive;
using (var archiveChecker = new SevenZipSharpArchiveHandler())
{ {
int offset; byte[] data = new byte[4];
bool isExecutable; fs.Read(data, 0, 4);
isArchive = archiveChecker.CheckSignature(filename, out offset, out isExecutable); if (!data.SequenceEqual(zipheader))
return null;
} }
if (!isArchive)
{
return null;
}
try try
{ {
ret._zip = new ZipFile(filename); ret._zip = new ZipFile(filename);