简体   繁体   English

NSIS安装程序:安装前在目录页面上运行功能

[英]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_SHOWMUI_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.

相关问题 为什么即使只选中了一个应用程序复选框,NSIS 安装程序也会为两个应用程序安装运行两次? - Why does NSIS installer run twice for two application installation even if only one app checkbox is selected? nsis 安装程序 autoexits/ 自动关闭,我正在使用 pre 和 show 函数来显示目录 MUI 页面 - nsis installer autoexits/ closes automatically , i am using pre and show functions to show a directory MUI page NSIS 无法运行驱动程序安装程序批处理文件 - NSIS failing to run driver installer batch file NSIS,在安装期间检测目录是否存在 - NSIS, detect if directory exists during installation NSIS:以兼容模式运行安装子文件 - NSIS: Run sub-file of Installation in compatibility mode Nsis 脚本:尝试编写一个脚本,从 zip 文件中提取特定目录并将其添加为安装程序的一部分(可执行文件) - Nsis script: Trying to write a script which extracts specific directory from a zip file and adds it as a part of installer(executable) wix,InnoSetup,nsis的安装程序开销 - Installer overhead of wix, InnoSetup, nsis 安装前运行自定义操作 - Visual Studio 安装程序 - Running Custom Action before installation - Visual studio installer NSIS卸载程序工作目录 - NSIS Uninstaller Working Directory 基本安装的简单 NSIS 配方 - Simple NSIS recipe for basic installation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM