0
votes

I have on text file which contains file name as a key and the path/location as its value separated by single space. The text file is as below-

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

The text file looks like above. I want to read it using nsis and I want to keep that index1.html or english.war etc etc files to its location given next to that file name. Here key is filename and its value is its path. Can anyone tell me how to read this text file as key value and how to place it at given path?

1

1 Answers

3
votes

Those are not Windows paths so I don't really know how you expect to copy something to those locations but parsing the file can be done like this:

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 "$PluginsDir\test.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 "$PluginsDir\test.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