diff --git a/.changes/store-main-binary-name.md b/.changes/store-main-binary-name.md new file mode 100644 index 000000000000..fff3fb793b53 --- /dev/null +++ b/.changes/store-main-binary-name.md @@ -0,0 +1,6 @@ +--- +"tauri-bundler": "patch:feat" +--- + +Store main binary name in registry for NSIS installer and delete old main binary on updates if the name changes. + diff --git a/Cargo.lock b/Cargo.lock index 9e0825f8de65..c573557e5bee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7120,6 +7120,7 @@ dependencies = [ "thiserror", "time", "ureq", + "url", "uuid", "walkdir", "windows-registry", diff --git a/crates/tauri-bundler/src/bundle/windows/msi/wix.rs b/crates/tauri-bundler/src/bundle/windows/msi/wix.rs index 362ca1ff87f1..2fcc2580ac37 100644 --- a/crates/tauri-bundler/src/bundle/windows/msi/wix.rs +++ b/crates/tauri-bundler/src/bundle/windows/msi/wix.rs @@ -540,8 +540,9 @@ pub fn build_wix_app_installer( 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)); + // Note: `main_binary_name` is not used in our template but we keep it as it is potentially useful for custom temples + let main_binary_name = settings.main_binary_name().to_string(); + data.insert("main_binary_name", to_json(&main_binary_name)); let binaries = generate_binaries_data(settings)?; diff --git a/crates/tauri-bundler/src/bundle/windows/templates/installer.nsi b/crates/tauri-bundler/src/bundle/windows/templates/installer.nsi index c6e728c66dde..35cede30caad 100644 --- a/crates/tauri-bundler/src/bundle/windows/templates/installer.nsi +++ b/crates/tauri-bundler/src/bundle/windows/templates/installer.nsi @@ -637,6 +637,15 @@ Section Install WriteRegStr SHCTX "${UNINSTKEY}" $MultiUser.InstallMode 1 !endif + ; Remove old main binary if it doesn't match new main binary name + ReadRegStr $0 SHCTX "${UNINSTKEY}" "MainBinaryName" + ${If} $0 != "${MAINBINARYNAME}.exe" + Delete "$INSTDIR\$0" + ${EndIf} + + ; Save current MAINBINARYNAME for future updates + WriteRegStr SHCTX "${UNINSTKEY}" "MainBinaryName" "${MAINBINARYNAME}.exe" + ; Registry information for add/remove programs WriteRegStr SHCTX "${UNINSTKEY}" "DisplayName" "${PRODUCTNAME}" WriteRegStr SHCTX "${UNINSTKEY}" "DisplayIcon" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\""