Compiling a script without including external files

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Compiling a script without including external files

18 Apr 2021, 06:42

Hi everybody,

I have a script that includes two external txt files (settings and hotkeys).
I'd like to give it to other users so they could configure settings and hotkeys to their liking.
I'd like to compile the main script into an exe file, so the script can't be modified, but the settings and hotkeys can.

Unfortunately, when compiling the script, it looks as if the settings and the hotkeys get included into the exe too.

What would be the proper way to compile the script without it including the external files ?
Do I need to change my #Include commands into something else ?

Thank you.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Compiling a script without including external files

18 Apr 2021, 07:04

ahk_h can dynamically load includes and reload itself but thats probably overkill(unless u specifically need the config files to be valid .ahk for some reason)
just change ur script to set its settings programmatically(eg Hotkey command)
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 07:08

Thanks for your swift reply :)
My config and hotkeys files don't need to be ahk, they can be plain editable txt files.
I should mention that I'm still a beginner. I have just discovered that the compiler had this behaviour that was unexpected for me.
Currently in my script there's these lines :
- In the initialization part : #Include %A_ScriptDir%\settings.txt
- At the very end of the script : #Include %A_ScriptDir%\hotkeys.txt
The settings.txt and hotkeys.txt files are quite long, with dozens of lines each.

I guess I would need to change those two lines. What should I put instead ? Thank you.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Compiling a script without including external files

18 Apr 2021, 07:32

settings.ini

Code: Select all

[MyScriptSettings]
DetectHiddenWindowsSetting=On

script.ahk

Code: Select all

IniRead DHW, settings.ini, MyScriptSettings, DetectHiddenWindowsSetting
DetectHiddenWindows % DHW
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Compiling a script without including external files

18 Apr 2021, 09:47

When you compile your script, the content of the included files should be added automatically to the script inside the executable, so you will be no longer in need for these files anymore.
You can use Resource Hacker or Resource Tunner to check the script inside the compiled executable.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 10:20

Thanks swagfag. I think I understand the idea. I've checked https://www.autohotkey.com/docs/commands/IniRead.htm.
In your example there is only one variable, DHW, that stores a value which is on in your case.

In my case I need to read a whole settings.ini file and add its contents to the initialization part of my script, exactly as I would with the #Include command.

I could do this in my main script's initialization section :
IniRead, Settings, settings.ini, MyScriptSettings, 1


And this in the settings.ini :

Code: Select all

[MyScriptSettings]
Key=1
Setting 1
...
Setting n
But it doesn't work so far. Am I missing a line where to "add" the contents of the Settings variable to the code ?
Last edited by Jose Hidalgo on 18 Apr 2021, 10:23, edited 2 times in total.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 10:21

Smile_, that's exactly what I'm trying to prevent. I don't want the contents of settings and hotkeys files to be automatically added ! I want users to be able to modify them on their own, easily. That's why they need to be outside the exe.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 11:10

OK, I'm not getting this. Why does everything have to be so complicated ?

Here's my test script :
IniRead, Settings, testini.ini, Init
MsgBox, %Settings%


Here's my testini.ini file :
[Init]
aaa := 1
bbb := 3


That currently doesn't work.
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Compiling a script without including external files

18 Apr 2021, 12:17

In the INI file we do Key=Value not Key := Value
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 12:29

Oh, silly me. In my defense, I've been trying to find a resource on the syntax and structure for an ini file, without success.
OK, that works now. I can read my whole ini file in a Settings variable. :)
But now how can I "add" Settings contents as part of the main script, just like I would with an #include command ?
Also, my ini file has a lot of global variables. Wouldn't that be a problem ?
I think I've been clear about what I want to do exactly, if not just ask.
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Compiling a script without including external files

18 Apr 2021, 12:38

Once you load it with the IniRead command, that means it is included, what is left is how to use it which is up to you.
For Global variables use Global VariableName(Settings) command before IniRead your file.
Or add Global at the first line inside of the function that you are going to use it in it[The function].
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 13:01

Maybe I should just show you my settings.ini file :

Code: Select all

[Initialization]

; =================================
; ===== CUSTOMIZABLE SETTINGS =====
; =================================

    ; Main app settings
    global Users        = 1				; Number of listeners                 (1 or 2)
    global UseGui       = 1				; Activate the pop-up GUIs by default (0 = no, 1 = yes)
    global UseHSV       = 1				; Use HeSuVi if it's installed        (0 = no, 1 = yes)

    ; Folder names and suffixes
    global AppFolder    = "M.A.T"			; App folder name
    global EQFolder     = "EQ"			; EQ subfolder name
    global ImgFolder    = "Images"			; Images folder name
    global Sx1          = "Left"			; (2 users) suffix for user1's EQ file & HeSuVi folder
    global Sx2          = "Right"			; (2 users) suffix for user2's EQ file & HeSuVi folder

    ; HP info
    global Manuf1       = "Audioquest" 		; Manufacturer (must be exactly as in EQ subfolders)
    global HP1          = "Nighthawk Carbon"	; HP model     (must be exactly as in EQ subfolders)

           Manuf2       = "Audioquest"
           HP2          = "Nighthawk Wood"

           Manuf3       = "Meze"
           HP3          = "99 Classics"

           Manuf4       = "Hifiman"
           HP4          = "Sundara (Revised Earpads)"

           Manuf5       = "Sennheiser"
           HP5          = "HD 600"

           Manuf6       = ""
           HP6          = ""

           Manuf7       = ""
           HP7          = ""

           Manuf8       = ""
           HP8          = ""

           Manuf9       = ""
           HP9          = ""

           Manuf10      = ""
           HP10         = ""

    ; EQ modes names (must be exactly as in EQ preset files)
    global Mode1        = "Original"
    global Mode2        = "Harman"
    global Mode3        = "Optimum"
    global Mode4        = ""					; To be defined
    global Mode5        = "----"				; To be defined
    global Mode6        = "----"				; To be defined

    ; Pop-up GUIs - Text messages
    global TextFont     = "Calibri"			; Text Font
    global TextSize     = 24					; Text Size
    global ModeText0    = "Equalizer OFF"
    global ModeText1    = "Original Sound"		; This text has the corresponding HP color
    global ModeText2    = "Harman Sound"
    global ModeText3    = "Optimum HiFi Sound"
    global ModeText4    = "Custom HiFi Sound"		; To be defined
    global ModeText5    = "---- Sound"			; To be defined
    global ModeText6    = "---- Sound"			; To be defined
    global HSVOFFText   = "HeSuVi OFF"
    global HSVONText    = "HeSuVi ON"

    ; Pop-up GUIs - Colors
    global BackColor    = "1E1E1E"				; Dark background color
    global OFFColor     = "FF0000"				; Red (for various off-related text messages)
    global ModeColor1   = "CCCCCC"				; Light grey
    global ModeColor2   = "00FFCC"				; Blue-Green
    global ModeColor3   = "FFFF00"				; Yellow
    global ModeColor4   = ""					; To be defined
    global ModeColor5   = ""					; To be defined
    global ModeColor6   = ""					; To be defined
    global HSVONColor   = "00FF00"				; Green

    ; Image-related
    global WantedHeight = A_ScreenHeight * 0.70	; Scale images relatively to screen's height

    ; GUI coordinates
    global MiddleGuiCenter = A_ScreenWidth * 0.5	; (1 user)  X coord. of the center of the middle GUI
    global LeftGuiCenter   = A_ScreenWidth * 0.25	; (2 users) X coord. of the center of the left   GUI
    global RightGuiCenter  = A_ScreenWidth * 0.75	; (2 users) X coord. of the center of the right  GUI
    global yTop            = 41				; (Always)  Y coord. of the top    of all the    GUIs

    StartupImage()						; Comment this line to bypass the startup image

; ========================================
; ===== END OF CUSTOMIZABLE SETTINGS =====
; ========================================
With #Include, everything was easy, I just had to include that file (with := instead of =) during the init part of my main script.
But now this doesn't seem to work in the main script :

Code: Select all

IniRead, Settings, settings.ini, Initialization
MsgBox, %Users%
The MsgBox is empty when it should show 1 as a result.
I didn't understand your explanation about global variables. Most of my variables are global, as you can see in my ini file. What should I do ?
I'm pulling my hair here. My script was working perfectly until now. I just want other people to be able to use it in .exe form by making changes to external settings and hotkeys files. Why is that so hard to achieve ?
Last edited by Jose Hidalgo on 18 Apr 2021, 13:10, edited 1 time in total.
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Compiling a script without including external files

18 Apr 2021, 13:09

This is not an INI file this is an AHK script
INI file structure must be exactly like this

[SectionName1]
Key1=Value1
Key2=Value2
...
Keyn=Valuen
[SectionName2]
Key1=Value1
Key2=Value2
...
Keyn=Valuen
...
[SectionNamen]
Key1=Value1
Key2=Value2
...
Keyn=Valuen


About the global thing:
You use that command inside your AHK script not the INI file.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Compiling a script without including external files

18 Apr 2021, 13:15

Of course it's an ahk script, well, a part of it. It worked perfectly with the #Include command, but that didn't allow me to create an .exe.
I never asked to have an ini file, but you guys seem to be telling me that it's the only way to achieve what I want.
Once again, I'm just a beginner trying to pull through. Sorry about that.
IMTheNachoMan
Posts: 59
Joined: 01 Mar 2022, 17:07
Contact:

Re: Compiling a script without including external files

19 Sep 2023, 18:38

Jose Hidalgo wrote: Of course it's an ahk script, well, a part of it. It worked perfectly with the #Include command, but that didn't allow me to create an .exe.
I never asked to have an ini file, but you guys seem to be telling me that it's the only way to achieve what I want.
Once again, I'm just a beginner trying to pull through. Sorry about that.
Did you ever figure this out? I am trying to do the exact same thing.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], just me, Rohwedder and 168 guests