Closed Zalexanninev15 closed 1 year ago
I solved the problem by digging into the questions. I leave an answer in case anyone has the same problem.
use pelite::FileMap;
fn parse_pe_version(file_path: &str) -> String {
match FileMap::open(file_path) {
Err(_) => "".to_string(),
Ok(file_map) => {
let result = match pelite::PeFile::from_bytes(&file_map) {
Err(e) => Err(e),
Ok(f) => f.resources(),
};
match result {
Err(_) => "".to_string(),
Ok(resources) => match resources.version_info() {
Err(_) => "".to_string(),
Ok(version_info) => match version_info.fixed() {
None => "".to_string(),
Some(fixed_info) => {
let version = fixed_info.dwFileVersion.to_string();
if version.len() > 0 {
version
} else {
fixed_info.dwProductVersion.to_string()
}
}
},
},
}
}
}
}
Please help me get the version of the file in string format (for comparison with another version). I've been trying to do everything normally for several days, but it doesn't work out. I'm still studying Rust, so I don't know much, please explain.