From dc55d11eb2d5150c26d4d609fab72574c8538cb7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 12 Feb 2016 19:07:18 -0800 Subject: [PATCH] Drop winapi/advapi32 deps They take a *long* time to compile on Windows and aren't necessarily worth it. --- Cargo.toml | 13 ------------- src/registry.rs | 52 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 676bcdc..1898a37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,5 @@ code. """ keywords = ["build-dependencies"] -[target.i686-pc-windows-msvc.dependencies] -winapi = "0.2.1" -advapi32-sys = "0.1.2" -[target.x86_64-pc-windows-msvc.dependencies] -winapi = "0.2.1" -advapi32-sys = "0.1.2" -[target.i686-pc-windows-gnu.dependencies] -winapi = "0.2.1" -advapi32-sys = "0.1.2" -[target.x86_64-pc-windows-gnu.dependencies] -winapi = "0.2.1" -advapi32-sys = "0.1.2" - [dev-dependencies] tempdir = "0.3" diff --git a/src/registry.rs b/src/registry.rs index 9dca15b..d871cd2 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -8,18 +8,56 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate winapi; -extern crate advapi32; - -use std::io; use std::ffi::{OsString, OsStr}; -use std::os::windows::prelude::*; +use std::io; use std::ops::RangeFrom; -use self::winapi::*; -use self::advapi32::*; +use std::os::raw; +use std::os::windows::prelude::*; pub struct RegistryKey(Repr); +type HKEY = *mut u8; +type DWORD = u32; +type LPDWORD = *mut DWORD; +type LPCWSTR = *const u16; +type LPWSTR = *mut u16; +type LONG = raw::c_long; +type PHKEY = *mut HKEY; +type PFILETIME = *mut u8; +type LPBYTE = *mut u8; +type REGSAM = u32; + +const ERROR_SUCCESS: DWORD = 0; +const ERROR_NO_MORE_ITEMS: DWORD = 259; +const HKEY_LOCAL_MACHINE: HKEY = 0x80000002 as HKEY; +const REG_SZ: DWORD = 1; +const KEY_READ: DWORD = 0x20019; +const KEY_WOW64_32KEY: DWORD = 0x200; + +#[link(name = "advapi32")] +extern "system" { + fn RegOpenKeyExW(key: HKEY, + lpSubKey: LPCWSTR, + ulOptions: DWORD, + samDesired: REGSAM, + phkResult: PHKEY) -> LONG; + fn RegEnumKeyExW(key: HKEY, + dwIndex: DWORD, + lpName: LPWSTR, + lpcName: LPDWORD, + lpReserved: LPDWORD, + lpClass: LPWSTR, + lpcClass: LPDWORD, + lpftLastWriteTime: PFILETIME) -> LONG; + fn RegQueryValueExW(hKey: HKEY, + lpValueName: LPCWSTR, + lpReserved: LPDWORD, + lpType: LPDWORD, + lpData: LPBYTE, + lpcbData: LPDWORD) -> LONG; + fn RegCloseKey(hKey: HKEY) -> LONG; +} + struct OwnedKey(HKEY); enum Repr {