mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
replaced ZLibNet with .Net DeflateStream class.
This commit is contained in:
parent
8eea67faee
commit
002298bb93
@ -33,7 +33,7 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Formats.Properties;
|
||||
|
||||
@ -303,6 +303,7 @@ namespace GameRes.Formats
|
||||
throw new FileFormatException ("GRP image encoder not available");
|
||||
bool is_grp = grp.Signature == FormatCatalog.ReadSignature (input);
|
||||
input.Position = 0;
|
||||
var start = output.Position;
|
||||
using (var zstream = new ZLibStream (output, CompressionMode.Compress, CompressionLevel.Level9, true))
|
||||
{
|
||||
if (is_grp)
|
||||
@ -317,9 +318,8 @@ namespace GameRes.Formats
|
||||
grp.Write (zstream, image);
|
||||
entry.UnpackedSize = (uint)zstream.TotalIn;
|
||||
}
|
||||
zstream.Flush();
|
||||
return (uint)zstream.TotalOut;
|
||||
}
|
||||
return (uint)(output.Position - start);
|
||||
}
|
||||
|
||||
public override ResourceOptions GetDefaultOptions ()
|
||||
|
@ -27,9 +27,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.AZSys
|
||||
{
|
||||
|
@ -29,8 +29,8 @@ using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.Selen
|
||||
{
|
||||
|
@ -51,6 +51,7 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Xaml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@ -58,10 +59,6 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="zlibnet, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\zlib\zlibnet.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ArcADPACK.cs" />
|
||||
@ -125,6 +122,7 @@
|
||||
<Compile Include="ArcRPA.cs" />
|
||||
<Compile Include="ArcS25.cs" />
|
||||
<Compile Include="ArcSAF.cs" />
|
||||
<Compile Include="ZLibStream.cs" />
|
||||
<None Include="ArcSeraph.cs" />
|
||||
<Compile Include="ArcSPack.cs" />
|
||||
<Compile Include="ArcSteinsGate.cs" />
|
||||
@ -290,14 +288,6 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="..\zlib\zlib32.dll">
|
||||
<Link>zlib32.dll</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\zlib\zlib64.dll">
|
||||
<Link>zlib64.dll</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<EmbeddedResource Include="Resources\ShiinaRio4.jpg" />
|
||||
<EmbeddedResource Include="Resources\ShiinaRio1.png" />
|
||||
<EmbeddedResource Include="Resources\ShiinaRio2.png" />
|
||||
|
@ -31,7 +31,7 @@ using System.ComponentModel.Composition;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Formats.Properties;
|
||||
|
||||
@ -200,13 +200,13 @@ namespace GameRes.Formats.NitroPlus
|
||||
{
|
||||
if (entry.IsPacked)
|
||||
{
|
||||
var start = destination.Position;
|
||||
using (var zstream = new ZLibStream (destination, CompressionMode.Compress,
|
||||
CompressionLevel.Level9, true))
|
||||
{
|
||||
file.CopyTo (zstream);
|
||||
zstream.Flush();
|
||||
entry.Size = (uint)zstream.TotalOut;
|
||||
}
|
||||
entry.Size = (uint)(destination.Position - start);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -32,7 +32,6 @@ using System.ComponentModel.Composition;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.NeXAS
|
||||
{
|
||||
|
@ -28,8 +28,8 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.NitroPlus
|
||||
{
|
||||
|
@ -31,9 +31,9 @@ using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Properties;
|
||||
using GameRes.Formats.Strings;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.RenPy
|
||||
{
|
||||
|
@ -27,8 +27,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.Lune
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.Seraphim
|
||||
{
|
||||
|
@ -31,10 +31,10 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Properties;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.ShiinaRio // 椎名里緒
|
||||
{
|
||||
@ -97,7 +97,7 @@ namespace GameRes.Formats.ShiinaRio // 椎名里緒
|
||||
Stream index;
|
||||
if (version >= 170)
|
||||
{
|
||||
if (0x78 != enc_index[8]) // FIXME: check if it looks like ZLib stream
|
||||
if (0x78 != enc_index[8]) // check if it looks like ZLib stream
|
||||
return null;
|
||||
var zindex = new MemoryStream (enc_index, 8, (int)index_length-8);
|
||||
index = new ZLibStream (zindex, CompressionMode.Decompress);
|
||||
|
@ -27,6 +27,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
@ -34,8 +35,8 @@ using System.Runtime.InteropServices;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Diagnostics;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Formats.Properties;
|
||||
|
||||
@ -174,7 +175,7 @@ namespace GameRes.Formats.KiriKiri
|
||||
entry.IsEncrypted = 0 != header.ReadUInt32();
|
||||
long file_size = header.ReadInt64();
|
||||
long packed_size = header.ReadInt64();
|
||||
if (file_size > uint.MaxValue || packed_size > uint.MaxValue)
|
||||
if (file_size > uint.MaxValue || packed_size > uint.MaxValue || packed_size > file.MaxOffset)
|
||||
{
|
||||
goto NextEntry;
|
||||
}
|
||||
@ -193,7 +194,7 @@ namespace GameRes.Formats.KiriKiri
|
||||
entry.Cipher = NoCryptAlgorithm;
|
||||
|
||||
char[] name = header.ReadChars (name_size);
|
||||
entry.Name = new string (name);
|
||||
entry.Name = NormalizePath (new string (name));
|
||||
entry.Type = FormatCatalog.Instance.GetTypeFromName (entry.Name);
|
||||
break;
|
||||
}
|
||||
@ -246,6 +247,13 @@ NextEntry:
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
static readonly Regex PathRe = new Regex (@"[^\\/]+[\\/]\.\.[\\/]");
|
||||
|
||||
private static string NormalizePath (string filename)
|
||||
{
|
||||
return PathRe.Replace (filename, "");
|
||||
}
|
||||
|
||||
private long SkipExeHeader (ArcView file)
|
||||
{
|
||||
long offset = 0x10;
|
||||
@ -507,13 +515,13 @@ NextEntry:
|
||||
};
|
||||
if (compress)
|
||||
{
|
||||
var start = output.Position;
|
||||
using (var zstream = new ZLibStream (output, CompressionMode.Compress, CompressionLevel.Level9, true))
|
||||
{
|
||||
xp3entry.Hash = CheckedCopy (file, zstream);
|
||||
zstream.Flush();
|
||||
segment.PackedSize = (uint)zstream.TotalOut;
|
||||
xp3entry.Size = segment.PackedSize;
|
||||
}
|
||||
segment.PackedSize = (uint)(output.Position - start);
|
||||
xp3entry.Size = segment.PackedSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -542,11 +550,9 @@ NextEntry:
|
||||
PackedSize = unpacked_size,
|
||||
};
|
||||
xp3entry.Segments.Add (segment);
|
||||
bool need_output_dispose = false;
|
||||
if (compress)
|
||||
{
|
||||
output = new ZLibStream (output, CompressionMode.Compress, CompressionLevel.Level9, true);
|
||||
need_output_dispose = true;
|
||||
}
|
||||
unsafe
|
||||
{
|
||||
@ -573,18 +579,17 @@ NextEntry:
|
||||
}
|
||||
if (hash_after_crypt)
|
||||
xp3entry.Hash = checksum.Value;
|
||||
if (compress)
|
||||
{
|
||||
output.Flush();
|
||||
segment.PackedSize = (uint)(output as ZLibStream).TotalOut;
|
||||
xp3entry.Size = segment.PackedSize;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
view.SafeMemoryMappedViewHandle.ReleasePointer();
|
||||
if (need_output_dispose)
|
||||
if (compress)
|
||||
{
|
||||
var dest = (output as ZLibStream).BaseStream;
|
||||
output.Dispose();
|
||||
segment.PackedSize = (uint)(dest.Position - segment.Offset);
|
||||
xp3entry.Size = segment.PackedSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Formats.Properties;
|
||||
using GameRes.Utility;
|
||||
@ -184,13 +184,13 @@ namespace GameRes.Formats.YuRis
|
||||
{
|
||||
if (entry.IsPacked)
|
||||
{
|
||||
var start = output.Position;
|
||||
using (var zstream = new ZLibStream (checked_stream, CompressionMode.Compress,
|
||||
CompressionLevel.Level9, true))
|
||||
{
|
||||
input.CopyTo (zstream);
|
||||
zstream.Flush();
|
||||
entry.Size = (uint)zstream.TotalOut;
|
||||
}
|
||||
entry.Size = (uint)(output.Position - start);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -26,8 +26,8 @@
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.Circus
|
||||
{
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.ScenePlayer
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.BlackRainbow
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
|
||||
namespace GameRes.Formats.AZSys
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ using System.IO;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media;
|
||||
using ZLibNet;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats
|
||||
|
@ -26,8 +26,8 @@
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.ScenePlayer
|
||||
{
|
||||
@ -50,10 +50,6 @@ namespace GameRes.Formats.ScenePlayer
|
||||
int first = stream.ReadByte() ^ 0x21;
|
||||
if (first != 0x78) // doesn't look like zlib stream
|
||||
return null;
|
||||
int flg = stream.ReadByte() ^ 0x21;
|
||||
int fcheck = first << 8 | flg;
|
||||
if (fcheck % 0x1f != 0)
|
||||
return null;
|
||||
|
||||
stream.Position = 0;
|
||||
using (var input = new XoredStream (stream, 0x21, true))
|
||||
|
@ -29,8 +29,8 @@ using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Utility;
|
||||
using ZLibNet;
|
||||
|
||||
namespace GameRes.Formats.AliceSoft
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using ZLibNet;
|
||||
using System.IO.Compression;
|
||||
|
||||
class Inflate
|
||||
{
|
||||
@ -16,8 +16,8 @@ class Inflate
|
||||
try
|
||||
{
|
||||
var input = File.Open (args[0], FileMode.Open, FileAccess.Read);
|
||||
// input.Position = 2;
|
||||
using (var stream = new ZLibStream (input, CompressionMode.Decompress))
|
||||
input.Position = 2;
|
||||
using (var stream = new DeflateStream (input, CompressionMode.Decompress))
|
||||
using (var output = File.Create (args[1]))
|
||||
stream.CopyTo (output);
|
||||
Console.WriteLine ("{0} => {1}", args[0], args[1]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user