我必须在安装的post部分编写配置文件,如果产品的旧版本存在,则从配置文件中读取。
配置文件是XML配置文件(.config) 配置文件将有如此多的条目,如
<name>
abcd
</name>
<company>
xyz
</company>
<choise>
choise1
</choise>
如何只读取标签的文本并仅覆盖选择标签的文本。
答案 0 :(得分:2)
NSIS共有4个XML插件可供选择; NsisXML (by Wizou),XML plug-in,NsisXML (by Joel)和NsXML
使用NsisXML(Wizou):
Outfile "$%temp%\NSISTest.exe"
RequestExecutionLevel user
Installdir "$Temp"
Showinstdetails show
!include LogicLib.nsh
Page InstFiles
!define XMLFILE "$instdir\myxml.xml"
Section
StrCpy $9 "Did not exist"
nsisXML::create
nsisXML::load "${XMLFILE}"
${If} $0 = 0
;build a new basic XML file:
nsisXML::create
nsisXML::createProcessingInstruction "xml" 'version="1.0" encoding="UTF-8" standalone="yes"'
nsisXML::appendChild
nsisXML::release $2
${EndIf}
nsisXML::select '/choise'
${If} $2 = 0
StrCpy $1 $0
nsisXML::createElement "choise"
nsisXML::appendChild
${Else}
nsisXML::getText
StrCpy $9 $3
${EndIf}
DetailPrint "Old value: $9"
System::Call 'kernel32::GetTickCount()i.r5' ;Get some "random" value to save
nsisXML::setText "$5"
nsisXML::release $2
nsisXML::save "${XMLFILE}"
nsisXML::release $0
DetailPrint "Saved new value: $5"
SectionEnd
首先我得到:
Old value: Did not exist
Saved new value: 709289703
Completed
在第二轮比赛中我得到了:
Old value: 709289703
Saved new value: 709308687
Completed