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
  
#pike __REAL_VERSION__ 
#require constant(Standards.UUID.make_version3) 
 
/* 
 * Make a Wix modules source XML file from an existing set of 
 * directories or files. 
 * 
 * 2004-11-02 Henrik Grubbström 
 */ 
 
constant description = "Creates a Wix modules source XML file."; 
 
int main(int argc, array(string) argv) 
{ 
  string base_guid = Standards.UUID.make_version1(-1)->str(); 
  string version_str = "1.0"; 
  string id; 
  string descr; 
  string manufacturer; 
  string comments; 
  string service; 
 
  foreach(Getopt.find_all_options(argv, ({ 
    ({"--guid", Getopt.HAS_ARG, ({"-g", "--guid"})}), 
    ({"--version", Getopt.MAY_HAVE_ARG, ({"-v", "--version"})}), 
    ({"--id", Getopt.HAS_ARG, ({"-i", "--id", "--identifier"})}), 
    ({"--description", Getopt.HAS_ARG, ({"-d", "--descr", "--description"})}), 
    ({"--manufacturer", Getopt.HAS_ARG, ({"-m", "--manufacturer"})}), 
    ({"--comments", Getopt.HAS_ARG, ({"-c", "--comment", "--comments"})}), 
    ({"--service", Getopt.HAS_ARG, ({"-s", "--service"})}), 
  })), array(string) opt) { 
    switch(opt[0]) { 
    case "--guid": 
      base_guid = Standards.UUID.UUID(opt[1])->str(); 
      break; 
    case "--version": 
      if (stringp(opt[1])) { 
        version_str = opt[1]; 
      } else { 
        write("%d.%d.%d\n", 
         (int)__REAL_VERSION__,__REAL_MINOR__,__REAL_BUILD__); 
        exit(0); 
      } 
      break; 
    case "--id": 
      id = opt[1]; 
      break; 
    case "--description": 
      descr = opt[1]; 
      break; 
    case "--manufacturer": 
      manufacturer = opt[1]; 
      break; 
    case "--comments": 
      comments = opt[1]; 
      break; 
    case "--service": 
      service = opt[1]; 
      break; 
    } 
  } 
 
  if (!id) { 
    werror("No identifier specified.\n"); 
    exit(1); 
  } 
 
  argv = Getopt.get_args(argv); 
 
  string version_guid = 
    Standards.UUID.make_version3(version_str, base_guid)->str(); 
  Standards.XML.Wix.Directory root = 
    Standards.XML.Wix.Directory("SourceDir", 
                                Standards.UUID.UUID(version_guid)->encode(), 
                                "TARGETDIR"); 
 
  string last_file; 
 
  foreach(argv[1..], string src) { 
    src = replace(src, "\\", "/"); 
    src = replace(src, "\"", "");       // FIXME: Remove junk 
    array(string) seg; 
    string dest; 
    if (sizeof(seg = (src/":")) > 1) { 
      // The destination name may be specified with 
      //   <dest>:<src> 
      dest = seg[0]; 
      src = seg[1..]*":"; 
    } 
    Stdio.Stat st = file_stat(src); 
    if (!st) { 
      werror("Failed to find %O\n", src); 
      exit(1); 
    } if (st->isdir) { 
      root->recurse_install_directory(dest||".", src); 
    } else { 
      root->install_file(dest||((src/"/")[-1]), src); 
      last_file = dest; 
    } 
  } 
 
  root->set_sources(); 
 
  write(Standards.XML.Wix.get_module_xml(root, id, version_str, 
                                         manufacturer, descr, version_guid, 
                                         comments)->render_xml()); 
}