summaryrefslogtreecommitdiffstats
path: root/src/wixl.vala
blob: 0c6c2f4d48437b36e47e21cdcfcd9781351997a0 (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
using Posix;

namespace Wixl {

static bool version;
[CCode (array_length = false, array_null_terminated = true)]
static string[] files;

private const OptionEntry[] options = {
    { "version", 0, 0, OptionArg.NONE, ref version, N_("Display version number"), null },
    { "", 0, 0, OptionArg.FILENAME_ARRAY, ref files, null, N_("OUTPUT_FILE INPUT_FILE...") },
    { null }
};

    int main (string[] args) {
        Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
        Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
        Intl.textdomain (Config.GETTEXT_PACKAGE);
        GLib.Environment.set_application_name (Config.PACKAGE_NAME);

        var parameter_string = _("- a msi building tool");
        var opt_context = new OptionContext (parameter_string);
        opt_context.set_help_enabled (true);
        opt_context.add_main_entries (options, null);

        try {
            opt_context.parse (ref args);
        } catch (OptionError.BAD_VALUE err) {
            GLib.stdout.printf (opt_context.get_help (true, null));
            exit (1);
        } catch (OptionError error) {
            warning (error.message);
        }

        if (version) {
            GLib.stdout.printf ("%s\n", Config.PACKAGE_VERSION);
            exit (0);
        }

        if (files.length != 2) {
            GLib.stderr.printf (_("Please specify a output and input files.\n"));
            exit (1);
        }

        try {
            var file = File.new_for_commandline_arg (files[1]);
            string data;
            FileUtils.get_contents (file.get_path (), out data);
            var doc = Xml.Parser.read_memory (data, data.length);
            var root = new WixRoot ();
            root.load_xml (doc);
            var builder = new WixBuilder (root);
            builder.add_path (file.get_parent ().get_path ());
            var msi = builder.build ();
            msi.build (files[0]);
        } catch (GLib.Error error) {
            printerr (error.message + "\n");
            return 1;
        }

        return 0;
    }

} // Wixl