将 Inno Setup 自定义页面字段值保存到 INI 文件

发布于 2024-09-30 03:49:01 字数 759 浏览 3 评论 0原文

如何读取两个页面字段值并将其存储到 INI 文件中?我使用 ISTool 在 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')

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);

I have also tried this and it does not work either:

SetIniString('AUTH', 'USERNAME', AuthPage.Values[0], '{app}\prefs.ini')
SetIniString('AUTH', 'PASSWORD', AuthPage.Values[1], '{app}\prefs.ini')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独岁月 2024-10-07 03:49:01

这应该有效:

; 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;

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;
我很坚强 2024-10-07 03:49:01

使用 [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;

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;
只等公子 2024-10-07 03:49:01

我相信您需要编写 ExpandConstant('{app}\prefs.ini') 来扩展 {app} 常量。

I believe you need to write ExpandConstant('{app}\prefs.ini') to expand the {app} constant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文