From 07f3c659b1e808767d16e13b123e84b606eafc1d Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Mon, 24 Jun 2024 12:48:07 +0200 Subject: [PATCH] fix: adjust to changes in win-msgbox --- src/extract.rs | 10 ++++------ src/result.rs | 18 +++++------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/extract.rs b/src/extract.rs index 2e31f1a..7650d6e 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -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> { @@ -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::(u16str.as_ptr()) - .title(w!("Chatterino Updater")) + let error = format!("Failed to install '{}':\n{e}", path.to_string_lossy()); + match win_msgbox::warning::(&error) + .title("Chatterino Updater") .show() { Ok(AbortRetryIgnore::Abort) => break Err(ExtractError::Aborted), diff --git a/src/result.rs b/src/result.rs index 53b6d49..f8704a9 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,8 +1,6 @@ use std::fmt::Display; -use widestring::{U16CStr, U16CString}; use win_msgbox::Okay; -use windows_sys::w; pub trait ResultExt { fn error_and_exit(self) -> T; @@ -14,18 +12,12 @@ impl ResultExt for Result { 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::(&e.to_string()) + .title("Chatterino Updater") + .show() + .ok(); + std::process::exit(1); } } } } - -fn show_and_exit(s: &U16CStr) -> ! { - win_msgbox::error::(s.as_ptr()) - .title(w!("Chatterino Updater")) - .show() - .ok(); - std::process::exit(1); -}