Wednesday, February 15, 2012

Inno Setup, Part 3. Creating configuration files during installation.

Often during program installation we need to create configuration file. In this article we will create a very simple configuration file in .ini style.
It will be created with the help of simple procedure written with the help of Inno Setup script:
[Code]
procedure CreateConfig();
var Strings : TArrayOfString;
begin
  SetArrayLength(Strings, 2);
  Strings[0] := 'InstallPath=' + ExpandConstant('{app}');
  Strings[1] := 'Language=' + ExpandConstant('{language}');

  SaveStringsToFile(ExpandConstant('{commonappdata}') +
    '\OurProgram\OurProgram.config', Strings, False);
end;
This procedure creates an array of strings which consists from two strings and contains information about application folder where the program is installed and language which was selected during installation. Later this information can be used in program, for instance, we can display user interface corresponding to the selected language. Of course, number of strings can be larger than 2.
When the procedure itself is ready, all what we need is to call it. We may call it in the [Files] section:
[Files]
Source: "OurProgram\bin\Release\OurProgram.exe"; DestDir: "{app}"; Components: Main; AfterInstall: CreateConfig; Flags: ignoreversion
Please note call of CreateConfig procedure after this file will be copied.
Our simple example is finished. You can check its work. In one of the next articles when we will discuss making custom windows in Inno Setup, we will describe how to save information which user types in one of the wizard windows in the configuration file, too.

1 comment: