将Inno Setup自定义页面字段值保存到INI文件中
问题描述:
如何读取和存储两个页面字段值的值到INI文件中?我使用ISTool在INI部分创建了两个密钥对。现在我该如何链接?将Inno Setup自定义页面字段值保存到INI文件中
的INI部分看起来是这样的:
[INI]
Filename: {app}\prefs.ini; Section: AUTH; Key: USERNAME; String:
Filename: {app}\prefs.ini; Section: AUTH; Key: PASSWORD; String:
页是这样创建的:
AuthPage := CreateInputQueryPage(wpWelcome,
'Account Information', 'Please enter your Account Information',
'');
AuthPage.Add('Username:', False);
AuthPage.Add('Password:', True);
编辑:
我做了如下补充。它不会因某种原因失效:
SetIniString('AUTH', 'USERNAME', AuthPage.Values[0], '{app}\prefs.ini')
SetIniString('AUTH', 'PASSWORD', AuthPage.Values[1], '{app}\prefs.ini')
答
这应该工作:
; 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;
答
我相信你需要写ExpandConstant('{app}\prefs.ini')
扩大{app}
不变。
+0
没有 - 你不这样做 - 这是只需要在代码段 – debracey 2012-11-29 21:56:19
答
使用scripted constant从[INI]
部分的条目:
[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;
如果转化用户输入的值到INI文件条目的逻辑是复杂的,你可能更希望使用SetIniString
从[Code]
部分。通常从CurStepChanged
事件功能:
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;
它做到了。我非常喜欢这个:“{code:GetUserName}”谢谢! – 2010-10-31 11:50:03
对于其他人获得“所需的函数或过程‘’”试图做同样的: 字符串:{代码:GetUserName} 字符串:{代码:GetUserName} 第一个将工作,第二一个不会。 –
lungic
2015-03-26 14:28:00