From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/winreg/src/decoder/mod.rs | 101 +++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 third_party/rust/winreg/src/decoder/mod.rs (limited to 'third_party/rust/winreg/src/decoder/mod.rs') diff --git a/third_party/rust/winreg/src/decoder/mod.rs b/third_party/rust/winreg/src/decoder/mod.rs new file mode 100644 index 0000000000..82493b846d --- /dev/null +++ b/third_party/rust/winreg/src/decoder/mod.rs @@ -0,0 +1,101 @@ +// Copyright 2017, Igor Shaula +// Licensed under the MIT License . This file +// may not be copied, modified, or distributed +// except according to those terms. +use super::enums::*; +use super::RegKey; +use std::error::Error; +use std::fmt; +use std::io; +use winapi::shared::minwindef::DWORD; + +macro_rules! read_value { + ($s:ident) => { + match mem::replace(&mut $s.f_name, None) { + Some(ref s) => $s.key.get_value(s).map_err(DecoderError::IoError), + None => Err(DecoderError::NoFieldName), + } + }; +} + +macro_rules! parse_string { + ($s:ident) => {{ + let s: String = read_value!($s)?; + s.parse() + .map_err(|e| DecoderError::ParseError(format!("{:?}", e))) + }}; +} + +macro_rules! no_impl { + ($e:expr) => { + Err(DecoderError::DecodeNotImplemented($e.to_owned())) + }; +} + +#[cfg(feature = "serialization-serde")] +mod serialization_serde; + +#[derive(Debug)] +pub enum DecoderError { + DecodeNotImplemented(String), + DeserializerError(String), + IoError(io::Error), + ParseError(String), + NoFieldName, +} + +impl fmt::Display for DecoderError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +impl Error for DecoderError {} + +impl From for DecoderError { + fn from(err: io::Error) -> DecoderError { + DecoderError::IoError(err) + } +} + +pub type DecodeResult = Result; + +#[derive(Debug)] +enum DecoderReadingState { + WaitingForKey, + WaitingForValue, +} + +#[derive(Debug)] +enum DecoderEnumerationState { + EnumeratingKeys(DWORD), + EnumeratingValues(DWORD), +} + +#[derive(Debug)] +pub struct Decoder { + key: RegKey, + f_name: Option, + reading_state: DecoderReadingState, + enumeration_state: DecoderEnumerationState, +} + +const DECODER_SAM: DWORD = KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS; + +impl Decoder { + pub fn from_key(key: &RegKey) -> DecodeResult { + key.open_subkey_with_flags("", DECODER_SAM) + .map(Decoder::new) + .map_err(DecoderError::IoError) + } + + fn new(key: RegKey) -> Decoder { + Decoder { + key, + f_name: None, + reading_state: DecoderReadingState::WaitingForKey, + enumeration_state: DecoderEnumerationState::EnumeratingKeys(0), + } + } +} -- cgit v1.2.3