From 865b500218a5325b2046195fbcc515b73e5f41db Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 5 Jul 2023 14:22:11 +1000 Subject: [PATCH] tugger-wix: Make msi option to add to path env optional. --- tugger-wix/src/simple_msi_builder.rs | 79 +++++++++++-------- .../tugger_starlark_type_wix_msi_builder.rst | 7 ++ tugger/src/starlark/wix_msi_builder.rs | 3 + 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/tugger-wix/src/simple_msi_builder.rs b/tugger-wix/src/simple_msi_builder.rs index 124246515..20efc122a 100644 --- a/tugger-wix/src/simple_msi_builder.rs +++ b/tugger-wix/src/simple_msi_builder.rs @@ -52,6 +52,7 @@ pub struct WiXSimpleMsiBuilder { product_icon: Option, help_url: Option, eula_rtf: Option, + add_to_path: Option, /// Banner BMP image. /// /// Dimensions are 493 x 58. @@ -168,6 +169,13 @@ impl WiXSimpleMsiBuilder { self } + /// Display option to add install folder to the PATH Environment. + #[must_use] + pub fn add_to_path(mut self, value: bool) -> Self { + self.add_to_path = Some(value); + self + } + /// Set the path to a bmp file containing a banner to use for install. /// /// The dimensions of the banner should be 493 x 58. @@ -367,25 +375,27 @@ impl WiXSimpleMsiBuilder { .attr("Name", &self.product_name), )?; - writer.write( - XmlEvent::start_element("Component") - .attr("Id", "Path") - .attr("Guid", &self.path_component_guid()) - .attr("Win64", "$(var.Win64)") - .attr("KeyPath", "yes"), - )?; - writer.write( - XmlEvent::start_element("Environment") - .attr("Id", "PATH") - .attr("Name", "PATH") - .attr("Value", "[APPLICATIONFOLDER]") - .attr("Permanent", "no") - .attr("Part", "last") - .attr("Action", "set") - .attr("System", "yes"), - )?; - writer.write(XmlEvent::end_element().name("Environment"))?; - writer.write(XmlEvent::end_element().name("Component"))?; + if self.add_to_path.unwrap_or(true) { + writer.write( + XmlEvent::start_element("Component") + .attr("Id", "Path") + .attr("Guid", &self.path_component_guid()) + .attr("Win64", "$(var.Win64)") + .attr("KeyPath", "yes"), + )?; + writer.write( + XmlEvent::start_element("Environment") + .attr("Id", "PATH") + .attr("Name", "PATH") + .attr("Value", "[APPLICATIONFOLDER]") + .attr("Permanent", "no") + .attr("Part", "last") + .attr("Action", "set") + .attr("System", "yes"), + )?; + writer.write(XmlEvent::end_element().name("Environment"))?; + writer.write(XmlEvent::end_element().name("Component"))?; + } if let Some(license_source) = &self.license_source { writer.write( @@ -435,22 +445,25 @@ impl WiXSimpleMsiBuilder { writer.write(XmlEvent::start_element("ComponentRef").attr("Id", "License"))?; writer.write(XmlEvent::end_element().name("ComponentRef"))?; } + if self.add_to_path.unwrap_or(true) { + + writer.write( + XmlEvent::start_element("Feature") + .attr("Id", "Environment") + .attr("Title", "PATH Environment Variable") + .attr( + "Description", + "Add the install location to the PATH system environment variable", + ) + .attr("Level", "1") + .attr("Absent", "allow"), + )?; - writer.write( - XmlEvent::start_element("Feature") - .attr("Id", "Environment") - .attr("Title", "PATH Environment Variable") - .attr( - "Description", - "Add the install location to the PATH system environment variable", - ) - .attr("Level", "1") - .attr("Absent", "allow"), - )?; - writer.write(XmlEvent::start_element("ComponentRef").attr("Id", "Path"))?; - writer.write(XmlEvent::end_element().name("ComponentRef"))?; - writer.write(XmlEvent::end_element().name("Feature"))?; + writer.write(XmlEvent::start_element("ComponentRef").attr("Id", "Path"))?; + writer.write(XmlEvent::end_element().name("ComponentRef"))?; + writer.write(XmlEvent::end_element().name("Feature"))?; + } writer.write(XmlEvent::end_element().name("Feature"))?; writer.write( diff --git a/tugger/docs/tugger_starlark_type_wix_msi_builder.rst b/tugger/docs/tugger_starlark_type_wix_msi_builder.rst index 4ecc7cee2..2c9ee2f54 100644 --- a/tugger/docs/tugger_starlark_type_wix_msi_builder.rst +++ b/tugger/docs/tugger_starlark_type_wix_msi_builder.rst @@ -112,6 +112,13 @@ Path to a file providing the icon for the installed application. + .. py:attribute:: add_to_path + + (``bool``) + + When set (on be default), provide an option in the msi installer wizard to + add the application install folder to the system PATH environment. + .. py:attribute:: upgrade_code (``str``) diff --git a/tugger/src/starlark/wix_msi_builder.rs b/tugger/src/starlark/wix_msi_builder.rs index c5f90f7b1..dc2d4673d 100644 --- a/tugger/src/starlark/wix_msi_builder.rs +++ b/tugger/src/starlark/wix_msi_builder.rs @@ -106,6 +106,9 @@ impl TypedValue for WiXMsiBuilderValue { "product_icon_path" => { inner.builder = inner.builder.clone().product_icon_path(value.to_string()); } + "add_to_path" => { + inner.builder = inner.builder.clone().add_to_path(value.to_bool()); + } "upgrade_code" => { inner.builder = inner.builder.clone().upgrade_code(value.to_string()); }