use std::io;
use std::ffi::{OsString, OsStr};
use std::os::windows::prelude::*;
-use std::ops::RangeFrom;
use std::ptr;
-use libc::{c_void, c_long};
+use libc::c_long;
-type DWORD = u32;
+pub type DWORD = u32;
type LPCWSTR = *const u16;
type LONG = c_long;
type LPDWORD = *mut DWORD;
const SYNCHRONIZE: REGSAM = 0x00100000;
const REG_SZ: DWORD = 1;
const ERROR_SUCCESS: i32 = 0;
-const ERROR_NO_MORE_ITEMS: DWORD = 259;
-enum __HKEY__ {}
+pub enum __HKEY__ {}
pub type HKEY = *mut __HKEY__;
pub type PHKEY = *mut HKEY;
pub type REGSAM = DWORD;
-pub type LPWSTR = *mut u16;
-pub type PFILETIME = *mut c_void;
#[link(name = "advapi32")]
extern "system" {
lpType: LPDWORD,
lpData: LPBYTE,
lpcbData: LPDWORD) -> LONG;
- fn RegEnumKeyExW(hKey: HKEY,
- dwIndex: DWORD,
- lpName: LPWSTR,
- lpcName: LPDWORD,
- lpReserved: LPDWORD,
- lpClass: LPWSTR,
- lpcClass: LPDWORD,
- lpftLastWriteTime: PFILETIME) -> LONG;
fn RegCloseKey(hKey: HKEY) -> LONG;
}
Owned(OwnedKey),
}
-pub struct Iter<'a> {
- idx: RangeFrom<DWORD>,
- key: &'a RegistryKey,
-}
-
unsafe impl Sync for RegistryKey {}
unsafe impl Send for RegistryKey {}
}
}
- pub fn iter(&self) -> Iter {
- Iter { idx: 0.., key: self }
- }
-
pub fn query_str(&self, name: &str) -> io::Result<OsString> {
let name: &OsStr = name.as_ref();
let name = name.encode_wide().chain(Some(0)).collect::<Vec<_>>();
unsafe { RegCloseKey(self.0); }
}
}
-
-impl<'a> Iterator for Iter<'a> {
- type Item = io::Result<OsString>;
-
- fn next(&mut self) -> Option<io::Result<OsString>> {
- self.idx.next().and_then(|i| unsafe {
- let mut v = Vec::with_capacity(256);
- let mut len = v.capacity() as DWORD;
- let ret = RegEnumKeyExW(self.key.raw(), i, v.as_mut_ptr(), &mut len,
- ptr::null_mut(), ptr::null_mut(), ptr::null_mut(),
- ptr::null_mut());
- if ret == ERROR_NO_MORE_ITEMS as LONG {
- None
- } else if ret != ERROR_SUCCESS {
- Some(Err(io::Error::from_raw_os_error(ret as i32)))
- } else {
- v.set_len(len as usize);
- Some(Ok(OsString::from_wide(&v)))
- }
- })
- }
-}