Inno Setup 系列之自定义窗口动态修改配置参数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36190858/article/details/84898679

需求

静默安装软件,动态配置参数

解决

第一步:按引导创建脚本,这部分就不描述了

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "My Test"
#define MyAppVersion "1.0"
#define MyAppPublisher "My Test, Test Inno Setup."
#define MyAppURL "http://www.test.com/"
#define MyAppExeName "setup.exe"

[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={{3FC1FD05-BEC7-430A-B7DB-F07155FDE93E} 
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DisableProgramGroupPage=yes
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
UsePreviousAppDir=yes
DisableStartupPrompt =no
PrivilegesRequired=admin

[Languages]

;Name: english; MessagesFile: compiler:Default.isl
Name: "chinese"; MessagesFile: "compiler:Languages\Chinese.isl"

[Tasks]

Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: checkablealone

[Files]

Source: C:\Test\setup.exe; DestDir: {app}; Flags: ignoreversion
Source: C:\Test\uninstall\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
Source: ISTask.dll; DestDir: {app}; Flags: ignoreversion; Attribs: hidden
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]

Name: {commonprograms}\{#MyAppName}; Filename: {app}\{#MyAppExeName}
Name: {commondesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon

[Run]

Filename: {app}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}; Flags: nowait postinstall skipifsilent

第二步:创建自定义窗口

[Code]

var
myPage:TwizardPage;//定义窗口
ed1:TEdit;//定义输入框
Lbl1: TNewStaticText;//标题

//定义校验方法,校验失败时,下一步按钮为空

procedure Key_Form_KeyChange(Sender: TObject);
begin
if(length(ed1.Text) <= 6) then
        WizardForm.NextButton.Enabled := True
    else
WizardForm.NextButton.Enabled := False;
end;

//初始化引导 窗口

procedure InitializeWizard();
begin
myPage:=CreateCustomPage(wpWelcome, '标题:标题', '描述:描述');
Lbl1 := TNewStaticText.Create(myPage);
Lbl1.Left := ScaleX(5);
Lbl1.Top := ScaleY(5);
Lbl1.Width := ScaleX(250);
Lbl1.Height := ScaleY(50);
Lbl1.Caption := '输入框标题';
Lbl1.Parent := myPage.Surface;
ed1:=TEdit.Create(myPage);
ed1.Width:=ScaleX(410);
ed1.Top := ScaleY(25);
ed1.Text :='999910';
ed1.Parent:=myPage.Surface;
ed1.OnChange := @Key_Form_KeyChange;//添加校验方法
end;

//添加步骤

procedure CurStepChanged(CurStep: TSetupStep);
var
    fileName,tempStr:String;
    svArray: TArrayOfString;
    nLines,i:Integer;
begin

if CurStep=ssinstall then
//安装前执行

       if CurStep=ssPostinstall then

//复制文件后执行

            begin

//开始修改文件

fileName := ExpandConstant('{app}\文件名');
LoadStringsFromFile(fileName, svArray);
nLines := GetArrayLength(svArray);//读取文件
  for i := 0 to nLines - 1 do
  begin
tempStr := svArray[i];
if (1 = Pos('查找内容', tempStr)) then//查找目标行
begin
  svArray[i] := ExpandConstant('修改内容'+ed1.Text);//修改行
  StringChangeEx(svArray[i], '\', '/', True);
end;
  end;
  SaveStringsToFile(fileName, svArray, false);
end;

if CurStep=ssDone then

//安装完成后执行

end;

Inno Setup 中文帮助文档
https://download.csdn.net/download/qq_36190858/10836946

猜你喜欢

转载自blog.csdn.net/qq_36190858/article/details/84898679