I have a very simple support installer that updates several XML databases with new versions:
[Files]
Source: "MSA_PublicTalks_???.xml"; DestDir: "{param:InstallPath}"; Flags: ignoreversion
Each of the database files has a Version
attribute. For example:
<?xml version="1.0" encoding="utf-8"?>
<PublicTalkTitles Version="1.0">
<!-- English -->
<eng>
<PublicTalk Number="1" IssueDate="2015-09-01" Media="false">Theme</PublicTalk>
<PublicTalk Number="1" IssueDate="2015-09-01" Media="false">Theme</PublicTalk>
</eng>
</PublicTalkTitles>
Each database file name includes the language code. For example:
MSA_PublicTalks_ENG.xml
Now, I have another database file, which is not part of the installer, that I want o put on my website. It looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<PublicTalkTitleUpdates>
<Database Language="eng" Version="1.0"/>
<Database Language="esp" Version="1.0"/>
</PublicTalkTitleUpdates>
What I would like to do is automate the creation of this latter database when I build this update installer:
n.n
.Can we do this with Inno Setup?
Try a powershell script
using assembly System.Xml.Linq
$folder = 'c:\temp'
$filename = 'c:\temp\test.xml'
$pattern = 'MSA_PublicTalks_(?<lang>[^.]+).xml'
$template = @"
<?xml version="1.0" encoding="utf-8"?>
<PublicTalkTitles Version="1.0">
</PublicTalkTitles>
"@
$doc = [System.Xml.Linq.XDocument]::Parse($template)
$talkTitles = $doc.Root
$files = Get-ChildItem -Path $folder | Where-Object { $_.Name -Match $pattern }
foreach($file in $files)
{
$file -Match $pattern | out-null
$lang = $Matches['lang'].ToLower()
$doc2 = [System.Xml.Linq.XDocument]::Load($file.fullname)
$root = $doc2.Root
$ver = $root.Attribute('Version').Value
$database = [System.Xml.Linq.XElement]::new([System.Xml.Linq.XName]::Get('Database'))
$language = [System.Xml.Linq.XAttribute]::new([System.Xml.Linq.XName]::Get('Language'),$lang)
$database.Add($language)
$version = [System.Xml.Linq.XAttribute]::new([System.Xml.Linq.XName]::Get('Version'),$ver)
$database.Add($version)
$talkTitles.Add($database)
}
$doc.Save($filename)