Răsfoiți Sursa

fix(windows): nsis failed to resolve resources with `$` in their name, closes #9657 (#9659)

Enkhjil Enkhbaatar 1 an în urmă
părinte
comite
ab9ec42c10

+ 5 - 0
.changes/bundler-nsis-resources-dollar.md

@@ -0,0 +1,5 @@
+---
+'tauri-bundler': 'patch:bug'
+---
+
+Fix failing to create NSIS installer when including resources that has `$` in its path.

+ 13 - 0
tooling/bundler/src/bundle/windows/nsis.rs

@@ -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() {
@@ -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> {

+ 2 - 2
tooling/bundler/src/bundle/windows/templates/installer.nsi

@@ -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