Skip to content

Commit

Permalink
fix(windows): nsis failed to resolve resources with $ in their name,
Browse files Browse the repository at this point in the history
…closes #9657 (#9659)
  • Loading branch information
enkhjile authored May 8, 2024
1 parent 07b6f9f commit ab9ec42
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/bundler-nsis-resources-dollar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-bundler': 'patch:bug'
---

Fix failing to create NSIS installer when including resources that has `$` in its path.
13 changes: 13 additions & 0 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ fn build_nsis_app_installer(
}

let mut handlebars = Handlebars::new();
handlebars.register_helper("unescape-dollar-sign", Box::new(unescape_dollar_sign));
handlebars.register_escape_fn(|s| {
let mut output = String::new();
for c in s.chars() {
Expand Down Expand Up @@ -504,6 +505,18 @@ fn build_nsis_app_installer(
Ok(vec![nsis_installer_path])
}

fn unescape_dollar_sign(
h: &handlebars::Helper<'_, '_>,
_: &Handlebars<'_>,
_: &handlebars::Context,
_: &mut handlebars::RenderContext<'_, '_>,
out: &mut dyn handlebars::Output,
) -> handlebars::HelperResult {
let content = h.param(0).unwrap().render();
out.write(&content.replace("$$", "$"))?;
Ok(())
}

/// BTreeMap<OriginalPath, (ParentOfTargetPath, TargetPath)>
type ResourcesMap = BTreeMap<PathBuf, (PathBuf, PathBuf)>;
fn generate_resource_data(settings: &Settings) -> crate::Result<ResourcesMap> {
Expand Down
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle/windows/templates/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,12 @@ Section Install
CreateDirectory "$INSTDIR\\{{this}}"
{{/each}}
{{#each resources}}
File /a "/oname={{this.[1]}}" "{{@key}}"
File /a "/oname={{this.[1]}}" "{{unescape-dollar-sign @key}}"
{{/each}}

; Copy external binaries
{{#each binaries}}
File /a "/oname={{this}}" "{{@key}}"
File /a "/oname={{this}}" "{{unescape-dollar-sign @key}}"
{{/each}}

; Create uninstaller
Expand Down

0 comments on commit ab9ec42

Please sign in to comment.