Skip to content

Commit

Permalink
fixed version getter scripts for ahk2
Browse files Browse the repository at this point in the history
  • Loading branch information
ewerybody committed Apr 10, 2024
1 parent 340121c commit 3bf04a2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 44 deletions.
35 changes: 17 additions & 18 deletions lib/_a2dev_find_py.ahk
Original file line number Diff line number Diff line change
@@ -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
}
}
}
18 changes: 12 additions & 6 deletions lib/_batches/versions/get_PySide_version.ahk
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -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
Expand All @@ -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, "*"
9 changes: 6 additions & 3 deletions lib/_batches/versions/get_Python_path.ahk
Original file line number Diff line number Diff line change
@@ -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, "*"
11 changes: 7 additions & 4 deletions lib/_batches/versions/get_python_version.ahk
Original file line number Diff line number Diff line change
@@ -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, "*"
24 changes: 12 additions & 12 deletions lib/a2_globals.ahk
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <Vista
GroupAdd, TaskbarGroup, ahk_class Shell_TrayWnd
GroupAdd, TaskbarGroup, ahk_class BaseBar
GroupAdd, TaskbarGroup, ahk_class DV2ControlHost
GroupAdd, TaskbarDesktopGroup, ahk_group DesktopGroup
GroupAdd, TaskbarDesktopGroup, ahk_group TaskbarGroup
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 <Vista
GroupAdd "TaskbarGroup", "ahk_class Shell_TrayWnd"
GroupAdd "TaskbarGroup", "ahk_class BaseBar"
GroupAdd "TaskbarGroup", "ahk_class DV2ControlHost"
GroupAdd "TaskbarDesktopGroup", "ahk_group DesktopGroup"
GroupAdd "TaskbarDesktopGroup", "ahk_group TaskbarGroup"

; mouse cursor image constants
global IDC_APPSTARTING := 32650
Expand All @@ -40,7 +40,7 @@ global IDC_WAIT := 32514
global IDC_HELP := 32651

;Invisible border size. Usually Autohotkey methods apply to the inner size
SysGet, WIN_FRAME_WIDTH, 32
SysGet, WIN_FRAME_HEIGHT, 33
WIN_FRAME_WIDTH := SysGet(32)
WIN_FRAME_HEIGHT := SysGet(33)
global WIN_FRAME_WIDTH
global WIN_FRAME_HEIGHT
2 changes: 1 addition & 1 deletion lib/cmds/get_AutoHotkey_version.ahk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FileAppend, %A_AhkVersion%, *
FileAppend A_AhkVersion, "*"

0 comments on commit 3bf04a2

Please sign in to comment.