winbrew_windows\registry/
product_options.rs

1use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
2
3const PRODUCT_OPTIONS_KEY: &str = r"SYSTEM\CurrentControlSet\Control\ProductOptions";
4const PRODUCT_TYPE_VALUE: &str = "ProductType";
5
6/// Read the Windows product type when it is available.
7pub(crate) fn read_product_type() -> Option<String> {
8    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
9
10    let Ok(product_options_key) = hklm.open_subkey(PRODUCT_OPTIONS_KEY) else {
11        return None;
12    };
13
14    let Ok(product_type) = product_options_key.get_value::<String, _>(PRODUCT_TYPE_VALUE) else {
15        return None;
16    };
17
18    let product_type = product_type.trim();
19    if product_type.is_empty() {
20        None
21    } else {
22        Some(product_type.to_string())
23    }
24}