您的位置:首页 > 其它

Inno setup自定义窗口动态修改配置参数

2017-07-27 17:22 381 查看
目标:静默安装软件,动态配置参数

初次使用inno setup ,完全不了解pascal语言,网上找了很多资料,很多也很零散,总结整理下,方便大家使用

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

; Script generated by the Inno Setup Script Wizard.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "My Program"

#define MyAppVersion "1.5"

#define MyAppPublisher "My Company, Inc."

#define MyAppURL "http://www.example.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={{A026898B-6C4E-41FA-8F26-9067D95C6BE0}

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

[Languages]

Name: english; MessagesFile: compiler:Default.isl

[Tasks]

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

[Files]

Source: C:\Submetering\setup.exe; DestDir: {app}; Flags: ignoreversion

Source: C:\Submetering\uninstall\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs

; 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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: