如何使用 NSIS 读取包含键值对的文本文件



我在文本文件上包含文件名作为键,路径/位置作为其值,由单个空格分隔。文本文件如下-

index1.html /htdocs/abc/htmls/
english.war /tomcat/webapps/
index10.html /htdocs/abc/home/auto/var/

文本文件如上所示。我想使用 nsis 读取它,我想将该 index1.html 或 english.war 等文件保留在该文件名旁边给出的位置。这里的键是文件名,它的值是它的路径。谁能告诉我如何将此文本文件读取为键值以及如何将其放置在给定路径上?

这些不是 Windows 路径,所以我真的不知道您希望如何将某些内容复制到这些位置,但解析文件可以像这样完成:

Function StrSplitOne
Exch $0 ; Separator
Exch 
Exch $1 ; String
Push $2
Push $3
StrCpy $2 0
loop:
    StrCpy $3 $1 1 $2
    IntOp $2 $2 + 1
    StrCmp $3 "" +3
    StrCmp $3 $0 0 loop
    IntOp $2 $2 - 1
    StrCpy $0 $1 $2
    IntOp $2 $2 + 1
    StrCpy $1 $1 "" $2
Pop $3
Pop $2
Exch $1 ; Remaining
Exch
Exch $0 ; Item
FunctionEnd
Section 
; Create config file for testing
InitPluginsDir
FileOpen $0 "$PluginsDirtest.txt" w
FileWrite $0 "index1.html /htdocs/abc/htmls/$r$n"
FileWrite $0 "english.war /tomcat/webapps/$r$n"
FileWrite $0 "index10.html /htdocs/abc/home/auto/var/$r$n"
FileClose $0
SectionEnd
Section
; Read and parse config file
FileOpen $0 "$PluginsDirtest.txt" r
loop:
    FileRead $0 $1
    StrCmp $1 '' eof
findnewline:
    StrCpy $2 $1 1 -1
    StrCmp $2 '$r' killnewline
    StrCmp $2 '$n' killnewline split
killnewline:
    StrCpy $1 $1 -1
    Goto findnewline
split:
    Push $1
    Push ' '
    Call StrSplitOne
    Pop $2
    Pop $3
    DetailPrint 'Use CopyFiles to copy "?:$2" to "?:$3"...'
    Goto loop
eof:
FileClose $0
SectionEnd

最新更新