diff options
author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2013-01-03 12:32:54 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@gmail.com> | 2013-01-06 16:38:26 +0100 |
commit | d4caf80554c05c9acc9e29ae8ab399b49fd0e06d (patch) | |
tree | ebcc0eb98e005af0aaa5730f5d7c8a7639b203f3 | |
parent | 886d64819cb0b686b097b9a05cec9dd9f566e37a (diff) | |
download | msitools-d4caf80554c05c9acc9e29ae8ab399b49fd0e06d.tar.gz msitools-d4caf80554c05c9acc9e29ae8ab399b49fd0e06d.tar.xz msitools-d4caf80554c05c9acc9e29ae8ab399b49fd0e06d.zip |
Populate Directory table
-rw-r--r-- | src/builder.vala | 12 | ||||
-rw-r--r-- | src/msi.vala | 28 | ||||
-rw-r--r-- | src/wix.vala | 58 |
3 files changed, 93 insertions, 5 deletions
diff --git a/src/builder.vala b/src/builder.vala index 151c79a..4a50c79 100644 --- a/src/builder.vala +++ b/src/builder.vala @@ -43,6 +43,18 @@ namespace Wixl { public override void visit_media (WixMedia media) throws GLib.Error { db.table_media.add (media.Id, media.EmbedCab, media.DiskPrompt, "#" + media.Cabinet); } + + public override void visit_directory (WixDirectory dir) throws GLib.Error { + if (dir.parent.get_type () == typeof (WixProduct)) { + if (dir.Id != "TARGETDIR") + throw new Wixl.Error.FAILED ("Invalid root directory"); + db.table_directory.add (dir.Id, null, dir.Name); + } else if (dir.parent.get_type () == typeof (WixDirectory)) { + var parent = dir.parent as WixDirectory; + db.table_directory.add (dir.Id, parent.Id, dir.Name); + } else + warning ("unhandled parent type %s", dir.parent.name); + } } } // Wixl diff --git a/src/msi.vala b/src/msi.vala index 24090be..48c2a92 100644 --- a/src/msi.vala +++ b/src/msi.vala @@ -288,6 +288,31 @@ namespace Wixl { } } + class MsiTableDirectory: MsiTable { + construct { + name = "Directory"; + } + + public void add (string Directory, string? Parent, string DefaultDir) throws GLib.Error { + var rec = new Libmsi.Record (3); + if (!rec.set_string (1, Directory) || + !rec.set_string (2, Parent) || + !rec.set_string (3, DefaultDir)) + throw new Wixl.Error.FAILED ("failed to add record"); + + records.append (rec); + } + + public override void create (Libmsi.Database db) throws GLib.Error { + var query = new Libmsi.Query (db, "CREATE TABLE `Directory` (`Directory` CHAR(72) NOT NULL, `Directory_Parent` CHAR(72), `DefaultDir` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `Directory`)"); + query.execute (null); + + query = new Libmsi.Query (db, "INSERT INTO `Directory` (`Directory`, `Directory_Parent`, `DefaultDir`) VALUES (?, ?, ?)"); + foreach (var r in records) + query.execute (r); + } + } + class MsiTable_Validation: MsiTable { construct { name = "_Validation"; @@ -353,6 +378,7 @@ namespace Wixl { public MsiTableProperty table_property; public MsiTableIcon table_icon; public MsiTableMedia table_media; + public MsiTableDirectory table_directory; HashTable<string, MsiTable> tables; @@ -378,6 +404,7 @@ namespace Wixl { table_property = new MsiTableProperty (); table_icon = new MsiTableIcon (); table_media = new MsiTableMedia (); + table_directory = new MsiTableDirectory (); foreach (var t in new MsiTable[] { new MsiTableAdminExecuteSequence (), @@ -387,6 +414,7 @@ namespace Wixl { new MsiTableFile (), new MsiTableInstallExecuteSequence (), new MsiTableInstallUISequence (), + table_directory, table_media, table_property, table_icon, diff --git a/src/wix.vala b/src/wix.vala index 1de68d0..df17fdc 100644 --- a/src/wix.vala +++ b/src/wix.vala @@ -6,11 +6,13 @@ namespace Wixl { public abstract void visit_package (WixPackage package) throws GLib.Error; public abstract void visit_property (WixProperty prop) throws GLib.Error; public abstract void visit_media (WixMedia media) throws GLib.Error; + public abstract void visit_directory (WixDirectory dir) throws GLib.Error; } public abstract class WixElement: Object { public class string name; public string Id { get; set; } + public WixElement parent; public List<WixElement> children; static construct { @@ -18,6 +20,7 @@ namespace Wixl { } public void add_child (WixElement e) { + e.parent = this; children.append (e); } @@ -45,13 +48,17 @@ namespace Wixl { str += " " + p.name + "=\"" + valstr + "\""; i += 1; } - str += ">\n"; - foreach (var child in children) { - str += child.to_string () + "\n"; - } + if (children.length () != 0) { + str += ">\n"; + + foreach (var child in children) { + str += child.to_string () + "\n"; + } - return str + "</" + name + ">"; + return str + "</" + name + ">"; + } else + return str + "/>"; } public static void value_to_string (Value src, out Value dest) { @@ -181,6 +188,11 @@ namespace Wixl { media.load (child); add_child (media); continue; + case "Directory": + var directory = new WixDirectory (); + directory.load (child); + add_child (directory); + continue; } break; } @@ -208,6 +220,42 @@ namespace Wixl { } } + public class WixDirectory: WixElement { + static construct { + name = "Directory"; + } + + public string Name { get; set; } + + public override void load (Xml.Node *node) throws Wixl.Error { + base.load (node); + + for (var child = node->children; child != null; child = child->next) { + switch (child->type) { + case Xml.ElementType.COMMENT_NODE: + case Xml.ElementType.TEXT_NODE: + continue; + case Xml.ElementType.ELEMENT_NODE: + switch (child->name) { + case "Directory": + var directory = new WixDirectory (); + directory.load (child); + add_child (directory); + continue; + } + break; + } + debug ("unhandled node %s", child->name); + } + } + + public override void accept (WixElementVisitor visitor) throws GLib.Error { + visitor.visit_directory (this); + + base.accept (visitor); + } + } + class WixRoot: WixElement { static construct { name = "Wix"; |