mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(ZIP): switched to #ZipLib because Net library does not support encrypted archives.
This commit is contained in:
@@ -67,7 +67,14 @@
|
|||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.IO.Compression" />
|
<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.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.Xaml" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
|||||||
@@ -32,34 +32,37 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using GameRes.Formats.Strings;
|
using GameRes.Formats.Strings;
|
||||||
|
|
||||||
|
using SharpZip = ICSharpCode.SharpZipLib.Zip;
|
||||||
|
|
||||||
namespace GameRes.Formats.PkWare
|
namespace GameRes.Formats.PkWare
|
||||||
{
|
{
|
||||||
internal class ZipEntry : PackedEntry
|
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;
|
NativeEntry = zip_entry;
|
||||||
Name = zip_entry.FullName;
|
Name = zip_entry.Name;
|
||||||
Type = FormatCatalog.Instance.GetTypeFromName (zip_entry.FullName);
|
Type = FormatCatalog.Instance.GetTypeFromName (zip_entry.Name);
|
||||||
IsPacked = true;
|
IsPacked = true;
|
||||||
// design decision of having 32bit entry sizes was made early during GameRes
|
// design decision of having 32bit entry sizes was made early during GameRes
|
||||||
// library development. nevertheless, large files will be extracted correctly
|
// library development. nevertheless, large files will be extracted correctly
|
||||||
// despite the fact that size is reported as uint.MaxValue, because extraction is
|
// despite the fact that size is reported as uint.MaxValue, because extraction is
|
||||||
// performed by .Net framework based on real size value.
|
// performed by .Net framework based on real size value.
|
||||||
Size = (uint)Math.Min (zip_entry.CompressedLength, uint.MaxValue);
|
Size = (uint)Math.Min (zip_entry.CompressedSize, uint.MaxValue);
|
||||||
UnpackedSize = (uint)Math.Min (zip_entry.Length, uint.MaxValue);
|
UnpackedSize = (uint)Math.Min (zip_entry.Size, uint.MaxValue);
|
||||||
// offset is unknown and reported as '0' for all files.
|
Offset = zip_entry.Offset;
|
||||||
Offset = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class PkZipArchive : ArcFile
|
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)
|
: base (arc, impl, dir)
|
||||||
{
|
{
|
||||||
m_zip = native;
|
m_zip = native;
|
||||||
@@ -72,7 +75,7 @@ namespace GameRes.Formats.PkWare
|
|||||||
if (!_zip_disposed)
|
if (!_zip_disposed)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
m_zip.Dispose();
|
m_zip.Close();
|
||||||
_zip_disposed = true;
|
_zip_disposed = true;
|
||||||
}
|
}
|
||||||
base.Dispose (disposing);
|
base.Dispose (disposing);
|
||||||
@@ -109,23 +112,29 @@ namespace GameRes.Formats.PkWare
|
|||||||
|
|
||||||
internal ArcFile OpenZipArchive (ArcView file, Stream input)
|
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
|
try
|
||||||
{
|
{
|
||||||
var dir = zip.Entries.Where (z => !z.FullName.EndsWith ("/"))
|
var files = zip.Cast<SharpZip.ZipEntry>().Where (z => !z.IsDirectory);
|
||||||
.Select (z => new ZipEntry (z) as Entry).ToList();
|
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);
|
return new PkZipArchive (file, this, dir, zip);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
zip.Dispose();
|
zip.Close();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
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>
|
/// <summary>
|
||||||
@@ -156,6 +165,11 @@ namespace GameRes.Formats.PkWare
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string QueryPassword (ArcView file)
|
||||||
|
{
|
||||||
|
return ""; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
public override ResourceOptions GetDefaultOptions ()
|
public override ResourceOptions GetDefaultOptions ()
|
||||||
{
|
{
|
||||||
Encoding enc;
|
Encoding enc;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configSections>
|
<configSections>
|
||||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<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>
|
</sectionGroup>
|
||||||
</configSections>
|
</configSections>
|
||||||
<userSettings>
|
<userSettings>
|
||||||
@@ -180,4 +180,25 @@
|
|||||||
</setting>
|
</setting>
|
||||||
</GameRes.Formats.Properties.Settings>
|
</GameRes.Formats.Properties.Settings>
|
||||||
</userSettings>
|
</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>
|
||||||
|
|||||||
@@ -2,4 +2,8 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="NVorbis" version="0.8.5.0" targetFramework="net46" />
|
<package id="NVorbis" version="0.8.5.0" targetFramework="net46" />
|
||||||
<package id="SharpZipLib" version="1.0.0-alpha2" 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>
|
</packages>
|
||||||
Reference in New Issue
Block a user