2013-10-27 22:07:40 +00:00
|
|
|
using System.Collections.Generic;
|
2014-01-08 03:53:53 +00:00
|
|
|
using System.IO;
|
2013-10-27 22:07:40 +00:00
|
|
|
|
|
|
|
using BizHawk.Common;
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Implementation of IHawkFileArchiveHandler using SevenZipSharp pure managed code
|
|
|
|
/// </summary>
|
|
|
|
public class SevenZipSharpArchiveHandler : IHawkFileArchiveHandler
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
private SevenZip.SevenZipExtractor _extractor;
|
|
|
|
|
2013-10-27 22:07:40 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
if (_extractor != null)
|
2013-10-27 22:07:40 +00:00
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
_extractor.Dispose();
|
|
|
|
_extractor = null;
|
2013-10-27 22:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CheckSignature(string fileName, out int offset, out bool isExecutable)
|
|
|
|
{
|
|
|
|
SevenZip.FileChecker.ThrowExceptions = false;
|
|
|
|
return SevenZip.FileChecker.CheckSignature(fileName, out offset, out isExecutable) != SevenZip.InArchiveFormat.None;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IHawkFileArchiveHandler Construct(string path)
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
var ret = new SevenZipSharpArchiveHandler();
|
2013-10-27 22:07:40 +00:00
|
|
|
ret.Open(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-08 03:53:53 +00:00
|
|
|
private void Open(string path)
|
2013-10-27 22:07:40 +00:00
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
_extractor = new SevenZip.SevenZipExtractor(path);
|
2013-10-27 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<HawkFileArchiveItem> Scan()
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
var ret = new List<HawkFileArchiveItem>();
|
|
|
|
for (int i = 0; i < _extractor.ArchiveFileData.Count; i++)
|
2013-10-27 22:07:40 +00:00
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
var afd = _extractor.ArchiveFileData[i];
|
|
|
|
if (afd.IsDirectory)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ai = new HawkFileArchiveItem
|
|
|
|
{
|
2014-02-04 21:15:33 +00:00
|
|
|
Name = HawkFile.Util_FixArchiveFilename(afd.FileName),
|
|
|
|
Size = (long)afd.Size, ArchiveIndex = i, Index = ret.Count
|
2014-01-08 03:53:53 +00:00
|
|
|
};
|
|
|
|
|
2013-10-27 22:07:40 +00:00
|
|
|
ret.Add(ai);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ExtractFile(int index, Stream stream)
|
|
|
|
{
|
2014-01-08 03:53:53 +00:00
|
|
|
_extractor.ExtractFile(index, stream);
|
2013-10-27 22:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|