[英]NSIS Installer: Run a function at the directory page before installation
I created a very simple installer that doesn't add any registry keys or anything. 我创建了一个非常简单的安装程序,它不添加任何注册表项或任何内容。 It just installs some files of some python executable program.
它只是安装一些python可执行程序的文件。 The installer contains only 1 step where it asks about the installation directory and then installs the software.
安装程序仅包含第一步,询问安装目录,然后安装软件。
The problem : In case a previous version of the program is installed or the directory chosen by the user contains files in it, I would like do some checks by running a function CleanInstallationDirectory
before the installation begins . 问题 :如果安装了程序的先前版本,或者用户选择的目录中包含文件,我想通过在安装开始之前运行功能
CleanInstallationDirectory
进行一些检查。
My question is : How can I run that function when the user chooses the directory and not after the installation progress starts? 我的问题是 :当用户选择目录时而不是在安装进度开始后,如何运行该功能? I would like to run that function, and based on that function's return or based on that function internal calls display a message confirming that everything in that directory will be deleted, then if the user confirms, then the installation starts.
我想运行该功能,并基于该功能的返回或基于该功能的内部调用显示一条消息,确认该目录中的所有内容都将被删除,然后如果用户确认,则安装开始。
Alternative : If it's not possible to do that, then I'm OK with the following: If the user says "No" during the installation, the installer should go back to the directory page to ask about a different directory. 替代方法 :如果不可能这样做,那么我可以进行以下操作:如果用户在安装过程中说“否”,则安装程序应返回目录页面询问其他目录。
Here's the current NSIS installer script I have: 这是我当前拥有的NSIS安装程序脚本:
Function CleanInstallationDirectory
## do stuff
FunctionEnd
Name "My Software"
OutFile "GNOMEAcqInstaller.exe"
InstallDir "D:\MySoftware"
RequestExecutionLevel admin
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section "Installation" InstallSection
SetOutPath "$INSTDIR"
Call CleanInstallationDirectory
File /r "MyFiles\*"
SectionEnd
LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
Thank you. 谢谢。
If you look in the "Page Custom Functions" section in the MUI documentation you will find the names of some defines you can set on a per-page basis that will call a custom function. 如果您在MUI文档的“页面自定义功能”部分中查找,则会找到一些定义的名称,您可以在每页的基础上进行设置,以调用自定义功能。 You want
MUI_PAGE_CUSTOMFUNCTION_SHOW
or MUI_PAGE_CUSTOMFUNCTION_LEAVE
depending on when you want your function to run. 您希望
MUI_PAGE_CUSTOMFUNCTION_SHOW
或MUI_PAGE_CUSTOMFUNCTION_LEAVE
取决于您希望函数何时运行。
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE CleanInstallationDirectory
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
You can prevent the installer from going to the next page if you call Abort
in a custom leave function. 如果您在自定义请假函数中调用
Abort
,则可以防止安装程序进入下一页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.