Dynamic NSIS基于文件夹创建组件

Dynamic NSIS基于文件夹创建组件,dynamic,components,nsis,sections,Dynamic,Components,Nsis,Sections,我正在创建一个安装程序,它有几个可以选择安装的应用程序。我想编写我的安装程序脚本,这样我就不需要在每次向我的应用程序目录添加新应用程序时更新它。NSIS能做到这一点吗?我有代码在文件夹中搜索子文件夹并提取它们的名称,但是在安装程序中使用它来制作组件时遇到了麻烦 文件夹结构 -Install_Directory -Main_Application -Applications -App_A -App_B -App_C

我正在创建一个安装程序,它有几个可以选择安装的应用程序。我想编写我的安装程序脚本,这样我就不需要在每次向我的应用程序目录添加新应用程序时更新它。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

当前代码

-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

当安装程序试图从宏创建的应用程序的子文件夹中安装文件时,安装程序会编译文件,但会抛出“打开文件进行写入时出错”错误。有什么方法可以实现我对NSIS的目标吗

我目前的工作计划是使用一个python文件,为应用程序的每个子文件夹生成一个节,并将其放入“autogen_sections.nsh”文件中,实际安装程序会将该文件包含在文件末尾。这似乎有效,但确实有点笨重。任何关于如何使用NSIS的提示都将不胜感激

“{PRJ_BASE}\releases”
不是有效路径
SetOutPath
通常设置为
$InstDir
$InstDir
内的子文件夹。如果PRJ_BASE是以
$InstDir
开头的定义,则必须使用
“${PRJ_BASE}\releases”
而不是
“{PRJ_BASE}\releases”

NSIS拥有
!允许您在编译时调用外部程序和批处理文件的系统
命令:

; 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不能在编译时枚举目录树,必须使用某种外部应用程序或脚本