Contents
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Search
Login
Who Is Online?
We have 151 guests online
Navigation
Home Source Code Inno Setup Unix-style configuration files with Inno Setup - Inno Setup Pascal script code
Most Recent
Featured Articles
Joomla 1.5 Featured Articles
Navigation
Home Source Code Inno Setup Unix-style configuration files with Inno Setup - Inno Setup Pascal script code
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Unix-style configuration files with Inno Setup - Inno Setup Pascal script code E-mail
User Rating: / 13
PoorBest 
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

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

Open UnixConfig.iss
 

UnixConfig.iss:

  1. ; Script generated by the Inno Setup Script Wizard.
  2. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
  3.  
  4. #define MyAppName "My Program"
  5. #define MyAppVerName "My Program 1.5"
  6. #define MyAppPublisher "My Company, Inc."
  7. #define MyAppURL "http://www.example.com/"
  8. #define MyAppExeName "MyProg.exe"
  9.  
  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
  26.  
  27. [Languages]
  28. Name: english; MessagesFile: compiler:Default.isl
  29.  
  30. [Code]
  31. var
  32. ConfigValues: TArrayOfString;
  33.  
  34. function ConfigReadFile (FileName: String): Boolean;
  35. begin
  36. Result := LoadStringsFromFile (FileName, ConfigValues);
  37. end;
  38.  
  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;
  59.  
  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;
  83.  
  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;
  106.  
  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;
  120.  
  121.  
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)