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.
Compiling a script without including external files
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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)
just change ur script to set its settings programmatically(eg Hotkey command)
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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.
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.
Re: Compiling a script without including external files
settings.ini
script.ahk
Code: Select all
[MyScriptSettings]
DetectHiddenWindowsSetting=On
script.ahk
Code: Select all
IniRead DHW, settings.ini, MyScriptSettings, DetectHiddenWindowsSetting
DetectHiddenWindows % DHW
Re: Compiling a script without including external files
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.
You can use Resource Hacker or Resource Tunner to check the script inside the compiled executable.
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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 :
But it doesn't work so far. Am I missing a line where to "add" the contents of the Settings variable to the code ?
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
Last edited by Jose Hidalgo on 18 Apr 2021, 10:23, edited 2 times in total.
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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.
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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.
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.
Re: Compiling a script without including external files
In the INI file we do Key=Value not Key := Value
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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.
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.
Re: Compiling a script without including external files
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].
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].
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
Maybe I should just show you my settings.ini file :
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 :
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 ?
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 =====
; ========================================
But now this doesn't seem to work in the main script :
Code: Select all
IniRead, Settings, settings.ini, Initialization
MsgBox, %Users%
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.
Re: Compiling a script without including external files
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.
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.
-
- Posts: 222
- Joined: 07 Mar 2021, 07:44
Re: Compiling a script without including external files
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.
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.
-
- Posts: 59
- Joined: 01 Mar 2022, 17:07
- Contact:
Re: Compiling a script without including external files
Did you ever figure this out? I am trying to do the exact same thing.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.