Skip to content

Commit b19d033

Browse files
committed
refactor(self-update): extract do_update_programs_display_version()
1 parent f26d16b commit b19d033

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/cli/self_update/windows.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,23 @@ pub(crate) fn do_remove_from_path() -> Result<()> {
500500

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

503+
fn rustup_uninstall_reg_key() -> Result<RegKey> {
504+
Ok(RegKey::predef(HKEY_CURRENT_USER)
505+
.create_subkey(RUSTUP_UNINSTALL_ENTRY)
506+
.context("Failed creating uninstall key")?
507+
.0)
508+
}
509+
510+
pub(crate) fn do_update_programs_display_version(version: &str) -> Result<()> {
511+
rustup_uninstall_reg_key()?
512+
.set_value("DisplayVersion", &version)
513+
.context("Failed to set display version")
514+
}
515+
503516
pub(crate) fn do_add_to_programs() -> Result<()> {
504517
use std::path::PathBuf;
505518

506-
let key = RegKey::predef(HKEY_CURRENT_USER)
507-
.create_subkey(RUSTUP_UNINSTALL_ENTRY)
508-
.context("Failed creating uninstall key")?
509-
.0;
519+
let key = rustup_uninstall_reg_key()?;
510520

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

534-
let current_version: &str = env!("CARGO_PKG_VERSION");
535-
536544
key.set_raw_value("UninstallString", &reg_value)
537545
.context("Failed to set uninstall string")?;
538546
key.set_value("DisplayName", &"Rustup: the Rust toolchain installer")
539547
.context("Failed to set display name")?;
540-
key.set_value("DisplayVersion", &current_version)
541-
.context("Failed to set display version")?;
548+
do_update_programs_display_version(env!("CARGO_PKG_VERSION"))?;
542549

543550
Ok(())
544551
}

0 commit comments

Comments
 (0)