summaryrefslogtreecommitdiff
path: root/modules/WixProjectCreator.pm
blob: 51da6a34425cc22283e6349592e1fbc66fb7e23d (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
225
226
227
228
229
230
231
232
233
package WixProjectCreator;

# ************************************************************
# Description   : A Wix Project Creator
# Author        : James H. Hill / Charles Calkins
# ************************************************************

# ************************************************************
# Pragmas
# ************************************************************

use strict;
use ProjectCreator;
use WinProjectBase;
use XMLProjectBase;
use GUID;

use vars qw(@ISA);
@ISA = qw(XMLProjectBase WinProjectBase ProjectCreator);

# ************************************************************
# Data Section
# ************************************************************

## NOTE: We call the constant as a function to support Perl 5.6.
my %info = (Creator::cplusplus() => {'ext'      => '.wxi',
                                     'dllexe'   => 'wix',
                                     'libexe'   => 'wix',
                                     'dll'      => 'wix',
                                     'lib'      => 'wix',
                                     'template' => 'wix',
                                    },
            Creator::csharp() => {'ext'      => '.wxi',
                                  'dllexe'   => 'wixcs',
                                  'libexe'   => 'wixcs',
                                  'dll'      => 'wixcs',
                                  'lib'      => 'wixcs',
                                  'template' => 'wixcs',
                                 },
           );

# ************************************************************
# Subroutine Section
# ************************************************************

sub languageSupported {
  return defined $info{$_[0]->get_language()};
}

sub convert_all_variables {
  return 1;
}

sub requires_forward_slashes {
  return 1;
}

sub expand_variables_from_template_values {
  return 1;
}

sub warn_useless_project {
  return 0;
}

sub convert_slashes {
  return 0;
}


sub is_culture_code {
  my $culture_code = shift;

  # from http://sharpertutorials.com/list-of-culture-codes/
  my @culture_codes = (
        'af', 'hu-HU', 'af-ZA', 'is', 'sq', 'is-IS',
        'sq-AL', 'id', 'ar', 'id-ID', 'ar-DZ', 'it',
        'ar-BH', 'it-IT', 'ar-EG', 'it-CH', 'ar-IQ', 'ja',
        'ar-JO', 'ja-JP', 'ar-KW', 'kn', 'ar-LB', 'kn-IN',
        'ar-LY', 'kk', 'ar-MA', 'kk-KZ', 'ar-OM', 'kok',
        'ar-QA', 'kok-IN', 'ar-SA', 'ko', 'ar-SY', 'ko-KR',
        'ar-TN', 'ky', 'ar-AE', 'ky-KG', 'ar-YE', 'lv',
        'hy', 'lv-LV', 'hy-AM', 'lt', 'az', 'lt-LT',
        'az-AZ-Cyrl', 'mk', 'az-AZ-Latn', 'mk-MK', 'eu', 'ms',
        'eu-ES', 'ms-BN', 'be', 'ms-MY', 'be-BY', 'mr',
        'bg', 'mr-IN', 'bg-BG', 'mn', 'ca', 'mn-MN',
        'ca-ES', 'no', 'zh-HK', 'nb-NO', 'zh-MO', 'nn-NO',
        'zh-CN', 'pl', 'zh-CHS', 'pl-PL', 'zh-SG', 'pt',
        'zh-TW', 'pt-BR', 'zh-CHT', 'pt-PT', 'hr', 'pa',
        'hr-HR', 'pa-IN', 'cs', 'ro', 'cs-CZ', 'ro-RO',
        'da', 'ru', 'da-DK', 'ru-RU', 'div', 'sa',
        'div-MV', 'sa-IN', 'nl', 'sr-SP-Cyrl', 'nl-BE', 'sr-SP-Latn',
        'nl-NL', 'sk', 'en', 'sk-SK', 'en-AU', 'sl',
        'en-BZ', 'sl-SI', 'en-CA', 'es', 'en-CB', 'es-AR',
        'en-IE', 'es-BO', 'en-JM', 'es-CL', 'en-NZ', 'es-CO',
        'en-PH', 'es-CR', 'en-ZA', 'es-DO', 'en-TT', 'es-EC',
        'en-GB', 'es-SV', 'en-US', 'es-GT', 'en-ZW', 'es-HN',
        'et', 'es-MX', 'et-EE', 'es-NI', 'fo', 'es-PA',
        'fo-FO', 'es-PY', 'fa', 'es-PE', 'fa-IR', 'es-PR',
        'fi', 'es-ES', 'fi-FI', 'es-UY', 'fr', 'es-VE',
        'fr-BE', 'sw', 'fr-CA', 'sw-KE', 'fr-FR', 'sv',
        'fr-LU', 'sv-FI', 'fr-MC', 'sv-SE', 'fr-CH', 'syr',
        'gl', 'syr-SY', 'gl-ES', 'ta', 'ka', 'ta-IN',
        'ka-GE', 'tt', 'de', 'tt-RU', 'de-AT', 'te',
        'de-DE', 'te-IN', 'de-LI', 'th', 'de-LU', 'th-TH',
        'de-CH', 'tr', 'el', 'tr-TR', 'el-GR', 'uk',
        'gu', 'uk-UA', 'gu-IN', 'ur', 'he', 'ur-PK',
        'he-IL', 'uz', 'hi', 'uz-UZ-Cyrl', 'hi-IN', 'uz-UZ-Latn',
        'hu', 'vi');

  return 1 if (exists {map { $_ => 1 } @culture_codes}->{$culture_code});
  return 0;
}




sub fill_value {
  my($self, $name) = @_;

  if ($name eq 'guid') {
    ## Return a repeatable GUID for use within the template.  The values
    ## provided will be hashed and returned in a format expected by Wix.
    return GUID::generate($self->project_file_name(),
                          $self->{'current_input'}, $self->getcwd());
  }
  elsif ($name eq 'source_directory') {
    my $source;

    if ($self->get_assignment('sharedname')) {
      $source = $self->get_assignment('dllout');

      if ($source eq '') {
        $source = $self->get_assignment('libout');
      }
    }
    elsif ($self->get_assignment('staticname')) {
      $source = $self->get_assignment('libout');
    }
    else {
      $source = $self->get_assignment('exeout');
    }

    ## Check for a variable in the source directory. We have to make
    ## sure we transform this correctly for WIX by adding the correct
    ## prefix. Otherwise, WIX will complain.
    if (defined $source && $source =~ /.*?\$\((.+?)\).*/) {
      my $prefix;
      my $varname = $1;

      if ($ENV{$varname}) {
        $prefix = "env";
      }
      else {
        $prefix = "var";
      }

      ## Add the correct prefix to the variable.
      $source =~ s/$varname/$prefix.$varname/g;
    }

    return $source;
  }
  elsif ($name eq 'cultures') {

    my $crlf = $self->crlf();

    # iterate over resx_files, make list of culture abbreviations
    my @resx_files  = $self->get_component_list('resx_files');

    my %cultures = ();
    foreach my $resx_file (@resx_files) {
      my @parts = split('\.', $resx_file);
      if ($parts[-1] eq 'resx') {  # if the file is a .resx file
        if (is_culture_code($parts[-2])) { # if a culture is specified
          $cultures{$parts[-2]} = 1;  # remember that culture
        }
        else {
          $cultures{'_neutral_'} = 1;  # have a neutral culture
        }
      }
    }

    # flatten into a string
    my $found_cultures = '';
    foreach my $culture (keys %cultures) {
      $found_cultures = $found_cultures . $culture . ' ';
    }

    return $found_cultures;
  }
  return undef;
}


sub get_info_hash {
  my($self, $key) = @_;

  ## If we have the setting in our information map, the use it.
  return $info{$key} if (defined $info{$key});
}

sub project_file_extension {
  return $_[0]->get_info_hash($_[0]->get_language())->{'ext'};
}


sub get_dll_exe_template_input_file {
  return $_[0]->get_info_hash($_[0]->get_language())->{'dllexe'};
}


sub get_lib_exe_template_input_file {
  return $_[0]->get_info_hash($_[0]->get_language())->{'libexe'};
}


sub get_dll_template_input_file {
  return $_[0]->get_info_hash($_[0]->get_language())->{'dll'};
}


sub get_lib_template_input_file {
  return $_[0]->get_info_hash($_[0]->get_language())->{'lib'};
}


sub get_template {
  return $_[0]->get_info_hash($_[0]->get_language())->{'template'};
}


1;