diff --git a/lib/_a2dev_find_py.ahk b/lib/_a2dev_find_py.ahk index 2e11a501..53900ada 100644 --- a/lib/_a2dev_find_py.ahk +++ b/lib/_a2dev_find_py.ahk @@ -1,41 +1,40 @@ a2dev_get_py() { ; TODO: this needs to be a little bit more dynamic - supported_versions := ["3.11", "3.10", "3.9"] - ;exe_type := {filename: "python.exe", reg_name: "ExecutablePath"} - exe_type := {filename: "pythonw.exe", reg_name: "WindowedExecutablePath"} - + supported_versions := ["3.12", "3.11", "3.10", "3.9"] ; First: Try to read python path from registry in either CURRENT_USER or LOCAL_MACHINE domain - pypath := check_registry(supported_versions, exe_type) + pypath := check_registry(supported_versions) if (pypath != "") Return pypath - versions_string := string_join(supported_versions) - - MsgBox, 16, No Matching Python Version!, Could not find a Python installation!`nSupported versions include: %versions_string%! + title := "No Matching Python Version!" + msg := "Could not find a Python installation!`nSupported versions include: " . string_join(supported_versions) . "!" + MsgBox(msg, title, 16) ExitApp } -check_registry(supported_versions, exe_type) { - reg_name := exe_type["reg_name"] - Loop, % supported_versions.MaxIndex() +check_registry(supported_versions) { + ;exe_type := {filename: "python.exe", reg_name: "ExecutablePath"} + exe_type := {filename: "pythonw.exe", reg_name: "WindowedExecutablePath"} + reg_name := exe_type.reg_name + + Loop(supported_versions.Length) { this_version := supported_versions[A_Index] - - py_key = HKEY_CURRENT_USER\Software\Python\PythonCore\%this_version%\InstallPath - RegRead, pypath, %py_key%, %reg_name% + py_key := "HKEY_CURRENT_USER\Software\Python\PythonCore\" . this_version . "\InstallPath" + pypath := RegRead(py_key, reg_name) if !string_endswith(pypath, exe_type.filename) { - py_key = HKEY_LOCAL_MACHINE\Software\Python\PythonCore\%this_version%\InstallPath - RegRead, pypath, %py_key%, %reg_name% + py_key := "HKEY_LOCAL_MACHINE\Software\Python\PythonCore\" . this_version . "\InstallPath" + pypath := RegRead(py_key, reg_name) } - IfExist, %pypath% + If FileExist(pypath) { global a2_PY_VERSION_SHORT := this_version - Return, pypath + Return pypath } } } diff --git a/lib/_batches/versions/get_PySide_version.ahk b/lib/_batches/versions/get_PySide_version.ahk index 929044bc..9a4d33b8 100644 --- a/lib/_batches/versions/get_PySide_version.ahk +++ b/lib/_batches/versions/get_PySide_version.ahk @@ -1,7 +1,11 @@ #include %A_ScriptDir%\..\..\_a2dev_find_py.ahk +#include %A_ScriptDir%\..\..\a2_globals.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\string.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\path.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\msgbox.ahk pydir := path_dirname(a2dev_get_py()) if (!pydir) { - MsgBox 16, Could not get "pydir" from "path_dirname(a2dev_get_py())" + msgbox_error('Could not get "pydir" from "path_dirname(a2dev_get_py())"') ExitApp } @@ -17,15 +21,17 @@ for _, rel_path in files if (!FileExist(file_path)) Continue - version := FileReadLine(file_path, 1) + FileObj := FileOpen(file_path, "r") + version := FileObj.ReadLine() + version_prefix := "__version__ = " if !string_startswith(version, version_prefix) { msgbox_error("Cannot get version from " rel_path "!`nExpected line: >" version_prefix "<`nFound: " version) ExitApp } - version := SubStr(version, StringLen(version_prefix)) - version := string_trim(version, " """) + version := SubStr(version, StrLen(version_prefix)) + version := string_trim(version, ' "') if version Break @@ -35,6 +41,6 @@ if (!version) { msg := "Unable to find any of those:`n " msg .= string_join(files, "`n ") . "`n" msg .= "Make sure at least one is installed!" - MsgBox, 16, No PySide Found!, %msg% + msgbox_error(msg, 'No PySide Found!') } else - FileAppend, %version%, * + FileAppend version, "*" diff --git a/lib/_batches/versions/get_Python_path.ahk b/lib/_batches/versions/get_Python_path.ahk index a30c244a..99fb7985 100644 --- a/lib/_batches/versions/get_Python_path.ahk +++ b/lib/_batches/versions/get_Python_path.ahk @@ -1,7 +1,10 @@ #include %A_ScriptDir%\..\..\_a2dev_find_py.ahk +#include %A_ScriptDir%\..\..\a2_globals.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\string.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\path.ahk py_exe := a2dev_get_py() if (!FileExist(py_exe)) - MsgBox, No Python Found here`n%py_exe% + MsgBox("No Python Found here`n" . py_exe) -SplitPath, py_exe,, py_dir -FileAppend, %py_dir%, * +SplitPath py_exe,, &py_dir +FileAppend py_dir, "*" diff --git a/lib/_batches/versions/get_python_version.ahk b/lib/_batches/versions/get_python_version.ahk index 11b95a1a..61b3241d 100644 --- a/lib/_batches/versions/get_python_version.ahk +++ b/lib/_batches/versions/get_python_version.ahk @@ -1,8 +1,11 @@ #include %A_ScriptDir%\..\..\_a2dev_find_py.ahk +#include %A_ScriptDir%\..\..\a2_globals.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\string.ahk +#include %A_ScriptDir%\..\..\Autohotkey\lib\path.ahk py := a2dev_get_py() if (!FileExist(py)) - MsgBox, No Python Found here`n%py% -FileGetVersion, version, %py% + MsgBox("No Python Found here`n" . py) +version := FileGetVersion(py) if (!version) - MsgBox, No Python Version found!`n%py% -FileAppend, %version%, * + MsgBox("No Python Version found!`n" . py) +FileAppend version, "*" diff --git a/lib/a2_globals.ahk b/lib/a2_globals.ahk index 00511fd3..a85c6c27 100644 --- a/lib/a2_globals.ahk +++ b/lib/a2_globals.ahk @@ -1,4 +1,4 @@ -global WinVer := windows_get_version() +; global WinVer := windows_get_version() global WIN_XP := 5.1 global WIN_XP64 := 5.2 global WIN_VISTA := 6.0 @@ -11,15 +11,15 @@ global A_AppDataLocal := path_join(path_dirname(A_AppData), "Local") global PYTHON_SUPPORTED_VERSIONS := ["3.11", "3.10", "3.9"] ; groups for explorer classes -GroupAdd, ExplorerGroup, ahk_class ExploreWClass -GroupAdd, ExplorerGroup, ahk_class CabinetWClass -GroupAdd, DesktopGroup, ahk_class WorkerW -GroupAdd, DesktopGroup, ahk_class Progman ;Progman for older windows versions