English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Who Is Online?
We have 140 guests online
Home Source Code Inno Setup Unix-style configuration files with Inno Setup
Most Recent
Featured Articles
Joomla 1.5 Featured Articles
Home Source Code Inno Setup Unix-style configuration files with Inno Setup
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Unix-style configuration files with Inno Setup E-mail
User Rating: / 13
Source Code - Inno Setup
Written by Thomas   
Saturday, 30 May 2009 16:17
Article Index
Unix-style configuration files with Inno Setup
Additional section name
Inno Setup Pascal script code
All Pages


Inno Setup is a Windows application, and therefore it is easy to create or modify Windows-style configuration files with it. Windows configuration files are sometimes referred to as ini files because of their filename extension '.ini'. Unix-style configuration files don't have section names, but that does not mean they can't be handled with Inno Setup.


Windows ini files can be created or modified with entries in Inno Setup's [Ini] section. An Inno Setup [Ini] section entry must specify a filename (the configiuration file), a section name (ini files are split up in sections), a key name (which turns up as 'key=...' in the file), and a value (everything on the right side of the '=' character). Inno Setup [Ini] section entries are basically wrappers for Windows' WritePrivateProfileString () API function.

Here's an example for a Windows configuration file (ini file):



setting=This is my setting


Wikipedia explains ini files in more detail: Ini file on Wikipedia


This configuration file format has been with Windows at least since Windows 3.1, and other operating systems like OS/2 supported it too. It was the standard way of preserving settings on Windows systems before Microsoft introduced the Windows registry. Ini files are still more compact than for example XML files.

The hassle starts with software that does not use standard ini files.

More and more software for Windows has its roots on Unix/Linux. Since the ini file format is more or less native to Windows, most Unix software uses slightly different configuration files. Inno Setup does by default not support the Unix-style config file format.

The files look pretty much like Windows ini files but don't have sections. They usually only consist of configuration entries and comments:


# This is a comment.

setting=This is my setting



There are several possible methods to handle Unix-style configuration files with Inno Setup, and they are all quite valuable for their purposes.

  • An external direct link library (DLL).
  • The trick with an additional section name.
  • Some [Code] in Inno Setup.

Writing an external DLL just to read and write some configuration settings for a particular file format seems overkill at first. A closer look reveals that there can very well be good reasons for this approach. For example, if a helper DLL exists already, the effort of squeezing a few more functions in to handle configurations might be worth a few lines of code.



In many cases the trick with an additional section name is sufficient enough. Most software that uses Unix-style configuration files won't care about sections if found in the file. The software usually ignores them.

I'd put a section name at the beginning of the file before deployment. Otherwise, if new settings are added, the Windows function WritePrivateProfileString () (and therefore Inno Setup's [Ini] section) would add the section name at the end of the file. It won't hurt the functionality, though, but I think it doesn't look very nice.

The benefit of this trick is that Inno Setup's standard [Ini] section can be used.


Finally, a few lines of Inno Setup Pascal script code can provide functions to read and write Unix-style configuration files:

Open UnixConfig.iss


  1. ; Script generated by the Inno Setup Script Wizard.
  4. #define MyAppName "My Program"
  5. #define MyAppVerName "My Program 1.5"
  6. #define MyAppPublisher "My Company, Inc."
  7. #define MyAppURL ""
  8. #define MyAppExeName "MyProg.exe"
  10. [Setup]
  11. ; NOTE: The value of AppId uniquely identifies this application.
  12. ; Do not use the same AppId value in installers for other applications.
  13. ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
  14. AppId={{753F2C1F-EA02-488E-A204-A047F1EFA0BC}
  15. AppName={#MyAppName}
  16. AppVerName={#MyAppVerName}
  17. AppPublisher={#MyAppPublisher}
  18. AppPublisherURL={#MyAppURL}
  19. AppSupportURL={#MyAppURL}
  20. AppUpdatesURL={#MyAppURL}
  21. DefaultDirName={pf}\{#MyAppName}
  22. DefaultGroupName={#MyAppName}
  23. OutputBaseFilename=setup
  24. Compression=lzma
  25. SolidCompression=yes
  27. [Languages]
  28. Name: english; MessagesFile: compiler:Default.isl
  30. [Code]
  31. var
  32. ConfigValues: TArrayOfString;
  34. function ConfigReadFile (FileName: String): Boolean;
  35. begin
  36. Result := LoadStringsFromFile (FileName, ConfigValues);
  37. end;
  39. function ConfigQueryValue (ValueName: String; var Value: String): Boolean;
  40. var
  41. I: LongInt;
  42. L: LongInt;
  43. S: String;
  44. begin
  45. S := ValueName + '=';
  46. L := Length (S);
  47. For I := 0 to GetArrayLength (ConfigValues) - 1 do
  48. begin
  49. if (copy (ConfigValues [I], 1, L) = S) then
  50. begin
  51. Value := copy (ConfigValues [I], L + 1,
  52. Length (ConfigValues [I]) - L);
  53. Result := TRUE;
  54. Exit;
  55. end;
  56. end;
  57. Result := FALSE;
  58. end;
  60. function ConfigWriteValue (ValueName: String; Value: String): Boolean;
  61. var
  62. I: LongInt;
  63. L: LongInt;
  64. A: LongInt;
  65. S: String;
  66. begin
  67. S := ValueName + '=';
  68. L := Length (S);
  69. A := GetArrayLength (ConfigValues);
  70. For I := 0 to A - 1 do
  71. begin
  72. if (copy (ConfigValues [I], 1, L) = S) then
  73. begin
  74. ConfigValues [I] := S + Value;
  75. Result := TRUE;
  76. Exit;
  77. end;
  78. end;
  79. SetArrayLength (ConfigValues, A + 1);
  80. ConfigValues [A] := S + Value;
  81. Result := FALSE;
  82. end;
  84. function ConfigWriteFile (FileName: String): Boolean;
  85. var
  86. bRet: Boolean;
  87. begin
  88. // FileName -> Backup.
  89. bRet := FileCopy (FileName,
  90. ExpandConstant ('{tmp}\' + ExtractFileName (FileName)),
  91. FALSE);
  92. if (bRet) then
  93. begin
  94. bRet := SaveStringsToFile (FileName, ConfigValues, FALSE);
  95. if (bRet) then
  96. begin
  97. Result := TRUE;
  98. Exit;
  99. end else
  100. begin
  101. // Maybe the backup file should be copied back here?
  102. end;
  103. end;
  104. Result := FALSE;
  105. end;
  107. procedure CurStepChanged (CurStep: TSetupStep);
  108. var
  109. Value: String;
  110. begin
  111. if (CurStep = ssInstall) then
  112. begin
  113. ConfigReadFile (ExpandConstant('{app}\settings.ini'));
  114. ConfigQueryValue ('MySetting', Value);
  115. MsgBox (Value, mbConfirmation, MB_OK);
  116. ConfigWriteValue ('MySetting', '"Ok"');
  117. ConfigWriteFile (ExpandConstant('{app}\settings.ini'));
  118. end;
  119. end;
Open UnixConfig.iss


The function ConfigReadFile () reads the config file in a string array. ConfigQueryValue () and ConfigWriteValue () read and wirte values, and the function ConfigWriteFile () writes the file back on disk. The reason for putting the file read and write operations in different functions is speed.


Last Updated on Wednesday, 03 June 2009 09:52
You need to login or register to post comments.
Discuss this item on the forums. (0 posts)
Discuss (0 posts)