Talk:NsisXML plug-in (by Wizou): Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
(Sample code for .NET config files)
Line 1: Line 1:
Many people find known memory leaks unacceptable. Granted, the NSIS probally won't listen on a port, and the memory will probally be freed after te process exits on 2000+. However, I don't think 9x cleans up memory too well and I've discovered memory leaks in my code that I wrote on a 2000 machine when it crashed on a NT 4.0 Machine. --[[User:Zippy1981|Zippy1981]] 08:56, 5 September 2006 (PDT)
Many people find known memory leaks unacceptable. Granted, the NSIS probally won't listen on a port, and the memory will probally be freed after te process exits on 2000+. However, I don't think 9x cleans up memory too well and I've discovered memory leaks in my code that I wrote on a 2000 machine when it crashed on a NT 4.0 Machine. --[[User:Zippy1981|Zippy1981]] 08:56, 5 September 2006 (PDT)
== Example Code - .NET Config Files ==
I'm using this plugin to adjust .NET config files.  It works wonderfully.  Here's what it looks like:
<highlight-nsis>
!macro AdjustConfigValue ConfigFile Key Value
  DetailPrint "Config: adding '${Key}'='${Value}' to ${ConfigFile}"
  nsisXML::create
  nsisXML::load ${ConfigFile}
  nsisXML::select "/configuration/appSettings/add[@key='${Key}']"
  nsisXML::setAttribute "value" ${Value}
  nsisXML::save ${ConfigFile}
!macroend
!insertmacro AdjustConfigValue "$INSTDIR\MyApp.exe.config" "ServiceURL" "http://127.0.0.1"
</highlight-nsis>
This adds a URL to a config file that resembles the following one:
<highlight-xml>
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="ServiceURL" value=""/>
  </appSettings>
</configuration>
</highlight-xml>
Note that in this case the specified key is being ''updated'', not added.  That is nice for me because my test environment (and what's in SVN) already includes the key.
It works by making an XPath query to the config file for an element named 'add' with an attribute 'key' equal to whatever variable <tt>${Key}</tt> is passed into the macro.  It's probably not hard to see how it might be adjusted for database connection strings.
Good luck!  --[[User:Ladenedge|Ladenedge]] 00:59, 10 February 2010 (UTC)

Revision as of 00:59, 10 February 2010

Many people find known memory leaks unacceptable. Granted, the NSIS probally won't listen on a port, and the memory will probally be freed after te process exits on 2000+. However, I don't think 9x cleans up memory too well and I've discovered memory leaks in my code that I wrote on a 2000 machine when it crashed on a NT 4.0 Machine. --Zippy1981 08:56, 5 September 2006 (PDT)

Example Code - .NET Config Files

I'm using this plugin to adjust .NET config files. It works wonderfully. Here's what it looks like:

!macro AdjustConfigValue ConfigFile Key Value
 
   DetailPrint "Config: adding '${Key}'='${Value}' to ${ConfigFile}"
 
   nsisXML::create
   nsisXML::load ${ConfigFile}
 
   nsisXML::select "/configuration/appSettings/add[@key='${Key}']"
   nsisXML::setAttribute "value" ${Value}
 
   nsisXML::save ${ConfigFile}
 
!macroend
 
!insertmacro AdjustConfigValue "$INSTDIR\MyApp.exe.config" "ServiceURL" "http://127.0.0.1"

This adds a URL to a config file that resembles the following one:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="ServiceURL" value=""/>
  </appSettings>
</configuration>

Note that in this case the specified key is being updated, not added. That is nice for me because my test environment (and what's in SVN) already includes the key.

It works by making an XPath query to the config file for an element named 'add' with an attribute 'key' equal to whatever variable ${Key} is passed into the macro. It's probably not hard to see how it might be adjusted for database connection strings.

Good luck! --Ladenedge 00:59, 10 February 2010 (UTC)