fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
  let mut resources = ResourceMap::new();
  let regex = Regex::new(r"[^\w\d\.]")?;
  let cwd = std::env::current_dir()?;

  let mut dlls = vec![];
  for dll in glob::glob(
    settings
      .project_out_directory()
      .join("*.dll")
      .to_string_lossy()
      .to_string()
      .as_str(),
  )? {
    let path = dll?;
    let filename = path
      .file_name()
      .expect("failed to extract resource filename")
      .to_os_string()
      .into_string()
      .expect("failed to convert resource filename to string");
    dlls.push(ResourceFile {
      guid: generate_guid(filename.as_bytes()).to_string(),
      path: path.to_string_lossy().to_string(),
      id: regex.replace_all(&filename, "").to_string(),
    });
  }
  if !dlls.is_empty() {
    resources.insert(
      "".to_string(),
      ResourceDirectory {
        name: "".to_string(),
        directories: vec![],
        files: dlls,
      },
    );
  }

  for src in settings.resource_files() {
    let src = src?;

    let filename = src
      .file_name()
      .expect("failed to extract resource filename")
      .to_os_string()
      .into_string()
      .expect("failed to convert resource filename to string");

    let resource_path = cwd
      .join(src.clone())
      .into_os_string()
      .into_string()
      .expect("failed to read resource path");

    let resource_entry = ResourceFile {
      guid: generate_guid(filename.as_bytes()).to_string(),
      path: resource_path,
      id: regex.replace_all(&filename, "").to_string(),
    };

    // split the resource path directories
    let mut directories = src
      .components()
      .filter(|component| {
        let comp = component.as_os_str();
        comp != "." && comp != ".."
      })
      .collect::<Vec<_>>();
    directories.truncate(directories.len() - 1);
    // transform the directory structure to a chained vec structure
    for directory in directories {
      let directory_name = directory
        .as_os_str()
        .to_os_string()
        .into_string()
        .expect("failed to read resource folder name");

      // if the directory is already on the map
      if resources.contains_key(&directory_name) {
        let directory_entry = &mut resources
          .get_mut(&directory_name)
          .expect("Unable to handle resources");
        if directory_entry.name == directory_name {
          // the directory entry is the root of the chain
          directory_entry.add_file(resource_entry.clone());
        } else {
          let index = directory_entry
            .directories
            .iter()
            .position(|f| f.name == directory_name);
          if index.is_some() {
            // the directory entry is already a part of the chain
            let dir = directory_entry
              .directories
              .get_mut(index.expect("Unable to get index"))
              .expect("Unable to get directory");
            dir.add_file(resource_entry.clone());
          } else {
            // push it to the chain
            directory_entry.directories.push(ResourceDirectory {
              name: directory_name.clone(),
              directories: vec![],
              files: vec![resource_entry.clone()],
            });
          }
        }
      } else {
        resources.insert(
          directory_name.clone(),
          ResourceDirectory {
            name: directory_name.clone(),
            directories: vec![],
            files: vec![resource_entry.clone()],
          },
        );
      }
    }
  }

  Ok(resources)
}
/// Generates the data required for the resource bundling on wix
Generates the data required for the resource bundling on wix
Generates the data required for the resource bundling on wix
fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
  let mut resources = ResourceMap::new();
  let regex = Regex::new(r"[^\w\d\.]")?;
  let cwd = std::env::current_dir()?;
  let mut dlls = vec![];
  for dll in glob::glob(
    settings
      .project_out_directory()
      .join("*.dll")
      .to_string_lossy()
      .to_string()
      .as_str(),
  )? {
    let path = dll?;
    let filename = path
      .file_name()
      .expect("failed to extract resource filename")
      .to_os_string()
      .into_string()
      .expect("failed to convert resource filename to string");
    dlls.push(ResourceFile {
      guid: generate_guid(filename.as_bytes()).to_string(),
      path: path.to_string_lossy().to_string(),
      id: regex.replace_all(&filename, "").to_string(),
    });
  }
  if !dlls.is_empty() {
    resources.insert(
      "".to_string(),
      ResourceDirectory {
        name: "".to_string(),
        directories: vec![],
        files: dlls,
      },
    );
  }
  for src in settings.resource_files() {
    let src = src?;
    let filename = src
      .file_name()
      .expect("failed to extract resource filename")
      .to_os_string()
      .into_string()
      .expect("failed to convert resource filename to string");
    let resource_path = cwd
      .join(src.clone())
      .into_os_string()
      .into_string()
      .expect("failed to read resource path");
    let resource_entry = ResourceFile {
      guid: generate_guid(filename.as_bytes()).to_string(),
      path: resource_path,
      id: regex.replace_all(&filename, "").to_string(),
    };
    // split the resource path directories
    let mut directories = src
      .components()
      .filter(|component| {
        let comp = component.as_os_str();
        comp != "." && comp != ".."
      })
      .collect::<Vec<_>>();
    directories.truncate(directories.len() - 1);
    // transform the directory structure to a chained vec structure
    for directory in directories {
      let directory_name = directory
        .as_os_str()
        .to_os_string()
        .into_string()
        .expect("failed to read resource folder name");
      // if the directory is already on the map
      if resources.contains_key(&directory_name) {
        let directory_entry = &mut resources
          .get_mut(&directory_name)
          .expect("Unable to handle resources");
        if directory_entry.name == directory_name {
          // the directory entry is the root of the chain
          directory_entry.add_file(resource_entry.clone());
        } else {
          let index = directory_entry
            .directories
            .iter()
            .position(|f| f.name == directory_name);
          if index.is_some() {
            // the directory entry is already a part of the chain
            let dir = directory_entry
              .directories
              .get_mut(index.expect("Unable to get index"))
              .expect("Unable to get directory");
            dir.add_file(resource_entry.clone());
          } else {
            // push it to the chain
            directory_entry.directories.push(ResourceDirectory {
              name: directory_name.clone(),
              directories: vec![],
              files: vec![resource_entry.clone()],
            });
          }
        }
      } else {
        resources.insert(
          directory_name.clone(),
          ResourceDirectory {
            name: directory_name.clone(),
            directories: vec![],
            files: vec![resource_entry.clone()],
          },
        );
      }
    }
  }
  Ok(resources)
}
fn generate_resource_data ( settings : & Settings ) -> crate :: Result < ResourceMap > { let mut resources = ResourceMap :: new ( ) ; let regex = Regex :: new ( r"[^\w\d\.]" ) ? ; let cwd = std :: env :: current_dir ( ) ? ; let mut dlls = vec ! [ ] ; for dll in glob :: glob ( settings . project_out_directory ( ) . join ( " " ) . to_string_lossy ( ) . to_string ( ) . as_str ( ) , ) ? { let path = dll ? ; let filename = path . file_name ( ) . expect ( " " ) . to_os_string ( ) . into_string ( ) . expect ( " " ) ; dlls . push ( ResourceFile { guid : generate_guid ( filename . as_bytes ( ) ) . to_string ( ) , path : path . to_string_lossy ( ) . to_string ( ) , id : regex . replace_all ( & filename , " " ) . to_string ( ) , } ) ; } if ! dlls . is_empty ( ) { resources . insert ( " " . to_string ( ) , ResourceDirectory { name : " " . to_string ( ) , directories : vec ! [ ] , files : dlls , } , ) ; } for src in settings . resource_files ( ) { let src = src ? ; let filename = src . file_name ( ) . expect ( " " ) . to_os_string ( ) . into_string ( ) . expect ( " " ) ; let resource_path = cwd . join ( src . clone ( ) ) . into_os_string ( ) . into_string ( ) . expect ( " " ) ; let resource_entry = ResourceFile { guid : generate_guid ( filename . as_bytes ( ) ) . to_string ( ) , path : resource_path , id : regex . replace_all ( & filename , " " ) . to_string ( ) , } ; // split the resource path directories let mut directories = src . components ( ) . filter ( | component | { let comp = component . as_os_str ( ) ; comp != " " && comp != " " } ) . collect :: < Vec < _ > > ( ) ; directories . truncate ( directories . len ( ) - 1 ) ; // transform the directory structure to a chained vec structure for directory in directories { let directory_name = directory . as_os_str ( ) . to_os_string ( ) . into_string ( ) . expect ( " " ) ; // if the directory is already on the map if resources . contains_key ( & directory_name ) { let directory_entry = & mut resources . get_mut ( & directory_name ) . expect ( " " ) ; if directory_entry . name == directory_name { // the directory entry is the root of the chain directory_entry . add_file ( resource_entry . clone ( ) ) ; } else { let index = directory_entry . directories . iter ( ) . position ( | f | f . name == directory_name ) ; if index . is_some ( ) { // the directory entry is already a part of the chain let dir = directory_entry . directories . get_mut ( index . expect ( " " ) ) . expect ( " " ) ; dir . add_file ( resource_entry . clone ( ) ) ; } else { // push it to the chain directory_entry . directories . push ( ResourceDirectory { name : directory_name . clone ( ) , directories : vec ! [ ] , files : vec ! [ resource_entry clone ( ) ] , } ) ; } } } else { resources . insert ( directory_name . clone ( ) , ResourceDirectory { name : directory_name . clone ( ) , directories : vec ! [ ] , files : vec ! [ resource_entry clone ( ) ] , } , ) ; } } } Ok ( resources ) }
Generates the data required for the resource bundling on wix
Generates the data required for the resource bundling on wix
settings
&Settings
settings
&Settings