main: fix issue with non-null-terminated registry entries

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-05-17 09:05:17 +08:00
parent 4608977088
commit fe74e7e6d0
1 changed files with 12 additions and 18 deletions

View File

@ -92,26 +92,20 @@ fn get_lark_path() -> Option<PathBuf> {
}?;
let v: std::io::Result<RegValue> = lark_cfg.get_raw_value("Lark Path");
let mut buf = v.unwrap();
// Strip off NULL termination
buf.bytes.pop();
buf.bytes.pop();
// Ensure the buffer is big enough.
if buf.bytes.len() <= 2 {
return None;
}
// Sometimes it adds a NULL at the end. Strip off NULL termination.
if buf.bytes[buf.bytes.len()-2] == b'\0' {
buf.bytes.pop();
buf.bytes.pop();
}
let osstr = std::ffi::OsString::from_reg_value(&buf).unwrap();
Some(Path::new(&osstr).to_owned())
// match v {
// Ok(v) => {
// print!("Values: ");
// use std::os::windows::ffi::OsStrExt;
// for (_idx, c) in v.encode_wide().enumerate() {
// print!(" {:04x}", c);
// }
// println!();
// let converted: PathBuf = v.into();
// Some(converted.to_owned())
// }
// Err(_) => None,
// }
// None
}
fn set_lark_path(new_path: &Path) -> std::io::Result<()> {