0

我有一个包含以下行的 .txt 文件:

  • 应用程序1
  • 应用程序2
  • 应用程序3
  • ...
  • 应用程序N

在我制作安装程序之前,我在 ${srcdir} 中有这些文件:

  • ${srcdir}\app1
  • ${srcdir}\app2
  • ${srcdir}\app3
  • ...
  • ${srcdir}\appN

文件列表总是会改变,所以我需要手动更正 nsi-script。

如何使用取决于 file.txt 的列表视图在自定义页面上制作复选框列表?

现在我正在使用组件页面和简单的构造来检查文件。

SectionGroup /e "Installing apps" SecApps

!if /FileExists "E:\src\app.dll"
Section "Install app1"
SetOutPath "$InstDir"
File "E:\src\app.dll"
SectionEnd
!endif

!if /FileExists "E:\src\app2.dll"
Section "Install app2"
SetOutPath "$InstDir"
File "E:\src\app2.dll"
SectionEnd
!endif

!if /FileExists "E:\src\app3.dll"
Section "Install app3"
SetOutPath "$InstDir"
File "E:\src\app3.dll"
SectionEnd
!endif

SectionGroupEnd
4

1 回答 1

0

当你想在编译时做一些高级的事情时,最好的选择通常是调用外部脚本/应用程序!system

!define srcdir "."

; Make some dummy files for this example
!appendfile "${srcdir}\foo.txt" "!"
!appendfile "${srcdir}\bar.txt" "!"
!delfile /nonfatal "${srcdir}\filelist.txt"
!appendfile "${srcdir}\filelist.txt" "foo.txt$\r$\n"
!appendfile "${srcdir}\filelist.txt" "bar.txt$\r$\n"

; Make batch file for this example (In a real installer you probably don't want to generate the .bat on the fly like this)
!define /redef batch "${__FILE__}\..\parsefile.bat"
!delfile /nonfatal "${batch}"
!appendfile "${batch}" "@echo off&setlocal ENABLEEXTENSIONS$\r$\n"
!appendfile "${batch}" `for /F "usebackq" %%A in ("%~2") do ($\r$\n`
!appendfile "${batch}" '  >> %1 echo Section "%%~nA"$\r$\n'
!appendfile "${batch}" '  >> %1 echo File "%%A"$\r$\n'
!appendfile "${batch}" '  >> %1 echo SectionEnd$\r$\n'
!appendfile "${batch}" ")$\r$\n"

!tempfile nsh
!system '"${batch}" "${nsh}" "${srcdir}\filelist.txt"' = 0
!include "${nsh}"
!delfile "${nsh}"
!undef nsh

Page Components
Page InstFiles
于 2020-07-07T21:33:27.437 回答