mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-20 11:35:48 +00:00
fix: remove checkerr macro, prefer using question mark operator and anyhow error
This commit is contained in:
parent
65d5e3cb5e
commit
fa6e8ac56a
5 changed files with 25 additions and 36 deletions
|
@ -1,8 +0,0 @@
|
|||
#[macro_export]
|
||||
macro_rules! checkerr {
|
||||
($ex:expr) => {
|
||||
if $ex.is_err() {
|
||||
return Err(());
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,18 +162,18 @@ impl App {
|
|||
|
||||
pub fn start_xrservice(&mut self, sender: ComponentSender<Self>, 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::<gtk::Window>()),
|
||||
);
|
||||
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::<gtk::Window>()),
|
||||
);
|
||||
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::<gtk::Window>()),
|
||||
);
|
||||
}
|
||||
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::<gtk::Window>()),
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue