Skip to content

Commit ab8975f

Browse files
committed
feat(self-update): add with_saved_programs_display_version()
1 parent 6d35ded commit ab8975f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/cli/self_update/test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ fn restore_path(p: Option<RegValue>) {
4848
#[cfg(unix)]
4949
fn restore_path(_: Option<()>) {}
5050

51+
#[cfg(windows)]
52+
pub fn with_saved_programs_display_version(f: &mut dyn FnMut()) {
53+
let root = &RegKey::predef(HKEY_CURRENT_USER);
54+
let key = super::windows::RUSTUP_UNINSTALL_ENTRY;
55+
let name = "DisplayVersion";
56+
with_saved_global_state(
57+
|| get_reg_value(root, key, name),
58+
|p| restore_reg_value(root, key, name, p),
59+
f,
60+
)
61+
}
62+
5163
#[cfg(windows)]
5264
fn get_reg_value(root: &RegKey, subkey: &str, name: &str) -> io::Result<Option<RegValue>> {
5365
let subkey = root

src/cli/self_update/windows.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ pub(crate) fn do_remove_from_path() -> Result<()> {
498498
_apply_new_path(new_path)
499499
}
500500

501-
const RUSTUP_UNINSTALL_ENTRY: &str = r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Rustup";
501+
pub(super) const RUSTUP_UNINSTALL_ENTRY: &str =
502+
r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Rustup";
502503

503504
fn rustup_uninstall_reg_key() -> Result<RegKey> {
504505
Ok(RegKey::predef(HKEY_CURRENT_USER)

src/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub use crate::cli::self_update::test::{get_path, with_saved_path};
1919
use crate::currentprocess;
2020
use crate::dist::dist::TargetTriple;
2121

22+
#[cfg(windows)]
23+
pub use crate::cli::self_update::test::with_saved_programs_display_version;
24+
2225
// Things that can have environment variables applied to them.
2326
pub trait Env {
2427
fn env<K, V>(&mut self, key: K, val: V)

0 commit comments

Comments
 (0)