@@ -81,6 +81,8 @@ struct ResourceFile {
8181/// This data structure is needed because WIX requires each path to have its own `id` and `guid`.
8282#[ derive( Serialize ) ]
8383struct ResourceDirectory {
84+ /// the directory path.
85+ path : String ,
8486 /// the directory name of the described resource.
8587 name : String ,
8688 /// the files of the described resource directory.
@@ -122,7 +124,8 @@ impl ResourceDirectory {
122124 format ! ( "{}{}" , files, directories)
123125 } else {
124126 format ! (
125- r#"<Directory Id="{name}" Name="{name}">{contents}</Directory>"# ,
127+ r#"<Directory Id="{id}" Name="{name}">{contents}</Directory>"# ,
128+ id = format!( "_{}" , Uuid :: new_v4( ) . to_simple( ) ) ,
126129 name = self . name,
127130 contents = format!( "{}{}" , files, directories)
128131 )
@@ -522,42 +525,31 @@ pub fn build_wix_app_installer(
522525/// Generates the data required for the external binaries and extra binaries bundling.
523526fn generate_binaries_data ( settings : & Settings ) -> crate :: Result < Vec < Binary > > {
524527 let mut binaries = Vec :: new ( ) ;
525- let regex = Regex :: new ( r"[^\w\d\.]" ) ?;
526528 let cwd = std:: env:: current_dir ( ) ?;
527529 for src in settings. external_binaries ( ) {
528530 let src = src?;
529- let filename = src
530- . file_name ( )
531- . expect ( "failed to extract external binary filename" )
532- . to_os_string ( )
533- . into_string ( )
534- . expect ( "failed to convert external binary filename to string" ) ;
535-
536- let guid = generate_guid ( filename. as_bytes ( ) ) . to_string ( ) ;
537531
538532 binaries. push ( Binary {
539- guid,
533+ guid : Uuid :: new_v4 ( ) . to_string ( ) ,
540534 path : cwd
541535 . join ( src)
542536 . into_os_string ( )
543537 . into_string ( )
544538 . expect ( "failed to read external binary path" ) ,
545- id : regex . replace_all ( & filename , "" ) . to_string ( ) ,
539+ id : Uuid :: new_v4 ( ) . to_string ( ) ,
546540 } ) ;
547541 }
548542
549543 for bin in settings. binaries ( ) {
550- let filename = bin. name ( ) ;
551- let guid = generate_guid ( filename. as_bytes ( ) ) . to_string ( ) ;
552544 if !bin. main ( ) {
553545 binaries. push ( Binary {
554- guid,
546+ guid : Uuid :: new_v4 ( ) . to_string ( ) ,
555547 path : settings
556548 . binary_path ( bin)
557549 . into_os_string ( )
558550 . into_string ( )
559551 . expect ( "failed to read binary path" ) ,
560- id : regex . replace_all ( & filename , "" ) . to_string ( ) ,
552+ id : Uuid :: new_v4 ( ) . to_string ( ) ,
561553 } )
562554 }
563555 }
@@ -600,7 +592,6 @@ fn get_merge_modules(settings: &Settings) -> crate::Result<Vec<MergeModule>> {
600592/// Generates the data required for the resource bundling on wix
601593fn generate_resource_data ( settings : & Settings ) -> crate :: Result < ResourceMap > {
602594 let mut resources = ResourceMap :: new ( ) ;
603- let regex = Regex :: new ( r"[^\w\d\.]" ) ?;
604595 let cwd = std:: env:: current_dir ( ) ?;
605596
606597 let mut dlls = vec ! [ ] ;
@@ -613,22 +604,18 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
613604 . as_str ( ) ,
614605 ) ? {
615606 let path = dll?;
616- let filename = path
617- . file_name ( )
618- . expect ( "failed to extract resource filename" )
619- . to_os_string ( )
620- . into_string ( )
621- . expect ( "failed to convert resource filename to string" ) ;
607+ let resource_path = path. to_string_lossy ( ) . to_string ( ) ;
622608 dlls. push ( ResourceFile {
623- guid : generate_guid ( filename . as_bytes ( ) ) . to_string ( ) ,
624- path : path . to_string_lossy ( ) . to_string ( ) ,
625- id : regex . replace_all ( & filename , "" ) . to_string ( ) ,
609+ id : format ! ( "_{}" , Uuid :: new_v4 ( ) . to_simple ( ) ) ,
610+ guid : Uuid :: new_v4 ( ) . to_string ( ) ,
611+ path : resource_path ,
626612 } ) ;
627613 }
628614 if !dlls. is_empty ( ) {
629615 resources. insert (
630616 "" . to_string ( ) ,
631617 ResourceDirectory {
618+ path : "" . to_string ( ) ,
632619 name : "" . to_string ( ) ,
633620 directories : vec ! [ ] ,
634621 files : dlls,
@@ -639,23 +626,16 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
639626 for src in settings. resource_files ( ) {
640627 let src = src?;
641628
642- let filename = src
643- . file_name ( )
644- . expect ( "failed to extract resource filename" )
645- . to_os_string ( )
646- . into_string ( )
647- . expect ( "failed to convert resource filename to string" ) ;
648-
649629 let resource_path = cwd
650630 . join ( src. clone ( ) )
651631 . into_os_string ( )
652632 . into_string ( )
653633 . expect ( "failed to read resource path" ) ;
654634
655635 let resource_entry = ResourceFile {
656- guid : generate_guid ( filename. as_bytes ( ) ) . to_string ( ) ,
636+ id : format ! ( "_{}" , Uuid :: new_v4( ) . to_simple( ) ) ,
637+ guid : Uuid :: new_v4 ( ) . to_string ( ) ,
657638 path : resource_path,
658- id : regex. replace_all ( & filename, "" ) . to_string ( ) ,
659639 } ;
660640
661641 // split the resource path directories
@@ -668,49 +648,68 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
668648 . collect :: < Vec < _ > > ( ) ;
669649 directories. truncate ( directories. len ( ) - 1 ) ;
670650 // transform the directory structure to a chained vec structure
671- for directory in directories {
651+ let first_directory = directories
652+ . first ( )
653+ . map ( |d| d. as_os_str ( ) . to_string_lossy ( ) . into_owned ( ) )
654+ . unwrap_or_else ( || String :: new ( ) ) ;
655+ let last_index = directories. len ( ) - 1 ;
656+ let mut path = String :: new ( ) ;
657+ for ( i, directory) in directories. into_iter ( ) . enumerate ( ) {
672658 let directory_name = directory
673659 . as_os_str ( )
674660 . to_os_string ( )
675661 . into_string ( )
676662 . expect ( "failed to read resource folder name" ) ;
663+ path. push_str ( directory_name. as_str ( ) ) ;
677664
678665 // if the directory is already on the map
679- if resources. contains_key ( & directory_name ) {
666+ if resources. contains_key ( & first_directory ) {
680667 let directory_entry = & mut resources
681- . get_mut ( & directory_name )
668+ . get_mut ( & first_directory )
682669 . expect ( "Unable to handle resources" ) ;
683- if directory_entry . name == directory_name {
670+ if last_index == 0 {
684671 // the directory entry is the root of the chain
685672 directory_entry. add_file ( resource_entry. clone ( ) ) ;
686673 } else {
687674 let index = directory_entry
688675 . directories
689676 . iter ( )
690- . position ( |f| f. name == directory_name ) ;
677+ . position ( |f| f. path == path ) ;
691678 if let Some ( index) = index {
692679 // the directory entry is already a part of the chain
693- let dir = directory_entry
694- . directories
695- . get_mut ( index)
696- . expect ( "Unable to get directory" ) ;
697- dir. add_file ( resource_entry. clone ( ) ) ;
680+ if i == last_index {
681+ let dir = directory_entry
682+ . directories
683+ . get_mut ( index)
684+ . expect ( "Unable to get directory" ) ;
685+ dir. add_file ( resource_entry. clone ( ) ) ;
686+ }
698687 } else {
699688 // push it to the chain
700689 directory_entry. directories . push ( ResourceDirectory {
690+ path : path. clone ( ) ,
701691 name : directory_name. clone ( ) ,
702692 directories : vec ! [ ] ,
703- files : vec ! [ resource_entry. clone( ) ] ,
693+ files : if i == last_index {
694+ vec ! [ resource_entry. clone( ) ]
695+ } else {
696+ vec ! [ ]
697+ } ,
704698 } ) ;
705699 }
706700 }
707701 } else {
708702 resources. insert (
709703 directory_name. clone ( ) ,
710704 ResourceDirectory {
705+ path : path. clone ( ) ,
711706 name : directory_name. clone ( ) ,
712707 directories : vec ! [ ] ,
713- files : vec ! [ resource_entry. clone( ) ] ,
708+ files : if i == last_index {
709+ vec ! [ resource_entry. clone( ) ]
710+ } else {
711+ vec ! [ ]
712+ } ,
714713 } ,
715714 ) ;
716715 }
0 commit comments