【问题标题】:NSIS Create components based on foldersNSIS 基于文件夹创建组件
【发布时间】:2018-09-26 15:28:24
【问题描述】:

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

安装程序编译但在尝试从宏创建的应用程序的子文件夹安装文件时抛出“错误打开文件以进行写入”错误。有没有办法实现我想用 NSIS 做的事情?

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

【问题讨论】:

    标签: dynamic components nsis sections


    【解决方案1】:

    "{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 无法在编译时枚举目录树,您必须使用某种外部应用程序或脚本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 2015-07-25
      • 2018-10-01
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      相关资源
      最近更新 更多