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;
初次使用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;
相关文章推荐
- 动态修改MYSQL配置参数
- mysql动态修改的配置参数
- JS动态添加网址参数,修改网址参数值的自定义功能函数
- 演示弹出窗口传递参数,并用参数来动态修改DataGrid的列
- 演示弹出窗口传递参数,并用参数来动态修改DataGrid的列
- JS自定义功能函数实现动态添加网址参数修改网址参数值
- mybatis-generator扩展教程系列 -- 自定义配置参数修改DAO,Mapper文件后缀
- 动态修改MYSQL配置参数
- redis动态修改参数配置
- pfile spfile静态和动态修改配置参数
- JS自定义功能函数实现动态添加网址参数修改网址参数值
- JS自定义功能函数实现动态添加网址参数修改网址参数值
- C#2005 动态修改配置参数
- mysql 动态修改配置参数
- 动态创建或修改数据窗口的参数
- 动态修改MYSQL配置参数
- log4j输出多个自定义日志文件,动态配置路径
- 以员工号和工资为参数,修改指定员工的工资。使用不带占位符的动态dml语句实现
- (六)、SpringBoot 自定义配置属性,可以在application.properties中修改
- 配置文件的动态修改