Merge pull request #154 from LukeMouse/luketmp
[MPC.git] / modules / WixProjectCreator.pm
blob51da6a34425cc22283e6349592e1fbc66fb7e23d
1 package WixProjectCreator;
3 # ************************************************************
4 # Description : A Wix Project Creator
5 # Author : James H. Hill / Charles Calkins
6 # ************************************************************
8 # ************************************************************
9 # Pragmas
10 # ************************************************************
12 use strict;
13 use ProjectCreator;
14 use WinProjectBase;
15 use XMLProjectBase;
16 use GUID;
18 use vars qw(@ISA);
19 @ISA = qw(XMLProjectBase WinProjectBase ProjectCreator);
21 # ************************************************************
22 # Data Section
23 # ************************************************************
25 ## NOTE: We call the constant as a function to support Perl 5.6.
26 my %info = (Creator::cplusplus() => {'ext' => '.wxi',
27 'dllexe' => 'wix',
28 'libexe' => 'wix',
29 'dll' => 'wix',
30 'lib' => 'wix',
31 'template' => 'wix',
33 Creator::csharp() => {'ext' => '.wxi',
34 'dllexe' => 'wixcs',
35 'libexe' => 'wixcs',
36 'dll' => 'wixcs',
37 'lib' => 'wixcs',
38 'template' => 'wixcs',
42 # ************************************************************
43 # Subroutine Section
44 # ************************************************************
46 sub languageSupported {
47 return defined $info{$_[0]->get_language()};
50 sub convert_all_variables {
51 return 1;
54 sub requires_forward_slashes {
55 return 1;
58 sub expand_variables_from_template_values {
59 return 1;
62 sub warn_useless_project {
63 return 0;
66 sub convert_slashes {
67 return 0;
71 sub is_culture_code {
72 my $culture_code = shift;
74 # from http://sharpertutorials.com/list-of-culture-codes/
75 my @culture_codes = (
76 'af', 'hu-HU', 'af-ZA', 'is', 'sq', 'is-IS',
77 'sq-AL', 'id', 'ar', 'id-ID', 'ar-DZ', 'it',
78 'ar-BH', 'it-IT', 'ar-EG', 'it-CH', 'ar-IQ', 'ja',
79 'ar-JO', 'ja-JP', 'ar-KW', 'kn', 'ar-LB', 'kn-IN',
80 'ar-LY', 'kk', 'ar-MA', 'kk-KZ', 'ar-OM', 'kok',
81 'ar-QA', 'kok-IN', 'ar-SA', 'ko', 'ar-SY', 'ko-KR',
82 'ar-TN', 'ky', 'ar-AE', 'ky-KG', 'ar-YE', 'lv',
83 'hy', 'lv-LV', 'hy-AM', 'lt', 'az', 'lt-LT',
84 'az-AZ-Cyrl', 'mk', 'az-AZ-Latn', 'mk-MK', 'eu', 'ms',
85 'eu-ES', 'ms-BN', 'be', 'ms-MY', 'be-BY', 'mr',
86 'bg', 'mr-IN', 'bg-BG', 'mn', 'ca', 'mn-MN',
87 'ca-ES', 'no', 'zh-HK', 'nb-NO', 'zh-MO', 'nn-NO',
88 'zh-CN', 'pl', 'zh-CHS', 'pl-PL', 'zh-SG', 'pt',
89 'zh-TW', 'pt-BR', 'zh-CHT', 'pt-PT', 'hr', 'pa',
90 'hr-HR', 'pa-IN', 'cs', 'ro', 'cs-CZ', 'ro-RO',
91 'da', 'ru', 'da-DK', 'ru-RU', 'div', 'sa',
92 'div-MV', 'sa-IN', 'nl', 'sr-SP-Cyrl', 'nl-BE', 'sr-SP-Latn',
93 'nl-NL', 'sk', 'en', 'sk-SK', 'en-AU', 'sl',
94 'en-BZ', 'sl-SI', 'en-CA', 'es', 'en-CB', 'es-AR',
95 'en-IE', 'es-BO', 'en-JM', 'es-CL', 'en-NZ', 'es-CO',
96 'en-PH', 'es-CR', 'en-ZA', 'es-DO', 'en-TT', 'es-EC',
97 'en-GB', 'es-SV', 'en-US', 'es-GT', 'en-ZW', 'es-HN',
98 'et', 'es-MX', 'et-EE', 'es-NI', 'fo', 'es-PA',
99 'fo-FO', 'es-PY', 'fa', 'es-PE', 'fa-IR', 'es-PR',
100 'fi', 'es-ES', 'fi-FI', 'es-UY', 'fr', 'es-VE',
101 'fr-BE', 'sw', 'fr-CA', 'sw-KE', 'fr-FR', 'sv',
102 'fr-LU', 'sv-FI', 'fr-MC', 'sv-SE', 'fr-CH', 'syr',
103 'gl', 'syr-SY', 'gl-ES', 'ta', 'ka', 'ta-IN',
104 'ka-GE', 'tt', 'de', 'tt-RU', 'de-AT', 'te',
105 'de-DE', 'te-IN', 'de-LI', 'th', 'de-LU', 'th-TH',
106 'de-CH', 'tr', 'el', 'tr-TR', 'el-GR', 'uk',
107 'gu', 'uk-UA', 'gu-IN', 'ur', 'he', 'ur-PK',
108 'he-IL', 'uz', 'hi', 'uz-UZ-Cyrl', 'hi-IN', 'uz-UZ-Latn',
109 'hu', 'vi');
111 return 1 if (exists {map { $_ => 1 } @culture_codes}->{$culture_code});
112 return 0;
118 sub fill_value {
119 my($self, $name) = @_;
121 if ($name eq 'guid') {
122 ## Return a repeatable GUID for use within the template. The values
123 ## provided will be hashed and returned in a format expected by Wix.
124 return GUID::generate($self->project_file_name(),
125 $self->{'current_input'}, $self->getcwd());
127 elsif ($name eq 'source_directory') {
128 my $source;
130 if ($self->get_assignment('sharedname')) {
131 $source = $self->get_assignment('dllout');
133 if ($source eq '') {
134 $source = $self->get_assignment('libout');
137 elsif ($self->get_assignment('staticname')) {
138 $source = $self->get_assignment('libout');
140 else {
141 $source = $self->get_assignment('exeout');
144 ## Check for a variable in the source directory. We have to make
145 ## sure we transform this correctly for WIX by adding the correct
146 ## prefix. Otherwise, WIX will complain.
147 if (defined $source && $source =~ /.*?\$\((.+?)\).*/) {
148 my $prefix;
149 my $varname = $1;
151 if ($ENV{$varname}) {
152 $prefix = "env";
154 else {
155 $prefix = "var";
158 ## Add the correct prefix to the variable.
159 $source =~ s/$varname/$prefix.$varname/g;
162 return $source;
164 elsif ($name eq 'cultures') {
166 my $crlf = $self->crlf();
168 # iterate over resx_files, make list of culture abbreviations
169 my @resx_files = $self->get_component_list('resx_files');
171 my %cultures = ();
172 foreach my $resx_file (@resx_files) {
173 my @parts = split('\.', $resx_file);
174 if ($parts[-1] eq 'resx') { # if the file is a .resx file
175 if (is_culture_code($parts[-2])) { # if a culture is specified
176 $cultures{$parts[-2]} = 1; # remember that culture
178 else {
179 $cultures{'_neutral_'} = 1; # have a neutral culture
184 # flatten into a string
185 my $found_cultures = '';
186 foreach my $culture (keys %cultures) {
187 $found_cultures = $found_cultures . $culture . ' ';
190 return $found_cultures;
192 return undef;
196 sub get_info_hash {
197 my($self, $key) = @_;
199 ## If we have the setting in our information map, the use it.
200 return $info{$key} if (defined $info{$key});
203 sub project_file_extension {
204 return $_[0]->get_info_hash($_[0]->get_language())->{'ext'};
208 sub get_dll_exe_template_input_file {
209 return $_[0]->get_info_hash($_[0]->get_language())->{'dllexe'};
213 sub get_lib_exe_template_input_file {
214 return $_[0]->get_info_hash($_[0]->get_language())->{'libexe'};
218 sub get_dll_template_input_file {
219 return $_[0]->get_info_hash($_[0]->get_language())->{'dll'};
223 sub get_lib_template_input_file {
224 return $_[0]->get_info_hash($_[0]->get_language())->{'lib'};
228 sub get_template {
229 return $_[0]->get_info_hash($_[0]->get_language())->{'template'};