diff --git a/src/checkerr.rs b/src/checkerr.rs deleted file mode 100644 index 4f39bf7..0000000 --- a/src/checkerr.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[macro_export] -macro_rules! checkerr { - ($ex:expr) => { - if $ex.is_err() { - return Err(()); - } - }; -} diff --git a/src/file_builders/active_runtime_json.rs b/src/file_builders/active_runtime_json.rs index 9076b0a..0f45807 100644 --- a/src/file_builders/active_runtime_json.rs +++ b/src/file_builders/active_runtime_json.rs @@ -1,5 +1,4 @@ use crate::{ - checkerr, file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly}, paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir, SYSTEM_PREFIX}, profile::{Profile, XRServiceType}, @@ -97,9 +96,9 @@ fn build_steam_active_runtime() -> ActiveRuntime { } } -pub fn set_current_active_runtime_to_steam() -> Result<(), ()> { - checkerr!(set_file_readonly(&get_active_runtime_json_path(), false)); - checkerr!(dump_current_active_runtime(&build_steam_active_runtime())); +pub fn set_current_active_runtime_to_steam() -> anyhow::Result<()> { + set_file_readonly(&get_active_runtime_json_path(), false)?; + dump_current_active_runtime(&build_steam_active_runtime())?; Ok(()) } @@ -156,9 +155,9 @@ fn relativize_active_runtime_lib_path(ar: &ActiveRuntime, dest: &str) -> ActiveR res } -pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), ()> { +pub fn set_current_active_runtime_to_profile(profile: &Profile) -> anyhow::Result<()> { let dest = get_active_runtime_json_path(); - checkerr!(set_file_readonly(&dest, false)); + set_file_readonly(&dest, false)?; backup_steam_active_runtime(); let pfx = profile.clone().prefix; let mut ar = build_profile_active_runtime(profile); @@ -166,8 +165,8 @@ pub fn set_current_active_runtime_to_profile(profile: &Profile) -> Result<(), () if pfx == SYSTEM_PREFIX { ar = relativize_active_runtime_lib_path(&ar, &dest); } - checkerr!(dump_current_active_runtime(&ar)); - checkerr!(set_file_readonly(&dest, true)); + dump_current_active_runtime(&ar)?; + set_file_readonly(&dest, true)?; Ok(()) } diff --git a/src/file_builders/openvrpaths_vrpath.rs b/src/file_builders/openvrpaths_vrpath.rs index 33da8c4..e48ee59 100644 --- a/src/file_builders/openvrpaths_vrpath.rs +++ b/src/file_builders/openvrpaths_vrpath.rs @@ -1,5 +1,4 @@ use crate::{ - checkerr, file_utils::{copy_file, deserialize_file, get_writer, set_file_readonly}, paths::{get_backup_dir, get_xdg_config_dir, get_xdg_data_dir}, profile::Profile, @@ -94,9 +93,9 @@ fn build_steam_openvrpaths() -> OpenVrPaths { } } -pub fn set_current_openvrpaths_to_steam() -> Result<(), ()> { - checkerr!(set_file_readonly(&get_openvrpaths_vrpath_path(), false)); - checkerr!(dump_current_openvrpaths(&build_steam_openvrpaths())); +pub fn set_current_openvrpaths_to_steam() -> anyhow::Result<()> { + set_file_readonly(&get_openvrpaths_vrpath_path(), false)?; + dump_current_openvrpaths(&build_steam_openvrpaths())?; Ok(()) } @@ -115,14 +114,14 @@ pub fn build_profile_openvrpaths(profile: &Profile) -> OpenVrPaths { } } -pub fn set_current_openvrpaths_to_profile(profile: &Profile) -> Result<(), ()> { +pub fn set_current_openvrpaths_to_profile(profile: &Profile) -> anyhow::Result<()> { let dest = get_openvrpaths_vrpath_path(); - checkerr!(set_file_readonly(&dest, false)); + set_file_readonly(&dest, false)?; backup_steam_openvrpaths(); - checkerr!(dump_current_openvrpaths(&build_profile_openvrpaths( + dump_current_openvrpaths(&build_profile_openvrpaths( profile - ))); - checkerr!(set_file_readonly(&dest, true)); + ))?; + set_file_readonly(&dest, true)?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index d102edc..8d5d642 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ use ui::app::{App, AppInit}; pub mod adb; pub mod build_tools; pub mod builders; -pub mod checkerr; pub mod cmd_runner; pub mod config; pub mod constants; @@ -48,7 +47,7 @@ fn restore_steam_xr_files() { if !file_builders::active_runtime_json::is_steam(&ar) { match set_current_active_runtime_to_steam() { Ok(_) => {} - Err(_) => println!("Warning: failed to restore active runtime to steam!"), + Err(e) => eprintln!("Warning: failed to restore active runtime to steam: {e}"), }; } } @@ -56,7 +55,7 @@ fn restore_steam_xr_files() { if !file_builders::openvrpaths_vrpath::is_steam(&ovrp) { match set_current_openvrpaths_to_steam() { Ok(_) => {} - Err(_) => println!("Warning: failed to restore openvrpaths to steam!"), + Err(e) => eprintln!("Warning: failed to restore openvrpaths to steam: {e}"), }; } } diff --git a/src/ui/app.rs b/src/ui/app.rs index ba011ad..a0e34b8 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -162,18 +162,18 @@ impl App { pub fn start_xrservice(&mut self, sender: ComponentSender, debug: bool) { let prof = self.get_selected_profile(); - if set_current_active_runtime_to_profile(&prof).is_err() { + if let Err(e) = set_current_active_runtime_to_profile(&prof) { alert( "Failed to start XR Service", - Some("Error setting current active runtime to profile"), + Some(&format!("Error setting current active runtime to profile: {e}")), Some(&self.app_win.clone().upcast::()), ); return; } - if set_current_openvrpaths_to_profile(&prof).is_err() { + if let Err(e) = set_current_openvrpaths_to_profile(&prof) { alert( "Failed to start XR Service", - Some("Error setting current openvrpaths file to profile"), + Some(&format!("Error setting current openvrpaths file to profile: {e}")), Some(&self.app_win.clone().upcast::()), ); return; @@ -218,17 +218,17 @@ impl App { } pub fn restore_openxr_openvr_files(&self) { - if set_current_active_runtime_to_steam().is_err() { + if let Err(e) = set_current_active_runtime_to_steam() { alert( "Could not restore Steam active runtime", - None, + Some(&format!("{e}")), Some(&self.app_win.clone().upcast::()), ); } - if set_current_openvrpaths_to_steam().is_err() { + if let Err(e) = set_current_openvrpaths_to_steam() { alert( "Could not restore Steam openvrpaths", - None, + Some(&format!("{e}")), Some(&self.app_win.clone().upcast::()), ); };