;@Ahk2Exe-AddResource LIB looking for standard lib

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
scsnake
Posts: 23
Joined: 05 Aug 2015, 03:19

;@Ahk2Exe-AddResource LIB looking for standard lib

06 Oct 2017, 10:37

I often use ahkmini/ahkthread with some #include inside the dynamic script. For example:

Code: Select all

#persistent
ahkmini("
(
#include <testlib>
msgbox
)")
If I want to compile for a single usable executable, I have to let the compiler include testlib in the resource. That is:

Code: Select all

;@Ahk2Exe-AddResource LIB FULL/PATH/TO/testlib.ahk
Using modified Directive_AddResource function inside the Compiler/Directives.ahk, along with ListIncludes.ahk, the compiler will looking for non-full-path library in Compiler/../Lib . Wish somebody help refine it and may be HotKeyIt will adapt this idea ~

Code: Select all

Directive_AddResource(state, UseCompression, UsePassword, rsrc, resName := "")
{
	global IncludedResource
	resType := "" ; auto-detect
	if RegExMatch(rsrc, "^\s*(\w+|d+)\s+(.+)$", o)
		resType := o1, rsrc := o2
	if !FileExist(resFile := Util_GetFullPath(rsrc)) && !FileExist(resFile := Util_GetFullPath(A_ScriptDir "\..\Lib\" rsrc))
		Util_Error("Error: specified resource does not exist: " rsrc)
	
	ToolTip % resFile
	
	SplitPath, resFile, resFileName,, resExt
	if !resName
		resName := resFileName, defResName := true
	StringUpper, resName, resName
	if (resType = "")
	{
		; Auto-detect resource type
		if InStr(".bmp.dib.","." resExt ".")
			resType := 2 ; RT_BITMAP
		else if (resExt = "ico")
			Util_Error("Error: Icon resource adding is not supported yet!")
		else if (resExt = "cur")
			Util_Error("Error: Cursor resource adding is not supported yet!")
		else if InStr(".htm.html.mht.js.css.","." resExt ".")
			resType := 23 ; RT_HTML
		else if resExt = manifest
		{
			resType := 24 ; RT_MANIFEST
			if defResName
				resName := 1
		} else
			resType := 10 ; RT_RCDATA
	}
	typeType := "str"
	nameType := "str"
	if resType is integer
		if resType between 0 and 0xFFFF
			typeType := "PTR"
	if resName is integer
		if resName between 0 and 0xFFFF
			nameType := "PTR"
	If UseCompression && resType=10{
		FileRead, tempdata, *c %resFile%
		FileGetSize, tempsize, %resFile%
		If !fSize := ZipRawMemory(&tempdata, tempsize, fData)
			Util_Error("Error: Could not compress the file to: " file)
	} else {
		FileGetSize, fSize, %resFile%
		FileRead, fData, *c %resFile%
	}
	pData := &fData
	if resType = 2
	{
		; Remove BM header in order to make it a valid bitmap resource
		if fSize < 14
			Util_Error("Error: Impossible BMP file!")
		pData += 14, fSize -= 14
	}
	if !DllCall("UpdateResource", "ptr", state.module, typeType, resType, nameType, resName
              , "ushort", state.resLang, "ptr", pData, "uint", fSize, "uint")
		Util_Error("Error adding resource:`n`n" rsrc)
	VarSetCapacity(fData, 0)
	IncludedResource[resFile]:=true
	includes:=ListIncludes(resFile, "|")
	Loop,Parse,includes,|
		if !IncludedResource.haskey(A_LoopField)
			Directive_AddResource(state, UseCompression, UsePassword, "LIB " A_LoopField, resName := "")
}

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 3 guests