From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/winreg/examples/installed_apps.rs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 third_party/rust/winreg/examples/installed_apps.rs (limited to 'third_party/rust/winreg/examples/installed_apps.rs') diff --git a/third_party/rust/winreg/examples/installed_apps.rs b/third_party/rust/winreg/examples/installed_apps.rs new file mode 100644 index 0000000000..f7d555b90d --- /dev/null +++ b/third_party/rust/winreg/examples/installed_apps.rs @@ -0,0 +1,43 @@ +// Copyright 2017, Igor Shaula +// Licensed under the MIT License . This file +// may not be copied, modified, or distributed +// except according to those terms. +#[macro_use] +extern crate serde_derive; +extern crate winreg; +use winreg::enums::*; +use std::collections::HashMap; +use std::fmt; + +#[allow(non_snake_case)] +#[derive(Debug, Serialize, Deserialize)] +struct InstalledApp { + DisplayName: Option, + DisplayVersion: Option, + UninstallString: Option +} + +macro_rules! str_from_opt { + ($s:expr) => { $s.as_ref().map(|x| &**x).unwrap_or("") } +} + +impl fmt::Display for InstalledApp { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}-{}", + str_from_opt!(self.DisplayName), + str_from_opt!(self.DisplayVersion)) + } +} + +fn main() { + let hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE); + let uninstall_key = hklm.open_subkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall") + .expect("key is missing"); + + let apps: HashMap = uninstall_key.decode().expect("deserialization failed"); + + for (_k, v) in &apps { + println!("{}", v); + } +} -- cgit v1.2.3