From 552a733296b4d5f9df508c13b285143616ef9837 Mon Sep 17 00:00:00 2001 From: Razor12911 Date: Sat, 31 Dec 2022 22:45:22 +0200 Subject: [PATCH] update to 0.6.9 se --- InitCode.pas | 92 ++++++++++++++++++++++++++++++ Unit1.fmx | 97 +++++++++++++++++++++----------- Unit1.pas | 70 ++++++++++++++++++++++- common/Utils.pas | 16 ++++-- imports/BrunsliDLL.pas | 5 +- imports/FLACDLL.pas | 7 ++- imports/FLZMA2DLL.pas | 10 ++-- imports/JoJpegDLL.pas | 5 +- imports/LZ4DLL.pas | 73 +----------------------- imports/LZODLL.pas | 5 +- imports/OodleDLL.pas | 13 +++-- imports/PackJPGDLL.pas | 5 +- imports/PreflateDLL.pas | 5 +- imports/ReflateDLL.pas | 7 ++- imports/XDeltaDLL.pas | 5 +- imports/ZLibDLL.pas | 12 ++-- imports/ZSTDDLL.pas | 5 +- io/IOExecute.pas | 3 +- precompressor/PrecompDLL.pas | 16 +++--- precompressor/PrecompEXE.pas | 9 +-- precompressor/PrecompINI.pas | 7 ++- precompressor/PrecompINIEx.pas | 7 ++- precompressor/PrecompLZ4.pas | 17 ++++-- precompressor/PrecompLZO.pas | 17 ++++-- precompressor/PrecompMain.pas | 14 ++--- precompressor/PrecompOodle.pas | 24 ++++++-- precompressor/PrecompSearch.pas | 5 +- precompressor/PrecompZSTD.pas | 9 ++- ui/UIMain.pas | 57 +------------------ xtool.dpr | 3 +- xtool.dproj | 1 + xtool.res | Bin 752 -> 804 bytes xtoolui.dpr | 3 + xtoolui.res | Bin 820 -> 760 bytes 34 files changed, 374 insertions(+), 250 deletions(-) create mode 100644 InitCode.pas diff --git a/InitCode.pas b/InitCode.pas new file mode 100644 index 0000000..0d665b3 --- /dev/null +++ b/InitCode.pas @@ -0,0 +1,92 @@ +unit InitCode; + +interface + +uses + Utils, LibImport, + System.SysUtils; + +const + PluginsParam1 = '--basedir='; + PluginsParam2 = '-bd'; + +type + PUIFuncs = ^TUIFuncs; + + TUIFuncs = record + IsZlibLoaded: Boolean; + IsReflateLoaded: Boolean; + IsPreflateLoaded: Boolean; + IsLZ4Loaded: Boolean; + IsLZOLoaded: Boolean; + IsZSTDLoaded: Boolean; + IsOodleLoaded: Boolean; + IsFLACLoaded: Boolean; + IsBrunsliLoaded: Boolean; + IsPackJPGLoaded: Boolean; + IsJoJpegLoaded: Boolean; + IsXDeltaLoaded: Boolean; + IsLZMALoaded: Boolean; + IsSrepAvailable: Boolean; + end; + +var + UILib: TLibImport; + PluginsPath: String = ''; + XTLUI1: procedure; + XTLUI2: function(Funcs: PUIFuncs; var Params: TArray; + out LibType: Integer; out LibPath: String): Boolean; + XTLAddPlugin: procedure(S: String; I: Integer); + XTLAddCodec: procedure(S: String); + UIDLLLoaded: Boolean = False; + +implementation + +procedure Init; +begin + UILib := TLibImport.Create(ChangeFileExt(Utils.GetModuleName, 'ui.dll')); + if UILib.Loaded then + begin + @XTLUI1 := UILib.GetProcAddr('XTLUI1'); + @XTLUI2 := UILib.GetProcAddr('XTLUI2'); + @XTLAddPlugin := UILib.GetProcAddr('XTLAddPlugin'); + @XTLAddCodec := UILib.GetProcAddr('XTLAddCodec'); + UIDLLLoaded := Assigned(XTLUI1); + end; +end; + +procedure Deinit; +begin + UILib.Free; +end; + +var + I: Integer; + +initialization + +Init; +if UIDLLLoaded and (ParamCount = 0) then + PluginsPath := IncludeTrailingBackSlash + (ExpandPath(GetIniString('UI', 'Plugins', '', + ChangeFileExt(Utils.GetModuleName, 'ui.ini')))); +for I := 1 to ParamCount do +begin + if ParamStr(I).StartsWith(PluginsParam1) then + begin + PluginsPath := ParamStr(I).Substring(PluginsParam1.Length); + break; + end; + if ParamStr(I).StartsWith(PluginsParam2) then + begin + PluginsPath := ParamStr(I).Substring(PluginsParam2.Length); + break; + end; +end; +PluginsPath := IncludeTrailingBackSlash(ExpandPath(PluginsPath)); + +finalization + +Deinit; + +end. diff --git a/Unit1.fmx b/Unit1.fmx index c4b4d59..a4406e3 100644 --- a/Unit1.fmx +++ b/Unit1.fmx @@ -4,13 +4,14 @@ object Form1: TForm1 BorderIcons = [biSystemMenu, biMinimize] BorderStyle = Single Caption = 'XTool' - ClientHeight = 410 + ClientHeight = 517 ClientWidth = 592 Position = ScreenCenter StyleBook = StyleBook1 FormFactor.Width = 320 FormFactor.Height = 480 FormFactor.Devices = [Desktop] + OnClose = FormClose OnShow = FormShow DesignerMasterStyle = 0 object StyleBook1: TStyleBook @@ -3361,24 +3362,52 @@ object Form1: TForm1 object Layout4: TLayout Align = Bottom Margins.Bottom = 8.000000000000000000 - Position.Y = 382.000000000000000000 + Position.Y = 487.000000000000000000 Size.Width = 592.000000000000000000 - Size.Height = 20.000000000000000000 + Size.Height = 22.000000000000000000 Size.PlatformDefault = False TabOrder = 3 object Button1: TButton Align = Right ModalResult = 1 Margins.Left = 8.000000000000000000 - Margins.Right = 8.000000000000000000 - Position.X = 504.000000000000000000 + Margins.Right = 16.000000000000000000 + Position.X = 496.000000000000000000 Size.Width = 80.000000000000000000 - Size.Height = 20.000000000000000000 + Size.Height = 22.000000000000000000 Size.PlatformDefault = False - TabOrder = 0 + TabOrder = 1 Text = 'Start' OnClick = Button1Click end + object Label5: TLabel + Align = Left + Margins.Left = 16.000000000000000000 + Margins.Right = 8.000000000000000000 + Position.X = 16.000000000000000000 + Size.Width = 96.000000000000000000 + Size.Height = 22.000000000000000000 + Size.PlatformDefault = False + Text = 'Base directory' + TabOrder = 2 + end + object Edit6: TEdit + Touch.InteractiveGestures = [LongTap, DoubleTap] + Align = Client + TabOrder = 0 + Size.Width = 368.000000000000000000 + Size.Height = 22.000000000000000000 + Size.PlatformDefault = False + object SearchEditButton5: TSearchEditButton + CanFocus = False + Cursor = crArrow + Size.Width = 28.000000000000000000 + Size.Height = 16.000000000000000000 + Size.PlatformDefault = False + TabOrder = 0 + OnClick = SearchEditButton5Click + end + end end object PopupMenu1: TPopupMenu Left = 368 @@ -3394,17 +3423,17 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 Size.Width = 576.000000000000000000 - Size.Height = 366.000000000000000000 + Size.Height = 471.000000000000000000 Size.PlatformDefault = False TabOrder = 0 - Viewport.Width = 560.000000000000000000 - Viewport.Height = 366.000000000000000000 + Viewport.Width = 576.000000000000000000 + Viewport.Height = 471.000000000000000000 object GroupBox1: TGroupBox Align = Top Margins.Left = 8.000000000000000000 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Input' @@ -3413,7 +3442,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 14 @@ -3426,7 +3455,7 @@ object Form1: TForm1 Margins.Top = 8.000000000000000000 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 - Size.Width = 440.000000000000000000 + Size.Width = 456.000000000000000000 Size.Height = 20.000000000000000000 Size.PlatformDefault = False object SearchEditButton1: TSearchEditButton @@ -3465,7 +3494,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 108.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 90.000000000000000000 Size.PlatformDefault = False Text = 'Options' @@ -3474,7 +3503,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 15 @@ -3558,7 +3587,7 @@ object Form1: TForm1 object Layout2: TLayout Align = Top Position.Y = 52.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 14 @@ -3625,7 +3654,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 54.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Output' @@ -3634,7 +3663,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 14 @@ -3647,7 +3676,7 @@ object Form1: TForm1 Margins.Top = 8.000000000000000000 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 - Size.Width = 440.000000000000000000 + Size.Width = 456.000000000000000000 Size.Height = 20.000000000000000000 Size.PlatformDefault = False object SearchEditButton3: TSearchEditButton @@ -3685,7 +3714,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 360.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Deduplication' @@ -3694,7 +3723,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 12 @@ -3749,7 +3778,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 414.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Compression' @@ -3758,10 +3787,10 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False - TabOrder = 13 + TabOrder = 14 object Label7: TLabel Align = Left Margins.Left = 8.000000000000000000 @@ -3827,7 +3856,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 198.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Method' @@ -3836,7 +3865,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 14 @@ -3849,7 +3878,7 @@ object Form1: TForm1 Margins.Top = 8.000000000000000000 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 - Size.Width = 440.000000000000000000 + Size.Width = 456.000000000000000000 Size.Height = 20.000000000000000000 Size.PlatformDefault = False end @@ -3858,7 +3887,7 @@ object Form1: TForm1 Margins.Top = 8.000000000000000000 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 - Position.X = 456.000000000000000000 + Position.X = 472.000000000000000000 Position.Y = 8.000000000000000000 Size.Width = 80.000000000000000000 Size.Height = 20.000000000000000000 @@ -3875,7 +3904,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 306.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Database' @@ -3884,7 +3913,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 14 @@ -3898,7 +3927,7 @@ object Form1: TForm1 Margins.Top = 8.000000000000000000 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 - Size.Width = 440.000000000000000000 + Size.Width = 456.000000000000000000 Size.Height = 20.000000000000000000 Size.PlatformDefault = False object SearchEditButton2: TSearchEditButton @@ -3938,7 +3967,7 @@ object Form1: TForm1 Margins.Right = 8.000000000000000000 Position.X = 8.000000000000000000 Position.Y = 252.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 54.000000000000000000 Size.PlatformDefault = False Text = 'Library checker' @@ -3947,7 +3976,7 @@ object Form1: TForm1 Align = Top Margins.Top = 16.000000000000000000 Position.Y = 16.000000000000000000 - Size.Width = 544.000000000000000000 + Size.Width = 560.000000000000000000 Size.Height = 36.000000000000000000 Size.PlatformDefault = False TabOrder = 14 @@ -3961,7 +3990,7 @@ object Form1: TForm1 Margins.Top = 8.000000000000000000 Margins.Right = 8.000000000000000000 Margins.Bottom = 8.000000000000000000 - Size.Width = 440.000000000000000000 + Size.Width = 456.000000000000000000 Size.Height = 20.000000000000000000 Size.PlatformDefault = False object SearchEditButton4: TSearchEditButton diff --git a/Unit1.pas b/Unit1.pas index ab71f7c..30aaefa 100644 --- a/Unit1.pas +++ b/Unit1.pas @@ -3,8 +3,9 @@ unit Unit1; interface uses + WinAPI.Windows, System.SysUtils, System.Types, System.UITypes, System.Classes, - System.Variants, System.Math, System.StrUtils, + System.Variants, System.Math, System.StrUtils, System.IniFiles, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl, FMX.Layouts, FMX.ListBox, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit, FMX.EditBox, FMX.SpinBox, FMX.Menus; @@ -66,6 +67,9 @@ type Edit5: TEdit; SearchEditButton4: TSearchEditButton; ComboBox4: TComboBox; + Label5: TLabel; + Edit6: TEdit; + SearchEditButton5: TSearchEditButton; procedure FormShow(Sender: TObject); procedure SearchEditButton1Click(Sender: TObject); procedure SearchEditButton3Click(Sender: TObject); @@ -77,6 +81,9 @@ type procedure SearchEditButton2Click(Sender: TObject); procedure ComboBox4Change(Sender: TObject); procedure SearchEditButton4Click(Sender: TObject); + procedure Edit6Change(Sender: TObject); + procedure SearchEditButton5Click(Sender: TObject); + procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public @@ -87,6 +94,10 @@ var Form1: TForm1; CmdStr: TArray; +function GetModuleName: string; +function GetIniString(Section, Key, Default, FileName: string): string; +procedure SetIniString(Section, Key, Value, FileName: string); + implementation {$R *.fmx} @@ -94,6 +105,41 @@ implementation uses Unit2; +function GetModuleName: string; +var + szFileName: array [0 .. MAX_PATH] of char; +begin + FillChar(szFileName, sizeof(szFileName), #0); + GetModuleFileName(hInstance, szFileName, MAX_PATH); + Result := szFileName; +end; + +function GetIniString(Section, Key, Default, FileName: string): string; +var + Ini: TIniFile; +begin + Ini := TIniFile.Create(FileName); + with Ini do + try + Result := Ini.ReadString(Section, Key, Default); + finally + Free; + end; +end; + +procedure SetIniString(Section, Key, Value, FileName: string); +var + Ini: TIniFile; +begin + Ini := TIniFile.Create(FileName); + with Ini do + try + Ini.WriteString(Section, Key, Value); + finally + Free; + end; +end; + procedure TForm1.Button1Click(Sender: TObject); begin SetLength(CmdStr, 0); @@ -119,6 +165,7 @@ begin if CheckBox4.IsChecked then Insert('--compress=' + 't' + SpinBox2.Text + ':l' + SpinBox7.Text + ':hi' + IfThen(CheckBox5.IsChecked, '1', '0'), CmdStr, Length(CmdStr)); + Insert('--basedir=' + Edit6.Text, CmdStr, Length(CmdStr)); Insert(Edit1.Text, CmdStr, Length(CmdStr)); if ComboBox3.ItemIndex = 0 then Insert(Edit3.Text, CmdStr, Length(CmdStr)); @@ -159,6 +206,19 @@ begin Edit5.Text := ''; end; +procedure TForm1.Edit6Change(Sender: TObject); +begin + ShowMessage('Restart required to reload new plugins folder.'); +end; + +procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); +begin + if Edit6.Text <> GetIniString('UI', 'Plugins', '', + ChangeFileExt(GetModuleName, '.ini')) then + SetIniString('UI', 'Plugins', Edit6.Text, + ChangeFileExt(GetModuleName, '.ini')); +end; + procedure TForm1.FormShow(Sender: TObject); var I: Integer; @@ -218,4 +278,12 @@ begin Edit5.Text := Dir; end; +procedure TForm1.SearchEditButton5Click(Sender: TObject); +var + Dir: string; +begin + if SelectDirectory('', '', Dir) then + Edit6.Text := Dir; +end; + end. diff --git a/common/Utils.pas b/common/Utils.pas index 745b55a..2369c35 100644 --- a/common/Utils.pas +++ b/common/Utils.pas @@ -8,6 +8,7 @@ uses System.SysUtils, System.Classes, System.SyncObjs, System.Math, System.Types, System.AnsiStrings, System.StrUtils, System.IniFiles, System.IOUtils, System.RTLConsts, System.TypInfo, System.ZLib, System.Net.HttpClientComponent, + System.Net.HttpClient, System.Generics.Defaults, System.Generics.Collections; procedure ShowMessage(Msg: string; Caption: string = ''); @@ -215,7 +216,7 @@ type TDownloadStream = class(TStream) private const - FChunkSize = 65536; + FChunkSize = 1048576; private FUrl: string; FNetHTTPClient: TNetHTTPClient; @@ -466,7 +467,8 @@ function GetFileList(const APath: TArray; SubDir: Boolean = True) procedure FileReadBuffer(Handle: THandle; var Buffer; Count: NativeInt); procedure FileWriteBuffer(Handle: THandle; const Buffer; Count: NativeInt); procedure CloseHandleEx(var Handle: THandle); -function ExpandPath(const AFileName: string): String; +function ExpandPath(const AFileName: string; + AFullPath: Boolean = False): String; function Exec(Executable, CommandLine, WorkDir: string): Boolean; function ExecStdin(Executable, CommandLine, WorkDir: string; InBuff: Pointer; @@ -1448,6 +1450,8 @@ begin end; function TDownloadStream.Read(var Buffer; Count: LongInt): LongInt; +var + Res: IHTTPResponse; begin if (FPosition >= 0) and (Count >= 0) then begin @@ -1459,9 +1463,9 @@ begin Result := FSize - FPosition; Result := Min(Result, FChunkSize); FMemoryStream.Position := 0; - FNetHTTPClient.GetRange(FUrl, FPosition, FPosition + Result, + Res := FNetHTTPClient.GetRange(FUrl, FPosition, FPosition + Result - 1, FMemoryStream); - Result := FMemoryStream.Position; + Result := Res.ContentLength; Move(FMemoryStream.Memory^, Buffer, Result); Inc(FPosition, Result); exit; @@ -3412,7 +3416,7 @@ begin end; end; -function ExpandPath(const AFileName: string): String; +function ExpandPath(const AFileName: string; AFullPath: Boolean): String; begin if AFileName = '' then Result := '' @@ -3420,6 +3424,8 @@ begin Result := AFileName else Result := ExtractFilePath(GetModuleName) + AFileName; + if AFullPath then + Result := TPath.GetFullPath(Result); end; function Exec(Executable, CommandLine, WorkDir: string): Boolean; diff --git a/imports/BrunsliDLL.pas b/imports/BrunsliDLL.pas index 3bcda33..feb6de2 100644 --- a/imports/BrunsliDLL.pas +++ b/imports/BrunsliDLL.pas @@ -3,7 +3,8 @@ unit BrunsliDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -44,7 +45,7 @@ var procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'brunsli.dll'); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'brunsli.dll', True)); if Lib.Loaded then begin @brunsli_alloc_JPEGData := Lib.GetProcAddr('brunsli_alloc_JPEGData'); diff --git a/imports/FLACDLL.pas b/imports/FLACDLL.pas index 60e44b6..a7c2ca1 100644 --- a/imports/FLACDLL.pas +++ b/imports/FLACDLL.pas @@ -3,7 +3,8 @@ unit FLACDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -126,8 +127,8 @@ var procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + - 'libFLAC_dynamic.dll'); + Lib := TLibImport.Create + (ExpandPath(PluginsPath + 'libFLAC_dynamic.dll', True)); if Lib.Loaded then begin @FLAC__stream_encoder_new := Lib.GetProcAddr('FLAC__stream_encoder_new'); diff --git a/imports/FLZMA2DLL.pas b/imports/FLZMA2DLL.pas index e89a7ca..1161e81 100644 --- a/imports/FLZMA2DLL.pas +++ b/imports/FLZMA2DLL.pas @@ -3,7 +3,8 @@ unit FLZMA2DLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes, System.Types; @@ -193,9 +194,6 @@ type implementation -uses - Utils; - var Lib: TLibImport; @@ -308,7 +306,7 @@ begin inherited Create; LConfig := AConfig; if LConfig = '' then - LConfig := 't50p'; + LConfig := 't25p'; FProp.Parse(LConfig); FInput := AInput; LSize := 0; @@ -367,7 +365,7 @@ end; procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'fast-lzma2.dll'); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'fast-lzma2.dll', True)); if Lib.Loaded then begin @FL2_compress := Lib.GetProcAddr('FL2_compress'); diff --git a/imports/JoJpegDLL.pas b/imports/JoJpegDLL.pas index 94e7e54..6a31dc2 100644 --- a/imports/JoJpegDLL.pas +++ b/imports/JoJpegDLL.pas @@ -3,7 +3,8 @@ unit JoJpegDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -37,7 +38,7 @@ var procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'jojpeg_dll.dll'); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'jojpeg_dll.dll', True)); if Lib.Loaded then begin @jojpeg_Init := Lib.GetProcAddr('jojpeg_Init'); diff --git a/imports/LZ4DLL.pas b/imports/LZ4DLL.pas index e4df675..3ed7ae7 100644 --- a/imports/LZ4DLL.pas +++ b/imports/LZ4DLL.pas @@ -3,6 +3,7 @@ unit LZ4DLL; interface uses + InitCode, Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Math; @@ -198,80 +199,12 @@ begin Result := Pos2; end; -function UnravelEncode(InBuff: Pointer; InSize: Integer; OutBuff: Pointer; - OutSize: Integer): Integer; -const - blockSize = 65536; -var - ctx: PLZ4_streamHC_t; - Pos1, Pos2, Res: Integer; - X, Y: Integer; -begin - Result := 0; - ctx := LZ4_createStreamHC; - LZ4_resetStreamHC(ctx, 9); - Pos1 := 0; - Pos2 := 0; - try - while (Pos1 < InSize) do - begin - X := Min(InSize - Pos1, blockSize); - Y := OutSize - (Pos2 + Integer.Size); - Res := LZ4_compress_HC_continue(ctx, PByte(InBuff) + Pos1, - PByte(OutBuff) + Pos2 + Integer.Size, X, Y); - if Res <= 0 then - begin - LZ4_freeStreamHC(ctx); - exit(-Pos2); - end; - PInteger(PByte(OutBuff) + Pos2)^ := Res; - Inc(Pos1, X); - Inc(Pos2, Res + Integer.Size); - end; - finally - LZ4_freeStreamHC(ctx); - end; - Result := Pos2; -end; - -function UnravelDecode(InBuff: Pointer; InSize: Integer; OutBuff: Pointer; - OutSize: Integer): Integer; -const - blockSize = 65536; -var - ctx: PLZ4_streamDecode_t; - Pos1, Pos2, Res: Integer; -begin - Result := 0; - ctx := LZ4_createStreamDecode; - Pos1 := 0; - Pos2 := 0; - try - while (Pos1 < InSize) and (Pos2 < OutSize) do - begin - Res := LZ4_decompress_safe_continue(ctx, PByte(InBuff) + Pos1 + - Integer.Size, PByte(OutBuff) + Pos2, PInteger(PByte(InBuff) + Pos1)^, - Min(OutSize - Pos2, blockSize)); - if Res <= 0 then - begin - LZ4_freeStreamDecode(ctx); - exit(-Pos2); - end; - Inc(Pos1, PInteger(PByte(InBuff) + Pos1)^ + Integer.Size); - Inc(Pos2, Res); - end; - finally - LZ4_freeStreamDecode(ctx); - end; - Result := Pos2; -end; - var Lib: TLibImport; procedure Init(Filename: String); begin - Lib := TLibImport.Create(ExpandPath(Filename)); + Lib := TLibImport.Create(ExpandPath(Filename, True)); if Lib.Loaded then begin @LZ4_decompress_safe := Lib.GetProcAddr('LZ4_decompress_safe'); @@ -320,7 +253,7 @@ var initialization -DLLFile := 'liblz4.dll'; +DLLFile := PluginsPath + 'liblz4.dll'; for I := 1 to ParamCount do begin if ParamStr(I).StartsWith(DLLParam1) then diff --git a/imports/LZODLL.pas b/imports/LZODLL.pas index 04deb5d..b015c75 100644 --- a/imports/LZODLL.pas +++ b/imports/LZODLL.pas @@ -3,6 +3,7 @@ unit LZODLL; interface uses + InitCode, Utils, LibImport, WinAPI.Windows, System.SysUtils; @@ -70,7 +71,7 @@ var procedure Init(Filename: String); begin - Lib := TLibImport.Create(ExpandPath(Filename)); + Lib := TLibImport.Create(ExpandPath(Filename, True)); if Lib.Loaded then begin @lzo1x_1_compress := Lib.GetProcAddr('lzo1x_1_compress'); @@ -103,7 +104,7 @@ var initialization -DLLFile := 'lzo2.dll'; +DLLFile := PluginsPath + 'lzo2.dll'; for I := 1 to ParamCount do begin if ParamStr(I).StartsWith(DLLParam1) then diff --git a/imports/OodleDLL.pas b/imports/OodleDLL.pas index 8f77727..f037ea8 100644 --- a/imports/OodleDLL.pas +++ b/imports/OodleDLL.pas @@ -3,6 +3,7 @@ unit OodleDLL; interface uses + InitCode, Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Types, System.IOUtils; @@ -82,13 +83,13 @@ var I: Integer; C: Cardinal; begin - Lib := TLibImport.Create(ExpandPath(Filename)); + Lib := TLibImport.Create(ExpandPath(Filename, True)); if not Lib.Loaded then for I := 1 to 9 do begin Lib.Free; - Lib := TLibImport.Create(ExpandPath('oo2core_' + I.ToString + - '_win64.dll')); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'oo2core_' + I.ToString + + '_win64.dll', True)); if Lib.Loaded then break; end; @@ -96,8 +97,8 @@ begin for I := 3 to 9 do begin Lib.Free; - Lib := TLibImport.Create(ExpandPath('oo2ext_' + I.ToString + - '_win64.dll')); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'oo2ext_' + I.ToString + + '_win64.dll', True)); if Lib.Loaded then break; end; @@ -211,7 +212,7 @@ var initialization -DLLFile := 'oo2core_9_win64.dll'; +DLLFile := PluginsPath + 'oo2core_9_win64.dll'; for I := 1 to ParamCount do begin if ParamStr(I).StartsWith(DLLParam1) then diff --git a/imports/PackJPGDLL.pas b/imports/PackJPGDLL.pas index bf63698..a52a426 100644 --- a/imports/PackJPGDLL.pas +++ b/imports/PackJPGDLL.pas @@ -3,7 +3,8 @@ unit PackJPGDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -30,7 +31,7 @@ var procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'packjpg_dll.dll'); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'packjpg_dll.dll', True)); if Lib.Loaded then begin @pjglib_convert_stream2stream := diff --git a/imports/PreflateDLL.pas b/imports/PreflateDLL.pas index 3bd6702..3aec51e 100644 --- a/imports/PreflateDLL.pas +++ b/imports/PreflateDLL.pas @@ -3,7 +3,8 @@ unit PreflateDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -23,7 +24,7 @@ var procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'preflate_dll.dll'); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'preflate_dll.dll', True)); if Lib.Loaded then begin @preflate_decode := Lib.GetProcAddr('decode'); diff --git a/imports/ReflateDLL.pas b/imports/ReflateDLL.pas index 7b050fa..8fc4eb4 100644 --- a/imports/ReflateDLL.pas +++ b/imports/ReflateDLL.pas @@ -3,7 +3,8 @@ unit ReflateDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -30,8 +31,8 @@ var procedure Init; begin - Lib1 := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'RAW2HIF_DLL.DLL'); - Lib2 := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'HIF2RAW_DLL.DLL'); + Lib1 := TLibImport.Create(ExpandPath(PluginsPath + 'RAW2HIF_DLL.DLL', True)); + Lib2 := TLibImport.Create(ExpandPath(PluginsPath + 'HIF2RAW_DLL.DLL', True)); if Lib1.Loaded and Lib2.Loaded then begin @raw2hif_Alloc := Lib1.GetProcAddr('raw2hif_Alloc'); diff --git a/imports/XDeltaDLL.pas b/imports/XDeltaDLL.pas index 41fbe39..22886a7 100644 --- a/imports/XDeltaDLL.pas +++ b/imports/XDeltaDLL.pas @@ -3,7 +3,8 @@ unit XDeltaDLL; interface uses - LibImport, + InitCode, + Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Classes; @@ -42,7 +43,7 @@ var procedure Init; begin - Lib := TLibImport.Create(ExtractFilePath(ParamStr(0)) + 'xdelta3_dll.dll'); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'xdelta3_dll.dll', True)); if Lib.Loaded then begin DLLLoaded := True; diff --git a/imports/ZLibDLL.pas b/imports/ZLibDLL.pas index e93eae4..bb96d44 100644 --- a/imports/ZLibDLL.pas +++ b/imports/ZLibDLL.pas @@ -3,6 +3,7 @@ unit ZLibDLL; interface uses + InitCode, Utils, LibImport, WinAPI.Windows, System.SysUtils, System.Types, System.IOUtils, System.ZLib; @@ -148,16 +149,11 @@ end; procedure Init(Filename: String); begin - Lib := TLibImport.Create(ExpandPath(Filename)); + Lib := TLibImport.Create(ExpandPath(Filename, True)); if not(Lib.Loaded and Assigned(Lib.GetProcAddr('zlibVersion'))) then begin Lib.Free; - Lib := TLibImport.Create(ExpandPath('zlibwapi.dll')); - end; - if not(Lib.Loaded and Assigned(Lib.GetProcAddr('zlibVersion'))) then - begin - Lib.Free; - Lib := TLibImport.Create(ExpandPath('zlib1.dll')); + Lib := TLibImport.Create(ExpandPath(PluginsPath + 'zlib1.dll', True)); end; if Lib.Loaded and Assigned(Lib.GetProcAddr('zlibVersion')) then begin @@ -201,7 +197,7 @@ var initialization -DLLFile := 'zlibwapi.dll'; +DLLFile := PluginsPath + 'zlibwapi.dll'; for I := 1 to ParamCount do begin if ParamStr(I).StartsWith(DLLParam1) then diff --git a/imports/ZSTDDLL.pas b/imports/ZSTDDLL.pas index 6cf8456..a0d865e 100644 --- a/imports/ZSTDDLL.pas +++ b/imports/ZSTDDLL.pas @@ -3,6 +3,7 @@ unit ZSTDDLL; interface uses + InitCode, Utils, LibImport, WinAPI.Windows, System.SysUtils; @@ -147,7 +148,7 @@ var procedure Init(Filename: String); begin - Lib := TLibImport.Create(ExpandPath(Filename)); + Lib := TLibImport.Create(ExpandPath(Filename, True)); if Lib.Loaded then begin @ZSTD_compress := Lib.GetProcAddr('ZSTD_compress'); @@ -194,7 +195,7 @@ var initialization -DLLFile := 'libzstd.dll'; +DLLFile := PluginsPath + 'libzstd.dll'; for I := 1 to ParamCount do begin if ParamStr(I).StartsWith(DLLParam1) then diff --git a/io/IOExecute.pas b/io/IOExecute.pas index 6c7192b..cedef7f 100644 --- a/io/IOExecute.pas +++ b/io/IOExecute.pas @@ -7,6 +7,7 @@ unit IOExecute; interface uses + InitCode, Threading, Utils, SynCommons, SynCrypto, ParseClass, ParseExpr, IOUtils, WinAPI.Windows, WinAPI.ShlObj, @@ -182,7 +183,7 @@ begin OutFile := ReplaceText(OutFile, '[fileout]', FILE_OUT); end; if I = 0 then - Exec := ExtractFilePath(Utils.GetModuleName) + S + Exec := ExpandPath(PluginsPath + S, True) else Param := Param + ' ' + IfThen(ContainsText(S, ' ') or (S = ''), '"' + S + '"', S); diff --git a/precompressor/PrecompDLL.pas b/precompressor/PrecompDLL.pas index ef5f0a4..3e6a4dc 100644 --- a/precompressor/PrecompDLL.pas +++ b/precompressor/PrecompDLL.pas @@ -3,6 +3,7 @@ unit PrecompDLL; interface uses + InitCode, Utils, UIMain, PrecompUtils, @@ -151,14 +152,15 @@ end; function DLLParse(Command: PChar; Option: PInteger; Funcs: PPrecompFuncs): Boolean; var - I: Integer; + I, J: Integer; begin Result := False; for I := Low(CodecDLL) to High(CodecDLL) do begin - if IndexText(Funcs^.GetCodec(Command, 0, False), CodecDLL[I].Names) >= 0 - then + J := IndexText(Funcs^.GetCodec(Command, 0, False), CodecDLL[I].Names); + if J >= 0 then begin + LongRec(Option^).Lo := J; LongRec(Option^).Hi := I; Result := True; break; @@ -355,7 +357,7 @@ var initialization -DLLList := TDirectory.GetFiles(ExtractFilePath(Utils.GetModuleName), '*.dll', +DLLList := TDirectory.GetFiles(ExpandPath(PluginsPath, True), '*.dll', TSearchOption.soTopDirectoryOnly); FuncList := TStringList.Create; for I := Low(DLLList) to High(DLLList) do @@ -376,7 +378,7 @@ begin @DLLStruct^.Scan2 := GetProcAddress(DLLHandle, 'PrecompScan2'); @DLLStruct^.Process := GetProcAddress(DLLHandle, 'PrecompProcess'); @DLLStruct^.Restore := GetProcAddress(DLLHandle, 'PrecompRestore'); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddplugin(ChangeFileExt(ExtractFileName(DLLList[I]), ''), PLUGIN_LIBRARY); Insert(DLLStruct^, CodecDLL, Length(CodecDLL)); @@ -387,7 +389,7 @@ begin Insert(S, CodecDLL[Pred(Length(CodecDLL))].Names, Length(CodecDLL[Pred(Length(CodecDLL))].Names)); Insert(S, Codec.Names, Length(Codec.Names)); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddCodec(S); Inc(J); end; @@ -398,7 +400,7 @@ begin Length(CodecDLL[Pred(Length(CodecDLL))].Names)); Insert(ChangeFileExt(ExtractFileName(DLLList[I]), ''), Codec.Names, Length(Codec.Names)); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddCodec(ChangeFileExt(ExtractFileName(DLLList[I]), '')); end; end; diff --git a/precompressor/PrecompEXE.pas b/precompressor/PrecompEXE.pas index 589382b..c6cd451 100644 --- a/precompressor/PrecompEXE.pas +++ b/precompressor/PrecompEXE.pas @@ -3,6 +3,7 @@ unit PrecompExe; interface uses + InitCode, Utils, Threading, SynCommons, SynCrypto, PrecompUtils, @@ -685,7 +686,8 @@ var initialization -S1 := ChangeFileExt(Utils.GetModuleName, '.ini'); +S1 := ExpandPath(PluginsPath, True) + + ChangeFileExt(ExtractFileName(Utils.GetModuleName), '.ini'); if FileExists(S1) then begin Ini := TMemIniFile.Create(S1); @@ -694,7 +696,7 @@ begin for I := 0 to SL.Count - 1 do begin List := DecodeStr(SL[I], ','); - if FileExists(ExtractFilePath(Utils.GetModuleName) + + if FileExists(ExpandPath(PluginsPath, True) + GetCmdStr(Ini.ReadString(SL[I], 'Decode', ''), 0)) then for K := Low(List) to High(List) do begin @@ -710,8 +712,7 @@ begin else S1 := Ini.ReadString(SL[I], 'Decode', ''); S1 := ReplaceText(S1, '', List[K]); - ExeStruct.Exec[X] := ExtractFilePath(Utils.GetModuleName) + - GetCmdStr(S1, 0); + ExeStruct.Exec[X] := ExpandPath(PluginsPath, True) + GetCmdStr(S1, 0); ExeStruct.Param[X] := ''; ExeStruct.Mode[X] := 0; for J := 1 to GetCmdCount(S1) - 1 do diff --git a/precompressor/PrecompINI.pas b/precompressor/PrecompINI.pas index 1fb7164..b5edb62 100644 --- a/precompressor/PrecompINI.pas +++ b/precompressor/PrecompINI.pas @@ -3,6 +3,7 @@ unit PrecompINI; interface uses + InitCode, Utils, ParseExpr, UIMain, PrecompUtils, @@ -379,7 +380,7 @@ var initialization -CfgList := TDirectory.GetFiles(ExtractFilePath(Utils.GetModuleName), '*.ini', +CfgList := TDirectory.GetFiles(ExpandPath(PluginsPath, True), '*.ini', TSearchOption.soTopDirectoryOnly); SL := TStringList.Create; SetLength(CodecCfg, 1); @@ -391,7 +392,7 @@ begin begin S1 := ChangeFileExt(ExtractFileName(CfgList[I]), ''); Insert(S1, Codec.Names, Length(Codec.Names)); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddplugin(S1, PLUGIN_CONFIG); SetLength(CodecCfg[0], Succ(Length(CodecCfg[0]))); CfgRecArray := @CodecCfg[0, Pred(Length(CodecCfg[0]))]; @@ -403,7 +404,7 @@ begin CfgRec := @CodecCfg[0, Pred(Length(CodecCfg[0])), J]; CfgRec^.Parser := TExpressionParser.Create; CfgRec^.Name := ReadString('Stream' + X.ToString, 'Name', ''); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddCodec(CfgRec^.Name); CfgRec^.Codec := ReadString('Stream' + X.ToString, 'Codec', ''); CfgRec^.BigEndian := ReadBool('Stream' + X.ToString, diff --git a/precompressor/PrecompINIEx.pas b/precompressor/PrecompINIEx.pas index 79e4185..0ad35f1 100644 --- a/precompressor/PrecompINIEx.pas +++ b/precompressor/PrecompINIEx.pas @@ -3,6 +3,7 @@ unit PrecompINIEx; interface uses + InitCode, Utils, ParseExpr, UIMain, PrecompUtils, @@ -500,7 +501,7 @@ var initialization -CfgList := TDirectory.GetFiles(ExtractFilePath(Utils.GetModuleName), '*.ini', +CfgList := TDirectory.GetFiles(ExpandPath(PluginsPath, True), '*.ini', TSearchOption.soTopDirectoryOnly); SL := TStringList.Create; SetLength(CodecCfg, 1); @@ -512,7 +513,7 @@ begin begin S1 := ChangeFileExt(ExtractFileName(CfgList[I]), ''); Insert(S1, Codec.Names, Length(Codec.Names)); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddplugin(S1, PLUGIN_CONFIG); SetLength(CodecCfg[0], Succ(Length(CodecCfg[0]))); CfgRecArray := @CodecCfg[0, Pred(Length(CodecCfg[0]))]; @@ -524,7 +525,7 @@ begin CfgRec := @CodecCfg[0, Pred(Length(CodecCfg[0])), J]; CfgRec^.Parser := TExpressionParser.Create; CfgRec^.Name := ReadString('StreamList' + X.ToString, 'Name', ''); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddCodec(CfgRec^.Name); CfgRec^.Codec := ReadString('StreamList' + X.ToString, 'Codec', ''); CfgRec^.BigEndian := ReadBool('StreamList' + X.ToString, diff --git a/precompressor/PrecompLZ4.pas b/precompressor/PrecompLZ4.pas index 5d82f21..2195d9f 100644 --- a/precompressor/PrecompLZ4.pas +++ b/precompressor/PrecompLZ4.pas @@ -31,6 +31,7 @@ const var SOList: array of array [0 .. CODEC_COUNT - 1] of TSOList; CodecAvailable, CodecEnabled: TArray; + LMaxSize: Integer = L_MAXSIZE; LBlockSize: Integer = L_BLOCKSIZE; LBlockDependency: Integer = L_BLOCKDEPENDENCY; LAcceleration: Integer = L_ACCELERATION; @@ -61,6 +62,8 @@ begin if (CompareText(S, LZ4Codecs[LZ4_CODEC]) = 0) and LZ4DLL.DLLLoaded then begin CodecEnabled[LZ4_CODEC] := True; + if Funcs^.GetParam(Command, X, 'm') <> '' then + LMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); if Funcs^.GetParam(Command, X, 'a') <> '' then LAcceleration := StrToInt(Funcs^.GetParam(Command, X, 'a')); end @@ -72,6 +75,8 @@ begin for I := Low(SOList) to High(SOList) do SOList[I][LZ4HC_CODEC].Update ([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True); + if Funcs^.GetParam(Command, X, 'm') <> '' then + LMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); end else if (CompareText(S, LZ4Codecs[LZ4F_CODEC]) = 0) and LZ4DLL.DLLLoaded then @@ -81,6 +86,8 @@ begin for I := Low(SOList) to High(SOList) do SOList[I][LZ4F_CODEC].Update ([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True); + if Funcs^.GetParam(Command, X, 'm') <> '' then + LMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); if Funcs^.GetParam(Command, X, 'b') <> '' then LBlockSize := StrToInt(Funcs^.GetParam(Command, X, 'b')) - 4; if Funcs^.GetParam(Command, X, 'd') <> '' then @@ -182,7 +189,7 @@ begin DI1.OldSize := SizeEx; if not CodecAvailable[X] then exit; - Y := Max(DI1.NewSize, L_MAXSIZE); + Y := Max(DI1.NewSize, LMaxSize); Buffer := Funcs^.Allocator(Instance, Y); case X of LZ4_CODEC, LZ4HC_CODEC: @@ -217,7 +224,7 @@ begin end; if BoolArray(CodecEnabled, False) then exit; - Buffer := Funcs^.Allocator(Instance, L_MAXSIZE); + Buffer := Funcs^.Allocator(Instance, LMaxSize); Pos := 0; while Pos < Size do begin @@ -225,7 +232,7 @@ begin (CodecEnabled[LZ4HC_CODEC] and (SOList[Instance][LZ4HC_CODEC].Count = 1)) then begin - Y := LZ4_decompress_safe(Input + Pos, Buffer, SizeEx - Pos, L_MAXSIZE); + Y := LZ4_decompress_safe(Input + Pos, Buffer, SizeEx - Pos, LMaxSize); if Abs(Y) > 256 then begin try @@ -260,7 +267,7 @@ begin if PCardinal(Input + Pos)^ = $184D2204 then begin Y := LZ4F_decompress_safe(Input + Pos, Buffer, SizeEx - Pos, - L_MAXSIZE, @X, @Z); + LMaxSize, @X, @Z); if (X < Y) then begin Output(Instance, Buffer, Y); @@ -296,7 +303,7 @@ begin X := GetBits(StreamInfo^.Option, 0, 5); if StreamInfo^.OldSize <= 0 then exit; - StreamInfo^.NewSize := Max(StreamInfo^.NewSize, L_MAXSIZE); + StreamInfo^.NewSize := Max(StreamInfo^.NewSize, LMaxSize); Buffer := Funcs^.Allocator(Instance, StreamInfo^.NewSize); case X of LZ4_CODEC, LZ4HC_CODEC: diff --git a/precompressor/PrecompLZO.pas b/precompressor/PrecompLZO.pas index 99ccddc..335856d 100644 --- a/precompressor/PrecompLZO.pas +++ b/precompressor/PrecompLZO.pas @@ -21,8 +21,8 @@ const LZO1C_CODEC = 2; const - L_WORKMEM = 524288; L_MAXSIZE = 16 * 1024 * 1024; + L_WORKMEM = 524288; LZO1X_999 = 999; LZO2A_999 = 999; LZO1C_999 = 999; @@ -34,6 +34,7 @@ var LZO2AVariant: Integer = LZO2A_999; LZO1CVariant: Integer = LZO1C_999; CodecAvailable, CodecEnabled: TArray; + LMaxSize: Integer = L_MAXSIZE; type PLZOSI = ^TLZOSI; @@ -134,6 +135,8 @@ begin for I := Low(SOList) to High(SOList) do SOList[I][LZO1X_CODEC].Update ([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True); + if Funcs^.GetParam(Command, X, 'm') <> '' then + LMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); end else if (CompareText(S, LZOCodecs[LZO2A_CODEC]) = 0) and LZODLL.DLLLoaded then @@ -141,6 +144,8 @@ begin CodecEnabled[LZO2A_CODEC] := True; if Funcs^.GetParam(Command, X, 'v') = '999' then LZO2AVariant := 999; + if Funcs^.GetParam(Command, X, 'm') <> '' then + LMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); end else if (CompareText(S, LZOCodecs[LZO1C_CODEC]) = 0) and LZODLL.DLLLoaded then @@ -148,6 +153,8 @@ begin CodecEnabled[LZO1C_CODEC] := True; if Funcs^.GetParam(Command, X, 'v') = '999' then LZO1CVariant := 999; + if Funcs^.GetParam(Command, X, 'm') <> '' then + LMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); end; Inc(X); end; @@ -240,7 +247,7 @@ begin exit; if not CodecAvailable[X] then exit; - Res := Max(DI1.NewSize, L_MAXSIZE); + Res := Max(DI1.NewSize, LMaxSize); Buffer := Funcs^.Allocator(Instance, Res); case X of LZO1X_CODEC: @@ -285,11 +292,11 @@ begin end; if BoolArray(CodecEnabled, False) then exit; - Buffer := Funcs^.Allocator(Instance, L_MAXSIZE); + Buffer := Funcs^.Allocator(Instance, LMaxSize); Pos := 0; while Pos < Size do begin - if GetLZO1XSI(Input + Pos, SizeEx - Pos, Buffer, L_MAXSIZE, @LZOSI) then + if GetLZO1XSI(Input + Pos, SizeEx - Pos, Buffer, LMaxSize, @LZOSI) then begin Output(Instance, Buffer, LZOSI.DSize); SI.Position := Pos; @@ -321,7 +328,7 @@ begin X := GetBits(StreamInfo^.Option, 0, 5); if StreamInfo^.OldSize <= 0 then exit; - Res := Max(StreamInfo^.NewSize, L_MAXSIZE); + Res := Max(StreamInfo^.NewSize, LMaxSize); Buffer := Funcs^.Allocator(Instance, Res); case X of LZO1X_CODEC: diff --git a/precompressor/PrecompMain.pas b/precompressor/PrecompMain.pas index 1bda118..62a0645 100644 --- a/precompressor/PrecompMain.pas +++ b/precompressor/PrecompMain.pas @@ -5,6 +5,7 @@ unit PrecompMain; interface uses + InitCode, Threading, Utils, SynCommons, ParseClass, ParseExpr, FLZMA2DLL, PrecompUtils, PrecompCrypto, PrecompZLib, PrecompLZ4, PrecompLZO, PrecompZSTD, PrecompOodle, PrecompMedia, PrecompINI, PrecompINIEx, PrecompSearch, @@ -197,7 +198,7 @@ begin StoreDD := -2; if ArgParse.AsBoolean('-dd') or ArgParse.AsBoolean('--dedup') then StoreDD := -1; - if FileExists(ExtractFilePath(Utils.GetModuleName) + 'srep.exe') then + if FileExists(ExpandPath(PluginsPath + 'srep.exe', True)) then begin StoreDD := ArgParse.AsInteger('--dedup=', 0, StoreDD); StoreDD := ArgParse.AsInteger('-dd', 0, StoreDD); @@ -1736,9 +1737,9 @@ begin 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 + with TProcessStream.Create(ExpandPath(PluginsPath + 'srep.exe', True), + '-m' + StoreDD.ToString + 'f ' + S + ' -', GetCurrentDir, nil, + Output) do try if Execute then begin @@ -2113,9 +2114,8 @@ begin begin if (Depth = 0) and (StoreDD >= 0) then begin - LStream := TProcessStream.Create(ExtractFilePath(Utils.GetModuleName) + - 'srep.exe', '-d -s -mem' + SrepMemCfg + ' - -', GetCurrentDir, - Input, nil); + LStream := TProcessStream.Create(ExpandPath(PluginsPath + 'srep.exe', + True), '-d -s -mem' + SrepMemCfg + ' - -', GetCurrentDir, Input, nil); if not LStream.Execute then raise EReadError.CreateRes(@SReadError); DecInput[Index] := TBufferedStream.Create(LStream, True, 4194304); diff --git a/precompressor/PrecompOodle.pas b/precompressor/PrecompOodle.pas index fa6dfb9..688a0f1 100644 --- a/precompressor/PrecompOodle.pas +++ b/precompressor/PrecompOodle.pas @@ -25,14 +25,17 @@ const LEVIATHAN_CODEC = 5; const + O_MAXSIZE = 16 * 1024 * 1024; O_LENGTH = 32; O_TRADEOFF = 256; - O_MAXSIZE = 16 * 1024 * 1024; + O_DICTIONARY = 0; var SOList: array of array [0 .. CODEC_COUNT - 1] of TSOList; + OMaxSize: Integer = O_MAXSIZE; OLength: Integer = O_LENGTH; OTradeOff: Integer = O_TRADEOFF; + ODictionary: Integer = O_DICTIONARY; CodecAvailable, CodecEnabled: TArray; type @@ -379,10 +382,14 @@ begin for I := Low(SOList) to High(SOList) do SOList[I][Y].Update ([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True); + if Funcs^.GetParam(Command, X, 'm') <> '' then + OMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); if Funcs^.GetParam(Command, X, 'n') <> '' then OLength := StrToInt(Funcs^.GetParam(Command, X, 'n')); if Funcs^.GetParam(Command, X, 't') <> '' then OTradeOff := StrToInt(Funcs^.GetParam(Command, X, 't')); + if Funcs^.GetParam(Command, X, 'd') <> '' then + ODictionary := StrToInt(Funcs^.GetParam(Command, X, 'd')); end; Inc(X); end; @@ -427,6 +434,8 @@ begin SetBits(Option^, 1, 12, 1); if Funcs^.GetParam(Command, I, 't') <> '' then SetBits(Option^, StrToInt(Funcs^.GetParam(Command, I, 't')), 13, 11); + if Funcs^.GetParam(Command, I, 'd') <> '' then + SetBits(Option^, StrToInt(Funcs^.GetParam(Command, I, 'd')), 24, 5); Result := True; end; Inc(I); @@ -462,7 +471,7 @@ begin if (X in [LZNA_CODEC, LEVIATHAN_CODEC]) and (DI1.NewSize <= 0) then exit; if DI1.NewSize <= 0 then - Res := O_MAXSIZE + Res := OMaxSize else Res := DI1.NewSize; Buffer := Funcs^.Allocator(Instance, Res); @@ -619,9 +628,11 @@ begin SizeOf(TOodleLZ_CompressOptions)); COptions.sendQuantumCRCs := GetBits(StreamInfo^.Option, 12, 1) = 1; COptions.spaceSpeedTradeoffBytes := GetBits(StreamInfo^.Option, 13, 11); - // COptions.dictionarySize := 262144; + COptions.dictionarySize := IfThen(GetBits(StreamInfo^.Option, 24, 5) = 0, 0, + Round(Power(2, GetBits(StreamInfo^.Option, 24, 5)))); Params := 'l' + I.ToString + ':' + 'c' + GetBits(StreamInfo^.Option, 12, 1) - .ToString + ':' + 't' + GetBits(StreamInfo^.Option, 13, 11).ToString; + .ToString + ':' + 't' + GetBits(StreamInfo^.Option, 13, 11).ToString + ':' + + 'd' + GetBits(StreamInfo^.Option, 24, 5).ToString; if not Result then Res1 := OodleLZ_Compress(Y, NewInput, StreamInfo^.NewSize, Buffer, I, @COptions); @@ -677,9 +688,12 @@ begin COptions, SizeOf(TOodleLZ_CompressOptions)); COptions.sendQuantumCRCs := GetBits(StreamInfo.Option, 12, 1) = 1; COptions.spaceSpeedTradeoffBytes := GetBits(StreamInfo.Option, 13, 11); + COptions.dictionarySize := IfThen(GetBits(StreamInfo.Option, 24, 5) = 0, 0, + Round(Power(2, GetBits(StreamInfo.Option, 24, 5)))); Params := 'l' + GetBits(StreamInfo.Option, 5, 7).ToString + ':' + 'c' + GetBits(StreamInfo.Option, 12, 1).ToString + ':' + 't' + - GetBits(StreamInfo.Option, 13, 11).ToString; + GetBits(StreamInfo.Option, 13, 11).ToString + ':' + 'd' + + GetBits(StreamInfo.Option, 24, 5).ToString; Res1 := OodleLZ_Compress(Y, Input, StreamInfo.NewSize, Buffer, GetBits(StreamInfo.Option, 5, 7), @COptions); Funcs^.LogRestore(OodleCodecs[GetBits(StreamInfo.Option, 0, 5)], diff --git a/precompressor/PrecompSearch.pas b/precompressor/PrecompSearch.pas index d78e442..a53ddb9 100644 --- a/precompressor/PrecompSearch.pas +++ b/precompressor/PrecompSearch.pas @@ -3,6 +3,7 @@ unit PrecompSearch; interface uses + InitCode, Utils, SynCommons, SynCrypto, UIMain, PrecompUtils, @@ -265,7 +266,7 @@ var initialization -SearchList := TDirectory.GetFiles(ExtractFilePath(Utils.GetModuleName), '*.xtl', +SearchList := TDirectory.GetFiles(ExpandPath(PluginsPath, True), '*.xtl', TSearchOption.soTopDirectoryOnly); for I := Low(SearchList) to High(SearchList) do begin @@ -282,7 +283,7 @@ begin SetLength(CodecSearch, Succ(J)); S := ChangeFileExt(ExtractFileName(SearchList[I]), ''); Insert(S, Codec.Names, Length(Codec.Names)); - if UIMain.DLLLoaded then + if InitCode.UIDLLLoaded then XTLAddplugin(S, PLUGIN_DATABASE); end; while FStream.Position < FStream.Size do diff --git a/precompressor/PrecompZSTD.pas b/precompressor/PrecompZSTD.pas index 3e7154a..327b4e3 100644 --- a/precompressor/PrecompZSTD.pas +++ b/precompressor/PrecompZSTD.pas @@ -27,6 +27,7 @@ var // cdict, ddict: Pointer; DStream: TMemoryStream; CodecAvailable, CodecEnabled: TArray; + ZMaxSize: Integer = Z_MAXSIZE; function ZSTDInit(Command: PChar; Count: Integer; Funcs: PPrecompFuncs) : Boolean; @@ -59,6 +60,8 @@ begin for I := Low(SOList) to High(SOList) do SOList[I][ZSTD_CODEC].Update ([StrToInt(Funcs^.GetParam(Command, X, 'l'))], True); + if Funcs^.GetParam(Command, X, 'm') <> '' then + ZMaxSize := ConvertToBytes(Funcs^.GetParam(Command, X, 'm')); end; Inc(X); end; @@ -143,7 +146,7 @@ begin exit; Y := ZSTD_findDecompressedSize(Input, SizeEx); if Y <= 0 then - Y := Z_MAXSIZE; + Y := ZMaxSize; Buffer := Funcs^.Allocator(Instance, Y); case X of ZSTD_CODEC: @@ -183,7 +186,7 @@ begin begin Z := ZSTD_findDecompressedSize(Input + Pos, X); if Z <= 0 then - Z := Z_MAXSIZE; + Z := ZMaxSize; Buffer := Funcs^.Allocator(Instance, Z); Y := ZSTD_decompressDCtx(dctx[Instance], Buffer, Z, Input + Pos, X); // Y := ZSTD_decompress_usingDDict(dctx[Instance], Buffer, Z, Input + Pos, X, ddict); @@ -224,7 +227,7 @@ begin if StreamInfo^.NewSize <= 0 then StreamInfo^.NewSize := ZSTD_findDecompressedSize(Input, Size); if StreamInfo^.NewSize <= 0 then - StreamInfo^.NewSize := Z_MAXSIZE; + StreamInfo^.NewSize := ZMaxSize; Buffer := Funcs^.Allocator(Instance, StreamInfo^.NewSize); case X of ZSTD_CODEC: diff --git a/ui/UIMain.pas b/ui/UIMain.pas index 054f905..f4cf0b8 100644 --- a/ui/UIMain.pas +++ b/ui/UIMain.pas @@ -3,30 +3,11 @@ unit UIMain; interface uses + InitCode, LibImport, WinAPI.Windows, System.SysUtils, System.Classes, System.Types; -type - PUIFuncs = ^TUIFuncs; - - TUIFuncs = record - IsZlibLoaded: Boolean; - IsReflateLoaded: Boolean; - IsPreflateLoaded: Boolean; - IsLZ4Loaded: Boolean; - IsLZOLoaded: Boolean; - IsZSTDLoaded: Boolean; - IsOodleLoaded: Boolean; - IsFLACLoaded: Boolean; - IsBrunsliLoaded: Boolean; - IsPackJPGLoaded: Boolean; - IsJoJpegLoaded: Boolean; - IsXDeltaLoaded: Boolean; - IsLZMALoaded: Boolean; - IsSrepAvailable: Boolean; - end; - const PLUGIN_DATABASE = 0; PLUGIN_CONFIG = 1; @@ -34,12 +15,6 @@ const var UIFuncs: TUIFuncs; - XTLUI1: procedure; - XTLUI2: function(Funcs: PUIFuncs; var Params: TArray; - out LibType: Integer; out LibPath: String): Boolean; - XTLAddPlugin: procedure(S: String; I: Integer); - XTLAddCodec: procedure(S: String); - DLLLoaded: Boolean = False; implementation @@ -48,27 +23,6 @@ uses PackJPGDLL, PreflateDLL, ReflateDLL, XDeltaDLL, ZLibDLL, ZSTDDLL, Utils; -var - Lib: TLibImport; - -procedure Init; -begin - Lib := TLibImport.Create(ChangeFileExt(Utils.GetModuleName, 'ui.dll')); - if Lib.Loaded then - begin - @XTLUI1 := Lib.GetProcAddr('XTLUI1'); - @XTLUI2 := Lib.GetProcAddr('XTLUI2'); - @XTLAddPlugin := Lib.GetProcAddr('XTLAddPlugin'); - @XTLAddCodec := Lib.GetProcAddr('XTLAddCodec'); - DLLLoaded := Assigned(XTLUI1); - end; -end; - -procedure Deinit; -begin - Lib.Free; -end; - initialization UIFuncs.IsZlibLoaded := ZLibDLL.DLLLoaded; @@ -84,12 +38,7 @@ UIFuncs.IsPackJPGLoaded := PackJPGDLL.DLLLoaded; UIFuncs.IsJoJpegLoaded := JoJpegDLL.DLLLoaded; UIFuncs.IsXDeltaLoaded := XDeltaDLL.DLLLoaded; UIFuncs.IsLZMALoaded := FLZMA2DLL.DLLLoaded; -UIFuncs.IsSrepAvailable := FileExists(ExtractFilePath(Utils.GetModuleName) + - 'srep.exe'); -Init; - -finalization - -Deinit; +UIFuncs.IsSrepAvailable := + FileExists(ExpandPath(PluginsPath + 'srep.exe', True)); end. diff --git a/xtool.dpr b/xtool.dpr index 03c0b78..9828a55 100644 --- a/xtool.dpr +++ b/xtool.dpr @@ -48,6 +48,7 @@ uses oObjects in 'contrib\ParseExpression\oObjects.pas', ParseClass in 'contrib\ParseExpression\ParseClass.pas', ParseExpr in 'contrib\ParseExpression\ParseExpr.pas', + InitCode in 'InitCode.pas', BrunsliDLL in 'imports\BrunsliDLL.pas', FLACDLL in 'imports\FLACDLL.pas', FLZMA2DLL in 'imports\FLZMA2DLL.pas', @@ -255,7 +256,7 @@ begin FormatSettings := TFormatSettings.Invariant; if not CheckInstance('XToolUI_Check') then ProgramInfo; - if UIMain.DLLLoaded and (ParamCount = 0) then + if InitCode.UIDLLLoaded and (ParamCount = 0) then begin XTLUI1; while XTLUI2(@UIFuncs, ParamStr_, LibType, LibPath) do diff --git a/xtool.dproj b/xtool.dproj index 3276fc1..fed78e5 100644 --- a/xtool.dproj +++ b/xtool.dproj @@ -165,6 +165,7 @@ + diff --git a/xtool.res b/xtool.res index d6ea49a4e5420db4e5e0fb931316d5d4fe445ad3..171aa0e72952225656cda5ae00bbc617ab5dbc88 100644 GIT binary patch delta 81 zcmeysx`b_l0^^d2it<3hF`9{mY2rL3#s?D*iW{0RurV+)xG`ih~vobK)F>p_IX4K^^1