nsis 从 txt 文件中读取目录?

nsis read directory from txt files?

我正在尝试从文本文件中读取目录,但没有成功!

test.txt 是一个两行文件,每个目录一行。

谁能帮帮我?

; example1.nsi
;
; This script is perhaps one of the simplest NSIs you can make. All of the
; optional settings are left to their default settings. The installer simply 
; prompts the user asking them where to install, and drops a copy of example1.nsi
; there. 

;--------------------------------

; The name of the installer
Name "Example1"

; The file to write
OutFile "example1.exe"

; The default installation directory
InstallDir $DESKTOP

; Request application privileges for Windows Vista
RequestExecutionLevel admin
!include "LogicLib.nsh"
!include FileFunc.nsh
ShowInstDetails show


;--------------------------------

; Pages


;--------------------------------


Function .onInit



functionend

; The stuff to install
Section "" ;No components page, name is not important
FileOpen [=10=] "test.txt" r
;FileSeek  1000 ; we want to start reading at the 1000th byte
FileRead [=10=]  ; we read until the end of line (including carriage return and new line) and save it to 
FileRead [=10=] 
;FileRead   10 ; read 10 characters from the next line
FileClose [=10=] ; and close the file
DetailPrint 
DetailPrint 


CopyFiles  "D:\Desktop\taobao"
  ; Set output path to the installation directory.
SetOutPath $INSTDIR


SectionEnd ; end the section

FileOpen [=11=] "test.txt" r 有两个问题。

  1. 您没有使用完整路径。
  2. 我假设最终用户机器上不存在此文件。您可能需要先从安装程序中提取它,然后才能阅读它。

另一个问题是 FileRead 在返回的字符串中包含换行符,如果不需要它们,则必须将其删除。 Windows.

上的路径中的换行符无效
; Create simple text file for this example:
!delfile /nonfatal "myexample.txt"
!appendfile "myexample.txt" "Hello$\r$\n"
!appendfile "myexample.txt" "W o r l d$\r$\n"

!include "StrFunc.nsh"
${StrTrimNewLines} ; Tell StrFunc.nsh to define this function for us

Section
SetOutPath $InstDir

InitPluginsDir ; Make sure $PluginsDir exists (it is automatically deleted by the installer when it quits)
File "/oname=$PluginsDir\data.txt" "myexample.txt" ; Extract our myexample.txt file to $PluginsDir\data.txt

FileOpen [=10=] "$PluginsDir\data.txt" r
FileRead [=10=] 
${StrTrimNewLines}  
FileRead [=10=] 
${StrTrimNewLines}  
FileClose [=10=]
DetailPrint "Line 1="
DetailPrint "Line 2="
SectionEnd