NSIS基于文件夹创建组件 [英] NSIS Create components based on folders

查看:251
本文介绍了NSIS基于文件夹创建组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on creating an installer that has several applications that can be optionally installed. I'd like to write my installer script so that I don't need to update it every time I add a new application to my apps directory. Is this possible with NSIS? I've got code to search through a folder for sub folders and extract their names, but am having trouble using that to make components in the installer.

文件夹结构

-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






安装程序编译但尝试安装文件时抛出打开文件时出错错误从Application cre的子文件夹中从宏有没有办法实现我要使用NSIS进行的工作?


The installer compiles but throws an "Error opening file for writing" error when trying to install files from a sub folder of Application created from the macro. Is there a way to achieve what I'm trying to do with NSIS?

我目前的工作计划是要使用一个python文件为每个子文件夹生成一个小节应用程序,并将其放在 autogen_sections.nsh文件中,实际安装程序会在文件末尾包含该文件。这似乎可行,但似乎有些笨拙。

My current working plan is to have a python file that generates a section for each sub folder of Applications and puts it in an "autogen_sections.nsh" file which the actual installer includes at the end of the file. That seems to work, but does seem a bit clunky. Any tips for how to do this with just NSIS would be greatly appreciated!

推荐答案

{PRJ_BASE},将不胜感激! \版本 不是有效路径。 SetOutPath 通常设置为 $ InstDir $ InstDir 。如果PRJ_BASE是以 $ InstDir 开头的定义,则必须使用 $ {PRJ_BASE} \releases 而不是 {PRJ_BASE} \版本

"{PRJ_BASE}\releases" is not a valid path. SetOutPath is usually set to $InstDir or a sub-folder inside $InstDir. If PRJ_BASE is a define starting with $InstDir then you must use "${PRJ_BASE}\releases" and not "{PRJ_BASE}\releases".

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

NSIS has the !system command that lets you call external programs and batch files at compile-time:

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

NSIS cannot enumerate a directory tree at compile time, you must use some kind of external application or script.

这篇关于NSIS基于文件夹创建组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆