Skip to content

Commit eba2a9f

Browse files
committed
Fixed the discovery of 32 bit registered versions >= 3.4 (PEP514)
1 parent 9cb1623 commit eba2a9f

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

PythonForDelphi/Components/Sources/Core/PythonEngine.pas

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9698,47 +9698,59 @@ function IsPythonVersionRegistered(PythonVersion : string;
96989698

96999699
// The above convension was changed in Python 3.5. Now even for all user
97009700
// installations the dll is located at the InstallPath.
9701+
// Also from version 3.5 onwards 32 bit version have a suffix -32 e.g. "3.6-32"
9702+
// See also PEP 514
97019703

97029704
var
97039705
key: string;
9706+
VersionSuffix: string;
97049707
MajorVersion : integer;
97059708
MinorVersion : integer;
97069709
begin
97079710
Result := False;
97089711
InstallPath := '';
97099712
AllUserInstall := False;
9713+
MajorVersion := StrToInt(PythonVersion[1]);
9714+
MinorVersion := StrToInt(PythonVersion[3]);
9715+
VersionSuffix := '';
9716+
{$IFDEF CPUX86}
9717+
if (MajorVersion > 3) or ((MajorVersion = 3) and (MinorVersion >= 5)) then
9718+
VersionSuffix := '-32';
9719+
{$ENDIF}
9720+
key := Format('\Software\Python\PythonCore\%s%s\InstallPath', [PythonVersion, VersionSuffix]);
9721+
9722+
// First try HKEY_CURRENT_USER as per PEP514
97109723
try
9711-
key := Format('\Software\Python\PythonCore\%s\InstallPath', [PythonVersion]);
97129724
with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do
97139725
try
9714-
RootKey := HKEY_LOCAL_MACHINE;
9715-
if KeyExists(key) then begin
9716-
AllUserInstall := True;
9726+
RootKey := HKEY_CURRENT_USER;
9727+
if OpenKey(Key, False) then begin
9728+
InstallPath := ReadString('');
97179729
Result := True;
9718-
MajorVersion := StrToInt(PythonVersion[1]);
9719-
MinorVersion := StrToInt(PythonVersion[3]);
9720-
if (MajorVersion > 3) or ((MajorVersion = 3) and (MinorVersion >= 5)) then
9721-
if OpenKey(Key, False) then
9722-
InstallPath := ReadString('');
9730+
Exit;
97239731
end;
97249732
finally
97259733
Free;
97269734
end;
97279735
except
97289736
end;
9729-
// We do not seem to have an All User Python Installation.
9730-
// Check whether we have a current user installation
9731-
if not AllUserInstall then
9737+
9738+
//Then try for an all user installation
9739+
try
97329740
with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do
97339741
try
9734-
RootKey := HKEY_CURRENT_USER;
9742+
RootKey := HKEY_LOCAL_MACHINE;
97359743
if OpenKey(Key, False) then begin
9736-
InstallPath := ReadString('');
9744+
AllUserInstall := True;
9745+
if (MajorVersion > 3) or ((MajorVersion = 3) and (MinorVersion >= 5)) then
9746+
InstallPath := ReadString('');
97379747
Result := True;
97389748
end;
97399749
finally
97409750
Free;
97419751
end;
9752+
except
9753+
end;
97429754
end;
97439755
{$ENDIF}
97449756

0 commit comments

Comments
 (0)