From efaf71ec04af0f6211db26e5b6f0feef3c66a299 Mon Sep 17 00:00:00 2001 From: Ethan Green Date: Sun, 3 Mar 2024 15:30:27 -0500 Subject: [PATCH] shim util::reg pending legit wine impl --- src/util/reg.rs | 86 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/src/util/reg.rs b/src/util/reg.rs index df39b19..f115886 100644 --- a/src/util/reg.rs +++ b/src/util/reg.rs @@ -1,4 +1,4 @@ -use winreg::RegKey; +pub use inner::*; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -19,36 +19,64 @@ pub struct RegKeyVal { pub val: String, } -pub fn get_value_at(hkey: HKey, subkey: &str, name: &str) -> Result { - open_subkey(hkey, subkey)? - .get_value(name) - .map_err(|_| Error::RegistryValueRead(subkey.to_string(), name.to_string())) -} +#[cfg(target_os = "windows")] +mod inner { + use winreg::RegKey; -pub fn get_keys_at(hkey: HKey, subkey: &str) -> Result, Error> { - open_subkey(hkey, subkey)? - .enum_keys() - .collect::, _>>() - .map_err(|_| Error::RegistrySubkeyRead(subkey.to_string())) -} + use super::{Error, HKey, RegKeyVal}; + + pub fn get_value_at(hkey: HKey, subkey: &str, name: &str) -> Result { + open_subkey(hkey, subkey)? + .get_value(name) + .map_err(|_| Error::RegistryValueRead(subkey.to_string(), name.to_string())) + } + + pub fn get_keys_at(hkey: HKey, subkey: &str) -> Result, Error> { + open_subkey(hkey, subkey)? + .enum_keys() + .collect::, _>>() + .map_err(|_| Error::RegistrySubkeyRead(subkey.to_string())) + } + + pub fn get_values_at(hkey: HKey, subkey: &str) -> Result, Error> { + open_subkey(hkey, subkey)? + .enum_values() + .map(|x| match x { + Ok((key, val)) => Ok(RegKeyVal { + key, + val: val.to_string(), + }), + Err(e) => Err(e), + }) + .collect::, _>>() + .map_err(|_| Error::RegistrySubkeyRead(subkey.to_string())) + } -pub fn get_values_at(hkey: HKey, subkey: &str) -> Result, Error> { - open_subkey(hkey, subkey)? - .enum_values() - .map(|x| match x { - Ok((key, val)) => Ok(RegKeyVal { - key, - val: val.to_string(), - }), - Err(e) => Err(e), - }) - .collect::, _>>() - .map_err(|_| Error::RegistrySubkeyRead(subkey.to_string())) + fn open_subkey(hkey: HKey, subkey: &str) -> Result { + let local = RegKey::predef(hkey as _); + local + .open_subkey(subkey) + .map_err(|_| Error::RegistrySubkeyRead(subkey.to_string())) + } } -fn open_subkey(hkey: HKey, subkey: &str) -> Result { - let local = RegKey::predef(hkey as _); - local - .open_subkey(subkey) - .map_err(|_| Error::RegistrySubkeyRead(subkey.to_string())) +#[cfg(target_os = "linux")] +mod inner { + use super::{Error, HKey, RegKeyVal}; + + fn get_prefix() -> Option { + todo!() + } + + pub fn get_value_at(hkey: HKey, subkey: &str, name: &str) -> Result { + todo!() + } + + pub fn get_keys_at(hkey: HKey, subkey: &str) -> Result, Error> { + todo!() + } + + pub fn get_values_at(hkey: HKey, subkey: &str) -> Result, Error> { + todo!() + } }