main: fix issue with non-null-terminated registry entries
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -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<()> {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user