diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/winreg/examples/installed_apps.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/winreg/examples/installed_apps.rs')
-rw-r--r-- | third_party/rust/winreg/examples/installed_apps.rs | 50 |
1 files changed, 50 insertions, 0 deletions
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..a7546847db --- /dev/null +++ b/third_party/rust/winreg/examples/installed_apps.rs @@ -0,0 +1,50 @@ +// Copyright 2017, Igor Shaula +// Licensed under the MIT License <LICENSE or +// http://opensource.org/licenses/MIT>. This file +// may not be copied, modified, or distributed +// except according to those terms. +#[macro_use] +extern crate serde_derive; +extern crate winreg; +use std::collections::HashMap; +use std::fmt; +use winreg::enums::*; + +#[allow(non_snake_case)] +#[derive(Debug, Serialize, Deserialize)] +struct InstalledApp { + DisplayName: Option<String>, + DisplayVersion: Option<String>, + UninstallString: Option<String>, +} + +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<String, InstalledApp> = + uninstall_key.decode().expect("deserialization failed"); + + for v in apps.values() { + println!("{}", v); + } +} |