2 # update_wix.perl updates the alphabet, training and color entries in the WIX installer
5 # Ron Bessems <ron.b@promixis.com>
9 use XML
::LibXML
::PrettyPrint
;
17 open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!";
19 while (my $row = <$fh>) {
20 my @matches = $row =~ @_[1];
21 if ( scalar @matches > 0 ) {
22 push @alphabets, @matches[0];
32 #Parses Makefile.am and extras the files it lists.
33 sub parse_alphabet_makefile
{
34 return parse_makefile
( @_[0], qr/(alphabet\.(:?\w|.)*\.xml)/);
37 #Parses Makefile.am and extras the files it lists.
38 sub parse_training_makefile
{
39 return parse_makefile
( @_[0], qr/(training_(:?\w|.)*\.txt)/);
42 #Parses Makefile.am and extras the files it lists.
43 sub parse_colours_makefile
{
44 return parse_makefile
( @_[0], qr/(colour(:?\w|.)*\.xml)/);
48 # Finds the node with specified xpath, removes it's subnodes and then adds the files as children.
55 my @nodes = $xc->findnodes($xpath);
56 if ( scalar @nodes != 1 ) {
57 die "Could not find $xpath Node.";
62 $node->removeChildNodes();
63 for my $file (@
$files) {
64 my $source = "$prefix$file";
65 my $fileNode = $node->addNewChild( '', 'File' );
67 $fileNode->setAttribute('Id', $file );
68 $fileNode->setAttribute('Name', $file );
69 $fileNode->setAttribute('DiskId', '1' );
70 $fileNode->setAttribute('Source', $source);
75 # Takes the source XML and replaces the alphabets, training and colours.
79 my $alphabets = @_[1];
83 my $parser = XML
::LibXML
->new;
84 my $dom = $parser->parse_file($filename) or die("Could not load $filename");
86 my $xc = XML
::LibXML
::XPathContext
->new($dom);
87 $xc->registerNs('Wix', 'http://schemas.microsoft.com/wix/2006/wi');
89 update_nodes
($xc, q
{//Wix
:Component
[@Id="Alphabets"]}, "..\\..\\Data\\alphabets\\", $alphabets);
90 update_nodes
($xc, q
{//Wix
:Component
[@Id="Training"]}, "..\\..\\Data\\training\\", $training);
91 update_nodes
($xc, q
{//Wix
:Component
[@Id="Colours"]}, "..\\..\\Data\\colours\\", $colours);
93 open my $out_fh, '>', $filename;
94 print {$out_fh} XML
::LibXML
::PrettyPrint
->pretty_print($dom);
98 my @alphabets = parse_alphabet_makefile
("../Data/alphabets/Makefile.am");
99 my @training = parse_training_makefile
("../Data/training/Makefile.am");
100 my @colours = parse_colours_makefile
("../Data/colours/Makefile.am");
102 print("Found " . scalar @alphabets . " alphabets\n");
103 print("Found " . scalar @training . " training files\n");
104 print("Found " . scalar @colours . " colours\n");
106 my @files = ( "Installer/Dasher.wxs", "InstallerTobii/InstallerTobii.wxs", "InstallerW2K/InstallerW2K.wxs");
108 for my $file (@files) {
109 parse_xml
( $file, \
@alphabets, \
@training, \
@colours);