mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Update RV Compress code
This commit is contained in:
@@ -362,7 +362,6 @@ namespace Compress.SevenZip.Compress.ZSTD
|
||||
sizeToGo -= sizenow;
|
||||
}
|
||||
|
||||
position += offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using Compress.SevenZip.Compress.ZSTD;
|
||||
using Compress.SevenZip.Structure;
|
||||
using FileInfo = RVIO.FileInfo;
|
||||
|
||||
@@ -9,6 +11,14 @@ namespace Compress.SevenZip
|
||||
{
|
||||
public partial class SevenZ : ICompress
|
||||
{
|
||||
|
||||
public enum sevenZipCompressType
|
||||
{
|
||||
uncompressed,
|
||||
lzma,
|
||||
zstd
|
||||
}
|
||||
|
||||
public static bool supportZstd
|
||||
{
|
||||
get;
|
||||
@@ -17,7 +27,14 @@ namespace Compress.SevenZip
|
||||
|
||||
public static void TestForZstd()
|
||||
{
|
||||
supportZstd = RVIO.File.Exists("libzstd.dll");
|
||||
supportZstd = false;
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
{
|
||||
var root = Path.GetDirectoryName(typeof(ZstandardInterop).Assembly.Location);
|
||||
var path = Environment.Is64BitProcess ? "x64" : "x86";
|
||||
var file = Path.Combine(root, path, "libzstd.dll");
|
||||
supportZstd = RVIO.File.Exists(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +60,7 @@ namespace Compress.SevenZip
|
||||
|
||||
private SignatureHeader _signatureHeader;
|
||||
|
||||
private bool _compressed = true;
|
||||
private sevenZipCompressType _compressed = sevenZipCompressType.lzma;
|
||||
|
||||
|
||||
private long _baseOffset;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Compress.SevenZip.Compress.LZMA;
|
||||
using Compress.SevenZip.Compress.ZSTD;
|
||||
using Compress.SevenZip.Structure;
|
||||
using Compress.Utils;
|
||||
using FileInfo = RVIO.FileInfo;
|
||||
@@ -19,16 +20,21 @@ namespace Compress.SevenZip
|
||||
|
||||
public ZipReturn ZipFileCreate(string newFilename)
|
||||
{
|
||||
return ZipFileCreate(newFilename, true);
|
||||
return ZipFileCreate(newFilename, sevenZipCompressType.lzma);
|
||||
}
|
||||
|
||||
|
||||
public ZipReturn ZipFileCreateFromUncompressedSize(string newFilename, ulong unCompressedSize)
|
||||
|
||||
public ZipReturn ZipFileCreateFromUncompressedSize(string newFilename, sevenZipCompressType ctype, ulong unCompressedSize)
|
||||
{
|
||||
return ZipFileCreate(newFilename, true, GetDictionarySizeFromUncompressedSize(unCompressedSize));
|
||||
if (ctype == sevenZipCompressType.zstd)
|
||||
{
|
||||
if (!supportZstd)
|
||||
ctype = sevenZipCompressType.lzma;
|
||||
}
|
||||
|
||||
return ZipFileCreate(newFilename, ctype, GetDictionarySizeFromUncompressedSize(unCompressedSize));
|
||||
}
|
||||
|
||||
public ZipReturn ZipFileCreate(string newFilename, bool compressOutput, int dictionarySize = 1 << 24, int numFastBytes = 64)
|
||||
public ZipReturn ZipFileCreate(string newFilename, sevenZipCompressType compressOutput, int dictionarySize = 1 << 24, int numFastBytes = 64)
|
||||
{
|
||||
if (ZipOpen != ZipOpenType.Closed)
|
||||
{
|
||||
@@ -59,22 +65,21 @@ namespace Compress.SevenZip
|
||||
_compressed = compressOutput;
|
||||
|
||||
_unpackedStreamSize = 0;
|
||||
if (_compressed)
|
||||
if (_compressed == sevenZipCompressType.lzma)
|
||||
{
|
||||
LzmaEncoderProperties ep = new LzmaEncoderProperties(true, dictionarySize, numFastBytes);
|
||||
LzmaStream lzs = new LzmaStream(ep, false, _zipFs);
|
||||
_codeMSbytes = lzs.Properties;
|
||||
_lzmaStream = lzs;
|
||||
|
||||
|
||||
/*
|
||||
ZstandardStream zss = new ZstandardStream(_zipFs, 22, true);
|
||||
_codeMSbytes = new byte[] { 1, 4, 18, 0, 0 };
|
||||
_lzmaStream = zss;
|
||||
*/
|
||||
_packStreamStart = (ulong)_zipFs.Position;
|
||||
}
|
||||
|
||||
else if (_compressed == sevenZipCompressType.zstd)
|
||||
{
|
||||
ZstandardStream zss = new ZstandardStream(_zipFs, 18, true);
|
||||
_codeMSbytes = new byte[] { 1, 4, 18, 0, 0 };
|
||||
_lzmaStream = zss;
|
||||
_packStreamStart = (ulong)_zipFs.Position;
|
||||
}
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
@@ -121,7 +126,7 @@ namespace Compress.SevenZip
|
||||
_unpackedStreamSize += uncompressedSize;
|
||||
|
||||
_localFiles.Add(lf);
|
||||
stream = _compressed ? _lzmaStream : _zipFs;
|
||||
stream = _compressed == sevenZipCompressType.uncompressed ? _zipFs : _lzmaStream;
|
||||
return ZipReturn.ZipGood;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Compress.SevenZip
|
||||
_header.StreamsInfo = new StreamsInfo { PackPosition = 0 };
|
||||
|
||||
//StreamsInfo.PackedStreamsInfo
|
||||
if (_compressed)
|
||||
if (_compressed!=sevenZipCompressType.uncompressed)
|
||||
{
|
||||
_header.StreamsInfo.PackedStreams = new PackedStreamInfo[1];
|
||||
_header.StreamsInfo.PackedStreams[0] = new PackedStreamInfo { PackedSize = _packStreamSize };
|
||||
@@ -105,7 +105,7 @@ namespace Compress.SevenZip
|
||||
}
|
||||
//StreamsInfo.PackedStreamsInfo, no CRC or StreamPosition required
|
||||
|
||||
if (_compressed)
|
||||
if (_compressed != sevenZipCompressType.uncompressed)
|
||||
{
|
||||
//StreamsInfo.Folders
|
||||
_header.StreamsInfo.Folders = new Folder[1];
|
||||
@@ -200,8 +200,9 @@ namespace Compress.SevenZip
|
||||
|
||||
private void CloseWriting7Zip()
|
||||
{
|
||||
if (_compressed)
|
||||
if (_compressed != sevenZipCompressType.uncompressed)
|
||||
{
|
||||
_lzmaStream.Flush();
|
||||
_lzmaStream.Close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user