(ZIP): switched to #ZipLib because Net library does not support encrypted archives.

This commit is contained in:
morkt 2018-01-29 03:49:43 +04:00
parent b4e1e41c93
commit f402d8272c
4 changed files with 65 additions and 19 deletions

View File

@ -67,7 +67,14 @@
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.FileSystem">
<HintPath>..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.0.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />

View File

@ -32,34 +32,37 @@ using System.Linq;
using System.Text;
using GameRes.Formats.Strings;
using SharpZip = ICSharpCode.SharpZipLib.Zip;
namespace GameRes.Formats.PkWare
{
internal class ZipEntry : PackedEntry
{
public readonly ZipArchiveEntry NativeEntry;
public readonly SharpZip.ZipEntry NativeEntry;
public ZipEntry (ZipArchiveEntry zip_entry)
public ZipEntry (SharpZip.ZipEntry zip_entry)
{
NativeEntry = zip_entry;
Name = zip_entry.FullName;
Type = FormatCatalog.Instance.GetTypeFromName (zip_entry.FullName);
Name = zip_entry.Name;
Type = FormatCatalog.Instance.GetTypeFromName (zip_entry.Name);
IsPacked = true;
// design decision of having 32bit entry sizes was made early during GameRes
// library development. nevertheless, large files will be extracted correctly
// despite the fact that size is reported as uint.MaxValue, because extraction is
// performed by .Net framework based on real size value.
Size = (uint)Math.Min (zip_entry.CompressedLength, uint.MaxValue);
UnpackedSize = (uint)Math.Min (zip_entry.Length, uint.MaxValue);
// offset is unknown and reported as '0' for all files.
Offset = 0;
Size = (uint)Math.Min (zip_entry.CompressedSize, uint.MaxValue);
UnpackedSize = (uint)Math.Min (zip_entry.Size, uint.MaxValue);
Offset = zip_entry.Offset;
}
}
internal class PkZipArchive : ArcFile
{
readonly ZipArchive m_zip;
readonly SharpZip.ZipFile m_zip;
public PkZipArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, ZipArchive native)
public SharpZip.ZipFile Native { get { return m_zip; } }
public PkZipArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, SharpZip.ZipFile native)
: base (arc, impl, dir)
{
m_zip = native;
@ -72,7 +75,7 @@ namespace GameRes.Formats.PkWare
if (!_zip_disposed)
{
if (disposing)
m_zip.Dispose();
m_zip.Close();
_zip_disposed = true;
}
base.Dispose (disposing);
@ -109,23 +112,29 @@ namespace GameRes.Formats.PkWare
internal ArcFile OpenZipArchive (ArcView file, Stream input)
{
var zip = new ZipArchive (input, ZipArchiveMode.Read, false, Encodings.cp932);
SharpZip.ZipConstants.DefaultCodePage = Properties.Settings.Default.ZIPEncodingCP;
var zip = new SharpZip.ZipFile (input);
try
{
var dir = zip.Entries.Where (z => !z.FullName.EndsWith ("/"))
.Select (z => new ZipEntry (z) as Entry).ToList();
var files = zip.Cast<SharpZip.ZipEntry>().Where (z => !z.IsDirectory);
bool has_encrypted = files.Any (z => z.IsCrypted);
if (has_encrypted)
zip.Password = QueryPassword (file);
var dir = files.Select (z => new ZipEntry (z) as Entry).ToList();
return new PkZipArchive (file, this, dir, zip);
}
catch
{
zip.Dispose();
zip.Close();
throw;
}
}
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
return ((ZipEntry)entry).NativeEntry.Open();
var zarc = (PkZipArchive)arc;
var zent = (ZipEntry)entry;
return zarc.Native.GetInputStream (zent.NativeEntry);
}
/// <summary>
@ -156,6 +165,11 @@ namespace GameRes.Formats.PkWare
}
}
string QueryPassword (ArcView file)
{
return ""; // TODO
}
public override ResourceOptions GetDefaultOptions ()
{
Encoding enc;

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="GameRes.Formats.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
<section name="GameRes.Formats.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
@ -180,4 +180,25 @@
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -2,4 +2,8 @@
<packages>
<package id="NVorbis" version="0.8.5.0" targetFramework="net46" />
<package id="SharpZipLib" version="1.0.0-alpha2" targetFramework="net46" />
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net46" />
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net46" />
<package id="System.Security.Cryptography.Algorithms" version="4.2.0" targetFramework="net46" />
<package id="System.Security.Cryptography.Primitives" version="4.0.0" targetFramework="net46" />
</packages>