Search code examples
autoit

Best way to input a compiled AUTOIT program


Context:

I am going to write a AUTOIT script that will distribute to many people (let's call it script.exe). People using my program required to input script.exe only once and may run script.exe many times. Of course people can freely update the input as many times as they will.

So first I came up with approach that using the input file, then my program could read, parse then use it. Some improvement could be done is using json format. But this way is so complicated in my opinion so I came up with solution 2.

Solution 2 is my script.exe will import input.au3 with content like:

$input1 = '...'
$input2 = '...'
$input3 = '...'
$input4 = '...'

Then I will compile script.exe and keep input.au3 not compiled so that people can freely update the input.au3. This approach help me solve the problem so naturally but I end up don't know how to do that.

So my question:

  1. How to compile a program but exclude some included file to be not compiled?
  2. Is there any way better than my solution? Or even any existed library that help solution 1 so easy to approach?

Solution

  • What you want (an external file that contains user-editable variables) is called an .INI file. Those files have historically a fixed format, structured in "Sections" and may look like:

    [INPUTFILE]
    ; comment
    Folder=C:\in
    File=test.txt
    
    [OUTPUTFILE]
    Folder=C:\out
    File=test.csv
    Delimiter=;
    

    AutoIt is able to work with those .INI files (read a key from a specific section, change it, or add one, or delete it).

    For example you can read a specific key with:

    $delim = Iniread(@ScriptDir & "\MyIni.ini", "OutputFile", "Delimiter", ",")
    

    where $delims defaults to ,, when the key was not found in the .ini file (last parameter)

    IniReadSection reads a whole section into an array.

    The advantage of an INI file is, it doesn't contain the actual variable names, but human-readable "keys"; their values are assigned to a variable with IniRead