1 |
|
procedure TFBClientAPI.LoadIBLibrary; |
2 |
|
|
3 |
+ |
function IsValidHandle(aHandle: TLibHandle): boolean; |
4 |
+ |
begin |
5 |
+ |
Result := aHandle > HINSTANCE_ERROR; |
6 |
+ |
end; |
7 |
+ |
|
8 |
|
function DoLoadLibrary(LibName: string): TLibHandle; |
9 |
|
begin |
10 |
|
Result := LoadLibrary(PChar(LibName)); |
11 |
< |
if Result <> NilHandle then |
11 |
> |
if IsValidHandle(Result) then |
12 |
|
begin |
13 |
|
FFBLibraryName := ExtractFileName(LibName); |
14 |
|
FFBLibraryPath := ExtractFileDir(LibName); |
15 |
|
end; |
16 |
|
end; |
17 |
|
|
18 |
+ |
function GetSpecialFolder(const CSIDL: integer) : string; |
19 |
+ |
{$IFDEF FPC} |
20 |
+ |
begin |
21 |
+ |
Result := GetWindowsSpecialDir(CSIDL); |
22 |
+ |
end; |
23 |
+ |
{$ELSE} |
24 |
+ |
var |
25 |
+ |
RecPath : PChar; |
26 |
+ |
begin |
27 |
+ |
RecPath := StrAlloc(MAX_PATH); |
28 |
+ |
try |
29 |
+ |
FillChar(RecPath^, MAX_PATH, 0); |
30 |
+ |
if SHGetSpecialFolderPath(0, RecPath, CSIDL, false) |
31 |
+ |
then result := RecPath |
32 |
+ |
else result := ''; |
33 |
+ |
finally |
34 |
+ |
StrDispose(RecPath); |
35 |
+ |
end; |
36 |
+ |
end; |
37 |
+ |
{$ENDIF} |
38 |
+ |
|
39 |
|
var InstallDir: string; |
40 |
|
dllPathName: string; |
41 |
|
oldFirebirdEV: string; |
42 |
|
begin |
43 |
< |
if IBLibrary <> NilHandle then Exit; |
43 |
> |
if IsValidHandle(IBLibrary) then Exit; |
44 |
|
|
45 |
|
{First try any user override} |
46 |
|
dllPathName := GetOverrideLibName; |
47 |
|
if dllPathName <> '' then |
48 |
|
begin |
49 |
|
IBLibrary := DoLoadLibrary(dllPathName); |
50 |
< |
FOwnsIBLibrary := IBLibrary <> NilHandle; |
50 |
> |
FOwnsIBLibrary := IsValidHandle(IBLibrary); |
51 |
|
Exit; |
52 |
|
end; |
53 |
|
|
71 |
|
try |
72 |
|
IBLibrary := DoLoadLibrary(dllPathName) |
73 |
|
finally |
74 |
< |
if IBLibrary = NILHandle then |
74 |
> |
if not IsValidHandle(IBLibrary) then |
75 |
|
SetEnvironmentVariable('FIREBIRD',PChar(oldFirebirdEV)); {restore} |
76 |
|
end; |
77 |
|
end; |
78 |
|
|
79 |
|
// writeln('Dir = ',InstallDir); |
80 |
|
{If FIREBIRD environment variable available then try this} |
81 |
< |
if IBLibrary = NilHandle then |
81 |
> |
if not IsValidHandle(IBLibrary) then |
82 |
|
begin |
83 |
|
InstallDir := GetEnvironmentVariable('FIREBIRD'); |
84 |
|
if (length(InstallDir) > 0) and (InstallDir[length(InstallDir)] <> DirectorySeparator) then |
85 |
< |
InstallDir += DirectorySeparator; |
85 |
> |
InstallDir := InstallDir + DirectorySeparator; |
86 |
|
if (InstallDir <> '') and FileExists(InstallDir + FIREBIRD_CLIENT) then |
87 |
|
begin |
88 |
|
//assume firebird.conf and firebird.msg in same dir |
97 |
|
end |
98 |
|
end; |
99 |
|
|
100 |
< |
if IBLibrary = NilHandle then |
100 |
> |
if not IsValidHandle(IBLibrary) then |
101 |
|
{Use Registry key if it exists to locate library} |
102 |
|
begin |
103 |
|
with TRegistry.Create do |
117 |
|
end; |
118 |
|
|
119 |
|
{Now try default install dir} |
120 |
< |
if IBLibrary = NilHandle then |
120 |
> |
if not IsValidHandle(IBLibrary) then |
121 |
|
begin |
122 |
< |
InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) + |
122 |
> |
InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) + |
123 |
|
DirectorySeparator + 'Firebird' + |
124 |
|
DirectorySeparator + 'Firebird_3_0' + |
125 |
|
DirectorySeparator + 'bin' + DirectorySeparator; |
127 |
|
IBLibrary := DoLoadLibrary(dllPathName) |
128 |
|
end; |
129 |
|
|
130 |
< |
if IBLibrary = NilHandle then |
130 |
> |
if not IsValidHandle(IBLibrary) then |
131 |
|
begin |
132 |
< |
InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) + |
132 |
> |
InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) + |
133 |
|
DirectorySeparator + 'Firebird' + |
134 |
|
DirectorySeparator + 'Firebird_2_5' + |
135 |
|
DirectorySeparator + 'bin' + DirectorySeparator; |
137 |
|
IBLibrary := DoLoadLibrary(dllPathName) |
138 |
|
end; |
139 |
|
|
140 |
< |
if IBLibrary = NilHandle then |
140 |
> |
if not IsValidHandle(IBLibrary) then |
141 |
|
begin |
142 |
< |
InstallDir := GetWindowsSpecialDir(CSIDL_PROGRAM_FILES) + |
142 |
> |
InstallDir := GetSpecialFolder(CSIDL_PROGRAM_FILES) + |
143 |
|
DirectorySeparator + 'Firebird' + |
144 |
|
DirectorySeparator + 'Firebird_2_1' + |
145 |
|
DirectorySeparator + 'bin' + DirectorySeparator; |
149 |
|
|
150 |
|
//Otherwise see if Firebird client is in path |
151 |
|
//and rely on registry for location of firebird.conf and firebird.msg |
152 |
< |
if IBLibrary = NilHandle then |
152 |
> |
if not IsValidHandle(IBLibrary) then |
153 |
|
begin |
154 |
|
IBLibrary := DoLoadLibrary(FIREBIRD_CLIENT); |
155 |
|
if IBLibrary <= HINSTANCE_ERROR then |
157 |
|
IBLibrary := DoLoadLibrary(IBASE_DLL); |
158 |
|
end; |
159 |
|
end; |
160 |
< |
FOwnsIBLibrary := IBLibrary <> NilHandle; |
160 |
> |
FOwnsIBLibrary := IsValidHandle(IBLibrary); |
161 |
|
end; |
162 |
|
|
163 |
|
|