Skip to content

Commit

Permalink
Add last_error_record function (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths authored Aug 6, 2022
1 parent 3232c78 commit 417f9be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern "C" {
#[link_name = "MsiDoActionA"]
pub fn MsiDoAction(hInstall: MSIHANDLE, szAction: LPCSTR) -> u32;

pub fn MsiGetLastErrorRecord() -> MSIHANDLE;

pub fn MsiGetMode(hInstall: MSIHANDLE, eRunMode: RunMode) -> BOOL;

#[link_name = "MsiGetPropertyA"]
Expand Down
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ pub enum RunMode {
Commit = 18,
}

/// Gets the last Windows Installer error for the current process.
///
/// # Example
///
/// ```
/// use msica::*;
///
/// if let Some(error) = last_error_record() {
/// println!("last error: {}", error.format_text());
/// }
/// ```
pub fn last_error_record() -> Option<Record> {
unsafe {
match ffi::MsiGetLastErrorRecord() {
h if !h.is_null() => Some(h.into()),
_ => None,
}
}
}

/// A Windows Installer handle. This handle is not automatically closed.
#[derive(Clone, Copy)]
#[repr(transparent)]
Expand All @@ -84,6 +104,10 @@ impl MSIHANDLE {
fn to_owned(&self) -> PMSIHANDLE {
PMSIHANDLE(*self)
}

fn is_null(&self) -> bool {
self.0 == 0
}
}

impl From<u32> for MSIHANDLE {
Expand Down
6 changes: 6 additions & 0 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ impl Deref for Record {
}
}

impl From<MSIHANDLE> for Record {
fn from(h: MSIHANDLE) -> Self {
Record { h: h.to_owned() }
}
}

impl From<&str> for Record {
fn from(s: &str) -> Self {
unsafe {
Expand Down

0 comments on commit 417f9be

Please sign in to comment.