Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jul 2, 2024
1 parent 32e14fd commit b559b92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
4 changes: 1 addition & 3 deletions plugins/updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ impl<R: Runtime, T: Manager<R>> UpdaterExt<R> for T {

let args = self.env().args_os;
if !args.is_empty() {
builder = builder
.nsis_installer_arg("/ARGS")
.nsis_installer_args(args);
builder = builder.current_exe_args(args);
}

#[cfg(any(
Expand Down
66 changes: 32 additions & 34 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub struct UpdaterBuilder {
timeout: Option<Duration>,
proxy: Option<Url>,
installer_args: Vec<OsString>,
nsis_installer_args: Vec<OsString>,
current_exe_args: Vec<OsString>,
on_before_exit: Option<OnBeforeExit>,
}

Expand All @@ -116,7 +116,7 @@ impl UpdaterBuilder {
.as_ref()
.map(|w| w.installer_args.clone())
.unwrap_or_default(),
nsis_installer_args: Vec::new(),
current_exe_args: Vec::new(),
current_version,
config,
version_comparator: None,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl UpdaterBuilder {
proxy: self.proxy,
endpoints,
installer_args: self.installer_args,
nsis_installer_args: self.nsis_installer_args,
current_exe_args: self.current_exe_args,
arch,
target,
json_target,
Expand All @@ -257,21 +257,13 @@ impl UpdaterBuilder {
}

impl UpdaterBuilder {
pub(crate) fn nsis_installer_arg<S>(mut self, arg: S) -> Self
where
S: Into<OsString>,
{
self.nsis_installer_args.push(arg.into());
self
}

pub(crate) fn nsis_installer_args<I, S>(mut self, args: I) -> Self
pub(crate) fn current_exe_args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<OsString>,
{
let args = args.into_iter().map(|a| a.into()).collect::<Vec<_>>();
self.nsis_installer_args.extend_from_slice(&args);
self.current_exe_args.extend_from_slice(&args);
self
}
}
Expand All @@ -294,7 +286,7 @@ pub struct Updater {
#[allow(unused)]
installer_args: Vec<OsString>,
#[allow(unused)]
nsis_installer_args: Vec<OsString>,
current_exe_args: Vec<OsString>,
}

impl Updater {
Expand Down Expand Up @@ -406,7 +398,7 @@ impl Updater {
proxy: self.proxy.clone(),
headers: self.headers.clone(),
installer_args: self.installer_args.clone(),
nsis_installer_args: self.nsis_installer_args.clone(),
current_exe_args: self.current_exe_args.clone(),
})
} else {
None
Expand Down Expand Up @@ -447,7 +439,7 @@ pub struct Update {
#[allow(unused)]
installer_args: Vec<OsString>,
#[allow(unused)]
nsis_installer_args: Vec<OsString>,
current_exe_args: Vec<OsString>,
}

impl Resource for Update {}
Expand Down Expand Up @@ -594,31 +586,37 @@ impl Update {

let updater_type = Self::extract(bytes)?;

let msi_args = self.nsis_installer_args()[2..]
.iter()
.map(escape_msi_property_arg)
.collect::<Vec<_>>()
.join(" ");
let msi_args = OsString::from(format!("LAUNCHAPPARGS=\"{msi_args}\""));

let install_mode = self.config.install_mode();
let current_args = &self.current_exe_args()[1..];
let msi_args;

let installer_args: Vec<&OsStr> = match &updater_type {
WindowsUpdaterType::Nsis { .. } => install_mode
.nsis_args()
.iter()
.map(OsStr::new)
.chain(once(OsStr::new("/UPDATE")))
.chain(self.nsis_installer_args())
.chain(once(OsStr::new("/ARGS")))
.chain(current_args.to_vec())
.chain(self.installer_args())
.collect(),
WindowsUpdaterType::Msi { path, .. } => [OsStr::new("/i"), path.as_os_str()]
.into_iter()
.chain(install_mode.msiexec_args().iter().map(OsStr::new))
.chain(once(OsStr::new("/promptrestart")))
.chain(self.installer_args())
.chain(once(OsStr::new("AUTOLAUNCHAPP=True")))
.chain(once(msi_args.as_os_str()))
.collect(),
WindowsUpdaterType::Msi { path, .. } => {
let escaped_args = current_args
.iter()
.map(escape_msi_property_arg)
.collect::<Vec<_>>()
.join(" ");
msi_args = OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""));

[OsStr::new("/i"), path.as_os_str()]
.into_iter()
.chain(install_mode.msiexec_args().iter().map(OsStr::new))
.chain(once(OsStr::new("/promptrestart")))
.chain(self.installer_args())
.chain(once(OsStr::new("AUTOLAUNCHAPP=True")))
.chain(once(msi_args.as_os_str()))
.collect()
}
};

if let Some(on_before_exit) = self.on_before_exit.as_ref() {
Expand Down Expand Up @@ -658,8 +656,8 @@ impl Update {
.collect::<Vec<_>>()
}

fn nsis_installer_args(&self) -> Vec<&OsStr> {
self.nsis_installer_args
fn current_exe_args(&self) -> Vec<&OsStr> {
self.current_exe_args
.iter()
.map(OsStr::new)
.collect::<Vec<_>>()
Expand Down

0 comments on commit b559b92

Please sign in to comment.