Skip to content

Commit

Permalink
shim util::reg pending legit wine impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ethangreen-dev committed Mar 20, 2024
1 parent 15b8079 commit efaf71e
Showing 1 changed file with 57 additions and 29 deletions.
86 changes: 57 additions & 29 deletions src/util/reg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use winreg::RegKey;
pub use inner::*;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -19,36 +19,64 @@ pub struct RegKeyVal {
pub val: String,
}

pub fn get_value_at(hkey: HKey, subkey: &str, name: &str) -> Result<String, Error> {
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<Vec<String>, Error> {
open_subkey(hkey, subkey)?
.enum_keys()
.collect::<Result<Vec<String>, _>>()
.map_err(|_| Error::RegistrySubkeyRead(subkey.to_string()))
}
use super::{Error, HKey, RegKeyVal};

pub fn get_value_at(hkey: HKey, subkey: &str, name: &str) -> Result<String, Error> {
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<Vec<String>, Error> {
open_subkey(hkey, subkey)?
.enum_keys()
.collect::<Result<Vec<String>, _>>()
.map_err(|_| Error::RegistrySubkeyRead(subkey.to_string()))
}

pub fn get_values_at(hkey: HKey, subkey: &str) -> Result<Vec<RegKeyVal>, 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::<Result<Vec<_>, _>>()
.map_err(|_| Error::RegistrySubkeyRead(subkey.to_string()))
}

pub fn get_values_at(hkey: HKey, subkey: &str) -> Result<Vec<RegKeyVal>, 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::<Result<Vec<_>, _>>()
.map_err(|_| Error::RegistrySubkeyRead(subkey.to_string()))
fn open_subkey(hkey: HKey, subkey: &str) -> Result<RegKey, Error> {
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<RegKey, Error> {
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<String> {
todo!()
}

pub fn get_value_at(hkey: HKey, subkey: &str, name: &str) -> Result<String, Error> {
todo!()
}

pub fn get_keys_at(hkey: HKey, subkey: &str) -> Result<Vec<String>, Error> {
todo!()
}

pub fn get_values_at(hkey: HKey, subkey: &str) -> Result<Vec<RegKeyVal>, Error> {
todo!()
}
}

0 comments on commit efaf71e

Please sign in to comment.