Proper fixes for all platforms

This commit is contained in:
Adam Hathcock
2018-04-29 16:27:26 +01:00
parent 91d753cbdb
commit abddabf18e
4 changed files with 31 additions and 9 deletions

View File

@@ -32,11 +32,28 @@ namespace SharpCompress.Common
Password = Encoding.UTF8;
}
#if NETSTANDARD1_3 || NETSTANDARD2_0
static ArchiveEncoding()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
#endif
public string Decode(byte[] bytes)
{
return Decode(bytes, 0, bytes.Length);
}
public string Decode437(byte[] bytes)
{
#if NETSTANDARD1_0
return Decode(bytes, 0, bytes.Length);
#else
var extendedASCIIEncoding = Encoding.GetEncoding(437);
return extendedASCIIEncoding.GetString(bytes, 0, bytes.Length);
#endif
}
public string Decode(byte[] bytes, int start, int length)
{
return GetDecoder().Invoke(bytes, start, length);

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Linq;
using System.Text;
@@ -34,12 +33,11 @@ namespace SharpCompress.Common.Zip.Headers
byte[] name = reader.ReadBytes(nameLength);
byte[] extra = reader.ReadBytes(extraLength);
byte[] comment = reader.ReadBytes(commentLength);
if ((Flags & HeaderFlags.UTF8) == 0)
{
// Use IBM Code Page 437 (IBM PC character encoding set)
var extendedASCIIEncoding = Encoding.GetEncoding("IBM437");
Name = extendedASCIIEncoding.GetString(name, 0, name.Length);
Comment = extendedASCIIEncoding.GetString(comment, 0, comment.Length);
Name = ArchiveEncoding.Decode437(name);
Comment = ArchiveEncoding.Decode437(comment);
}
else
{
@@ -62,10 +60,12 @@ namespace SharpCompress.Common.Zip.Headers
{
CompressedSize = zip64ExtraData.CompressedSize;
}
if (UncompressedSize == uint.MaxValue)
{
UncompressedSize = zip64ExtraData.UncompressedSize;
}
if (RelativeOffsetOfEntryHeader == uint.MaxValue)
{
RelativeOffsetOfEntryHeader = zip64ExtraData.RelativeOffsetOfEntryHeader;

View File

@@ -28,8 +28,7 @@ namespace SharpCompress.Common.Zip.Headers
if ((Flags & HeaderFlags.UTF8) == 0)
{
// Use IBM Code Page 437 (IBM PC character encoding set)
var extendedASCIIEncoding = Encoding.GetEncoding("IBM437");
Name = extendedASCIIEncoding.GetString(name, 0, name.Length);
Name = ArchiveEncoding.Decode437(name);
}
else
{

View File

@@ -19,7 +19,7 @@
<PackageLicenseUrl>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</PackageLicenseUrl>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Description>SharpCompress is a compression library for NET Standard 1.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</Description>
<Description>SharpCompress is a compression library for NET Standard 1.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</Description>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.0' ">
<DefineConstants>$(DefineConstants);NO_FILE;NO_CRYPTO;SILVERLIGHT</DefineConstants>
@@ -27,7 +27,13 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0"/>
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0"/>
</ItemGroup>
</Project>