Upcoming Ahk2Exe Changes (2019)

Post your working scripts, libraries and tools
User avatar
joedf
Posts: 7287
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Upcoming Ahk2Exe Changes (2019)

10 Aug 2019, 07:48

Cool stuff TAC109! :+1:
@Drugwash i think adding A_AhkVersion is great. also, maybe a way to specify a custom bin in the GUI would be nice too. However, you could still specify one with the command line parameters. I’m not sure v1.0 will work tho... i think there’s some code to detect and stop compilation of v1.0 scripts because there have been some changes since. Or maybe I’m wrong ahaha :crazy:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
Drugwash
Posts: 737
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Upcoming Ahk2Exe Changes (2019)

10 Aug 2019, 10:35

Well, A_AhkVersion is working without problems, just the documentation fails to mention it. Dunno if there are others in that situation. Considering directives are a new feature to AHK_L I presume most users will turn to the documentation to find out what and how, and if they find things missing they'll start asking questions or shy away from using them, which would be a shame because these directives are just the cherry on top of the cake. ;)

As for using command line for Windows applications in Linux under Wine... oh man! Nah, I'd rather fire up the Win98SE machine and compile there if I really need to.

All things considered, this (the directives) is the kind of improvement we should've had ten years ago already. But as they say: it's never too late. ;)
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

10 Aug 2019, 20:46

@Drugwash Thanks for your prompt testing! To deal with the issues you mentioned:-
  • Backslash issue:- As mentioned in previous posts, this one is over to you to sort out I'm afraid.
  • Set Version problem:- 'SetProp' and 'Set prop' directives are processed in alphabetical order of property, regardless of the order they are specified. (I've put this into the documentation.) However, I'll make 'Set FileVersion' behave the same as 'SetVersion' in the next release, so using 'Set FileVersion' in conjunction with 'Set ProductVersion' will achieve what you want.
  • I'll add the missing 'A_AhkVersion' (and also 'A_PtrSize') to the documentation.
  • Ahk version 1.0:- sorry, as @joedf says, v1.1 of Ahk2Exe will not work with the older Ahk v1.0 files. The process is completely different, and Ahk2exe v1.1 will throw an error in this case.


@joedf Thanks for your comments! If you are referring to being able to specify the *.bin in a Compiler Directive, this would be difficult to achieve. Ahk2Exe needs to know the bin file to be used prior to processing the script so that the relevant 'A_' built-in variables can be set first. Nice idea, but not achievable with the current program.

If no one else finds problems in the next few days, I'll release a new beta which will include the above changes.

Edit: Clarified 'alphabetical order'.
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
User avatar
joedf
Posts: 7287
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Upcoming Ahk2Exe Changes (2019)

10 Aug 2019, 23:09

Oh I meant in the GUI :)
Also, I think maybe during a “pre-preprocess” step to get the bin file path, but either not crucial :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

10 Aug 2019, 23:40

@joedf
Ahk2Exe needs to follow script #Includes, which may refer to built-in variables, which may vary depending on the particular *.bin being used.... You see the problem?

The GUI has the 'bin' parameter, so the user can select the *.bin to use. If required, non-standard bin's can be copied to the AutoHotkey\Compiler folder and will be available to the GUI.

Let me know if I’m not understanding.
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
User avatar
Drugwash
Posts: 737
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Upcoming Ahk2Exe Changes (2019)

11 Aug 2019, 03:09

I think what Joe is trying to say (and what I thought of when mentioning the AHK 1.0 binary) is that an extra item (called Custom binary or whatever) could be added to the bin selector dropdown, and when the user selects that item a [...] (browse) button would appear next to the DDL where the user could search and select a custom binary to be used with the current script.

That path would be remembered between sessions and displayed somewhere in the GUI when selected in the list. Or, more conveniently, a dropdown list of - say - ten last used binary paths (not just version numbers, since they may be the same version but different in code) could be displayed below the binary selector DDL, with the very last used one preselected.

Such option would most likely be useful to testers that may want to compile the same script with various (older) versions of the AHK binary, for whatever reason, but there may be other usage patterns too.

Thank you for the clarifications. I'll see what can be done about the backslash.
In regard to version setting, currently neither FileVersion nor ProductVersion don't change the binary version numbers - they only change the string version numbers. They should both be modified to change binary numbers too.

EDIT: There may be certain info needed in a directive, that requires preprocessing. For example, a string that reads either Unicode or ANSI according to the currently selected binary. Or one that reads x64 or is blank, according to the binary bitness. Or current date/time in a system-defined or user-defined format. How could that be achieved? Regular expressions and A_PriorLine are not enough. Could there be something like this?

Code: Select all

;@Ahk2Exe-Let type = %A_IsUnicode ? "Unicode" : "ANSI"%
;@Ahk2Exe-Do FormatTime`, ecd`, L1033`, MMMM d`, yyyy
;@Ahk2Exe-Set Comments, Compiled in %A_AhkVersion% %U_type% on %U_ecd%.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
ahk7
Posts: 209
Joined: 06 Nov 2013, 16:35

Re: Upcoming Ahk2Exe Changes (2019)

11 Aug 2019, 05:17

Just a thought:
1) for those who compile often it might be tedious to open the Gui, select files and options so why not add a "save as" option which will simple generate a script so you can run it with the cli options. (patch for ahk2exe.ahk below)
2) perhaps the /cp option should be added to the GUI, you can define it when you compile it via the command line but not the Gui?

84a85
> Gui, Add, Button, xp+248 yp w75 h28 Default gConvertCLIGenerate, &Save As
353a355,367
>
> ConvertCLIGenerate:
> Gui, +OwnDialogs
> Gui, Submit, NoHide
> BinFile := A_ScriptDir "\" BinFiles[BinFileId]
> SaveAs:=""
> FileSelectFile, SaveAs, S, , Save As, *.ahk
> If (SaveAs = "") or ErrorLevel
> Return
> If !RegExMatch(SaveAs,"\.ahk$")
> SaveAs.=".ahk"
> FileAppend, RunWait "%A_ScriptDir%\Ahk2Exe.exe" /in "%AhkFile%" /out "%ExeFile%" /icon "%IcoFile%" /bin "%BinFile%" /mpress "%UseMpress%", %SaveAs%
> Return
robodesign
Posts: 550
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

Re: Upcoming Ahk2Exe Changes (2019)

11 Aug 2019, 06:27

Yes, I would love that. I often have to recompile my scripts.....
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

11 Aug 2019, 19:45

@Drugwash
*.bin selection
I'm not convinced that your suggestion of a full-blown *.bin selection system is warranted for Ahk2Exe. There are Ahk version management systems out there such as AHK-EXE-Swapper, which could be enhanced to also swap the Compiler\*.bin files needed for the compiler. Something like this would keep all Ahk files in step and also allow interpretive testing as well as compiling at the same selected version of Ahk.

Your code example
The first line of your code could be replaced with the following:

Code: Select all

;@Ahk2Exe-Let isUni = ANSI, isUni1 = Unicode, type = isUni%A_IsUnicode%
Edit: whoa! That won’t work! Let me think on that one too.

The (edited) second code line looks interesting; I'll cogitate on that some more.


@ahk7
Your ideas are useful, and it is always nice to see example code! I'll put something into the next beta.
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

11 Aug 2019, 23:14

@Drugwash
Ok, I'm thinking something like this would be a useful enhancement:

Code: Select all

Obey
Obeys an AHK command or expression in isolation, with result in U_'Name'.

;@Ahk2Exe-Obey Name, CmdOrExp

Name      The name of the variable (without the leading 'U_') to receive the result.

CmdOrExp  The command or expression to evaluate.
          Expressions must start with '='.
          Commands must use 'Name' (as specified above) as the output variable (usually as the first parameter).
This should handle the examples you provided.

Edit: Changed some definition details.
Edit2: Changed the directive name (In homage to the ICL 1900 and 290x mainframes I used to work with.)
Last edited by TAC109 on 13 Aug 2019, 17:51, edited 1 time in total.
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
User avatar
joedf
Posts: 7287
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Upcoming Ahk2Exe Changes (2019)

12 Aug 2019, 11:00

Cool suggestions! :+1:
@TAC109 I have thought about that already. I meant just a simple search for a line with a token for something like ;@Ahk2Exe-TryBin C:\path\to\file.bin before any actual language, other directives or everything else at all is interpreted or preprocessed. This is would a simple line search in the main .ahk script and should not be valid in any included file or any other context. I think this would be complementary to the /bin command-line operator, but perhaps this is not warranted. It is simply a suggestion, I don't think it is necessary. :+1:

Excited to see this fully released. :)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
ahk7
Posts: 209
Joined: 06 Nov 2013, 16:35

Re: Upcoming Ahk2Exe Changes (2019)

12 Aug 2019, 11:33

More ideas:

Replace the DDL for the BIN with a multi-select listbox or listview so you can select multiple bins and compile, that way you can compile 32 and 64 bit at the same time or multiple bins if you add more.

Non-functional GUI below. I chose listview as it allows for more information using multiple columns in need be (see "append name")

A user could add/remove BINs - there will always be a Default of course and if nothing is checked Default would be the BIN used.
(again not functional here, just to illustrate)

For each checked BIN (apart from default) a user could define a "append name" so if the script is called MyScript.ahk it would generate MyScript.exe (default), MyScript_x64.exe, MyScript_v1.27.01.exe etc (_x64 and _v1.27.01 would be define by the user)

Perhaps data shouldn't be in the Registry but in Appdata\autohotkey\compiler so it is easier to store settings via INI (perhaps allow for different INIs to be loaded?)

/CP could be a DDL

Might make it too complicated.

Further changes:
- Help to the RIGHT
- All X/Y positions of controls are relative

Code: Select all

;
; File encoding:  UTF-8
;
; Script description:
;	Ahk2Exe - AutoHotkey Script Compiler
;	Written by fincs - Interface based on the original Ahk2Exe
;

;@Ahk2Exe-SetName         Ahk2Exe
;@Ahk2Exe-SetDescription  AutoHotkey Script Compiler
;@Ahk2Exe-SetCopyright    Copyright (c) since 2004
;@Ahk2Exe-SetCompanyName  AutoHotkey
;@Ahk2Exe-SetOrigFilename Ahk2Exe.ahk
;@Ahk2Exe-SetMainIcon     Ahk2Exe.ico

#NoEnv
#NoTrayIcon
#SingleInstance Off
#Include %A_ScriptDir%
#Include Compiler.ahk
SendMode Input

OnExit("Util_HideHourglass")            ; Reset cursor on exit

CompressDescr := {-1:" UPX  (if prese&nt)", 0:" (&none)", 1:" MPRESS  (if prese&nt)"}

global DEBUG := !A_IsCompiled

gosub BuildBinFileList
gosub LoadSettings
gosub ParseCmdLine
if !UsesCustomBin
	gosub CheckAutoHotkeySC

if CLIMode
{
	gosub ConvertCLI
	ExitApp, 0 ; Success
}

IcoFile = %LastIcon%
BinFileId := FindBinFile(LastBinFile)
ScriptFileCP := A_FileEncoding

#include *i __debug.ahk

Menu, FileMenu, Add, &Convert (EXE), Convert
Menu, FileMenu, Add, Export (as AHK), Convert
Menu, FileMenu, Add
Menu, FileMenu, Add, E&xit`tAlt+F4, GuiClose
Menu, HelpMenu, Add, &Help, Help, Right
Menu, HelpMenu, Add
Menu, HelpMenu, Add, &About, About
Menu, MenuBar,  Add, &File, :FileMenu
Menu, MenuBar,  Add, &Help, :HelpMenu, Right
Gui, Menu, MenuBar

Gui, +LastFound
GuiHwnd := WinExist("")
Gui, Add, Link, x287 y20,
(
©2004-2009 Chris Mallet
©2008-2011 Steve Gray (Lexikos)
©2011-2016 fincs
<a href="https://www.autohotkey.com">https://www.autohotkey.com</a>
Note: Compiling does not guarantee source code protection.
)
Gui, Add, Text    , x10 y100 w570 h2 +0x1007

Gui, Add, GroupBox, xp     yp+10   w570 h55 cBlue              , Required Parameter
Gui, Add, Text    , xp+10  yp+25                              , &Source (script file)
Gui, Add, Edit    , xp+120 yp-5   w325 h23  +Disabled vAhkFile, %AhkFile%
Gui, Add, Button  , xp+330 yp     w50  h23  gBrowseAhk        , &Browse

Gui, Add, GroupBox, xp-460 yp+40  w570 h230 cBlue             , Optional Parameters
Gui, Add, Text    , xp+10  yp+25                              , &Destination (.exe file)
Gui, Add, Edit    , xp+120 yp-5   w325 h23 +Disabled vExeFile , %Exefile%
Gui, Add, Button  , xp+330 yp     w50  h23 gBrowseExe         , B&rowse
Gui, Add, Text    , xp-450 yp+40                              , Custom &Icon (.ico file)
Gui, Add, Edit    , xp+120 yp-5   w325 h23 +Disabled vIcoFile , %IcoFile%
Gui, Add, Button  , xp+330 yp     w50  h23 gBrowseIco         , Br&owse
Gui, Add, Button  , xp+50  yp     w50  h23 gDefaultIco        , D&efault
Gui, Add, Text    , xp-500 yp+40                              , Base File (.bin)
;Gui, Add, DDL, x137 y270 w315 h23 R10 AltSubmit vBinFileId Choose%BinFileId%, %c%
Gui, Add, ListView, xp+120 yp w325 H100 -Hdr Checked, bin
Gosub, UpdateListView
Gui, Add, Button  , xp+330 yp     w50  h23        , Add BIN
Gui, Add, Button  , xp+50  yp     w50  h23        , Del BIN

Gui, Add, Text    , xp-500 yp+110                             , Compress exe with
Gui, Add, CheckBox, xp+120 yp-3     w160 h20 Check3 vUseMpress gcompress Checked%LastUseMPRESS%, % CompressDescr[LastUseMPRESS]

Gui, Add, Text    , xp+200 yp+3                               , Code page:
Gui, Add, Edit    , xp+65  yp-3     w60 R1  vCP hwndHED1      ,
Gui, Add, Button  , xp-45 yp+40    w100 h30 Default           , Export (as AHK)
Gui, font, bold
Gui, Add, Button  , xp+110 yp       w110 h30 Default gConvert , &Convert (EXE)
Gui, font, 

Gui, Add, StatusBar,, Ready
;@Ahk2Exe-IgnoreBegin
Gui, Add, Pic, x30 y15 w240 h78, %A_ScriptDir%\logo.png
;@Ahk2Exe-IgnoreEnd
/*@Ahk2Exe-Keep
gosub AddPicture
*/
GuiControl, Focus, Button1
Gui, Show, , Ahk2Exe for AutoHotkey v%A_AhkVersion% -- Script to EXE Converter
SetEditCueBanner(HED1, "/CPn")
return

UpdateListView:
Gui, default
LV_Delete()
Loop, parse, BinNames , |
	LV_Add(A_Index,A_LoopField)
Return

GuiClose:
Gui, Submit
gosub SaveSettings
ExitApp

compress:
gui, Submit, NoHide
GuiControl Text, UseMpress, % CompressDescr[UseMPRESS]

GuiDropFiles:
if A_EventInfo > 3
	Util_Error("You cannot drop more than one file of each type into this window!", 0x51)
loop, parse, A_GuiEvent, `n
{
	SplitPath, A_LoopField,,, dropExt
	if SubStr(dropExt,1,2) = "ah"          ; Allow for v2, e.g. ah2, ahk2, etc
		GuiControl,, AhkFile, %A_LoopField%
	else GuiControl,, %dropExt%File, %A_LoopField%
}
return

/*@Ahk2Exe-Keep

AddPicture:
; Code based on http://www.autohotkey.com/forum/viewtopic.php?p=147052
Gui, Add, Text, x29 y16 w240 h78 +0xE hwndhPicCtrl

;@Ahk2Exe-AddResource logo.png
hRSrc := DllCall("FindResource", "ptr", 0, "str", "LOGO.PNG", "ptr", 10, "ptr")
sData := DllCall("SizeofResource", "ptr", 0, "ptr", hRSrc, "uint")
hRes  := DllCall("LoadResource", "ptr", 0, "ptr", hRSrc, "ptr")
pData := DllCall("LockResource", "ptr", hRes, "ptr")
hGlob := DllCall("GlobalAlloc", "uint", 2, "uint", sData, "ptr") ; 2=GMEM_MOVEABLE
pGlob := DllCall("GlobalLock", "ptr", hGlob, "ptr")
DllCall("msvcrt\memcpy", "ptr", pGlob, "ptr", pData, "uint", sData, "CDecl")
DllCall("GlobalUnlock", "ptr", hGlob)
DllCall("ole32\CreateStreamOnHGlobal", "ptr", hGlob, "int", 1, "ptr*", pStream)

hGdip := DllCall("LoadLibrary", "str", "gdiplus")
VarSetCapacity(si, 16, 0), NumPut(1, si, "UChar")
DllCall("gdiplus\GdiplusStartup", "ptr*", gdipToken, "ptr", &si, "ptr", 0)
DllCall("gdiplus\GdipCreateBitmapFromStream", "ptr", pStream, "ptr*", pBitmap)
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "ptr", pBitmap, "ptr*", hBitmap, "uint", 0)
SendMessage, 0x172, 0, hBitmap,, ahk_id %hPicCtrl% ; 0x172=STM_SETIMAGE, 0=IMAGE_BITMAP
GuiControl, Move, %hPicCtrl%, w240 h78

DllCall("gdiplus\GdipDisposeImage", "ptr", pBitmap)
DllCall("gdiplus\GdiplusShutdown", "ptr", gdipToken)
DllCall("FreeLibrary", "ptr", hGdip)
ObjRelease(pStream)
return

*/

BuildBinFileList:
BinFiles := ["AutoHotkeySC.bin"]
BinNames = (Default)
Loop, %A_ScriptDir%\*.bin
{
	SplitPath, A_LoopFileFullPath,,,, n
	if n = AutoHotkeySC
		continue
	FileGetVersion, v, %A_LoopFileFullPath%
	BinFiles.Insert(n ".bin")
	BinNames .= "|v" v " " n
}
return

CheckAutoHotkeySC:
IfNotExist, %A_ScriptDir%\AutoHotkeySC.bin
{
	; Check if we can actually write to the compiler dir
	try FileAppend, test, %A_ScriptDir%\___.tmp
	catch
	{
		MsgBox, 52, Ahk2Exe Error,
		(LTrim
		Unable to copy the appropriate binary file as AutoHotkeySC.bin because the current user does not have write/create privileges in the %A_ScriptDir% folder (perhaps you should run this program as administrator?)
		
		Do you still want to continue?
		)
		IfMsgBox, Yes
			return
		ExitApp, 0x2 ; Compilation cancelled
	}
	FileDelete, %A_ScriptDir%\___.tmp
	
	IfNotExist, %A_ScriptDir%\..\AutoHotkey.exe
	{
		binFile = %A_ScriptDir%\Unicode 32-bit.bin

		if !FileExist(BinFile)                  ; Ahk2Exe in non-standard folder?
		{	FileCopy  %A_AhkPath%\..\Compiler\Unicode 32-bit.bin
			       ,  %A_ScriptDir%\AutoHotkeySC.bin
			BinFile = %A_ScriptDir%\AutoHotkeySC.bin
			FileCopy  %A_AhkPath%\..\Compiler\*bit.bin, %A_ScriptDir%\, 1

	}	} else
	{
		try FileDelete, %A_Temp%\___temp.ahk
		FileAppend, ExitApp `% (A_IsUnicode=1) << 8 | (A_PtrSize=8) << 9, %A_Temp%\___temp.ahk
		RunWait, "%A_ScriptDir%\..\AutoHotkey.exe" "%A_Temp%\___temp.ahk"
		rc := ErrorLevel
		FileDelete,  %A_Temp%\___temp.ahk
		if rc = 0
			binFile = %A_ScriptDir%\ANSI 32-bit.bin
		else if rc = 0x100
			binFile = %A_ScriptDir%\Unicode 32-bit.bin
		else if rc = 0x300
			binFile = %A_ScriptDir%\Unicode 64-bit.bin
		; else: shouldn't happen
	}
	
	IfNotExist, %binFile%
	{
		MsgBox, 52, Ahk2Exe Error,
		(LTrim
		Unable to copy the appropriate binary file as AutoHotkeySC.bin because said file does not exist:
		%binFile%
		
		Do you still want to continue?
		)
		IfMsgBox, Yes
			return
		ExitApp, 0x2 ; Compilation cancelled
	}
	
	FileCopy, %binFile%, %A_ScriptDir%\AutoHotkeySC.bin
}
return

FindBinFile(name)
{
	global BinFiles
	for k,v in BinFiles
		if (v = name)
			return k
	return 1
}

ParseCmdLine:
if 0 = 0
	return

Error_ForceExit := true

p := []
Loop, %0%
{
	if %A_Index% = /NoDecompile
		Util_Error("Error: /NoDecompile is not supported.", 0x23)
	else p.Insert(%A_Index%)
}

if Mod(p.MaxIndex(), 2)
	goto BadParams

Loop, % p.MaxIndex() // 2
{
	p1 := p[2*(A_Index-1)+1]
	p2 := p[2*(A_Index-1)+2]
	
	if p1 not in /in,/out,/icon,/pass,/bin,/mpress,/compress,/cp
		goto BadParams
	
	if p1 = /bin
		UsesCustomBin := true
	
	if p1 = /pass
		Util_Error("Error: Password protection is not supported.", 0x24)
	
	if p2 =
		goto BadParams
	
	StringTrimLeft, p1, p1, 1
	gosub _Process%p1%
}

if !AhkFile
	goto BadParams

if !IcoFile
	IcoFile := LastIcon

if !BinFile
	BinFile := A_ScriptDir "\" LastBinFile

if UseMPRESS =
	UseMPRESS := LastUseMPRESS

CLIMode := true
return

BadParams:
Util_Info("Command Line Parameters:`n`n" A_ScriptName "`n`t /in infile.ahk`n`t [/out outfile.exe]`n`t [/icon iconfile.ico]`n`t [/bin AutoHotkeySC.bin]`n`t [/compress 0 (none), 1 (MPRESS), or -1 (UPX)]`n`t [/cp codepage]")
ExitApp, 0x3

_ProcessIn:
AhkFile := p2
return

_ProcessOut:
ExeFile := p2
return

_ProcessIcon:
IcoFile := p2
return

_ProcessBin:
CustomBinFile := true
BinFile := p2
return

_ProcessMPRESS:
UseMPRESS := p2
return

_ProcessCompress:
UseMPRESS := p2
return

_ProcessCP: ; for example: '/cp 1252' or '/cp UTF-8'
if p2 is number
	ScriptFileCP := "CP" p2
else
	ScriptFileCP := p2
return

BrowseAhk:
Gui, +OwnDialogs
FileSelectFile, ov, 1, %LastScriptDir%, Open, AutoHotkey files (*.ahk)
if ErrorLevel
	return
GuiControl,, AhkFile, %ov%
return

BrowseExe:
Gui, +OwnDialogs
FileSelectFile, ov, S16, %LastExeDir%, Save As, Executable files (*.exe)
if ErrorLevel
	return
if !RegExMatch(ov, "\.[^\\/]+$") ;~ append a default file extension is none specified
	ov .= ".exe"
GuiControl,, ExeFile, %ov%
return

BrowseIco:
Gui, +OwnDialogs
FileSelectFile, ov, 1, %LastIconDir%, Open, Icon files (*.ico)
if ErrorLevel
	return
GuiControl,, IcoFile, %ov%
return

DefaultIco:
GuiControl,, IcoFile
return

Convert:
Gui, +OwnDialogs
Gui, Submit, NoHide
OutputBins:=""
RowNumber = 0  ; This causes the first loop iteration to start the search at the top of the list.
Loop
{
    RowNumber := LV_GetNext(RowNumber,"Checked")  ; Resume the search at the row after that found by the previous iteration.
    if not RowNumber  ; The above returned zero, so there are no more selected rows.
        break
    LV_GetText(Text, RowNumber)
    OutputBins .= Text "|"
}
If (OutputBins = "")
	OutputBins:="(Default)"
MsgBox % OutputBins
Return

; BinFile := A_ScriptDir "\" BinFiles[BinFileId]
ConvertCLI:
AhkCompile(AhkFile, ExeFile, IcoFile, BinFile, UseMpress, ScriptFileCP)
if !CLIMode
	Util_Info("Conversion complete.")
else
	FileAppend, Successfully compiled: %ExeFile%`n, *
return

LoadSettings:
RegRead, LastScriptDir, HKCU, Software\AutoHotkey\Ahk2Exe, LastScriptDir
RegRead, LastExeDir, HKCU, Software\AutoHotkey\Ahk2Exe, LastExeDir
RegRead, LastIconDir, HKCU, Software\AutoHotkey\Ahk2Exe, LastIconDir
RegRead, LastIcon, HKCU, Software\AutoHotkey\Ahk2Exe, LastIcon
RegRead, LastBinFile, HKCU, Software\AutoHotkey\Ahk2Exe, LastBinFile
RegRead, LastUseMPRESS, HKCU, Software\AutoHotkey\Ahk2Exe, LastUseMPRESS
if !FileExist(LastIcon)
	LastIcon := ""
if (LastBinFile = "") || !FileExist(LastBinFile)
	LastBinFile = AutoHotkeySC.bin
if !CompressDescr[LastUseMPRESS]
	LastUseMPRESS := false
return

SaveSettings:
SplitPath, AhkFile,, AhkFileDir
if ExeFile
	SplitPath, ExeFile,, ExeFileDir
else
	ExeFileDir := LastExeDir
if IcoFile
	SplitPath, IcoFile,, IcoFileDir
else
	IcoFileDir := ""
RegWrite, REG_SZ, HKCU, Software\AutoHotkey\Ahk2Exe, LastScriptDir, %AhkFileDir%
RegWrite, REG_SZ, HKCU, Software\AutoHotkey\Ahk2Exe, LastExeDir, %ExeFileDir%
RegWrite, REG_SZ, HKCU, Software\AutoHotkey\Ahk2Exe, LastIconDir, %IcoFileDir%
RegWrite, REG_SZ, HKCU, Software\AutoHotkey\Ahk2Exe, LastIcon, %IcoFile%
RegWrite, REG_SZ, HKCU, Software\AutoHotkey\Ahk2Exe, LastUseMPRESS, %UseMPRESS%
if !CustomBinFile
	RegWrite, REG_SZ, HKCU, Software\AutoHotkey\Ahk2Exe, LastBinFile, % BinFiles[BinFileId]
return

Help:
helpfile = %A_ScriptDir%\..\AutoHotkey.chm
IfNotExist, %helpfile%
	Util_Error("Error: cannot find AutoHotkey help file!", 0x52)

VarSetCapacity(ak, ak_size := 8+5*A_PtrSize+4, 0) ; HH_AKLINK struct
NumPut(ak_size, ak, 0, "UInt")
name = Ahk2Exe
NumPut(&name, ak, 8)
DllCall("hhctrl.ocx\HtmlHelp", "ptr", GuiHwnd, "str", helpfile, "uint", 0x000D, "ptr", &ak) ; 0x000D: HH_KEYWORD_LOOKUP
return

About:
Gui, +OwnDialogs
MsgBox, 64, About Ahk2Exe,
(
Ahk2Exe - Script to EXE Converter

Original version:
  Copyright ©1999-2003 Jonathan Bennett & AutoIt Team
  Copyright ©2004-2009 Chris Mallet
  Copyright ©2008-2011 Steve Gray (Lexikos)

Script rewrite:
  Copyright ©2011-2016 fincs

Special thanks:
  TAC109, joedf, aviaryan
)
return

Util_Status(s)
{
	SB_SetText(s)
}

Util_Error(txt, exitcode, extra := "")
{
	global CLIMode, Error_ForceExit, ExeFileTmp
	
	if (exitcode && ExeFileTmp && FileExist(ExeFileTmp))
	{
		FileDelete, %ExeFileTmp%
		ExeFileTmp =
	}
	
	if extra
		txt .= "`n`nSpecifically: " extra
	
	Util_HideHourglass()
	if exitcode
		MsgBox, 16, Ahk2Exe Error, % txt
	else
		MsgBox, 48, Ahk2Exe Warning, % txt

	
	if CLIMode && exitcode
	{
		FileAppend, Failed to compile: %ExeFile%`n, *
		Util_Status("Ready")
	}
	
	if exitcode
		if !Error_ForceExit
			Exit, exitcode
		else
			ExitApp, exitcode
}

Util_Info(txt)
{
	MsgBox, 64, Ahk2Exe, % txt
}

Util_DisplayHourglass()
{                          ; Change IDC_ARROW (32512) to IDC_APPSTARTING (32650)
  DllCall("SetSystemCursor",Ptr,DllCall("LoadCursor",Ptr,0,Ptr,32512),Ptr,32650)
}

Util_HideHourglass()
{                                              ; Reset arrow cursor to standard
  DllCall("SystemParametersInfo", Ptr,0x57, Ptr,0, Ptr,0, Ptr,0)
}

; just me
; https://autohotkey.com/board/topic/76540-function-seteditcuebanner-ahk-l/
SetEditCueBanner(HWND, Cue) {  ; requires AHL_L
   Static EM_SETCUEBANNER := (0x1500 + 1)
   Return DllCall("User32.dll\SendMessageW", "Ptr", HWND, "Uint", EM_SETCUEBANNER, "Ptr", True, "WStr", Cue)
}
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

12 Aug 2019, 17:58

@ahk7
I personally don’t see the need for extensive *.bin handling. The .exe created using u32 bin will run on all supported versions of Windows. Possible exceptions are if large amounts of ram needed (>2GB), or old ANSII code not Unicode compatible.

For rare situations where several compiles are needed, one could use your 'Save script settings as ...' enhancement, then modify the generated script to generate multiple .exe's. (Btw I propose to implement this as an entry on the 'files' menu. This will allow a longer description.)

Regarding the /CP parameter, this is rarely needed, if at all. This was added when someone was using an editor which couldn’t save a UTF8 file with BOM. (Also adds compatibility with AutoHotkey.exe which has the same rarely-used parameter.) So I don’t think it is worth cluttering the window with this addition, which will seldom if ever be used.

If you felt strongly about these changes you could always write a front end GUI. ;)

@joedf
Thanks for your comments. See above. :)
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

13 Aug 2019, 02:07

@joedf
I’ll give your special directive idea some further thought... ;)
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
User avatar
joedf
Posts: 7287
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Upcoming Ahk2Exe Changes (2019)

13 Aug 2019, 08:32

@TAC109
Ahaha no worries, I was thinking this would be something @Drugwash would use. :+1:
I think specifying A32, U32, U64 is all that I would need. I personally don't use custom binaries that often. :mrgreen:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
ahk7
Posts: 209
Joined: 06 Nov 2013, 16:35

Re: Upcoming Ahk2Exe Changes (2019)

13 Aug 2019, 13:09

@TAC109 no problem, thought I'd share some ideas during development. Nice to hear about the File, Save as... :)
User avatar
Drugwash
Posts: 737
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Upcoming Ahk2Exe Changes (2019)

16 Aug 2019, 10:46

joedf wrote:
13 Aug 2019, 08:32
I was thinking this would be something @Drugwash would use. :+1:
I think specifying A32, U32, U64 is all that I would need. I personally don't use custom binaries that often. :mrgreen:
It doesn't have to be custom binaries. Think of a script that should be (mostly) compatible with both AHK_L and AHK_H. Won't throw AHK1.0 into the mix now. Or a command/function compatibility test (or bug hunt) with a handful of older AHK_L versions besides the latest, all installed side by side. Actually ahk7's idea of a multi-select list is great, it would allow chained compilations with a single click, and also would allow (de)selecting binaries and viewing their versions in a much easier manner than editing a user-modified script.
I thought AHK was all about automation - maybe I was wrong... :roll:

@ TAC109: Obey sounds weird. Eval might be more appropriate. Beyond that though, commands and expressions should appear as much similar as in a normal script line, without any preceding signs that may confuse the user. And keep in mind that there may also be function calls whose results may come both in function return value and ByRef variables. That's mostly valid for DllCalls.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
joedf
Posts: 7287
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Upcoming Ahk2Exe Changes (2019)

16 Aug 2019, 11:07

@Drugwash
+1
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
TAC109
Posts: 405
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Upcoming Ahk2Exe Changes (2019)

16 Aug 2019, 19:06

Drugwash wrote:
16 Aug 2019, 10:46
It doesn't have to be custom binaries. Think of a script that should be (mostly) compatible with both AHK_L and AHK_H. Won't throw AHK1.0 into the mix now. Or a command/function compatibility test (or bug hunt) with a handful of older AHK_L versions besides the latest, all installed side by side. Actually ahk7's idea of a multi-select list is great, it would allow chained compilations with a single click, and also would allow (de)selecting binaries and viewing their versions in a much easier manner than editing a user-modified script.
I thought AHK was all about automation - maybe I was wrong... :roll:
So you don’t debug your *.ahk scripts interactively before the final compilation phase? I find that very strange :!: If this really important to you, you can always write a compiler front-end as I suggested to @ahk7.
Obey sounds weird. Eval might be more appropriate.
'Obey' is the directive name I’ve chosen.
And keep in mind that there may also be function calls whose results may come both in function return value and ByRef variables. That's mostly valid for DllCalls.
Please give real world examples where you need to call a function returning multiple return values in the compiling situation.

@joedf You might be able to help here also.
My programs:-
ReClip - a Text Reformatting and Clip Management utility
XRef - Produces Cross Reference lists for scripts
User avatar
Drugwash
Posts: 737
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Upcoming Ahk2Exe Changes (2019)

19 Aug 2019, 03:33

I had already built a compiler front-end years ago, it worked with premodified binaries (since AHK1.0 was not being worked on anymore) and it was meant to also be a resource editor but it was left in the viewer state. Wanted to post a screenshot the other day but due to some issues with Wine I couldn't get it to fully work and then it froze the machine (yeah, Linux can be brought to its knees by M$ code) and then forgot about it.
There it is, source (not fully AHK_L-compatible and definitely not x64-compatible) and ANSI executable (built with AHK 1.0.48.05):
myCompiler0242_src.7z
myCompiler - source
(70.72 KiB) Downloaded 15 times
myCompiler0242.7z
myCompiler - ANSI executable
(313.56 KiB) Downloaded 16 times
Now, since this new AHK 1.1+ compiler doesn't contain any "secret" code anymore and all its code is readily available, it may be best to just enhance it with the desired capabilities rather than build a front-end to it.

As for debugging, there may be situations where the uncompiled code works fine while the compiled one doesn't, and one only finds that out after compilation. Anyway, that would be a different topic.
Please give real world examples where you need to call a function returning multiple return values in the compiling situation.
Can't think of any off the top of my head but the possibility exists and I believe it should be considered, if only to avoid confusion or issues in the future. Cover all the bases.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 21 guests