pub fn reg_vjoy_devices() -> Result<Vec<VJDevice>, VJDRegistryError> {
    let mut captured_device_numbers: Vec<VJDevice> = Vec::new();

    let devices_path =
        match RegKey::predef(HKEY_LOCAL_MACHINE).open_subkey(VJGeneral::REG_DEVICES_PATH) {
            Ok(reg_key) => reg_key,
            Err(error) => return Err(VJDRegistryError::PathError(error)),
        };

    let reg_device_prefix = VJGeneral::REG_DEVICE_PREFIX;

    for i in devices_path.enum_keys().map(|x| x.unwrap()) {
        // First check reg key starts with 'Device' with a potential following number.
        if i.starts_with(reg_device_prefix) && i.len() > reg_device_prefix.len() {
            // Then check the potential number is really a valid number.
            if let Ok(val) = i[reg_device_prefix.len()..].parse::<u8>() {
                // A device number should be in the correct range in registry
                if !(1..=VJGeneral::MAX_DEVICES).contains(&val) {
                    return Err(VJDRegistryError::InvalidDevice);
                } else {
                    for i in &captured_device_numbers {
                        match (*i as u8).cmp(&val) {
                            // A device number should not appear twice in registry
                            Ordering::Equal => return Err(VJDRegistryError::DuplicateEntry),

                            // A device number should not appear in unordered fashion in registry
                            Ordering::Greater => return Err(VJDRegistryError::InvalidOrder),
                            _ => {}
                        }
                    }
                }

                let device = match VJDevice::get_from(val) {
                    Some(vjd) => vjd,
                    None => return Err(VJDRegistryError::InvalidDevice),
                };

                captured_device_numbers.push(device);
            }
        };
    }

    Ok(captured_device_numbers)
}
/**
    Returns a list of device numbers registered in the windows registry, or [`VJDRegistryError`] if it fails. The list is ordered.
*/
Returns a list of device numbers registered in the windows registry, or [`VJDRegistryError`] if it fails. The list is ordered.
Returns a list of device numbers registered in the windows registry or [ ` VJDRegistryError ` ] if it fails . The list is ordered .
pub fn reg_vjoy_devices() -> Result<Vec<VJDevice>, VJDRegistryError> {
    let mut captured_device_numbers: Vec<VJDevice> = Vec::new();
    let devices_path =
        match RegKey::predef(HKEY_LOCAL_MACHINE).open_subkey(VJGeneral::REG_DEVICES_PATH) {
            Ok(reg_key) => reg_key,
            Err(error) => return Err(VJDRegistryError::PathError(error)),
        };
    let reg_device_prefix = VJGeneral::REG_DEVICE_PREFIX;
    for i in devices_path.enum_keys().map(|x| x.unwrap()) {
        // First check reg key starts with 'Device' with a potential following number.
        if i.starts_with(reg_device_prefix) && i.len() > reg_device_prefix.len() {
            // Then check the potential number is really a valid number.
            if let Ok(val) = i[reg_device_prefix.len()..].parse::<u8>() {
                // A device number should be in the correct range in registry
                if !(1..=VJGeneral::MAX_DEVICES).contains(&val) {
                    return Err(VJDRegistryError::InvalidDevice);
                } else {
                    for i in &captured_device_numbers {
                        match (*i as u8).cmp(&val) {
                            // A device number should not appear twice in registry
                            Ordering::Equal => return Err(VJDRegistryError::DuplicateEntry),
                            // A device number should not appear in unordered fashion in registry
                            Ordering::Greater => return Err(VJDRegistryError::InvalidOrder),
                            _ => {}
                        }
                    }
                }
                let device = match VJDevice::get_from(val) {
                    Some(vjd) => vjd,
                    None => return Err(VJDRegistryError::InvalidDevice),
                };
                captured_device_numbers.push(device);
            }
        };
    }
    Ok(captured_device_numbers)
}
pub fn reg_vjoy_devices ( ) -> Result < Vec < VJDevice > , VJDRegistryError > { let mut captured_device_numbers : Vec < VJDevice > = Vec :: new ( ) ; let devices_path = match RegKey :: predef ( HKEY_LOCAL_MACHINE ) . open_subkey ( VJGeneral :: REG_DEVICES_PATH ) { Ok ( reg_key ) => reg_key , Err ( error ) => return Err ( VJDRegistryError :: PathError ( error ) ) , } ; let reg_device_prefix = VJGeneral :: REG_DEVICE_PREFIX ; for i in devices_path . enum_keys ( ) . map ( | x | x . unwrap ( ) ) { // First check reg key starts with 'Device' with a potential following number. if i . starts_with ( reg_device_prefix ) && i . len ( ) > reg_device_prefix . len ( ) { // Then check the potential number is really a valid number. if let Ok ( val ) = i [ reg_device_prefix . len ( ) .. ] . parse :: < u8 > ( ) { // A device number should be in the correct range in registry if ! ( 1 ..= VJGeneral :: MAX_DEVICES ) . contains ( & val ) { return Err ( VJDRegistryError :: InvalidDevice ) ; } else { for i in & captured_device_numbers { match ( * i as u8 ) . cmp ( & val ) { // A device number should not appear twice in registry Ordering :: Equal => return Err ( VJDRegistryError :: DuplicateEntry ) , // A device number should not appear in unordered fashion in registry Ordering :: Greater => return Err ( VJDRegistryError :: InvalidOrder ) , _ => { } } } } let device = match VJDevice :: get_from ( val ) { Some ( vjd ) => vjd , None => return Err ( VJDRegistryError :: InvalidDevice ) , } ; captured_device_numbers . push ( device ) ; } } ; } Ok ( captured_device_numbers ) }
Returns a list of device numbers registered in the windows registry, or [`VJDRegistryError`] if it fails.
Returns a list of device numbers registered in the windows registry or [ ` VJDRegistryError ` ] if it fails .