Ahk2Exe ignore error
Ahk2Exe ignore error
Would it be possible to have a command line parameter that would instruct Ahk2Exe to compile the script even if it finds syntax errors ?
Re: Ahk2Exe ignore error
Could you provide an example of how this could be useful?
Re: Ahk2Exe ignore error
My injector compiles several scripts like this:GeekDude wrote:Could you provide an example of how this could be useful?
Code: Select all
LoadResource(resource, module = "")
{
if not module
hModule := dllcall("GetModuleHandle", uint, 0)
else FreeLater := hModule := dllcall("LoadLibraryW", str, module)
HRSRC := dllcall("FindResourceW", uint, hModule, str, resource, ptr, 10)
hResource := dllcall("LoadResource", uint, hModule, uint, HRSRC)
DataSize := DllCall("SizeofResource", ptr, hModule, ptr, HRSRC, uint)
pResData := dllcall("LockResource", uint, hResource, ptr)
ret := strget(pResData, DataSize, "UTF-8")
;dllcall("FreeResource", uint, hResource)
FreeLater ? dllcall("FreeLibrary", uint, hModule)
return ret
}
compileScript(script)
{
if A_iscompiled
return
splitpath, script, , , ,script_name
runwait, Ahk2Exe.exe /in %script% /out %script_name%.exe
script_txt := LoadResource(">AUTOHOTKEY SCRIPT<", script_name ".exe")
filedelete, %script_name%.txt
fileappend, %script_txt%, %script_name%.txt
}
if not A_iscompiled
{
FileInstall, ..\Xinput.ahk, ?Dummy
FileInstall, gdi.hooks.ahk, ?Dummy
;compileScript("exlib.ahk")
FileInstall, exlib.txt, ?Dummy
;compileScript("remote_lib.ahk")
FileInstall, remote_lib.txt, ?Dummy
;compileScript("dshow.hooks.ahk")
FileInstall, dshow.hooks.txt, ?Dummy
;compileScript("dsound.hooks.ahk")
FileInstall, dsound.hooks.txt, ?Dummy
;compileScript("dinput.hooks.ahk")
FileInstall, dinput.hooks.txt, ?Dummy
;compileScript("d3D.hooks.ahk")
FileInstall, d3D.hooks.txt, ?Dummy
compileScript("gl.hooks.ahk")
FileInstall, gl.hooks.txt, ?Dummy
runwait, Ahk2Exe.exe /in %A_scriptName% /out Injector.exe
}
Code: Select all
if g_globals.controller
g_globals.remoteScript .= "`n" LoadResource("dinput.hooks.txt") "`n"
if (g_globals.d3D > 0 and g_globals.d3D < 4) or g_globals.d3D = 7 or g_globals.upScale or g_globals.8bitColorFix or g_globals.ddraw
g_globals.remoteScript .= "`n" LoadResource("d3D.hooks.txt")
if ...
success := dllcallEx(g_globals.proc.hProcess, "autohotkey.dll", "ahktextdll", g_globals.remoteScript)
Re: Ahk2Exe ignore error
It doesn't make sense to generate a "compiled script" which can't be run.
Why are you "compiling" the script? If it's to pre-process/merge #includes, I think you would be better off taking the Ahk2Exe source code and adapting it to your purpose.
Why are you "compiling" the script? If it's to pre-process/merge #includes, I think you would be better off taking the Ahk2Exe source code and adapting it to your purpose.
Re: Ahk2Exe ignore error
Yes, that's why i'm compiling them.lexikos wrote:It doesn't make sense to generate a "compiled script" which can't be run.
Why are you "compiling" the script? If it's to pre-process/merge #includes, I think you would be better off taking the Ahk2Exe source code and adapting it to your purpose.
Fortunately for me, old version of the compiler show a messagebox but still compile the script
Re: Ahk2Exe ignore error
I've actually already ripped out the preprocessing bit myself.
Code: Select all
ExtraFiles := []
PreprocessScript(Text, "C:\Path\To\Script.ahk", ExtraFiles)
MsgBox, % Text
PreprocessScript(ByRef ScriptText, AhkScript, ExtraFiles, FileList="", FirstScriptDir="", Options="", iOption=0)
{
SplitPath, AhkScript, ScriptName, ScriptDir
if !IsObject(FileList)
{
FileList := [AhkScript]
; ScriptText := "; <COMPILER: v" A_AhkVersion ">`n"
FirstScriptDir := ScriptDir
IsFirstScript := true
Options := { comm: ";", esc: "``" }
OldWorkingDir := A_WorkingDir
SetWorkingDir, %ScriptDir%
}
IfNotExist, %AhkScript%
if !iOption
Util_Error((IsFirstScript ? "Script" : "#include") " file """ AhkScript """ cannot be opened.")
else return
cmtBlock := false, contSection := false
Loop, Read, %AhkScript%
{
tline := Trim(A_LoopReadLine)
if !cmtBlock
{
if !contSection
{
if StrStartsWith(tline, Options.comm)
continue
else if tline =
continue
else if StrStartsWith(tline, "/*")
{
cmtBlock := true
continue
}
}
if StrStartsWith(tline, "(") && !IsFakeCSOpening(tline)
contSection := true
else if StrStartsWith(tline, ")")
contSection := false
tline := RegExReplace(tline, "\s+" RegExEscape(Options.comm) ".*$", "")
if !contSection && RegExMatch(tline, "i)^#Include(Again)?[ \t]*[, \t]?\s+(.*)$", o)
{
IsIncludeAgain := (o1 = "Again")
IgnoreErrors := false
IncludeFile := o2
if RegExMatch(IncludeFile, "\*[iI]\s+?(.*)", o)
IgnoreErrors := true, IncludeFile := Trim(o1)
if RegExMatch(IncludeFile, "^<(.+)>$", o)
&& (IncFile2 := FindLibraryFile(o1, FirstScriptDir))
{
IncludeFile := IncFile2
}
else
{
StringReplace, IncludeFile, IncludeFile, `%A_ScriptDir`%, %FirstScriptDir%, All
StringReplace, IncludeFile, IncludeFile, `%A_AppData`%, %A_AppData%, All
StringReplace, IncludeFile, IncludeFile, `%A_AppDataCommon`%, %A_AppDataCommon%, All
StringReplace, IncludeFile, IncludeFile, `%A_LineFile`%, %AhkScript%, All
if InStr(FileExist(IncludeFile), "D")
{
SetWorkingDir, %IncludeFile%
continue ; Done processing this line, go to next line
}
}
IncludeFile := Util_GetFullPath(IncludeFile)
AlreadyIncluded := InArray(FileList, IncludeFile)
if(IsIncludeAgain || !AlreadyIncluded)
{
if !AlreadyIncluded
FileList.Push(IncludeFile)
PreprocessScript(ScriptText, IncludeFile, ExtraFiles, FileList, FirstScriptDir, Options, IgnoreErrors)
}
}
else if !contSection && tline ~= "i)^FileInstall[, \t]"
{
if tline ~= "^\w+\s+(:=|\+=|-=|\*=|/=|//=|\.=|\|=|&=|\^=|>>=|<<=)"
continue ; This is an assignment!
if !RegExMatch(tline, "i)^FileInstall[ \t]*[, \t][ \t]*([^,]+?)[ \t]*(,|$)", o) || o1 ~= "[^``]%" ; TODO: implement `, detection
Util_Error("Error: Invalid ""FileInstall"" syntax found. Note that the first parameter must not be specified using a continuation section.")
_ := Options.esc
StringReplace, o1, o1, %_%`%, `%, All
StringReplace, o1, o1, %_%`,, `,, All
StringReplace, o1, o1, %_%%_%,, %_%,, All
ExtraFiles.Insert(o1)
ScriptText .= tline "`n"
}else if !contSection && RegExMatch(tline, "i)^#CommentFlag\s+(.+)$", o)
Options.comm := o1, ScriptText .= tline "`n"
else if !contSection && RegExMatch(tline, "i)^#EscapeChar\s+(.+)$", o)
Options.esc := o1, ScriptText .= tline "`n"
else if !contSection && RegExMatch(tline, "i)^#DerefChar\s+(.+)$", o)
Util_Error("Error: #DerefChar is not supported.")
else if !contSection && RegExMatch(tline, "i)^#Delimiter\s+(.+)$", o)
Util_Error("Error: #Delimiter is not supported.")
else
ScriptText .= (contSection ? A_LoopReadLine : tline) "`n"
}else if StrStartsWith(tline, "*/")
cmtBlock := false
}
Loop, % !!IsFirstScript ; equivalent to "if IsFirstScript" except you can break from the block
{
static AhkPath := A_IsCompiled ? A_ScriptDir "\..\AutoHotkey.exe" : A_AhkPath
IfNotExist, %AhkPath%
break ; Don't bother with auto-includes because the file does not exist
Util_Status("Auto-including any functions called from a library...")
ilibfile = %A_Temp%\_ilib.ahk
IfExist, %ilibfile%, FileDelete, %ilibfile%
AhkType := AHKType(AhkPath)
if AhkType = FAIL
Util_Error("Error: The AutoHotkey build used for auto-inclusion of library functions is not recognized.", 1, AhkPath)
if AhkType = Legacy
Util_Error("Error: Legacy AutoHotkey versions (prior to v1.1) are not allowed as the build used for auto-inclusion of library functions.", 1, AhkPath)
RunWait, "%AhkPath%" /iLib "%ilibfile%" /ErrorStdOut "%AhkScript%", %FirstScriptDir%, UseErrorLevel
if (ErrorLevel = 2)
Util_Error("Error: The script contains syntax errors.")
IfExist, %ilibfile%
{
PreprocessScript(ScriptText, ilibfile, ExtraFiles, FileList, FirstScriptDir, Options)
FileDelete, %ilibfile%
}
StringTrimRight, ScriptText, ScriptText, 1 ; remove trailing newline
}
if OldWorkingDir
SetWorkingDir, %OldWorkingDir%
}
InArray(Array, Value)
{
for k, v in Array
if (v = Value)
return true
return false
}
IsFakeCSOpening(tline)
{
Loop, Parse, tline, %A_Space%%A_Tab%
if !StrStartsWith(A_LoopField, "Join") && InStr(A_LoopField, ")")
return true
return false
}
FindLibraryFile(name, ScriptDir)
{
libs := [ScriptDir "\Lib", A_MyDocuments "\AutoHotkey\Lib", A_ScriptDir "\..\Lib"]
p := InStr(name, "_")
if p
name_lib := SubStr(name, 1, p-1)
for each,lib in libs
{
file := lib "\" name ".ahk"
IfExist, %file%
return file
if !p
continue
file := lib "\" name_lib ".ahk"
IfExist, %file%
return file
}
}
StrStartsWith(ByRef v, ByRef w)
{
return SubStr(v, 1, StrLen(w)) = w
}
RegExEscape(t)
{
static _ := "\.*?+[{|()^$"
Loop, Parse, _
StringReplace, t, t, %A_LoopField%, \%A_LoopField%, All
return t
}
Util_GetFullPath(path)
{
VarSetCapacity(fullpath, 260 * (!!A_IsUnicode + 1))
if DllCall("GetFullPathName", "str", path, "uint", 260, "str", fullpath, "ptr", 0, "uint")
return fullpath
else
return ""
}
Util_Error(txt, doexit=1, extra="")
{
if extra
txt .= "`n`nSpecifically: " extra
MsgBox, 16, Ahk2Exe Error, % txt
if doexit
ExitApp
}
Util_Status(s)
{
static _ := DllCall("AllocConsole")
FileAppend, %s%`n, CONOUT$
}
; Based on code from SciTEDebug.ahk
AHKType(exeName)
{
FileGetVersion, vert, %exeName%
if !vert
return "FAIL"
StringSplit, vert, vert, .
vert := vert4 | (vert3 << 8) | (vert2 << 16) | (vert1 << 24)
exeMachine := GetExeMachine(exeName)
if !exeMachine
return "FAIL"
if (exeMachine != 0x014C) && (exeMachine != 0x8664)
return "FAIL"
if !(VersionInfoSize := DllCall("version\GetFileVersionInfoSize", "str", exeName, "uint*", null, "uint"))
return "FAIL"
VarSetCapacity(VersionInfo, VersionInfoSize)
if !DllCall("version\GetFileVersionInfo", "str", exeName, "uint", 0, "uint", VersionInfoSize, "ptr", &VersionInfo)
return "FAIL"
if !DllCall("version\VerQueryValue", "ptr", &VersionInfo, "str", "\VarFileInfo\Translation", "ptr*", lpTranslate, "uint*", cbTranslate)
return "FAIL"
oldFmt := A_FormatInteger
SetFormat, IntegerFast, H
wLanguage := NumGet(lpTranslate+0, "UShort")
wCodePage := NumGet(lpTranslate+2, "UShort")
id := SubStr("0000" SubStr(wLanguage, 3), -3, 4) SubStr("0000" SubStr(wCodePage, 3), -3, 4)
SetFormat, IntegerFast, %oldFmt%
if !DllCall("version\VerQueryValue", "ptr", &VersionInfo, "str", "\StringFileInfo\" id "\ProductName", "ptr*", pField, "uint*", cbField)
return "FAIL"
; Check it is actually an AutoHotkey executable
if !InStr(StrGet(pField, cbField), "AutoHotkey")
return "FAIL"
; We're dealing with a legacy version if it's prior to v1.1
return vert >= 0x01010000 ? "Modern" : "Legacy"
}
GetExeMachine(exepath)
{
exe := FileOpen(exepath, "r")
if !exe
return
exe.Seek(60), exe.Seek(exe.ReadUInt()+4)
return exe.ReadUShort()
}
Who is online
Users browsing this forum: No registered users and 25 guests