update to 0.6.6

This commit is contained in:
Razor12911
2022-11-11 11:12:43 +02:00
parent fb6bcfa239
commit 5c4cd7a5b0
35 changed files with 1673 additions and 4019 deletions

View File

@@ -274,7 +274,6 @@ begin
S := ReplaceText(S, '<insize>', StreamInfo^.OldSize.ToString);
S := ReplaceText(S, '<outsize>', StreamInfo^.NewSize.ToString);
Res := 0;
Res := 0;
if ContainsText(S, '<fileres>') and Funcs^.GetResource(StreamInfo^.Resource,
nil, @Res) and (Res > 0) then
begin
@@ -680,7 +679,7 @@ var
Bytes: TBytes;
Ini: TMemIniFile;
SL: TStringList;
ExeStruct: PExeStruct;
ExeStruct: TExeStruct;
Y, Z: Integer;
List: TStringDynArray;
@@ -699,80 +698,84 @@ begin
GetCmdStr(Ini.ReadString(SL[I], 'Decode', ''), 0)) then
for K := Low(List) to High(List) do
begin
New(ExeStruct);
Insert(List[K], Codec.Names, Length(Codec.Names));
ExeStruct^.Name := List[K];
Bytes := BytesOf(ExeStruct^.Name);
ExeStruct^.ID := Utils.Hash32(0, @Bytes[0], Length(Bytes));
ExeStruct.Name := List[K];
Bytes := BytesOf(ExeStruct.Name);
ExeStruct.ID := Utils.Hash32(0, @Bytes[0], Length(Bytes));
for X := 0 to 1 do
begin
ExeStruct^.IsLib[X] := False;
ExeStruct.IsLib[X] := False;
if X = 0 then
S1 := Ini.ReadString(SL[I], 'Encode', '')
else
S1 := Ini.ReadString(SL[I], 'Decode', '');
S1 := ReplaceText(S1, '<codec>', List[K]);
ExeStruct^.Exec[X] := ExtractFilePath(Utils.GetModuleName) +
ExeStruct.Exec[X] := ExtractFilePath(Utils.GetModuleName) +
GetCmdStr(S1, 0);
ExeStruct^.Param[X] := '';
ExeStruct^.Mode[X] := 0;
ExeStruct.Param[X] := '';
ExeStruct.Mode[X] := 0;
for J := 1 to GetCmdCount(S1) - 1 do
begin
S2 := GetCmdStr(S1, J);
if ContainsText(S2, '<library>') then
begin
SetBits(ExeStruct^.Mode[X], STDIO_MODE, 0, 2);
ExeStruct^.IsLib[X] := True;
SetBits(ExeStruct.Mode[X], STDIO_MODE, 0, 2);
ExeStruct.IsLib[X] := True;
continue;
end
else if ContainsText(S2, '<stdin>') or ContainsText(S2, '[stdin]')
then
begin
SetBits(ExeStruct^.Mode[X], 1, 0, 1);
SetBits(ExeStruct.Mode[X], 1, 0, 1);
continue;
end
else if ContainsText(S2, '<stdout>') or ContainsText(S2, '[stdout]')
then
begin
SetBits(ExeStruct^.Mode[X], 1, 1, 1);
SetBits(ExeStruct.Mode[X], 1, 1, 1);
continue;
end
else if ContainsText(S2, '<filein>') or ContainsText(S2, '[filein]')
then
begin
S3 := IfThen(X = 0, FILE_IN, FILE_OUT);
SetBits(ExeStruct^.Mode[X], 0, 0, 1);
SetBits(ExeStruct.Mode[X], 0, 0, 1);
if ContainsText(S2, '<filein>') then
ExeStruct^.InFile[X] := ExtractStr('<filein>', S2)
ExeStruct.InFile[X] := ExtractStr('<filein>', S2)
else
ExeStruct^.InFile[X] := ExtractStr('[filein]', S2);
S2 := ReplaceText(S2, ExeStruct^.InFile[X], S3);
ExeStruct^.InFile[X] := ReplaceText(ExeStruct^.InFile[X],
ExeStruct.InFile[X] := ExtractStr('[filein]', S2);
S2 := ReplaceText(S2, ExeStruct.InFile[X], S3);
ExeStruct.InFile[X] := ReplaceText(ExeStruct.InFile[X],
'<filein>', S3);
ExeStruct^.InFile[X] := ReplaceText(ExeStruct^.InFile[X],
ExeStruct.InFile[X] := ReplaceText(ExeStruct.InFile[X],
'[filein]', S3);
S2 := ExeStruct.InFile[X];
if ContainsText(S2, '[filein]') then
continue;
end
else if ContainsText(S2, '<fileout>') or
ContainsText(S2, '[fileout]') then
begin
S3 := IfThen(X = 0, FILE_OUT, FILE_IN);
SetBits(ExeStruct^.Mode[X], 0, 1, 1);
SetBits(ExeStruct.Mode[X], 0, 1, 1);
if ContainsText(S2, '<fileout>') then
ExeStruct^.OutFile[X] := ExtractStr('<fileout>', S2)
ExeStruct.OutFile[X] := ExtractStr('<fileout>', S2)
else
ExeStruct^.OutFile[X] := ExtractStr('[fileout]', S2);
S2 := ReplaceText(S2, ExeStruct^.OutFile[X], S3);
ExeStruct^.OutFile[X] := ReplaceText(ExeStruct^.OutFile[X],
ExeStruct.OutFile[X] := ExtractStr('[fileout]', S2);
ExeStruct.OutFile[X] := ReplaceText(ExeStruct.OutFile[X],
'<fileout>', S3);
ExeStruct^.OutFile[X] := ReplaceText(ExeStruct^.OutFile[X],
ExeStruct.OutFile[X] := ReplaceText(ExeStruct.OutFile[X],
'[fileout]', S3);
S2 := ExeStruct.OutFile[X];
if ContainsText(S2, '[fileout]') then
continue;
end;
S2 := IfThen((Pos(' ', S2) > 0) or (S2 = ''), '"' + S2 + '"', S2);
ExeStruct^.Param[X] := ExeStruct^.Param[X] + ' ' + S2;
ExeStruct.Param[X] := ExeStruct.Param[X] + ' ' + S2;
end;
ExeStruct^.Param[X] := Trim(ExeStruct^.Param[X]);
ExeStruct.Param[X] := Trim(ExeStruct.Param[X]);
end;
Insert(ExeStruct^, CodecExe, Length(CodecExe));
Insert(ExeStruct, CodecExe, Length(CodecExe));
end;
end;
SL.Free;

View File

@@ -3,9 +3,11 @@ unit PrecompLZ4;
interface
uses
LZ4DLL, XDeltaDLL,
LZ4DLL,
lz4,
Utils,
PrecompUtils,
WinAPI.Windows,
System.SysUtils, System.StrUtils, System.Classes, System.Math;
var
@@ -163,7 +165,8 @@ procedure LZ4Scan1(Instance, Depth: Integer; Input: PByte;
Funcs: PPrecompFuncs);
var
Buffer: PByte;
X, Y: Integer;
Pos: NativeInt;
X, Y, Z: Integer;
SI: _StrInfo1;
DI1, DI2: TDepthInfo;
DS: TPrecompStr;
@@ -173,8 +176,10 @@ begin
if DS <> '' then
begin
X := IndexTextW(@DS[0], LZ4Codecs);
if (X < 0) or (DI1.OldSize <> SizeEx) then
if X < 0 then
exit;
if DI1.OldSize = 0 then
DI1.OldSize := SizeEx;
if not CodecAvailable[X] then
exit;
Y := Max(DI1.NewSize, L_MAXSIZE);
@@ -212,6 +217,71 @@ begin
end;
if BoolArray(CodecEnabled, False) then
exit;
Buffer := Funcs^.Allocator(Instance, L_MAXSIZE);
Pos := 0;
while Pos < Size do
begin
if CodecEnabled[LZ4_CODEC] or
(CodecEnabled[LZ4HC_CODEC] and (SOList[Instance][LZ4HC_CODEC].Count = 1))
then
begin
Y := LZ4_decompress_safe(Input + Pos, Buffer, SizeEx - Pos, L_MAXSIZE);
if Abs(Y) > 256 then
begin
try
X := LZ4_decompress_generic(Input + Pos, Buffer, SizeEx - Pos, Abs(Y),
Integer(endOnOutputSize));
except
X := 0;
end;
// X := Abs(X);
Y := Abs(Y);
if (Round(X * 1.4) < Y) and (X < Y) and (X > 256) then
begin
Output(Instance, Buffer, Y);
SI.Position := Pos;
SI.OldSize := X;
SI.NewSize := Y;
SI.Option := 0;
if CodecEnabled[LZ4_CODEC] then
SetBits(SI.Option, LZ4_CODEC, 0, 5)
else
SetBits(SI.Option, LZ4HC_CODEC, 0, 5);
SI.Status := TStreamStatus.None;
Funcs^.LogScan1(LZ4Codecs[GetBits(SI.Option, 0, 5)], SI.Position,
SI.OldSize, SI.NewSize);
Add(Instance, @SI, nil, nil);
Inc(Pos, 256);
continue;
end;
end;
end;
if CodecEnabled[LZ4F_CODEC] then
if PCardinal(Input + Pos)^ = $184D2204 then
begin
Y := LZ4F_decompress_safe(Input + Pos, Buffer, SizeEx - Pos,
L_MAXSIZE, @X, @Z);
if (X < Y) then
begin
Output(Instance, Buffer, Y);
SI.Position := Pos;
SI.OldSize := X;
SI.NewSize := Y;
SI.Option := 0;
SetBits(SI.Option, LZ4F_CODEC, 0, 5);
SetBits(SI.Option, Z - 4, 12, 2);
SetBits(SI.Option, 0, 14, 1);
SetBits(SI.Option, LAcceleration, 15, 7);
SI.Status := TStreamStatus.None;
Funcs^.LogScan1(LZ4Codecs[GetBits(SI.Option, 0, 5)], SI.Position,
SI.OldSize, SI.NewSize);
Add(Instance, @SI, nil, nil);
Inc(Pos, SI.OldSize);
continue;
end;
end;
Inc(Pos);
end;
end;
function LZ4Scan2(Instance, Depth: Integer; Input: Pointer; Size: NativeInt;
@@ -271,7 +341,7 @@ begin
if GetBits(StreamInfo^.Option, 5, 7) <> I then
continue;
if (StreamInfo^.Status = TStreamStatus.Database) and
(GetBits(StreamInfo^.Option, 1, 31) = 0) then
(GetBits(StreamInfo^.Option, 31, 1) = 0) then
begin
Res1 := StreamInfo^.OldSize;
Result := True;
@@ -283,6 +353,8 @@ begin
begin
Params := 'a' + GetBits(StreamInfo^.Option, 15, 7).ToString;
if not Result then
{ Res1 := LZ4_compress_block(NewInput, Buffer,
StreamInfo^.NewSize, Y); }
Res1 := LZ4_compress_fast(NewInput, Buffer, StreamInfo^.NewSize, Y,
GetBits(StreamInfo^.Option, 15, 7));
end;
@@ -314,7 +386,7 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(LZ4Codecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
if Result or (StreamInfo^.Status >= TStreamStatus.Predicted) then
break;
end;
if (Result = False) and ((StreamInfo^.Status >= TStreamStatus.Predicted) or

View File

@@ -3,7 +3,7 @@ unit PrecompLZO;
interface
uses
LZODLL, XDeltaDLL,
LZODLL,
Utils,
PrecompUtils,
System.SysUtils, System.Classes, System.Math;
@@ -14,19 +14,25 @@ var
implementation
const
LZOCodecs: array of PChar = ['lzo1x'];
CODEC_COUNT = 1;
LZOCodecs: array of PChar = ['lzo1x', 'lzo2a', 'lzo1c'];
CODEC_COUNT = 3;
LZO1X_CODEC = 0;
LZO2A_CODEC = 1;
LZO1C_CODEC = 2;
const
L_WORKMEM = 524288;
L_MAXSIZE = 16 * 1024 * 1024;
LZO1X_999 = 0;
LZO1X_999 = 999;
LZO2A_999 = 999;
LZO1C_999 = 999;
var
SOList: array of array [0 .. CODEC_COUNT - 1] of TSOList;
WrkMem: array of array [0 .. L_WORKMEM - 1] of Byte;
LZO1XVariant: Integer = LZO1X_999;
LZO2AVariant: Integer = LZO2A_999;
LZO1CVariant: Integer = LZO1C_999;
CodecAvailable, CodecEnabled: TArray<Boolean>;
type
@@ -39,7 +45,7 @@ type
var
LZOSB: array of Byte = [$11, $00, $00];
function GetLZOSI(InBuff: Pointer; InSize: Integer; OutBuff: Pointer;
function GetLZO1XSI(InBuff: Pointer; InSize: Integer; OutBuff: Pointer;
OutSize: Integer; StreamInfo: PLZOSI): Boolean;
const
MinSize = 256;
@@ -123,11 +129,25 @@ begin
begin
CodecEnabled[LZO1X_CODEC] := True;
if Funcs^.GetParam(Command, X, 'v') = '999' then
LZO1XVariant := 0;
LZO1XVariant := 999;
if Funcs^.GetParam(Command, X, 'l') <> '' then
for I := Low(SOList) to High(SOList) do
SOList[I][LZO1X_CODEC].Update
([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True);
end
else if (CompareText(S, LZOCodecs[LZO2A_CODEC]) = 0) and LZODLL.DLLLoaded
then
begin
CodecEnabled[LZO2A_CODEC] := True;
if Funcs^.GetParam(Command, X, 'v') = '999' then
LZO2AVariant := 999;
end
else if (CompareText(S, LZOCodecs[LZO1C_CODEC]) = 0) and LZODLL.DLLLoaded
then
begin
CodecEnabled[LZO1C_CODEC] := True;
if Funcs^.GetParam(Command, X, 'v') = '999' then
LZO1CVariant := 999;
end;
Inc(X);
end;
@@ -135,9 +155,14 @@ begin
for I := 1 to 9 do
Insert(I, Options, Length(Options));
for X := Low(SOList) to High(SOList) do
for Y := Low(SOList[X]) to High(SOList[X]) do
if SOList[X, Y].Count = 0 then
SOList[X, Y].Update(Options);
if SOList[X, LZO1X_CODEC].Count = 0 then
SOList[X, LZO1X_CODEC].Update(Options);
for X := Low(SOList) to High(SOList) do
if SOList[X, LZO2A_CODEC].Count = 0 then
SOList[X, LZO2A_CODEC].Update([1]);
for X := Low(SOList) to High(SOList) do
if SOList[X, LZO1C_CODEC].Count = 0 then
SOList[X, LZO1C_CODEC].Update([1]);
end;
procedure LZOFree(Funcs: PPrecompFuncs);
@@ -164,11 +189,29 @@ begin
if (CompareText(S, LZOCodecs[LZO1X_CODEC]) = 0) and LZODLL.DLLLoaded then
begin
SetBits(Option^, LZO1X_CODEC, 0, 5);
SetBits(Option^, LZO1XVariant, 12, 5);
SetBits(Option^, LZO1XVariant, 12, 12);
if Funcs^.GetParam(Command, I, 'l') <> '' then
SetBits(Option^, StrToInt(Funcs^.GetParam(Command, I, 'l')), 5, 7);
if Funcs^.GetParam(Command, I, 'v') = '999' then
SetBits(Option^, 0, 12, 5);
SetBits(Option^, 999, 12, 12);
Result := True;
end
else if (CompareText(S, LZOCodecs[LZO2A_CODEC]) = 0) and LZODLL.DLLLoaded
then
begin
SetBits(Option^, LZO2A_CODEC, 0, 5);
SetBits(Option^, LZO2AVariant, 12, 12);
if Funcs^.GetParam(Command, I, 'v') = '999' then
SetBits(Option^, 999, 12, 12);
Result := True;
end
else if (CompareText(S, LZOCodecs[LZO1C_CODEC]) = 0) and LZODLL.DLLLoaded
then
begin
SetBits(Option^, LZO1C_CODEC, 0, 5);
SetBits(Option^, LZO1CVariant, 12, 12);
if Funcs^.GetParam(Command, I, 'v') = '999' then
SetBits(Option^, 999, 12, 12);
Result := True;
end;
Inc(I);
@@ -203,6 +246,12 @@ begin
LZO1X_CODEC:
if not lzo1x_decompress_safe(Input, DI1.OldSize, Buffer, @Res) = 0 then
Res := 0;
LZO2A_CODEC:
if not lzo2a_decompress_safe(Input, DI1.OldSize, Buffer, @Res) = 0 then
Res := 0;
LZO1C_CODEC:
if not lzo1c_decompress_safe(Input, DI1.OldSize, Buffer, @Res) = 0 then
Res := 0;
end;
if (Res > DI1.OldSize) then
begin
@@ -212,6 +261,14 @@ begin
SI.NewSize := Res;
SI.Option := 0;
SetBits(SI.Option, X, 0, 5);
case X of
LZO1X_CODEC:
SetBits(SI.Option, LZO1XVariant, 12, 12);
LZO2A_CODEC:
SetBits(SI.Option, LZO2AVariant, 12, 12);
LZO1C_CODEC:
SetBits(SI.Option, LZO1CVariant, 12, 12);
end;
if System.Pos(SPrecompSep2, DI1.Codec) > 0 then
SI.Status := TStreamStatus.Predicted
else
@@ -232,13 +289,15 @@ begin
Pos := 0;
while Pos < Size do
begin
if GetLZOSI(Input + Pos, SizeEx - Pos, Buffer, L_MAXSIZE, @LZOSI) then
if GetLZO1XSI(Input + Pos, SizeEx - Pos, Buffer, L_MAXSIZE, @LZOSI) then
begin
Output(Instance, Buffer, LZOSI.DSize);
SI.Position := Pos;
SI.OldSize := LZOSI.CSize;
SI.NewSize := LZOSI.DSize;
SI.Option := 0;
SetBits(SI.Option, LZO1X_CODEC, 0, 5);
SetBits(SI.Option, LZO1XVariant, 12, 12);
SI.Status := TStreamStatus.None;
Funcs^.LogScan1(LZOCodecs[GetBits(SI.Option, 0, 5)], SI.Position,
SI.OldSize, SI.NewSize);
@@ -269,6 +328,14 @@ begin
if not lzo1x_decompress_safe(Input, StreamInfo^.OldSize, Buffer, @Res) = 0
then
Res := 0;
LZO2A_CODEC:
if not lzo2a_decompress_safe(Input, StreamInfo^.OldSize, Buffer, @Res) = 0
then
Res := 0;
LZO1C_CODEC:
if not lzo1c_decompress_safe(Input, StreamInfo^.OldSize, Buffer, @Res) = 0
then
Res := 0;
end;
if Res > StreamInfo^.OldSize then
begin
@@ -303,7 +370,7 @@ begin
if GetBits(StreamInfo^.Option, 5, 7) <> I then
continue;
if (StreamInfo^.Status = TStreamStatus.Database) and
(GetBits(StreamInfo^.Option, 1, 31) = 0) then
(GetBits(StreamInfo^.Option, 31, 1) = 0) then
begin
Res1 := StreamInfo^.OldSize;
Result := True;
@@ -313,19 +380,38 @@ begin
Res1 := StreamInfo^.NewSize;
case X of
LZO1X_CODEC:
case GetBits(StreamInfo^.Option, 12, 5) of
case GetBits(StreamInfo^.Option, 12, 12) of
LZO1X_999:
begin
Params := 'l' + I.ToString + ':' + 'v' +
GetBits(StreamInfo^.Option, 12, 5).ToString;
GetBits(StreamInfo^.Option, 12, 12).ToString;
if not Result then
if not lzo1x_999_compress_level(NewInput, StreamInfo^.NewSize,
Buffer, @Res1, @WrkMem[Instance, 0], nil, 0, nil, I) = 0 then
Res1 := 0;
end;
{ if not lzo1x_1_compress(NewInput, StreamInfo^.NewSize, Buffer,
@Res1, @WrkMem[Instance, 0]) = 0 then
Res1 := 0; }
end;
LZO2A_CODEC:
case GetBits(StreamInfo^.Option, 12, 12) of
LZO2A_999:
begin
Params := 'v' + GetBits(StreamInfo^.Option, 12, 12).ToString;
if not Result then
if not lzo2a_999_compress(NewInput, StreamInfo^.NewSize, Buffer,
@Res1, @WrkMem[Instance, 0]) = 0 then
Res1 := 0;
end;
end;
LZO1C_CODEC:
case GetBits(StreamInfo^.Option, 12, 12) of
LZO1C_999:
begin
Params := 'v' + GetBits(StreamInfo^.Option, 12, 12).ToString;
if not Result then
if not lzo1c_999_compress(NewInput, StreamInfo^.NewSize, Buffer,
@Res1, @WrkMem[Instance, 0]) = 0 then
Res1 := 0;
end;
end;
end;
if not Result then
@@ -333,25 +419,25 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(LZOCodecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
if Result or (StreamInfo^.Status >= TStreamStatus.Predicted) then
break;
end;
if (Result = False) and ((StreamInfo^.Status >= TStreamStatus.Predicted) or
{ if (Result = False) and ((StreamInfo^.Status >= TStreamStatus.Predicted) or
(SOList[Instance][X].Count = 1)) and (DIFF_TOLERANCE > 0) then
begin
begin
Buffer := Funcs^.Allocator(Instance, Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);
SOList[Instance][X].Add(I);
Result := True;
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);
SOList[Instance][X].Add(I);
Result := True;
end;
end;
end; }
if Result then
begin
SetBits(StreamInfo^.Option, I, 5, 7);
@@ -377,17 +463,37 @@ begin
Res1 := StreamInfo.NewSize;
case X of
LZO1X_CODEC:
case GetBits(StreamInfo.Option, 12, 5) of
case GetBits(StreamInfo.Option, 12, 12) of
LZO1X_999:
begin
Params := 'l' + GetBits(StreamInfo.Option, 5, 7).ToString + ':' +
'v' + GetBits(StreamInfo.Option, 12, 5).ToString;
'v' + GetBits(StreamInfo.Option, 12, 12).ToString;
if not lzo1x_999_compress_level(Input, StreamInfo.NewSize, Buffer,
@Res1, @WrkMem[Instance, 0], nil, 0, nil,
GetBits(StreamInfo.Option, 5, 7)) = 0 then
Res1 := 0;
end;
end;
LZO2A_CODEC:
case GetBits(StreamInfo.Option, 12, 12) of
LZO2A_999:
begin
Params := 'v' + GetBits(StreamInfo.Option, 12, 12).ToString;
if not lzo2a_999_compress(Input, StreamInfo.NewSize, Buffer, @Res1,
@WrkMem[Instance, 0]) = 0 then
Res1 := 0;
end;
end;
LZO1C_CODEC:
case GetBits(StreamInfo.Option, 12, 12) of
LZO1C_999:
begin
Params := 'v' + GetBits(StreamInfo.Option, 12, 12).ToString;
if not lzo2a_999_compress(Input, StreamInfo.NewSize, Buffer, @Res1,
@WrkMem[Instance, 0]) = 0 then
Res1 := 0;
end;
end;
end;
Funcs^.LogRestore(LZOCodecs[GetBits(StreamInfo.Option, 0, 5)], PChar(Params),
StreamInfo.OldSize, StreamInfo.NewSize, Res1, True);

View File

@@ -104,7 +104,7 @@ var
DBFile: String = '';
ExtDir: String = '';
UseDB: Boolean = False;
StoreDD: Boolean = False;
StoreDD: Integer = -2;
VERBOSE: Boolean = False;
EXTRACT: Boolean = False;
DupSysMem: Int64 = 0;
@@ -183,26 +183,31 @@ begin
S := ReplaceText(S, 'p', '%');
S := ReplaceText(S, '%', '%*' + CPUCount.ToString);
Options.Threads := Max(1, Round(ExpParse.Evaluate(S)));
Options.Depth := EnsureRange(Succ(ArgParse.AsInteger('-d')), 1, 10);
Options.Depth := EnsureRange(Succ(ArgParse.AsInteger('-d', 0, 0)), 1, 10);
Options.LowMem := ArgParse.AsBoolean('-lm');
UseDB := ArgParse.AsBoolean('--dbase');
UseDB := ArgParse.AsBoolean('-db') or ArgParse.AsBoolean('--dbase');
Options.DBaseFile := ArgParse.AsString('--dbase=');
if Options.DBaseFile <> '' then
UseDB := True;
StoreDD := ArgParse.AsBoolean('--dedup');
StoreDD := -2;
if ArgParse.AsBoolean('-dd') or ArgParse.AsBoolean('--dedup') then
StoreDD := -1;
if FileExists(ExtractFilePath(Utils.GetModuleName) + 'srep.exe') then
StoreDD := ArgParse.AsInteger('--dedup=', 0, StoreDD);
S := ArgParse.AsString('--diff=', 0, '5p');
S := ReplaceText(S, 'p', '%');
DIFF_TOLERANCE := Max(0.00, ExpParse.Evaluate(S));
VERBOSE := ArgParse.AsBoolean('--verbose');
VERBOSE := ArgParse.AsBoolean('-v') or ArgParse.AsBoolean('--verbose');
Options.ExtractDir := ArgParse.AsString('--extract=');
if Options.ExtractDir <> '' then
EXTRACT := DirectoryExists(Options.ExtractDir);
Options.DoCompress := ArgParse.AsBoolean('--compress');
Options.DoCompress := ArgParse.AsBoolean('--compress') and
FLZMA2DLL.DLLLoaded;
S := ArgParse.AsString('--compress=');
S := ReplaceText(S, SPrecompSep3, SPrecompSep2);
Options.CompressCfg := S;
if Options.CompressCfg <> '' then
Options.DoCompress := True;
Options.DoCompress := FLZMA2DLL.DLLLoaded;
finally
ArgParse.Free;
ExpParse.Free;
@@ -1191,7 +1196,7 @@ begin
for I := Low(DBInfo) to High(DBInfo) do
DBCount[I] := 0;
end;
if StoreDD then
if StoreDD > -2 then
begin
SetLength(DDInfo, $10000);
SetLength(DDCount1, $10000);
@@ -1409,6 +1414,7 @@ var
BlockSize: Int64;
UI32: UInt32;
I, J, K, X: Integer;
S: String;
W: Word;
I64: Int64;
LastStream, LastPos: Int64;
@@ -1420,8 +1426,11 @@ var
begin
if (Depth = 0) then
begin
if StoreDD then
TempOutput := TPrecompVMStream.Create
if StoreDD > -2 then
TempOutput := TBufferedStream.Create
(TFileStream.Create
(LowerCase(ChangeFileExt(ExtractFileName(Utils.GetModuleName),
'-dd.tmp')), fmCreate or fmShareDenyNone), False, 4194304)
else
TempOutput := Output;
end
@@ -1525,7 +1534,7 @@ begin
begin
Inc(StreamCount);
DupBool := False;
if (Depth = 0) and StoreDD then
if (Depth = 0) and (StoreDD > -2) then
DupBool := not FindOrAddDD(StreamInfo, @DupIdx2, @DupCount);
if DupBool then
begin
@@ -1580,7 +1589,7 @@ begin
while J >= 0 do
begin
DupBool := False;
if (Depth = 0) and StoreDD then
if (Depth = 0) and (StoreDD > -2) then
DupBool := FindDD(StreamInfo, @DupIdx2, @DupCount);
if (DupBool = False) or (DupIdx1 = DupIdx2) then
begin
@@ -1663,9 +1672,9 @@ begin
with WorkStream[0] do
begin
Position := 0;
for W := 0 to $10000 - 1 do
for W := Low(DBInfo) to High(DBInfo) do
begin
J := DBCount[I];
J := DBCount[W];
if J > 0 then
begin
WriteBuffer(W, W.Size);
@@ -1682,7 +1691,7 @@ begin
Free;
end;
end;
if StoreDD then
if StoreDD > -2 then
begin
with WorkStream[0] do
begin
@@ -1703,9 +1712,37 @@ begin
end;
Output.WriteBuffer(UI32, UI32.Size);
Output.WriteBuffer(WorkStream[0].Memory^, WorkStream[0].Position);
Output.CopyFrom(TempOutput, 0);
try
EncFree;
finally
end;
S := TFileStream(TBufferedStream(TempOutput).Instance).Filename;
TBufferedStream(TempOutput).Flush;
if StoreDD >= 0 then
begin
with TProcessStream.Create(ExtractFilePath(Utils.GetModuleName) +
'srep.exe', '-m' + StoreDD.ToString + 'f ' + S + ' -', GetCurrentDir,
nil, Output) do
try
if Execute then
begin
Wait;
Done;
end;
finally
Free;
end;
end
else
Output.CopyFrom(TempOutput, 0);
TempOutput.Free;
end;
DeleteFile(S);
end
else
try
EncFree;
finally
end;
end;
end;
@@ -1776,7 +1813,7 @@ procedure PrecompOutput2(Instance: Integer; const Buffer: Pointer;
begin
with ComVars2[CurDepth[Instance]] do
DecOutput[Instance].WriteBuffer(Buffer^, Size);
if StoreDD and (CurDepth[Instance] = 0) then
if (StoreDD > -2) and (CurDepth[Instance] = 0) then
if ((DDIndex2 < DDCount2) and (DDIndex1 = DDList2[DDIndex2].Index)) then
DataMgr.Write(DDIndex1, Buffer, Size);
end;
@@ -1821,7 +1858,7 @@ begin
end
else
begin
if StoreDD and (Depth = 0) then
if (StoreDD > -2) and (Depth = 0) then
begin
Inc(DDIndex1);
if ((DDIndex2 < DDCount2) and (DDIndex1 = DDList2[DDIndex2].Index))
@@ -1886,7 +1923,7 @@ begin
end
else
begin
if StoreDD and (Depth = 0) then
if (StoreDD > -2) and (Depth = 0) then
if ((DDIndex2 < DDCount2) and (DDIndex1 = DDList2[DDIndex2].Index))
then
Inc(DDIndex2);
@@ -2039,11 +2076,12 @@ var
CurrPos: Int64;
UI32: UInt32;
I, J: Integer;
LStream: TProcessStream;
begin
if Depth = 0 then
begin
UI32 := 0;
if StoreDD then
if (StoreDD > -2) then
begin
Input.ReadBuffer(UI32, UI32.Size);
SetLength(DDList2, UI32);
@@ -2057,7 +2095,16 @@ begin
end;
with ComVars2[Depth] do
begin
DecInput[Index] := Input;
if (Depth = 0) and (StoreDD >= 0) then
begin
LStream := TProcessStream.Create(ExtractFilePath(Utils.GetModuleName) +
'srep.exe', '-d -s - -', GetCurrentDir, Input, nil);
if not LStream.Execute then
raise EReadError.CreateRes(@SReadError);
DecInput[Index] := TBufferedStream.Create(LStream, True, 4194304);
end
else
DecInput[Index] := Input;
DecOutput[Index] := Output;
DecInput[Index].ReadBuffer(StreamCount[Index]^, StreamCount[Index]^.Size);
while StreamCount[Index]^ >= 0 do
@@ -2137,7 +2184,7 @@ begin
if IsErrored(Tasks) then
for I := Low(Tasks) to High(Tasks) do
Tasks[I].RaiseLastError;
if StoreDD and (Depth = 0) then
if (StoreDD > -2) and (Depth = 0) then
begin
Inc(DDIndex1);
if ((DDIndex2 < DDCount2) and (DDIndex1 = DDList2[DDIndex2].Index))
@@ -2168,6 +2215,15 @@ begin
CopyStreamEx(DecInput[Index], DecOutput[Index], UI32);
DecInput[Index].ReadBuffer(StreamCount[Index]^, StreamCount[Index]^.Size);
end;
if (Depth = 0) and (StoreDD >= 0) then
begin
with LStream do
begin
Wait;
Done;
end;
DecInput[Index].Free;
end;
end;
end;
@@ -2294,7 +2350,7 @@ begin
if Options.DoCompress then
LOutput.Free;
try
EncFree;
// EncFree;
finally
Stopwatch.Stop;
end;

View File

@@ -5,7 +5,7 @@ unit PrecompMedia;
interface
uses
BrunsliDLL, FLACDLL, PackJPGDLL, JoJpegDLL, XDeltaDLL,
BrunsliDLL, FLACDLL, PackJPGDLL, JoJpegDLL,
Utils,
PrecompUtils,
System.SysUtils, System.Classes, System.Math;

View File

@@ -3,26 +3,11 @@ unit PrecompOodle;
interface
uses
OodleDLL, XDeltaDLL,
OodleDLL,
Utils,
PrecompUtils,
System.SysUtils, System.Classes, System.Types, System.Math;
{ 8C 07 - 0:LZH
8C 00 - 1:LZHLW
8C 01 - 2:LZNIB
CC 07 - 3:None
8C 02 - 4:LZB16
8C 03 - 5:LZBLW
8C 04 - 6:LZA
8C 05 - 7:LZNA
8C 06 - 8:Kraken
8C 0A - 9:Mermaid
8C 0B - 10:BitKnit
8C 0A - 11:Selkie
8C 0A - 12:Hydra
8C 0C - 13:Leviathan }
var
Codec: TPrecompressor;
@@ -40,13 +25,13 @@ const
LEVIATHAN_CODEC = 5;
const
O_COUNT = 0;
O_LENGTH = 32;
O_TRADEOFF = 256;
O_MAXSIZE = 16 * 1024 * 1024;
var
SOList: array of array [0 .. CODEC_COUNT - 1] of TSOList;
OCount: Integer = O_COUNT;
OLength: Integer = O_LENGTH;
OTradeOff: Integer = O_TRADEOFF;
CodecAvailable, CodecEnabled: TArray<Boolean>;
@@ -247,135 +232,36 @@ begin
Result := A;
end;
function CustomLZ_Decompress0(src, dst: PByte; srcSize, dstCapacity: Integer;
function CustomLZ_Decompress(src, dst: PByte; srcSize, dstCapacity: Integer;
var Res: Integer): Boolean;
type
T3Res = array [0 .. 2] of Integer;
procedure AddRes(const I: Integer; var Res: T3Res);
begin
Res[0] := Res[1];
Res[1] := Res[2];
Res[2] := I;
end;
const
MinSize = 64;
BlkSize = 262144;
Range = 262144;
function ValidSize(Res: T3Res): Boolean;
const
ThresSize = 32;
begin
Result := (Res[0] > 0) and (Res[0] < Res[1]) and
InRange(Res[0], Res[0], Res[2] + 32);
end;
var
LBuffer: array [0 .. BlkSize - 1] of Byte;
I, J, W, X, Y, Z: Integer;
LR1, LR2: T3Res;
W, X, Y, Z: Integer;
begin
Result := False;
Y := Max(LocalLZ_Decompress(src, dst, srcSize, dstCapacity, 0, Z),
LocalLZ_Decompress(src, dst, srcSize, dstCapacity, 1, Z));
if Y > MinSize then
Y := 0;
X := dstCapacity;
X := Min(Max(LocalLZ_Decompress(src, dst, srcSize, X, 0, Y),
LocalLZ_Decompress(src, dst, srcSize, X, 1, Z)), Pred(X));
W := X;
while (Y = 0) and (X > dstCapacity - BlkSize) and (W - X < OLength) do
begin
W := IfThen(Y mod BlkSize = 0, Pred(Y div BlkSize), Y div BlkSize)
* BlkSize;
Move((dst + W)^, LBuffer[0], Y - W);
X := Min(Max(LocalLZ_Decompress(src, dst, srcSize, X, 0, Y),
LocalLZ_Decompress(src, dst, srcSize, X, 1, Y)), Pred(X));
end;
if (Y = Z) and (Y = dstCapacity) then
X := Min(Succ(W), dstCapacity);
while (Z = 0) and (X < Min(W + OLength, dstCapacity)) do
begin
LocalLZ_Decompress(src, dst, srcSize, X, 0, Z);
Inc(X);
end;
Y := Max(Y, Z);
if (Y > 0) then
begin
Res := Y;
I := Max(LocalLZ_Decompress(src, dst, srcSize, dstCapacity - 1, 0, Z),
LocalLZ_Decompress(src, dst, srcSize, dstCapacity - 1, 1, Z));
if (Res <> I) and (Res <> Pred(I)) then
begin
Move(LBuffer[0], (dst + W)^, Res - W);
Result := True;
exit;
end;
Result := True;
end;
FillChar(LR1, SizeOf(T3Res), 0);
FillChar(LR2, SizeOf(T3Res), 0);
I := Y;
J := Min(dstCapacity, Y + Range);
while I < J do
begin
Y := Max(LocalLZ_Decompress(src, dst, srcSize, I, 0, Z),
LocalLZ_Decompress(src, dst, srcSize, I, 1, Z));
AddRes(Y, LR1);
AddRes(Z, LR2);
if (LR1[1] = LR2[1]) and ValidSize(LR1) then
begin
Res := LR1[1];
Move(LBuffer[0], (dst + W)^, Res - W);
Result := True;
break;
end;
if Y > MinSize then
begin
W := IfThen(Y mod BlkSize = 0, Pred(Y div BlkSize), Y div BlkSize)
* BlkSize;
Move((dst + W)^, LBuffer[0], Y - W);
end;
Inc(I);
end;
end;
function CustomLZ_DecompressN(src, dst: PByte; srcSize, dstCapacity: Integer;
var Res: TIntegerDynArray): Boolean;
const
BlkSize = 262144;
UpLen = 128;
DownLen = 16;
var
I, J, X, Y, Z: Integer;
Sizes: array [0 .. UpLen + DownLen - 1] of Integer;
begin
SetLength(Res, 0);
Y := Max(LocalLZ_Decompress(src, dst, srcSize, dstCapacity, 0, Z),
LocalLZ_Decompress(src, dst, srcSize, dstCapacity, 1, Z));
for I := Low(Sizes) to High(Sizes) do
Sizes[I] := -1;
J := Min(dstCapacity, Y + UpLen);
I := Max(IfThen(dstCapacity mod BlkSize = 0, Pred(dstCapacity div BlkSize),
dstCapacity div BlkSize) * BlkSize, Y - DownLen);
X := J - I;
while (J > I) do
begin
Y := Max(LocalLZ_Decompress(src, dst, srcSize, J, 0, Z),
LocalLZ_Decompress(src, dst, srcSize, J, 1, Z));
Sizes[Length(Sizes) - (J - I)] := Z;
Dec(J);
end;
for I := Low(Sizes) to High(Sizes) do
begin
X := Sizes[I];
for J := Low(Sizes) to High(Sizes) do
begin
Y := Sizes[J];
if I <> J then
if X = Y then
begin
Sizes[I] := -1;
Sizes[J] := -1;
end;
end;
end;
for I := Low(Sizes) to High(Sizes) do
if Sizes[I] > srcSize then
if OodleLZ_Decompress(src, srcSize, dst, Sizes[I]) = Sizes[I] then
begin
Insert(Sizes[I], Res, Length(Res));
if Length(Res) >= OCount then
break;
end;
Result := Length(Res) > 0;
end;
function GetOodleUS(Instance: Integer; Input: PByte; Pos: NativeInt;
@@ -386,25 +272,29 @@ const
var
Buffer: PByte;
B: Boolean;
I: Integer;
ResultN: TIntegerDynArray;
SI: _StrInfo1;
begin
Result := 0;
{ if StreamInfo^.Codec = 3 then
exit; }
// StreamInfo^.DSize:=$8001;
Buffer := Funcs^.Allocator(Instance, StreamInfo^.DSize);
if OCount <= 0 then
B := CustomLZ_Decompress0(Input + Pos, Buffer, StreamInfo^.CSize,
StreamInfo^.DSize, Result)
case StreamInfo^.Codec of
1:
if (CodecEnabled[KRAKEN_CODEC] = False) and
(CodecEnabled[HYDRA_CODEC] = False) then
exit;
2:
if (CodecEnabled[MERMAID_CODEC] = False) and
(CodecEnabled[SELKIE_CODEC] = False) and
(CodecEnabled[HYDRA_CODEC] = False) then
exit;
3:
if (CodecEnabled[LEVIATHAN_CODEC] = False) and
(CodecEnabled[HYDRA_CODEC] = False) then
exit;
else
begin
B := CustomLZ_DecompressN(Input + Pos, Buffer, StreamInfo^.CSize,
StreamInfo^.DSize, ResultN);
if B then
Result := ResultN[0];
exit;
end;
Buffer := Funcs^.Allocator(Instance, StreamInfo^.DSize);
B := CustomLZ_Decompress(Input + Pos, Buffer, StreamInfo^.CSize,
StreamInfo^.DSize, Result);
If B then
if (Result > MinSize) and (Result > StreamInfo^.CSize) then
begin
@@ -415,37 +305,25 @@ begin
SetBits(SI.Option, OTradeOff, 13, 11);
case StreamInfo^.Codec of
1:
SetBits(SI.Option, KRAKEN_CODEC, 0, 5);
if CodecEnabled[KRAKEN_CODEC] then
SetBits(SI.Option, KRAKEN_CODEC, 0, 5);
2:
if CodecEnabled[MERMAID_CODEC] then
SetBits(SI.Option, MERMAID_CODEC, 0, 5)
else
else if CodecEnabled[SELKIE_CODEC] then
SetBits(SI.Option, SELKIE_CODEC, 0, 5);
3:
SetBits(SI.Option, LEVIATHAN_CODEC, 0, 5);
if CodecEnabled[LEVIATHAN_CODEC] then
SetBits(SI.Option, LEVIATHAN_CODEC, 0, 5);
end;
if CodecEnabled[HYDRA_CODEC] then
SetBits(SI.Option, HYDRA_CODEC, 0, 5);
SetBits(SI.Option, Integer(StreamInfo^.HasCRC), 12, 1);
SI.Status := TStreamStatus.None;
if OCount <= 0 then
begin
SI.NewSize := Result;
Funcs^.LogScan1(OodleCodecs[GetBits(SI.Option, 0, 5)], SI.Position,
SI.OldSize, SI.NewSize);
Add(Instance, @SI, nil, nil);
end
else
begin
if Length(ResultN) > 0 then
for I := Low(ResultN) to High(ResultN) do
begin
SI.NewSize := ResultN[I];
Funcs^.LogScan1(OodleCodecs[GetBits(SI.Option, 0, 5)], SI.Position,
SI.OldSize, SI.NewSize);
Add(Instance, @SI, nil, nil);
end;
end;
SI.NewSize := Result;
Funcs^.LogScan1(OodleCodecs[GetBits(SI.Option, 0, 5)], SI.Position,
SI.OldSize, SI.NewSize);
Add(Instance, @SI, nil, nil);
end;
end;
@@ -502,7 +380,7 @@ begin
SOList[I][Y].Update
([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True);
if Funcs^.GetParam(Command, X, 'n') <> '' then
OCount := StrToInt(Funcs^.GetParam(Command, X, 'n'));
OLength := StrToInt(Funcs^.GetParam(Command, X, 'n'));
if Funcs^.GetParam(Command, X, 't') <> '' then
OTradeOff := StrToInt(Funcs^.GetParam(Command, X, 't'));
end;
@@ -573,7 +451,11 @@ begin
if DS <> '' then
begin
X := IndexTextW(@DS[0], OodleCodecs);
if (X < 0) or (DI1.OldSize <> SizeEx) then
if X < 0 then
exit;
if DI1.OldSize = 0 then
DI1.OldSize := SizeEx;
if not CodecAvailable[X] then
exit;
if not CodecAvailable[X] then
exit;
@@ -589,7 +471,7 @@ begin
begin
if DI1.NewSize <= 0 then
begin
if not CustomLZ_Decompress0(Input, Buffer, DI1.OldSize, Res, Res)
if not CustomLZ_Decompress(Input, Buffer, DI1.OldSize, Res, Res)
then
Res := 0;
end
@@ -678,7 +560,7 @@ begin
then
begin
Buffer := Funcs^.Allocator(Instance, OodleSI.DSize);
if CustomLZ_Decompress0(Input, Buffer, StreamInfo^.OldSize,
if CustomLZ_Decompress(Input, Buffer, StreamInfo^.OldSize,
OodleSI.DSize, Res) then
begin
Output(Instance, Buffer, Res);
@@ -716,7 +598,7 @@ begin
if GetBits(StreamInfo^.Option, 5, 7) <> I then
continue;
if (StreamInfo^.Status = TStreamStatus.Database) and
(GetBits(StreamInfo^.Option, 1, 31) = 0) then
(GetBits(StreamInfo^.Option, 31, 1) = 0) then
begin
Res1 := StreamInfo^.OldSize;
Result := True;
@@ -726,6 +608,7 @@ begin
SizeOf(TOodleLZ_CompressOptions));
COptions.sendQuantumCRCs := GetBits(StreamInfo^.Option, 12, 1) = 1;
COptions.spaceSpeedTradeoffBytes := GetBits(StreamInfo^.Option, 13, 11);
// COptions.dictionarySize := 262144;
Params := 'l' + I.ToString + ':' + 'c' + GetBits(StreamInfo^.Option, 12, 1)
.ToString + ':' + 't' + GetBits(StreamInfo^.Option, 13, 11).ToString;
if not Result then
@@ -739,22 +622,22 @@ begin
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
break;
end;
if (Result = False) and ((StreamInfo^.Status >= TStreamStatus.Predicted) or
{ if (Result = False) and ((StreamInfo^.Status >= TStreamStatus.Predicted) or
(SOList[Instance][X].Count = 1)) and (DIFF_TOLERANCE > 0) then
begin
begin
Buffer := Funcs^.Allocator(Instance, Res1 + Max(StreamInfo^.OldSize, Res1));
Res2 := PrecompEncodePatch(OldInput, StreamInfo^.OldSize, Buffer, Res1,
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Buffer + Res1, Max(StreamInfo^.OldSize, Res1));
Funcs^.LogPatch1(StreamInfo^.OldSize, Res1, Res2,
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2));
if Funcs^.AcceptPatch(StreamInfo^.OldSize, Res1, Res2) then
begin
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);
SOList[Instance][X].Add(I);
Result := True;
Output(Instance, Buffer + Res1, Res2);
SetBits(StreamInfo^.Option, 1, 31, 1);
SOList[Instance][X].Add(I);
Result := True;
end;
end;
end; }
if Result then
begin
SetBits(StreamInfo^.Option, I, 5, 7);

View File

@@ -16,7 +16,7 @@ resourcestring
SPrecompSep2 = ':';
SPrecompSep3 = ',';
SPrecompSep4 = '/';
SPrecompSep5 = '/';
SPrecompSep5 = '\';
const
SuccessStatus = 4;
@@ -276,7 +276,7 @@ type
procedure SetSize(const NewSize: Int64); override;
procedure SetSize(NewSize: Longint); override;
private
FInitialised: Boolean;
FInitialised, FDone: Boolean;
FStream: TStream;
FFilename: String;
procedure Initialise;
@@ -286,6 +286,8 @@ type
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override;
procedure Done;
property FileName: String read FFilename;
end;
PResData = ^TResData;
@@ -449,13 +451,15 @@ constructor TPrecompVMStream.Create;
begin
inherited Create;
FInitialised := False;
FDone := False;
end;
destructor TPrecompVMStream.Destroy;
begin
if FInitialised then
begin
FStream.Free;
if not FDone then
FStream.Free;
DeleteFile(FFilename);
end;
inherited Destroy;
@@ -521,6 +525,12 @@ begin
Result := 0;
end;
procedure TPrecompVMStream.Done;
begin
FStream.Free;
FDone := True;
end;
function PrecompGetCodec(Cmd: PChar; Index: Integer; WithParams: Boolean)
: TPrecompStr;
var
@@ -567,14 +577,16 @@ begin
List2 := DecodeStr(List1[Index], SPrecompSep2);
if Param = '' then
begin
if Length(List1) > 1 then
begin
S := '';
if not ResourceExists(List2[I]) then
S := S + List2[I] + SPrecompSep2;
if Length(S) > 0 then
S := S.Remove(Pred(Length(S)));
end;
S := '';
for I := Succ(Low(List2)) to High(List2) do
if ResourceExists(List2[I]) = False then
begin
if S <> '' then
S := S + SPrecompSep2;
S := S + List2[I];
end;
if S = '' then
S := ' ';
end
else
begin
@@ -705,8 +717,9 @@ var
S: String;
begin
Result := 0;
case IndexText(Codec, ['zlib', 'lz4', 'lz4hc', 'lzo1c', 'lzo1x', 'lzo2a',
'zstd', 'lzna', 'kraken', 'mermaid', 'selkie', 'hydra', 'leviathan']) of
case IndexText(Codec, ['zlib', 'lz4', 'lz4hc', 'lz4f', 'lzo1c', 'lzo1x',
'lzo2a', 'zstd', 'lzna', 'kraken', 'mermaid', 'selkie', 'hydra',
'leviathan']) of
0:
if ZLibDLL.DLLLoaded then
begin
@@ -729,10 +742,13 @@ begin
1, 2:
if LZ4DLL.DLLLoaded then
Result := LZ4_decompress_safe(InBuff, OutBuff, InSize, OutSize);
6:
3:
if LZ4DLL.DLLLoaded then
Result := LZ4F_decompress_safe(InBuff, OutBuff, InSize, OutSize);
7:
if ZSTDDLL.DLLLoaded then
Result := ZSTD_decompress(OutBuff, OutSize, InBuff, InSize);
7 .. 12:
8 .. 13:
if OodleDLL.DLLLoaded then
Result := OodleLZ_Decompress(InBuff, InSize, OutBuff, OutSize);
end;
@@ -855,6 +871,8 @@ var
Res: NativeUInt;
begin
Result := 0;
if not XDeltaDLL.DLLLoaded then
exit;
if xd3_encode(OldBuff, OldSize, NewBuff, NewSize, PatchBuff, @Res, PatchSize,
Integer(XD3_NOCOMPRESS)) = 0 then
Result := Res;
@@ -868,6 +886,8 @@ var
Res: NativeUInt;
begin
Result := 0;
if not XDeltaDLL.DLLLoaded then
exit;
if xd3_decode(PatchBuff, PatchSize, OldBuff, OldSize, NewBuff, @Res, NewSize,
Integer(XD3_NOCOMPRESS)) = 0 then
Result := Res;
@@ -1234,5 +1254,7 @@ EncodeSICmp := TEncodeSIComparer.Create;
FutureSICmp := TFutureSIComparer.Create;
StockMethods := TStringList.Create;
ExternalMethods := TStringList.Create;
if not XDeltaDLL.DLLLoaded then
DIFF_TOLERANCE := 0;
end.

View File

@@ -530,7 +530,7 @@ begin
Res := inflate(ZStream^, Z_BLOCK);
if not(Res in [Z_OK, Z_STREAM_END]) then
begin
if (LastIn >= Z_MINSIZE) then
if (Res <> Z_DATA_ERROR) and (LastIn >= Z_MINSIZE) then
Res := Z_STREAM_END;
break;
end;

View File

@@ -3,7 +3,7 @@ unit PrecompZSTD;
interface
uses
ZSTDDLL, XDeltaDLL,
ZSTDDLL,
Utils,
PrecompUtils,
System.SysUtils, System.Classes, System.Math;
@@ -267,7 +267,7 @@ begin
if GetBits(StreamInfo^.Option, 5, 7) <> I then
continue;
if (StreamInfo^.Status = TStreamStatus.Database) and
(GetBits(StreamInfo^.Option, 1, 31) = 0) then
(GetBits(StreamInfo^.Option, 31, 1) = 0) then
begin
Res1 := StreamInfo^.OldSize;
Result := True;
@@ -317,7 +317,7 @@ begin
StreamInfo^.OldSize);
Funcs^.LogProcess(ZSTDCodecs[GetBits(StreamInfo^.Option, 0, 5)],
PChar(Params), StreamInfo^.OldSize, StreamInfo^.NewSize, Res1, Result);
if Result or (StreamInfo^.Status = TStreamStatus.Predicted) then
if Result or (StreamInfo^.Status >= TStreamStatus.Predicted) then
break;
end;
if Res1 < 0 then