summaryrefslogtreecommitdiffstats
path: root/src/wix.vala
blob: 36159127632ca1eb8ba560d505a6014b4a31d46e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
namespace Wixl {

    public abstract class WixElementVisitor: Object {
        public abstract void visit_product (WixProduct product) throws GLib.Error;
        public abstract void visit_icon (WixIcon icon) throws GLib.Error;
        public abstract void visit_package (WixPackage package) throws GLib.Error;
        public abstract void visit_property (WixProperty prop) throws GLib.Error;
    }

    public abstract class WixElement: Object {
        public static string name;
        public string Id { get; set; }
        public List<WixElement> children;

        static construct {
            Value.register_transform_func (typeof (WixElement), typeof (string), (ValueTransform)WixElement.value_to_string);
        }

        public void add_child (WixElement e) {
            children.append (e);
        }

        public virtual void load (Xml.Node *node) throws Wixl.Error {
            if (node->name != name)
                throw new Error.FAILED ("%s: invalid node %s".printf (name, node->name));

            for (var prop = node->properties; prop != null; prop = prop->next) {
                if (prop->type == Xml.ElementType.ATTRIBUTE_NODE)
                    set_property (prop->name, get_attribute_content (prop));
            }
        }

        public string to_string () {
            var type = get_type ();
            var klass = (ObjectClass)type.class_ref ();
            var str = type.name () + " {";

            var i = 0;
            foreach (var p in klass.list_properties ()) {
                var value = Value (p.value_type);
                get_property (p.name, ref value);
                var valstr = value.holds (typeof (string)) ?
                    (string)value : value.strdup_contents ();
                str += (i == 0 ? "" : ", ") + p.name + ": " + valstr;
                i += 1;
            }

            return str + "}";
        }

        public static void value_to_string (Value src, out Value dest) {
            WixElement e = value_get_element (src);

            dest = e.to_string ();
        }

        public static WixElement? value_get_element (Value value) {
            if (! value.holds (typeof (WixElement)))
                return null;

            return (WixElement)value.get_object ();
        }

        public virtual void accept (WixElementVisitor visitor) throws GLib.Error {
            foreach (var child in children)
                child.accept (visitor);
        }
    }

    public class WixProperty: WixElement {
        static construct {
            name = "Property";
        }

        public string Value { get; set; }

        public override void accept (WixElementVisitor visitor) throws GLib.Error {
            visitor.visit_property (this);
        }
    }

    public class WixPackage: WixElement {
        static construct {
            name = "Package";
        }

        public string Keywords { get; set; }
        public string InstallerDescription { get; set; }
        public string InstallerComments { get; set; }
        public string Manufacturer { get; set; }
        public string InstallerVersion { get; set; }
        public string Languages { get; set; }
        public string Compressed { get; set; }
        public string SummaryCodepage { get; set; }
        public string Comments { get; set; }
        public string Description { 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) {
                    }
                    break;
                }
                debug ("unhandled node %s", child->name);
            }
        }

        public override void accept (WixElementVisitor visitor) throws GLib.Error {
            visitor.visit_package (this);
            base.accept (visitor);
        }
    }

    public class WixIcon: WixElement {
        static construct {
            name = "Icon";
        }

        public string SourceFile { get; set; }

        public override void accept (WixElementVisitor visitor) throws GLib.Error {
            visitor.visit_icon (this);
        }
    }

    public class WixProduct: WixElement {
        static construct {
            name = "Product";
        }

        public string Name { get; set; }
        public string UpgradeCode { get; set; }
        public string Language { get; set; }
        public string Codepage { get; set; }
        public string Version { get; set; }
        public string Manufacturer { get; set; }

        public WixProduct () {
        }

        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 "Package":
                        var package = new WixPackage ();
                        package.load (child);
                        add_child (package);
                        continue;
                    case "Icon":
                        var icon = new WixIcon ();
                        icon.load (child);
                        add_child (icon);
                        continue;
                    case "Property":
                        var prop = new WixProperty ();
                        prop.load (child);
                        add_child (prop);
                        continue;
                    }
                    break;
                }
                debug ("unhandled node %s", child->name);
            }
        }

        public override void accept (WixElementVisitor visitor) throws GLib.Error {
            visitor.visit_product (this);
            base.accept (visitor);
        }
    }

    class WixRoot: WixElement {
        static construct {
            name = "Wix";
        }

        public string xmlns { get; set; }

        public WixRoot () {
        }

        public void load_xml (Xml.Doc *doc) throws Wixl.Error {
            var root = doc->children;
            load (root);

            if (root->ns != null)
                xmlns = root->ns->href;

            for (var child = root->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 "Product":
                        var product = new WixProduct ();
                        product.load (child);
                        add_child (product);
                        continue;
                    }
                    break;
                }

                debug ("unhandled node %s", child->name);
            }
        }
    }

} // Wixl