NSIS 基于文件夹创建组件

NSIS Create components based on folders

我正在创建一个安装程序,其中包含多个可选择安装的应用程序。我想编写我的安装程序脚本,这样我就不需要在每次将新应用程序添加到我的应用程序目录时都更新它。 NSIS 可以吗?我有代码可以在文件夹中搜索子文件夹并提取它们的名称,但是我无法使用它在安装程序中制作组件。


文件夹结构

-Install_Directory
    -Main_Application    
    -Applications
        -App_A
        -App_B
        -App_C
        -...

当前代码

!macro insert_application_section name
  Section "${name}"
    SetOutPath "{PRJ_BASE}\releases"
    File /nonfatal /r "..\releases${name}"
  SectionEnd
!macroend

SectionGroup "Applications"
    !insertmacro insert_release_section "App_A"
SectionGroupEnd

安装程序编译但在尝试从宏创建的应用程序子文件夹安装文件时抛出 "Error opening file for writing" 错误。有没有办法实现我想用 NSIS 做的事情?

我目前的工作计划是有一个 python 文件,它为应用程序的每个子文件夹生成一个部分,并将其放入一个 "autogen_sections.nsh" 文件中,实际安装程序包含在该文件的末尾文件。这似乎有效,但似乎有点笨拙。非常感谢有关如何仅使用 NSIS 执行此操作的任何提示!

"{PRJ_BASE}\releases" 不是有效路径。 SetOutPath 通常设置为 $InstDir$InstDir 中的子文件夹。如果 PRJ_BASE 是以 $InstDir 开头的定义,那么您必须使用 "${PRJ_BASE}\releases" 而不是 "{PRJ_BASE}\releases".

NSIS 具有 !system 命令,可让您在编译时调用外部程序和批处理文件:

; Generate batch file on the fly because this is a self-contained example
!delfile "creatensh.bat"
!appendfile "creatensh.bat" '@echo off$\r$\n'
!appendfile "creatensh.bat" 'cd /D %1$\r$\n'
!appendfile "creatensh.bat" 'FOR /D %%A in (*) DO ($\r$\n'
!appendfile "creatensh.bat" '   >> %2 echo !insertmacro insert_application_section "%%~A"$\r$\n'
!appendfile "creatensh.bat" ')$\r$\n'

; Running the batch file
!define PRJ_BASE "$InstDir\Something"

!macro insert_application_section name
  Section "${name}"
    SetOutPath "${PRJ_BASE}\releases"
    File /nonfatal /r "..\releases${name}"
  SectionEnd
!macroend

!tempfile tmpnsh
!system '"creatensh.bat" "c:\myfiles\Install_Directory\Applications" "${tmpnsh}"'
!include "${tmpnsh}"
!delfile "${tmpnsh}"

NSIS 无法在编译时枚举目录树,您必须使用某种外部应用程序或脚本。