Implement IHawkFileArchiveHandler using NuGet package SharpCompress
This commit is contained in:
parent
3c8c761cca
commit
d9c42f44a1
|
@ -56,6 +56,10 @@
|
|||
<HintPath>..\output\dll\nlua\NLua.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="SharpCompress, Version=0.24.0.0, Culture=neutral, PublicKeyToken=afb0a02973931d96">
|
||||
<HintPath>..\packages\SharpCompress.0.24.0\lib\net45\SharpCompress.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.105.2, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64">
|
||||
|
@ -260,6 +264,7 @@
|
|||
<Compile Include="SavestateManager.cs" />
|
||||
<Compile Include="SevenZipSharpArchiveHandler.cs" />
|
||||
<Compile Include="SevenZipWriter.cs" />
|
||||
<Compile Include="SharpCompressArchiveHandler.cs" />
|
||||
<Compile Include="SharpZipWriter.cs" />
|
||||
<Compile Include="SystemInfo.cs" />
|
||||
<Compile Include="tools\Cheat.cs" />
|
||||
|
@ -321,6 +326,9 @@
|
|||
<Name>BizHawk.Bizware.BizwareGL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="IHawkFileArchiveHandler">ArchiveHandler</see> implemented using SharpCompress from NuGet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Intended for Unix, which can't use SevenZipSharp, but later we might sacrifice whatever speed advantage that library has for the lower workload of one cross-platform library.
|
||||
/// </remarks>
|
||||
/// <seealso cref="SevenZipSharpArchiveHandler"/>
|
||||
public class SharpCompressArchiveHandler : IHawkFileArchiveHandler
|
||||
{
|
||||
private IArchive _archive;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_archive?.Dispose();
|
||||
_archive = null;
|
||||
}
|
||||
|
||||
public bool CheckSignature(string fileName, out int offset, out bool isExecutable)
|
||||
{
|
||||
offset = 0;
|
||||
isExecutable = false;
|
||||
try
|
||||
{
|
||||
using (var arcTest = ArchiveFactory.Open(fileName))
|
||||
switch (arcTest.Type)
|
||||
{
|
||||
case ArchiveType.Zip:
|
||||
case ArchiveType.SevenZip:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IHawkFileArchiveHandler Construct(string path)
|
||||
{
|
||||
var ret = new SharpCompressArchiveHandler();
|
||||
ret.Open(path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void Open(string path) => _archive = ArchiveFactory.Open(path);
|
||||
|
||||
public List<HawkFileArchiveItem> Scan() =>
|
||||
_archive.Entries.Where(e => !e.IsDirectory)
|
||||
.Select((e, i) => new HawkFileArchiveItem
|
||||
{
|
||||
Name = HawkFile.Util_FixArchiveFilename(e.Key),
|
||||
Size = e.Size,
|
||||
Index = i,
|
||||
ArchiveIndex = i
|
||||
})
|
||||
.ToList();
|
||||
|
||||
public void ExtractFile(int index, Stream stream)
|
||||
{
|
||||
using (var entryStream = _archive.Entries.Where(e => !e.IsDirectory).ElementAt(index).OpenEntryStream())
|
||||
entryStream.CopyTo(stream);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="SharpCompress" version="0.24.0" targetFramework="net461" />
|
||||
</packages>
|
|
@ -117,7 +117,20 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
BizHawk.Common.TempFileManager.Start();
|
||||
|
||||
HawkFile.ArchiveHandlerFactory = new SevenZipSharpArchiveHandler();
|
||||
#if true // switch to if false for system-agnostic glory!
|
||||
switch (EXE_PROJECT.OSTailoredCode.CurrentOS)
|
||||
{
|
||||
case EXE_PROJECT.OSTailoredCode.DistinctOS.Linux:
|
||||
case EXE_PROJECT.OSTailoredCode.DistinctOS.macOS:
|
||||
HawkFile.ArchiveHandlerFactory = new SharpCompressArchiveHandler();
|
||||
break;
|
||||
case EXE_PROJECT.OSTailoredCode.DistinctOS.Windows:
|
||||
HawkFile.ArchiveHandlerFactory = new SevenZipSharpArchiveHandler();
|
||||
break;
|
||||
}
|
||||
#else
|
||||
HawkFile.ArchiveHandlerFactory = new SharpCompressArchiveHandler();
|
||||
#endif
|
||||
|
||||
string cmdConfigFile = ArgParser.GetCmdConfigFile(args);
|
||||
if (cmdConfigFile != null) PathManager.SetDefaultIniPath(cmdConfigFile);
|
||||
|
|
Loading…
Reference in New Issue