Browse Source

fix(bundler): Fix nsis resource paths on non-windows build systems. (#9281)

* fix(bundler): Fix nsis resource paths on non-windows build systems.

* remove leftover from alternative
Fabian-Lars 1 year ago
parent
commit
017861e4d5
2 changed files with 30 additions and 0 deletions
  1. 5 0
      .changes/bundler-resources-unix.md
  2. 25 0
      tooling/bundler/src/bundle/windows/nsis.rs

+ 5 - 0
.changes/bundler-resources-unix.md

@@ -0,0 +1,5 @@
+---
+'tauri-bundler': 'patch:bug'
+---
+
+Fixed an issue causing the NSIS bundler to install resources incorrectly when the installer was built on a non-Windows system.

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

@@ -339,6 +339,31 @@ fn build_nsis_app_installer(
   resources_ancestors.sort_by_key(|p| std::cmp::Reverse(p.components().count()));
   resources_ancestors.pop(); // Last one is always ""
 
+  // We need to convert / to \ for nsis to move the files into the correct dirs
+  #[cfg(not(target_os = "windows"))]
+  let resources: ResourcesMap = resources
+    .into_iter()
+    .map(|(r, p)| {
+      (
+        r,
+        (
+          p.0.display().to_string().replace('/', "\\").into(),
+          p.1.display().to_string().replace('/', "\\").into(),
+        ),
+      )
+    })
+    .collect();
+  #[cfg(not(target_os = "windows"))]
+  let resources_ancestors: Vec<PathBuf> = resources_ancestors
+    .into_iter()
+    .map(|p| p.display().to_string().replace('/', "\\").into())
+    .collect();
+  #[cfg(not(target_os = "windows"))]
+  let resources_dirs: Vec<PathBuf> = resources_dirs
+    .into_iter()
+    .map(|p| p.display().to_string().replace('/', "\\").into())
+    .collect();
+
   data.insert("resources_ancestors", to_json(resources_ancestors));
   data.insert("resources_dirs", to_json(resources_dirs));
   data.insert("resources", to_json(&resources));