InnoSetup是一个开源的安装包制作工具。
如果是简单的安装,例如安装流程只需要用户选一个安装路径,那么直接按引导操作就行,甚至不需要写代码。
如果有更复杂的需求,通常需要使用Inno支持的Pascal脚本进行自定义。
Inno打包程序脚本引导部分比较简单,资料网上也非常多,这里不再赘述。
对于Revit插件安装,特别的是最后要把addin文件复制到合适的位置,并且修改内容,指向对应文件,这部分网上内容相对少,记录一下。
下面三个示例,第一个是常规打包,
第二个与第一个类似,但增加了一个自定义页面,让用户设置一个资源存放的文件夹,计划用于存放依赖资源,
第三个则是通过调用一个外部程序来执行addin修改操作——如果对Pascal脚本不熟悉,可以用熟悉的语言写一个程序,然后在脚本中进行调用,从而执行类似操作
示例一(常规打包)
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "MyRevitPlugin"
#define MyAppVersion "1.0"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
[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={{782BAC7F-2B51-4378-B9CC-8559EB6E2CE7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf64}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=F:\packet_ex
OutputBaseFilename=mysetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
// 调整dll路径;addin.template其实是常规的addin文件改了下文件名
[Files]
Source: "C:\Users\lisiting01\source\repos\MyRevitPlugin\MyRevitPlugin\bin\x64\Debug\MyRevitPlugin.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\addin\2019.addin.template"; DestDir: "{app}\addin"; Flags: ignoreversion
[UninstallDelete]
Type: files; Name: "C:\ProgramData\Autodesk\Revit\Addins\2019\RevitPlugin.addin"
[Code]
var
InstallPath: string;
// CurStepChanged事件,安装阶段变化时触发
procedure CurStepChanged(CurStep: TSetupStep);
var
AddinTemplateFile: string;
AddinTargetFile: string;
AddinContentANSI: AnsiString;
AddinContentUCS: string;
begin
// 到达 ssPostInstall 阶段时(安装后)触发事件
if CurStep = ssPostInstall then
begin
// 安装路径
InstallPath := ExpandConstant('{app}');
// .addin 模板文件和目标文件路径
AddinTemplateFile := InstallPath + '\addin\2019.addin.template';
AddinTargetFile := 'C:\ProgramData\Autodesk\Revit\Addins\2019\RevitPlugin.addin';
// 注册 .addin 文件并指向到安装目录
if LoadStringFromFile(AddinTemplateFile, AddinContentANSI) then
begin
AddinContentUCS := String(AddinContentANSI);
StringChangeEx(AddinContentUCS, '{InstallPath}', InstallPath, True);
SaveStringToFile(AddinTargetFile, AddinContentUCS, False);
end;
end;
end;
示例二(自定义页面)
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "MyRevitPlugin"
#define MyAppVersion "1.0"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
[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={{782BAC7F-2B51-4378-B9CC-8559EB6E2CE7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf64}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=F:\packet_ex
OutputBaseFilename=mysetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
// 调整dll路径;addin.template其实是常规的addin文件改了下文件名
[Files]
Source: "C:\Users\lisiting01\source\repos\MyRevitPlugin\MyRevitPlugin\bin\x64\Debug\MyRevitPlugin.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\addin\2019.addin.template"; DestDir: "{app}\addin"; Flags: ignoreversion
[UninstallDelete]
Type: files; Name: "{app}\Settings.ini"
Type: files; Name: "C:\ProgramData\Autodesk\Revit\Addins\2019\RevitPlugin.addin"
[Code]
var
InstallPath: string;
InputDirWizardPage: TInputDirWizardPage;
// InitializeWizard事件,初始化安装向导时触发
procedure InitializeWizard;
begin
// 创建自定义页面
InputDirWizardPage := CreateInputDirPage(wpSelectDir,
'设置资源文件夹路径', '这个文件夹将用于存放相关资源(族、贴图、渲染资源等)',
'设置资源文件夹,然后点击下一步',
True, 'BIMResource');
InputDirWizardPage.Add('');
InputDirWizardPage.Values[0] := ExpandConstant('{userdocs}')+'\BIMResource';
end;
// CurStepChanged事件,安装阶段变化时触发
procedure CurStepChanged(CurStep: TSetupStep);
var
AddinTemplateFile: string;
AddinTargetFile: string;
AddinContentANSI: AnsiString;
AddinContentUCS: string;
ConfigFile: string;
begin
// 到达 ssPostInstall 阶段时(安装后)触发事件
if CurStep = ssPostInstall then
begin
// 安装路径
InstallPath := ExpandConstant('{app}');
// .addin 模板文件和目标文件路径
AddinTemplateFile := InstallPath + '\addin\2019.addin.template';
AddinTargetFile := 'C:\ProgramData\Autodesk\Revit\Addins\2019\RevitPlugin.addin';
// 配置文件路径
ConfigFile := InstallPath + '\Settings.ini';
// 注册 .addin 文件并指向到安装目录
if LoadStringFromFile(AddinTemplateFile, AddinContentANSI) then
begin
AddinContentUCS := String(AddinContentANSI);
StringChangeEx(AddinContentUCS, '{InstallPath}', InstallPath, True);
SaveStringToFile(AddinTargetFile, AddinContentUCS, False);
end;
// 创建用户指定的资源文件夹
CreateDir(InputDirWizardPage.Values[0]);
// 设置配置文件
SaveStringToFile(ConfigFile, 'BIMResource=' + InputDirWizardPage.Values[0] , False);
end;
end;
// 更新准备安装页的信息
function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
S: String;
begin
S := '';
S := S + '安装路径:' + NewLine;
S := S + Space + ExpandConstant('{app}') + NewLine;
S := S + NewLine;
S := S + '资源路径:' + NewLine;
S := S + Space + InputDirWizardPage.Values[0] + NewLine;
Result := S;
end;
示例三(调用程序执行)
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "MyRevitPlugin"
#define MyAppVersion "1.0"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
[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={{782BAC7F-2B51-4378-B9CC-8559EB6E2CE7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf64}\{#MyAppName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=F:\packet_ex
OutputBaseFilename=mysetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
// 调整dll路径;addin.template其实是常规的addin文件改了下文件名
[Files]
Source: "C:\Users\lisiting01\source\repos\MyRevitPlugin\MyRevitPlugin\bin\x64\Debug\MyRevitPlugin.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "F:\SetupProgram.exe"; DestDir: "{app}"; Flags: ignoreversion
[UninstallDelete]
Type: files; Name: "C:\ProgramData\Autodesk\Revit\Addins\2019\RevitPlugin.addin"
[Code]
var
InstallPath: string;
// CurStepChanged事件,安装阶段变化时触发
procedure CurStepChanged(CurStep: TSetupStep);
begin
// 到达 ssPostInstall 阶段时(安装后)触发事件
if CurStep = ssPostInstall then
begin
// 安装路径
InstallPath := ExpandConstant('{app}');
// 执行 SetupProgram.exe
Exec(ExpandConstant(InstallPath + '\SetupProgram.exe'), '', '', SW_SHOW, ewNoWait, ResultCode);
end;
end;
资料:
InnoSetup文档:https://jrsoftware.org/ishelp.php
中文安装语言:https://github.com/kira-96/Inno-Setup-Chinese-Simplified-Translation