Last active
October 3, 2022 17:47
-
-
Save heaths/cad76bc83752b21886169b546210acf7 to your computer and use it in GitHub Desktop.
Shows how to read a property value from an MSI on any platform using Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::path::PathBuf; | |
use std::result::Result; | |
use std::{error::Error, ops::Index}; | |
use clap::{arg, command, value_parser, Arg}; | |
use msi::{self, Expr, Select, Value}; | |
fn main() -> Result<(), Box<dyn Error>> { | |
let matches = command!() | |
.arg( | |
Arg::new("path") | |
.help("Path to a Windows Installer package (MSI)") | |
.value_parser(value_parser!(PathBuf)) | |
.required(true), | |
) | |
.arg(arg!(-p --property <NAME> "The property name to get").default_value("ProductCode")) | |
.get_matches(); | |
let path = matches.get_one::<PathBuf>("path").expect("path required"); | |
let property = matches | |
.get_one::<String>("property") | |
.expect("property name required"); | |
let mut package = msi::open(path)?; | |
let columns = vec!["Value"]; | |
let query = Select::table("Property") | |
.columns(&columns) | |
.with(Expr::col("Property").eq(Expr::string(property))); | |
let rows = package.select_rows(query)?; | |
for row in rows { | |
if let Value::Str(value) = row.index(0) { | |
println!("{}", value); | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment