Skip to content

Commit

Permalink
fix: adjust to changes in win-msgbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Jun 24, 2024
1 parent 4278c3e commit 07f3c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
10 changes: 4 additions & 6 deletions src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{ffi::OsStr, io, path::Path, time::Duration};

use widestring::U16CString;
use win_msgbox::AbortRetryIgnore;
use windows_sys::{w, Win32::Foundation::ERROR_SHARING_VIOLATION};
use windows_sys::Win32::Foundation::ERROR_SHARING_VIOLATION;
use zip::read::ZipFile;

pub struct Args<'a> {
Expand Down Expand Up @@ -87,11 +86,10 @@ fn process_file_retrying<'a>(file: &mut ZipFile, path: &Path) -> Result<(), Extr
let Err(e) = process_file_backoff(file, path) else {
break Ok(());
};
let error_message = format!("Failed to install '{}':\n{e}", path.to_string_lossy());
let u16str = U16CString::from_str_truncate(error_message);

match win_msgbox::warning::<AbortRetryIgnore>(u16str.as_ptr())
.title(w!("Chatterino Updater"))
let error = format!("Failed to install '{}':\n{e}", path.to_string_lossy());
match win_msgbox::warning::<AbortRetryIgnore>(&error)
.title("Chatterino Updater")
.show()
{
Ok(AbortRetryIgnore::Abort) => break Err(ExtractError::Aborted),
Expand Down
18 changes: 5 additions & 13 deletions src/result.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fmt::Display;

use widestring::{U16CStr, U16CString};
use win_msgbox::Okay;
use windows_sys::w;

pub trait ResultExt<T> {
fn error_and_exit(self) -> T;
Expand All @@ -14,18 +12,12 @@ impl<T, E: Display> ResultExt<T> for Result<T, E> {
match self {
Ok(r) => r,
Err(e) => {
// Can't avoid creating a string here
let s = U16CString::from_str_truncate(e.to_string());
show_and_exit(&s);
win_msgbox::error::<Okay>(&e.to_string())
.title("Chatterino Updater")
.show()
.ok();
std::process::exit(1);
}
}
}
}

fn show_and_exit(s: &U16CStr) -> ! {
win_msgbox::error::<Okay>(s.as_ptr())
.title(w!("Chatterino Updater"))
.show()
.ok();
std::process::exit(1);
}

0 comments on commit 07f3c65

Please sign in to comment.