xtool/InitCode.pas

111 lines
2.3 KiB
ObjectPascal
Raw Permalink Normal View History

2022-12-31 22:45:22 +02:00
unit InitCode;
interface
uses
Utils, LibImport,
2023-09-10 15:03:26 +02:00
WinAPI.Windows,
System.SysUtils, System.Classes, System.Types, System.StrUtils;
2022-12-31 22:45:22 +02:00
const
2023-09-10 15:03:26 +02:00
PLUGIN_DATABASE = 0;
PLUGIN_CONFIG = 1;
PLUGIN_LIBRARY = 2;
2023-04-29 22:51:51 +02:00
PluginsParam = '-bd';
2022-12-31 22:45:22 +02:00
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
2023-04-29 22:51:51 +02:00
DEBUG: Boolean = False;
2022-12-31 22:45:22 +02:00
UILib: TLibImport;
PluginsPath: String = '';
XTLUI1: procedure;
XTLUI2: function(Funcs: PUIFuncs; var Params: TArray<String>;
out LibType: Integer; out LibPath: String): Boolean;
XTLAddPlugin: procedure(S: String; I: Integer);
XTLAddCodec: procedure(S: String);
UIDLLLoaded: Boolean = False;
implementation
procedure Init;
begin
2023-09-10 15:03:26 +02:00
if Win32MajorVersion < 6 then
exit;
UILib := TLibImport.Create;
UILib.LoadLib(ChangeFileExt(Utils.GetModuleName, 'ui.dll'));
2022-12-31 22:45:22 +02:00
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
2023-09-10 15:03:26 +02:00
if Win32MajorVersion < 6 then
exit;
2022-12-31 22:45:22 +02:00
UILib.Free;
end;
var
I: Integer;
initialization
2023-09-10 15:03:26 +02:00
if not IsLibrary then
2023-04-29 22:51:51 +02:00
begin
2023-09-10 15:03:26 +02:00
for I := 1 to ParamCount do
2023-04-29 22:51:51 +02:00
begin
2023-09-10 15:03:26 +02:00
if (ParamStr(I) = '--debug') then
begin
DEBUG := True;
break;
end;
2023-04-29 22:51:51 +02:00
end;
2023-09-10 15:03:26 +02:00
Init;
if UIDLLLoaded and (ParamCount = 0) then
PluginsPath := IncludeTrailingBackSlash
(ExpandPath(GetIniString('UI', 'Plugins', '',
ChangeFileExt(Utils.GetModuleName, 'ui.ini'))));
for I := 1 to ParamCount do
2022-12-31 22:45:22 +02:00
begin
2023-09-10 15:03:26 +02:00
if ParamStr(I).StartsWith(PluginsParam) then
begin
PluginsPath := ParamStr(I).Substring(PluginsParam.Length);
break;
end;
2022-12-31 22:45:22 +02:00
end;
end;
PluginsPath := IncludeTrailingBackSlash(ExpandPath(PluginsPath));
2023-09-10 15:03:26 +02:00
if not DirectoryExists(ExpandPath(PluginsPath, True)) then
PluginsPath := ExtractFilePath(Utils.GetModuleName);
2022-12-31 22:45:22 +02:00
finalization
2023-09-10 15:03:26 +02:00
if not IsLibrary then
Deinit;
2022-12-31 22:45:22 +02:00
end.