How do I read and store the values of two page field values to an INI file? I created two key pairs at the INI section using ISTool. Now how do I link this up?
The INI Section looks like this:
[INI]
Filename: {app}\prefs.ini; Section: AUTH; Key: USERNAME; String:
Filename: {app}\prefs.ini; Section: AUTH; Key: PASSWORD; String:
Page is created like this:
AuthPage := CreateInputQueryPage(wpWelcome,
'Account Information', 'Please enter your Account Information',
'');
AuthPage.Add('Username:', False);
AuthPage.Add('Password:', True);
EDIT:
I made the following additions. It doesn't work for some reason:
SetIniString('AUTH', 'USERNAME', AuthPage.Values[0], '{app}\prefs.ini')
SetIniString('AUTH', 'PASSWORD', AuthPage.Values[1], '{app}\prefs.ini')
This should work:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{82C8C949-44A8-49C4-8CED-8DD0ACD0DCCF}
AppName=My Program
AppVerName=My Program 1.5
AppPublisher=My Company, Inc.
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "C:\util\innosetup\5.3.7\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
Name: "{commondesktop}\My Program"; Filename: "{app}\MyProg.exe"; Tasks: desktopicon
[Run]
Filename: "{app}\MyProg.exe"; Description: "{cm:LaunchProgram,My Program}"; Flags: nowait postinstall skipifsilent
[INI]
Filename: {app}\prefs.ini; Section: AUTH; Key: USERNAME; String: {code:GetUserName}
Filename: {app}\prefs.ini; Section: AUTH; Key: PASSWORD; String: {code:GetPassword}
[code]
var
AuthPage : TInputQueryWizardPage;
procedure InitializeWizard;
begin
AuthPage := CreateInputQueryPage(wpWelcome,
'Account Information', 'Please enter your Account Information',
'');
AuthPage.Add('Username:', False);
AuthPage.Add('Password:', True);
end;
function AuthForm_NextButtonClick(Page: TWizardPage): Boolean;
begin
Result := True;
end;
function GetUserName(Param: String): string;
begin
result := AuthPage.Values[0];
end;
function GetPassword(Param: String): string;
begin
result := AuthPage.Values[1];
end;
Use a scripted constant from [INI]
section entries:
[INI]
Filename: {app}\prefs.ini; Section: AUTH; Key: USERNAME; String: {code:GetAuth|0}
Filename: {app}\prefs.ini; Section: AUTH; Key: PASSWORD; String: {code:GetAuth|1}
[Code]
var
AuthPage: TInputQueryWizardPage;
procedure InitializeWizard();
begin
AuthPage := CreateInputQueryPage(wpWelcome,
'Account Information', 'Please enter your Account Information',
'');
AuthPage.Add('Username:', False);
AuthPage.Add('Password:', True);
end;
function GetAuth(Param: String): string;
begin
Result := AuthPage.Values[StrToInt(Param)];
end;
If a logic of transforming user-entered values into the INI file entries is complex, you may rather want to use SetIniString
from [Code]
section. Typically from CurStepChanged
event function:
procedure CurStepChanged(CurStep: TSetupStep);
var
IniFileName: string;
begin
if CurStep = ssPostInstall then
begin
IniFileName := ExpandConstant('{app}\prefs.ini');
SetIniString('AUTH', 'USERNAME', AuthPage.Values[0], IniFileName);
SetIniString('AUTH', 'PASSWORD', AuthPage.Values[1], IniFileName);
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With