@@ -11,14 +11,14 @@ use crate::bundle::{
1111
1212use handlebars:: { to_json, Handlebars } ;
1313use regex:: Regex ;
14- use serde:: Serialize ;
14+ use serde:: { Deserialize , Serialize } ;
1515use sha2:: Digest ;
1616use uuid:: Uuid ;
1717use zip:: ZipArchive ;
1818
1919use std:: {
20- collections:: BTreeMap ,
21- fs:: { create_dir_all, remove_dir_all, write, File } ,
20+ collections:: { BTreeMap , HashMap } ,
21+ fs:: { create_dir_all, remove_dir_all, rename , write, File } ,
2222 io:: { Cursor , Read , Write } ,
2323 path:: { Path , PathBuf } ,
2424 process:: { Command , Stdio } ,
@@ -52,6 +52,14 @@ const UUID_NAMESPACE: [u8; 16] = [
5252/// Mapper between a resource directory name and its ResourceDirectory descriptor.
5353type ResourceMap = BTreeMap < String , ResourceDirectory > ;
5454
55+ #[ derive( Debug , Deserialize ) ]
56+ struct LanguageMetadata {
57+ #[ serde( rename = "asciiCode" ) ]
58+ ascii_code : usize ,
59+ #[ serde( rename = "langId" ) ]
60+ lang_id : usize ,
61+ }
62+
5563/// A binary to bundle with WIX.
5664/// External binaries or additional project binaries are represented with this data structure.
5765/// This data structure is needed because WIX requires each path to have its own `id` and `guid`.
@@ -313,10 +321,10 @@ fn run_candle(
313321fn run_light (
314322 wix_toolset_path : & Path ,
315323 build_path : & Path ,
316- wixobjs : & [ & str ] ,
324+ arguments : Vec < String > ,
317325 output_path : & Path ,
318326 settings : & Settings ,
319- ) -> crate :: Result < PathBuf > {
327+ ) -> crate :: Result < ( ) > {
320328 let light_exe = wix_toolset_path. join ( "light.exe" ) ;
321329
322330 let mut args: Vec < String > = vec ! [
@@ -326,8 +334,8 @@ fn run_light(
326334 output_path. display( ) . to_string( ) ,
327335 ] ;
328336
329- for p in wixobjs {
330- args. push ( ( * p ) . to_string ( ) ) ;
337+ for p in arguments {
338+ args. push ( p ) ;
331339 }
332340
333341 let mut cmd = Command :: new ( & light_exe) ;
@@ -336,19 +344,16 @@ fn run_light(
336344 . stdout ( Stdio :: piped ( ) )
337345 . current_dir ( build_path) ;
338346
339- common:: print_info ( format ! ( "running light to produce {}" , output_path. display( ) ) . as_str ( ) ) ?;
340- common:: execute_with_verbosity ( & mut cmd, settings)
341- . map ( |_| output_path. to_path_buf ( ) )
342- . map_err ( |_| {
343- crate :: Error :: ShellScriptError ( format ! (
344- "error running light.exe{}" ,
345- if settings. is_verbose( ) {
346- ""
347- } else {
348- ", try running with --verbose to see command output"
349- }
350- ) )
351- } )
347+ common:: execute_with_verbosity ( & mut cmd, settings) . map_err ( |_| {
348+ crate :: Error :: ShellScriptError ( format ! (
349+ "error running light.exe{}" ,
350+ if settings. is_verbose( ) {
351+ ""
352+ } else {
353+ ", try running with --verbose to see command output"
354+ }
355+ ) )
356+ } )
352357}
353358
354359// fn get_icon_data() -> crate::Result<()> {
@@ -406,6 +411,29 @@ pub fn build_wix_app_installer(
406411
407412 let mut data = BTreeMap :: new ( ) ;
408413
414+ let language_map: HashMap < String , LanguageMetadata > =
415+ serde_json:: from_str ( include_str ! ( "./languages.json" ) ) . unwrap ( ) ;
416+
417+ let ( language, language_metadata) = if let Some ( wix) = & settings. windows ( ) . wix {
418+ let metadata = language_map. get ( & wix. language ) . unwrap_or_else ( || {
419+ panic ! (
420+ "Language {} not found. It must be one of {}" ,
421+ wix. language,
422+ language_map
423+ . keys( )
424+ . cloned( )
425+ . collect:: <Vec <String >>( )
426+ . join( ", " )
427+ )
428+ } ) ;
429+ ( wix. language . clone ( ) , metadata)
430+ } else {
431+ common:: print_info ( "Wix settings not found. Using `en-US` as language." ) ?;
432+ ( "en-US" . into ( ) , language_map. get ( "en-US" ) . unwrap ( ) )
433+ } ;
434+ data. insert ( "language_id" , to_json ( language_metadata. lang_id ) ) ;
435+ data. insert ( "ascii_codepage" , to_json ( language_metadata. ascii_code ) ) ;
436+
409437 data. insert ( "product_name" , to_json ( settings. product_name ( ) ) ) ;
410438 data. insert ( "version" , to_json ( settings. version_string ( ) ) ) ;
411439 let manufacturer = settings. bundle_identifier ( ) . to_string ( ) ;
@@ -511,16 +539,26 @@ pub fn build_wix_app_installer(
511539 run_candle ( settings, wix_toolset_path, & output_path, wxs) ?;
512540 }
513541
514- let wixobjs = vec ! [ "*.wixobj" ] ;
515- let target = run_light (
542+ let arguments = vec ! [
543+ format!( "-cultures:{}" , language. to_lowercase( ) ) ,
544+ "*.wixobj" . into( ) ,
545+ ] ;
546+ let msi_output_path = output_path. join ( "output.msi" ) ;
547+ let msi_path = app_installer_dir ( settings) ?;
548+ create_dir_all ( msi_path. parent ( ) . unwrap ( ) ) ?;
549+
550+ common:: print_info ( format ! ( "running light to produce {}" , msi_path. display( ) ) . as_str ( ) ) ?;
551+
552+ run_light (
516553 wix_toolset_path,
517554 & output_path,
518- & wixobjs ,
519- & app_installer_dir ( settings ) ? ,
555+ arguments ,
556+ & msi_output_path ,
520557 settings,
521558 ) ?;
559+ rename ( & msi_output_path, & msi_path) ?;
522560
523- Ok ( target )
561+ Ok ( msi_path )
524562}
525563
526564/// Generates the data required for the external binaries and extra binaries bundling.
0 commit comments