pub fn build_wix_app_installer(
  settings: &Settings,
  wix_toolset_path: &Path,
) -> crate::Result<PathBuf> {
  let arch = match settings.binary_arch() {
    "x86_64" => "x64",
    "x86" => "x86",
    target => {
      return Err(crate::Error::ArchError(format!(
        "unsupported target: {}",
        target
      )))
    }
  };

  // target only supports x64.
  common::print_info(format!("Target: {}", arch).as_str())?;

  let output_path = settings
    .project_out_directory()
    .join("bundle/msi")
    .join(arch);

  let mut data = BTreeMap::new();

  if crate::bundle::tauri_config::get().is_ok() {
    data.insert("embedded_server", to_json(true));
  }

  data.insert("product_name", to_json(settings.bundle_name()));
  data.insert("version", to_json(settings.version_string()));
  let manufacturer = settings.bundle_identifier().to_string();
  data.insert("manufacturer", to_json(manufacturer.as_str()));
  let upgrade_code = Uuid::new_v5(
    &Uuid::NAMESPACE_DNS,
    format!("{}.app.x64", &settings.main_binary_name()).as_bytes(),
  )
  .to_string();

  data.insert("upgrade_code", to_json(&upgrade_code.as_str()));

  let path_guid = generate_package_guid(settings).to_string();
  data.insert("path_component_guid", to_json(&path_guid.as_str()));

  let shortcut_guid = generate_package_guid(settings).to_string();
  data.insert("shortcut_guid", to_json(&shortcut_guid.as_str()));

  let app_exe_name = settings.main_binary_name().to_string();
  data.insert("app_exe_name", to_json(&app_exe_name));

  let binaries = generate_binaries_data(&settings)?;

  let binaries_json = to_json(&binaries);
  data.insert("binaries", binaries_json);

  let resources = generate_resource_data(&settings)?;
  let mut resources_wix_string = String::from("");
  let mut files_ids = Vec::new();
  for (_, dir) in resources {
    let (wix_string, ids) = dir.get_wix_data()?;
    resources_wix_string.push_str(wix_string.as_str());
    for id in ids {
      files_ids.push(id);
    }
  }

  data.insert("resources", to_json(resources_wix_string));
  data.insert("resource_file_ids", to_json(files_ids));

  let main_binary = settings
    .binaries()
    .iter()
    .find(|bin| bin.main())
    .ok_or_else(|| anyhow::anyhow!("Failed to get main binary"))?;
  let app_exe_source = settings.binary_path(main_binary).display().to_string();

  data.insert("app_exe_source", to_json(&app_exe_source));

  // copy icons from icons folder to resource folder near msi
  let image_path = copy_icons(&settings)?;

  let path = image_path.join("icon.ico").display().to_string();

  data.insert("icon_path", to_json(path.as_str()));

  let temp = HANDLEBARS.render("main.wxs", &data)?;

  if output_path.exists() {
    remove_dir_all(&output_path)?;
  }

  create_dir_all(&output_path)?;

  let main_wxs_path = output_path.join("main.wxs");
  write(&main_wxs_path, temp)?;

  let input_basenames = vec!["main"];

  for basename in &input_basenames {
    let wxs = format!("{}.wxs", basename);
    run_candle(settings, &wix_toolset_path, &output_path, &wxs)?;
  }

  let wixobjs = vec!["main.wixobj"];
  let target = run_light(
    &wix_toolset_path,
    &output_path,
    &wixobjs,
    &app_installer_dir(&settings)?,
    &settings,
  )?;

  Ok(target)
}
// Entry point for bundling and creating the MSI installer. For now the only supported platform is Windows x64.
Entry point for bundling and creating the MSI installer. For now the only supported platform is Windows x64.
Entry point for bundling and creating the MSI installer . For now the only supported platform is Windows x64 .
pub fn build_wix_app_installer(
  settings: &Settings,
  wix_toolset_path: &Path,
) -> crate::Result<PathBuf> {
  let arch = match settings.binary_arch() {
    "x86_64" => "x64",
    "x86" => "x86",
    target => {
      return Err(crate::Error::ArchError(format!(
        "unsupported target: {}",
        target
      )))
    }
  };
  // target only supports x64.
  common::print_info(format!("Target: {}", arch).as_str())?;
  let output_path = settings
    .project_out_directory()
    .join("bundle/msi")
    .join(arch);
  let mut data = BTreeMap::new();
  if crate::bundle::tauri_config::get().is_ok() {
    data.insert("embedded_server", to_json(true));
  }
  data.insert("product_name", to_json(settings.bundle_name()));
  data.insert("version", to_json(settings.version_string()));
  let manufacturer = settings.bundle_identifier().to_string();
  data.insert("manufacturer", to_json(manufacturer.as_str()));
  let upgrade_code = Uuid::new_v5(
    &Uuid::NAMESPACE_DNS,
    format!("{}.app.x64", &settings.main_binary_name()).as_bytes(),
  )
  .to_string();
  data.insert("upgrade_code", to_json(&upgrade_code.as_str()));
  let path_guid = generate_package_guid(settings).to_string();
  data.insert("path_component_guid", to_json(&path_guid.as_str()));
  let shortcut_guid = generate_package_guid(settings).to_string();
  data.insert("shortcut_guid", to_json(&shortcut_guid.as_str()));
  let app_exe_name = settings.main_binary_name().to_string();
  data.insert("app_exe_name", to_json(&app_exe_name));
  let binaries = generate_binaries_data(&settings)?;
  let binaries_json = to_json(&binaries);
  data.insert("binaries", binaries_json);
  let resources = generate_resource_data(&settings)?;
  let mut resources_wix_string = String::from("");
  let mut files_ids = Vec::new();
  for (_, dir) in resources {
    let (wix_string, ids) = dir.get_wix_data()?;
    resources_wix_string.push_str(wix_string.as_str());
    for id in ids {
      files_ids.push(id);
    }
  }
  data.insert("resources", to_json(resources_wix_string));
  data.insert("resource_file_ids", to_json(files_ids));
  let main_binary = settings
    .binaries()
    .iter()
    .find(|bin| bin.main())
    .ok_or_else(|| anyhow::anyhow!("Failed to get main binary"))?;
  let app_exe_source = settings.binary_path(main_binary).display().to_string();
  data.insert("app_exe_source", to_json(&app_exe_source));
  // copy icons from icons folder to resource folder near msi
  let image_path = copy_icons(&settings)?;
  let path = image_path.join("icon.ico").display().to_string();
  data.insert("icon_path", to_json(path.as_str()));
  let temp = HANDLEBARS.render("main.wxs", &data)?;
  if output_path.exists() {
    remove_dir_all(&output_path)?;
  }
  create_dir_all(&output_path)?;
  let main_wxs_path = output_path.join("main.wxs");
  write(&main_wxs_path, temp)?;
  let input_basenames = vec!["main"];
  for basename in &input_basenames {
    let wxs = format!("{}.wxs", basename);
    run_candle(settings, &wix_toolset_path, &output_path, &wxs)?;
  }
  let wixobjs = vec!["main.wixobj"];
  let target = run_light(
    &wix_toolset_path,
    &output_path,
    &wixobjs,
    &app_installer_dir(&settings)?,
    &settings,
  )?;
  Ok(target)
}
pub fn build_wix_app_installer ( settings : & Settings , wix_toolset_path : & Path , ) -> crate :: Result < PathBuf > { let arch = match settings . binary_arch ( ) { " " => " " , " " => " " , target => { return Err ( crate :: Error :: ArchError ( format ! ( " " target ) ) ) } } ; // target only supports x64. common :: print_info ( format ! ( " " arch ) . as_str ( ) ) ? ; let output_path = settings . project_out_directory ( ) . join ( " " ) . join ( arch ) ; let mut data = BTreeMap :: new ( ) ; if crate :: bundle :: tauri_config :: get ( ) . is_ok ( ) { data . insert ( " " , to_json ( true ) ) ; } data . insert ( " " , to_json ( settings . bundle_name ( ) ) ) ; data . insert ( " " , to_json ( settings . version_string ( ) ) ) ; let manufacturer = settings . bundle_identifier ( ) . to_string ( ) ; data . insert ( " " , to_json ( manufacturer . as_str ( ) ) ) ; let upgrade_code = Uuid :: new_v5 ( & Uuid :: NAMESPACE_DNS , format ! ( " " settings main_binary_name ( ) ) . as_bytes ( ) , ) . to_string ( ) ; data . insert ( " " , to_json ( & upgrade_code . as_str ( ) ) ) ; let path_guid = generate_package_guid ( settings ) . to_string ( ) ; data . insert ( " " , to_json ( & path_guid . as_str ( ) ) ) ; let shortcut_guid = generate_package_guid ( settings ) . to_string ( ) ; data . insert ( " " , to_json ( & shortcut_guid . as_str ( ) ) ) ; let app_exe_name = settings . main_binary_name ( ) . to_string ( ) ; data . insert ( " " , to_json ( & app_exe_name ) ) ; let binaries = generate_binaries_data ( & settings ) ? ; let binaries_json = to_json ( & binaries ) ; data . insert ( " " , binaries_json ) ; let resources = generate_resource_data ( & settings ) ? ; let mut resources_wix_string = String :: from ( " " ) ; let mut files_ids = Vec :: new ( ) ; for ( _ , dir ) in resources { let ( wix_string , ids ) = dir . get_wix_data ( ) ? ; resources_wix_string . push_str ( wix_string . as_str ( ) ) ; for id in ids { files_ids . push ( id ) ; } } data . insert ( " " , to_json ( resources_wix_string ) ) ; data . insert ( " " , to_json ( files_ids ) ) ; let main_binary = settings . binaries ( ) . iter ( ) . find ( | bin | bin . main ( ) ) . ok_or_else ( | | anyhow :: anyhow ! ( " " ) ) ? ; let app_exe_source = settings . binary_path ( main_binary ) . display ( ) . to_string ( ) ; data . insert ( " " , to_json ( & app_exe_source ) ) ; // copy icons from icons folder to resource folder near msi let image_path = copy_icons ( & settings ) ? ; let path = image_path . join ( " " ) . display ( ) . to_string ( ) ; data . insert ( " " , to_json ( path . as_str ( ) ) ) ; let temp = HANDLEBARS . render ( " " , & data ) ? ; if output_path . exists ( ) { remove_dir_all ( & output_path ) ? ; } create_dir_all ( & output_path ) ? ; let main_wxs_path = output_path . join ( " " ) ; write ( & main_wxs_path , temp ) ? ; let input_basenames = vec ! [ " " ] ; for basename in & input_basenames { let wxs = format ! ( " " basename ) ; run_candle ( settings , & wix_toolset_path , & output_path , & wxs ) ? ; } let wixobjs = vec ! [ " " ] ; let target = run_light ( & wix_toolset_path , & output_path , & wixobjs , & app_installer_dir ( & settings ) ? , & settings , ) ? ; Ok ( target ) }
Entry point for bundling and creating the MSI installer.
Entry point for bundling and creating the MSI installer .
settings
&Settings
wix_toolset_path
&Path
settings
&Settings
wix_toolset_path
&Path