@@ -9,7 +9,6 @@ use super::{
99} ;
1010
1111use handlebars:: { to_json, Handlebars } ;
12- use lazy_static:: lazy_static;
1312use regex:: Regex ;
1413use serde:: Serialize ;
1514use sha2:: Digest ;
@@ -55,19 +54,6 @@ const UUID_NAMESPACE: [u8; 16] = [
5554 0xfd , 0x85 , 0x95 , 0xa8 , 0x17 , 0xa3 , 0x47 , 0x4e , 0xa6 , 0x16 , 0x76 , 0x14 , 0x8d , 0xfa , 0x0c , 0x7b ,
5655] ;
5756
58- // setup for the main.wxs template file using handlebars. Dynamically changes the template on compilation based on the application metadata.
59- lazy_static ! {
60- static ref HANDLEBARS : Handlebars <' static > = {
61- let mut handlebars = Handlebars :: new( ) ;
62-
63- handlebars
64- . register_template_string( "main.wxs" , include_str!( "templates/main.wxs" ) )
65- . map_err( |e| e. to_string( ) )
66- . expect( "Failed to setup handlebar template" ) ;
67- handlebars
68- } ;
69- }
70-
7157/// Mapper between a resource directory name and its ResourceDirectory descriptor.
7258type ResourceMap = BTreeMap < String , ResourceDirectory > ;
7359
@@ -478,6 +464,8 @@ pub fn build_wix_app_installer(
478464 data. insert ( "icon_path" , to_json ( icon_path) ) ;
479465
480466 let mut fragment_paths = Vec :: new ( ) ;
467+ let mut handlebars = Handlebars :: new ( ) ;
468+ let mut has_custom_template = false ;
481469
482470 if let Some ( wix) = & settings. windows ( ) . wix {
483471 data. insert ( "component_group_refs" , to_json ( & wix. component_group_refs ) ) ;
@@ -486,9 +474,23 @@ pub fn build_wix_app_installer(
486474 data. insert ( "feature_refs" , to_json ( & wix. feature_refs ) ) ;
487475 data. insert ( "merge_refs" , to_json ( & wix. merge_refs ) ) ;
488476 fragment_paths = wix. fragment_paths . clone ( ) ;
477+
478+ if let Some ( temp_path) = & wix. template {
479+ let template = std:: fs:: read_to_string ( temp_path) ?;
480+ handlebars
481+ . register_template_string ( "main.wxs" , & template)
482+ . or_else ( |e| Err ( e. to_string ( ) ) )
483+ . expect ( "Failed to setup custom handlebar template" ) ;
484+ has_custom_template = true ;
485+ }
489486 }
490487
491- let temp = HANDLEBARS . render ( "main.wxs" , & data) ?;
488+ if !has_custom_template {
489+ handlebars
490+ . register_template_string ( "main.wxs" , include_str ! ( "templates/main.wxs" ) )
491+ . map_err ( |e| e. to_string ( ) )
492+ . expect ( "Failed to setup handlebar template" ) ;
493+ } ;
492494
493495 if output_path. exists ( ) {
494496 remove_dir_all ( & output_path) ?;
@@ -497,7 +499,7 @@ pub fn build_wix_app_installer(
497499 create_dir_all ( & output_path) ?;
498500
499501 let main_wxs_path = output_path. join ( "main.wxs" ) ;
500- write ( & main_wxs_path, temp ) ?;
502+ write ( & main_wxs_path, handlebars . render ( "main.wxs" , & data ) ? ) ?;
501503
502504 let mut candle_inputs = vec ! [ "main.wxs" . into( ) ] ;
503505
0 commit comments