FIX: Load RSVG library and it dependencies from the same path (fixes #752)

This commit is contained in:
Alexander Koblov 2023-02-19 14:01:06 +03:00
commit 6cf2d25f7b
2 changed files with 70 additions and 2 deletions

View file

@ -248,6 +248,7 @@ function mbSysErrorMessage(ErrorCode: Integer): String; overload;
}
function mbGetModuleName(Address: Pointer = nil): String;
function mbLoadLibrary(const Name: String): TLibHandle;
function mbLoadLibraryEx(const Name: String): TLibHandle;
function SafeGetProcAddress(Lib: TLibHandle; const ProcName: AnsiString): Pointer;
{en
Reads the concrete file's name that the link points to.
@ -1731,6 +1732,45 @@ begin
end;
{$ENDIF}
function mbLoadLibraryEx(const Name: String): TLibHandle;
{$IF DEFINED(MSWINDOWS)}
const
PATH_ENV = 'PATH';
var
APath: String;
usName: UnicodeString;
begin
usName:= CeUtf8ToUtf16(Name);
if CheckWin32Version(10)then
begin
Result:= LoadLibraryExW(PWideChar(usName), 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR or LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
end
else if CheckWin32Version(6) then
begin
SetDllDirectoryW(PWideChar(ExtractFileDir(usName)));
try
Result:= LoadLibraryW(PWideChar(usName));
finally
SetDllDirectoryW(nil);
end;
end
else begin
APath:= mbGetEnvironmentVariable(PATH_ENV);
try
mbSetEnvironmentVariable(PATH_ENV, ExtractFileDir(Name));
Result:= LoadLibraryW(PWideChar(usName));
finally
mbSetEnvironmentVariable(PATH_ENV, APath);
end;
end;
end;
{$ELSE}
begin
Result:= TLibHandle(dlopen(PChar(UTF8ToSys(Name)), RTLD_LAZY));
end;
{$ENDIF}
function SafeGetProcAddress(Lib: TLibHandle; const ProcName: AnsiString): Pointer;
begin
Result:= GetProcedureAddress(Lib, ProcName);

View file

@ -3,7 +3,7 @@
-------------------------------------------------------------------------
Scalable Vector Graphics reader implementation (via rsvg and cairo)
Copyright (C) 2012-2022 Alexander Koblov (alexx2000@mail.ru)
Copyright (C) 2012-2023 Alexander Koblov (alexx2000@mail.ru)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -249,11 +249,39 @@ const
var
libcairo, librsvg, libgobject: TLibHandle;
procedure Initialize;
procedure LoadLibraries;
{$IF DEFINED(UNIX)}
begin
libcairo:= LoadLibrary(cairolib);
librsvg:= LoadLibrary(rsvglib);
libgobject:= LoadLibrary(gobjectlib);
end;
{$ELSEIF DEFINED(MSWINDOWS)}
var
I: Integer;
Path, FullName: String;
Value: TStringArray;
begin
Path:= GetEnvironmentVariable('PATH');
Value:= Path.Split([PathSeparator], TStringSplitOptions.ExcludeEmpty);
for I:= Low(Value) to High(Value) do
begin
Path:= IncludeTrailingPathDelimiter(Value[I]);
FullName:= Path + rsvglib;
if mbFileExists(FullName)then
begin
librsvg:= mbLoadLibraryEx(FullName);
libcairo:= mbLoadLibraryEx(Path + cairolib);
libgobject:= mbLoadLibraryEx(Path + gobjectlib);
Break;
end;
end;
end;
{$ENDIF}
procedure Initialize;
begin
LoadLibraries;
if (libcairo <> NilHandle) and (librsvg <> NilHandle) and (libgobject <> NilHandle) then
try