我必须在安装的后期部分编写一个配置文件,如果存在旧版本的产品,则必须从配置文件中读取。
配置文件是 XML 配置文件 (.config)
配置文件将有很多条目,例如
<name>
abcd
</name>
<company>
xyz
</company>
<choise>
choise1
</choise>
如何仅读取选择标签的文本并仅覆盖选择标签的文本。
NSIS一共有4个XML插件可供选择;NsisXML(由 Wizou 提供) http://nsis.sourceforge.net/NsisXML_plug-in_%28by_Wizou%29, XML 插件 http://nsis.sourceforge.net/XML_plug-in, NsisXML(作者:Joel) http://nsis.sourceforge.net/NsisXML_plug-in_%28by_Joel%29 and NsXML http://nsis.sourceforge.net/NsXML_plug-in_%28by_rsegal%29
使用 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)