Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 5b6d30dfb8
120 lines (96 sloc) 3.21 KB
#Include ScriptParser.ahk
#Include IconChanger.ahk
AhkCompile(ByRef AhkFile, ExeFile="", ByRef CustomIcon="", BinFile="", UseMPRESS="")
global ExeFileTmp
AhkFile := Util_GetFullPath(AhkFile)
if AhkFile =
Util_Error("Error: Source file not specified.")
SplitPath, AhkFile,, AhkFile_Dir,, AhkFile_NameNoExt
if ExeFile =
ExeFile = %AhkFile_Dir%\%AhkFile_NameNoExt%.exe
ExeFile := Util_GetFullPath(ExeFile)
ExeFileTmp := ExeFile
if BinFile =
BinFile = %A_ScriptDir%\AutoHotkeySC.bin
IfNotExist, %BinFile%
Util_Error("Error: The selected AutoHotkeySC binary does not exist.", 1, BinFile)
try FileCopy, %BinFile%, %ExeFile%, 1
Util_Error("Error: Unable to copy AutoHotkeySC binary file to destination.")
BundleAhkScript(ExeFile, AhkFile, CustomIcon)
if FileExist(A_ScriptDir "\mpress.exe") && UseMPRESS
Util_Status("Compressing final executable...")
RunWait, "%A_ScriptDir%\mpress.exe" -q -x "%ExeFile%",, Hide
BundleAhkScript(ExeFile, AhkFile, IcoFile="")
SplitPath, AhkFile,, ScriptDir
ExtraFiles := []
PreprocessScript(ScriptBody, AhkFile, ExtraFiles)
;FileDelete, %ExeFile%.ahk
;FileAppend, % ScriptBody, %ExeFile%.ahk
VarSetCapacity(BinScriptBody, BinScriptBody_Len := StrPut(ScriptBody, "UTF-8") - 1)
StrPut(ScriptBody, &BinScriptBody, "UTF-8")
module := DllCall("BeginUpdateResource", "str", ExeFile, "uint", 0, "ptr")
if !module
Util_Error("Error: Error opening the destination file.")
if IcoFile
Util_Status("Changing the main icon...")
if !ReplaceAhkIcon(module, IcoFile, ExeFile)
; Error was already displayed
gosub _EndUpdateResource
Util_Error("Error changing icon: Unable to read icon or icon was of the wrong format.")
Util_Status("Compressing and adding: Master Script")
if !DllCall("UpdateResource", "ptr", module, "ptr", 10, "str", IcoFile ? ">AHK WITH ICON<" : ">AUTOHOTKEY SCRIPT<"
, "ushort", 0x409, "ptr", &BinScriptBody, "uint", BinScriptBody_Len, "uint")
goto _FailEnd
oldWD := A_WorkingDir
SetWorkingDir, %ScriptDir%
for each,file in ExtraFiles
Util_Status("Compressing and adding: " file)
StringUpper, resname, file
IfNotExist, %file%
goto _FailEnd2
; This "old-school" method of reading binary files is way faster than using file objects.
FileGetSize, filesize, %file%
VarSetCapacity(filedata, filesize)
FileRead, filedata, *c %file%
if !DllCall("UpdateResource", "ptr", module, "ptr", 10, "str", resname
, "ushort", 0x409, "ptr", &filedata, "uint", filesize, "uint")
goto _FailEnd2
VarSetCapacity(filedata, 0)
SetWorkingDir, %oldWD%
gosub _EndUpdateResource
gosub _EndUpdateResource
Util_Error("Error adding script file:`n`n" AhkFile)
gosub _EndUpdateResource
Util_Error("Error adding FileInstall file:`n`n" file)
if !DllCall("EndUpdateResource", "ptr", module, "uint", 0)
Util_Error("Error: Error opening the destination file.")
VarSetCapacity(fullpath, 260 * (!!A_IsUnicode + 1))
if DllCall("GetFullPathName", "str", path, "uint", 260, "str", fullpath, "ptr", 0, "uint")
return fullpath
return ""
Jump to Line
Something went wrong with that request. Please try again.