#![allow(
non_snake_case,
non_camel_case_types,
non_upper_case_globals,
dead_code,
clippy::all
)]
use std::path::PathBuf;
mod bindings;
pub(crate) use bindings::*;
pub(crate) const FOLDERID_PROGRAM_DATA: GUID = GUID {
data1: 0x62AB_00DC,
data2: 0x680E,
data3: 0x4B1D,
data4: [0x82, 0xD8, 0x86, 0xED, 0x55, 0x7D, 0xBC, 0x6C],
};
pub(crate) fn open_hklm(
path: &str,
write: bool,
) -> windows_registry::Result<windows_registry::Key> {
let mut options = windows_registry::LOCAL_MACHINE.options();
options.read();
if write {
options.write();
}
options.wow64_64().open(path)
}
pub(crate) fn create_hklm(path: &str) -> windows_registry::Result<windows_registry::Key> {
windows_registry::LOCAL_MACHINE
.options()
.read()
.write()
.create()
.wow64_64()
.open(path)
}
pub(crate) unsafe fn wide_to_string(pointer: *const u16) -> String {
if pointer.is_null() {
return String::new();
}
let mut len = 0usize;
unsafe {
while *pointer.add(len) != 0 {
len += 1;
}
String::from_utf16_lossy(std::slice::from_raw_parts(pointer, len))
}
}
pub(crate) unsafe fn wide_to_path(pointer: *const u16) -> PathBuf {
PathBuf::from(unsafe { wide_to_string(pointer) })
}