nsis читать каталог из txt файлов? - PullRequest
0 голосов
/ 06 января 2019

Я пытаюсь прочитать каталог из текстового файла, но он не работает!

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 $0 "test.txt" r
;FileSeek $4 1000 ; we want to start reading at the 1000th byte
FileRead $0 $1 ; we read until the end of line (including carriage return and new line) and save it to $1
FileRead $0 $2
;FileRead $4 $2 10 ; read 10 characters from the next line
FileClose $0 ; and close the file
DetailPrint $1
DetailPrint $2


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


SectionEnd ; end the section

1 Ответ

0 голосов
/ 07 января 2019

FileOpen $0 "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 $0 "$PluginsDir\data.txt" r
FileRead $0 $1
${StrTrimNewLines} $1 $1
FileRead $0 $2
${StrTrimNewLines} $2 $2
FileClose $0
DetailPrint "Line 1=$1"
DetailPrint "Line 2=$2"
SectionEnd
...