Skip to content

Commit

Permalink
refactor(self-update): extract do_update_programs_display_version()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Apr 21, 2024
1 parent f26d16b commit b19d033
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,23 @@ pub(crate) fn do_remove_from_path() -> Result<()> {

const RUSTUP_UNINSTALL_ENTRY: &str = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Rustup";

fn rustup_uninstall_reg_key() -> Result<RegKey> {
Ok(RegKey::predef(HKEY_CURRENT_USER)
.create_subkey(RUSTUP_UNINSTALL_ENTRY)
.context("Failed creating uninstall key")?
.0)
}

pub(crate) fn do_update_programs_display_version(version: &str) -> Result<()> {
rustup_uninstall_reg_key()?
.set_value("DisplayVersion", &version)
.context("Failed to set display version")
}

pub(crate) fn do_add_to_programs() -> Result<()> {
use std::path::PathBuf;

let key = RegKey::predef(HKEY_CURRENT_USER)
.create_subkey(RUSTUP_UNINSTALL_ENTRY)
.context("Failed creating uninstall key")?
.0;
let key = rustup_uninstall_reg_key()?;

// Don't overwrite registry if Rustup is already installed
let prev = key
Expand All @@ -531,14 +541,11 @@ pub(crate) fn do_add_to_programs() -> Result<()> {
vtype: RegType::REG_SZ,
};

let current_version: &str = env!("CARGO_PKG_VERSION");

key.set_raw_value("UninstallString", &reg_value)
.context("Failed to set uninstall string")?;
key.set_value("DisplayName", &"Rustup: the Rust toolchain installer")
.context("Failed to set display name")?;
key.set_value("DisplayVersion", &current_version)
.context("Failed to set display version")?;
do_update_programs_display_version(env!("CARGO_PKG_VERSION"))?;

Ok(())
}
Expand Down

0 comments on commit b19d033

Please sign in to comment.