Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bundler/nsis): write installer templates UTF16LE encoded, closes #7036 #7040

Merged
merged 6 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/nsis-encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-bundler': 'patch'
lucasfernog marked this conversation as resolved.
Show resolved Hide resolved
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
---

Fix NSIS bundler failing to build when `productName` contained chinsese characters.
1 change: 0 additions & 1 deletion tooling/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ handlebars = "4.3"
tempfile = "3.5.0"
log = { version = "0.4.17", features = [ "kv_unstable" ] }
dirs-next = "2.0"
encoding_rs = "0.8"
os_pipe = "1"
attohttpc = { version = "0.25", default-features = false }
hex = "0.4"
Expand Down
89 changes: 32 additions & 57 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,14 @@ fn build_nsis_app_installer(
.expect("Failed to setup handlebar template");
}
let installer_nsi_path = output_path.join("installer.nsi");
write(
write_ut16_le_with_bom(
&installer_nsi_path,
encoding_rs::UTF_8
.encode(handlebars.render("installer.nsi", &data)?.as_str())
.0,
handlebars.render("installer.nsi", &data)?.as_str(),
)?;

for (lang, data) in languages_data.iter() {
if let Some((content, encoding)) = data {
write(
output_path.join(lang).with_extension("nsh"),
encoding.encode(content).0,
)?;
if let Some(content) = data {
write_ut16_le_with_bom(output_path.join(lang).with_extension("nsh"), &content)?;
}
}

Expand Down Expand Up @@ -553,12 +548,7 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<BinariesMap> {
fn get_lang_data(
lang: &str,
custom_lang_files: Option<&HashMap<String, PathBuf>>,
) -> Option<(
String,
Option<(&'static str, &'static encoding_rs::Encoding)>,
)> {
use encoding_rs::*;

) -> Option<(String, Option<&'static str>)> {
if let Some(path) = custom_lang_files.and_then(|h| h.get(lang)) {
return Some((
dunce::canonicalize(path)
Expand All @@ -573,86 +563,71 @@ fn get_lang_data(
match lang.to_lowercase().as_str() {
"arabic" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/Arabic.nsh"),
UTF_16LE,
)),
Some(include_str!("./templates/nsis-languages/Arabic.nsh")),
)),
"dutch" => Some((
lang_file,
Some((include_str!("./templates/nsis-languages/Dutch.nsh"), UTF_8)),
Some(include_str!("./templates/nsis-languages/Dutch.nsh")),
)),
"english" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/English.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/English.nsh")),
)),
"japanese" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/Japanese.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/Japanese.nsh")),
)),
"korean" => Some((
lang_file,
Some((include_str!("./templates/nsis-languages/Korean.nsh"), UTF_8)),
Some(include_str!("./templates/nsis-languages/Korean.nsh")),
)),
"portuguesebr" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/PortugueseBR.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/PortugueseBR.nsh")),
)),
"tradchinese" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/TradChinese.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/TradChinese.nsh")),
)),
"simpchinese" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/SimpChinese.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/SimpChinese.nsh")),
)),
"french" => Some((
lang_file,
Some((include_str!("./templates/nsis-languages/French.nsh"), UTF_8)),
Some(include_str!("./templates/nsis-languages/French.nsh")),
)),
"spanish" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/Spanish.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/Spanish.nsh")),
)),
"spanishinternational" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/SpanishInternational.nsh"),
UTF_8,
Some(include_str!(
"./templates/nsis-languages/SpanishInternational.nsh"
)),
)),
"persian" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/Persian.nsh"),
UTF_16LE,
)),
Some(include_str!("./templates/nsis-languages/Persian.nsh")),
)),
"turkish" => Some((
lang_file,
Some((
include_str!("./templates/nsis-languages/Turkish.nsh"),
UTF_8,
)),
Some(include_str!("./templates/nsis-languages/Turkish.nsh")),
)),
_ => None,
}
}

fn write_ut16_le_with_bom<P: AsRef<Path>>(path: P, content: &str) -> crate::Result<()> {
use std::fs::File;
use std::io::{BufWriter, Write};

let file = File::create(path)?;
let mut output = BufWriter::new(file);
output.write_all(&[0xFF, 0xFE])?; // the BOM part
for utf16 in content.encode_utf16() {
output.write_all(&utf16.to_le_bytes())?;
}
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ LangString webview2DownloadSuccess ${LANG_PERSIAN} "WebView2 بوت استرپر
LangString webview2Downloading ${LANG_PERSIAN} "دانلود بوت استرپر WebView2..."
LangString webview2InstallError ${LANG_PERSIAN} "ارور: نصب WebView2 با کد $1 شکست خورد"
LangString webview2InstallSuccess ${LANG_PERSIAN} "WebView2 با موفقیت نصب شد"
LangString deleteAppData ${LANG_PERSIAN} "حذف دیتا های اپلیکیشن"
LangString deleteAppData ${LANG_PERSIAN} "حذف دیتا های اپلیکیشن"
44 changes: 37 additions & 7 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.