Skip to content

Commit

Permalink
Fix stdlib to be relative to AutoHotkey.exe, not Ahk2Exe
Browse files Browse the repository at this point in the history
Change /ahk to take priority even if the file doesn't exist (more cautious)
  • Loading branch information
Lexikos committed May 1, 2021
1 parent 310b680 commit ff1a2da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 14 additions & 0 deletions Compiler.ahk
Expand Up @@ -47,6 +47,20 @@ AhkCompile(ByRef AhkFile, ExeFile="", ByRef CustomIcon="", BinFile="", UseMPRESS
DerefIncludeVars.A_PtrSize := BinType.PtrSize
DerefIncludeVars.A_IsUnicode := BinType.IsUnicode

global AhkPath := UseAhkPath
if (AhkPath = "")
{
if !A_IsCompiled
AhkPath := A_AhkPath
else
FileExist(AhkPath := A_ScriptDir "\..\AutoHotkey.exe")
|| !BinType.IsUnicode && FileExist(AhkPath := A_ScriptDir "\..\AutoHotkeyA32.exe")
|| FileExist(AhkPath := A_ScriptDir "\..\AutoHotkeyU32.exe")
|| FileExist(AhkPath := A_AhkPath)
}
;else even if !FileExist(UseAhkPath), don't fall back to a potentially incompatible EXE.
global StdLibDir := Util_GetFullPath(AhkPath "\..\Lib")

ExeFileG := ExeFile
BundleAhkScript(ExeFileTmp, AhkFile, UseMPRESS, CustomIcon, fileCP)

Expand Down
12 changes: 3 additions & 9 deletions ScriptParser.ahk
Expand Up @@ -171,14 +171,7 @@ PreprocessScript(ByRef ScriptText, AhkScript, ExtraFiles, FileList := "", FirstS

Loop, % !!IsFirstScript ; Like "if IsFirstScript" but can "break" from block
{
global AhkPath := UseAhkPath
if (AhkPath = "")
AhkPath := A_IsCompiled ? A_ScriptDir "\..\AutoHotkey.exe" : A_AhkPath
if (!FileExist(AhkPath) && !DerefIncludeVars.A_IsUnicode)
AhkPath := A_ScriptDir "\..\AutoHotkeyA32.exe"
AhkPath := FileExist(AhkPath) ? AhkPath :A_ScriptDir "\..\AutoHotkeyU32.exe"
AhkPath := FileExist(AhkPath) ? AhkPath : A_AhkPath

global AhkPath
IfNotExist, %AhkPath%
{ Util_Error("Warning: AutoHotkey.exe could not be located!`n`nAuto-include"
. "s from Function Libraries, and 'Obey' directives will not be processed.",0)
Expand Down Expand Up @@ -235,7 +228,8 @@ IsFakeCSOpening(tline)

FindLibraryFile(name, ScriptDir)
{
libs := [ScriptDir "\Lib", A_MyDocuments "\AutoHotkey\Lib", A_ScriptDir "\..\Lib"]
global StdLibDir
libs := [ScriptDir "\Lib", A_MyDocuments "\AutoHotkey\Lib", StdLibDir]
p := InStr(name, "_")
if p
name_lib := SubStr(name, 1, p-1)
Expand Down

0 comments on commit ff1a2da

Please sign in to comment.