diff --git a/Cargo.lock b/Cargo.lock index f206c94..baa1b20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,6 +63,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "anyhow" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" + [[package]] name = "arboard" version = "3.6.1" @@ -820,6 +826,7 @@ dependencies = [ name = "gta-tools" version = "0.11.0" dependencies = [ + "anyhow", "catppuccin-egui", "eframe", "egui_extras", diff --git a/Cargo.toml b/Cargo.toml index deb7660..e9f3e2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ authors = ["futile "] description = "A toolset of convenient things for GTA V Online." [dependencies] +anyhow = "1.0.100" catppuccin-egui = { version = "5.6.0", default-features = false, features = [ "egui32", ] } diff --git a/src/features/empty_session.rs b/src/features/empty_session.rs index ebeeee0..66be4c9 100644 --- a/src/features/empty_session.rs +++ b/src/features/empty_session.rs @@ -3,10 +3,8 @@ use crate::util::{ firewall::{Firewall, RuleDirection, RuleMode, RuleProtocol}, system_info::SystemInfo, }; -use std::{ - error::Error, - time::{Duration, Instant}, -}; +use anyhow::Result; +use std::time::{Duration, Instant}; const FILTER_NAME_EMPTY_SESSION_IN: &str = "[GTA Tools] Block inbound UDP traffic for all of GTA V"; const FILTER_NAME_EMPTY_SESSION_OUT: &str = @@ -32,7 +30,7 @@ impl Default for EmptySession { } impl EmptySession { - pub fn run_timers(&mut self, firewall: &Firewall) -> Result<(), Box> { + pub fn run_timers(&mut self, firewall: &Firewall) -> Result<()> { if self.disabled { self.countdown.count(); } else { @@ -46,7 +44,7 @@ impl EmptySession { } } -pub fn activate(system_info: &mut SystemInfo, firewall: &Firewall) -> Result> { +pub fn activate(system_info: &mut SystemInfo, firewall: &Firewall) -> Result { let Some(exe_path) = system_info.get_game_exe_path() else { log::info!("wasn't able to find game exe"); return Ok(false); @@ -66,7 +64,7 @@ pub fn activate(system_info: &mut SystemInfo, firewall: &Firewall) -> Result Result<(), Box> { +pub fn deactivate(firewall: &Firewall) -> Result<()> { firewall.remove(FILTER_NAME_EMPTY_SESSION_IN)?; firewall.remove(FILTER_NAME_EMPTY_SESSION_OUT)?; Ok(()) diff --git a/src/features/game_networking.rs b/src/features/game_networking.rs index 122b43a..ced99c8 100644 --- a/src/features/game_networking.rs +++ b/src/features/game_networking.rs @@ -5,7 +5,7 @@ use crate::{ system_info::SystemInfo, }, }; -use std::error::Error; +use anyhow::Result; use strum::{Display, EnumIter}; const FILTER_NAME_EXE: &str = "[GTA Tools] Block outbound traffic for all of GTA V"; @@ -40,11 +40,7 @@ impl Default for GameNetworking { } impl GameNetworking { - pub fn block_exe( - &mut self, - system_info: &mut SystemInfo, - firewall: &Firewall, - ) -> Result<(), Box> { + pub fn block_exe(&mut self, system_info: &mut SystemInfo, firewall: &Firewall) -> Result<()> { let Some(exe_path) = system_info.get_game_exe_path() else { log::warn!("Unable to find game executable path."); return Ok(()); @@ -59,17 +55,13 @@ impl GameNetworking { .inspect(|_| self.blocked = BlockedStatus::ExeBlocked) } - pub fn unblock_exe(&mut self, firewall: &Firewall) -> Result<(), Box> { + pub fn unblock_exe(&mut self, firewall: &Firewall) -> Result<()> { firewall .remove(FILTER_NAME_EXE) .inspect(|_| self.blocked = BlockedStatus::NotBlocked) } - pub fn block_save_server( - &mut self, - save_server_ip: &str, - firewall: &Firewall, - ) -> Result<(), Box> { + pub fn block_save_server(&mut self, save_server_ip: &str, firewall: &Firewall) -> Result<()> { firewall .add( FILTER_NAME_SAVE_SERVER, @@ -80,7 +72,7 @@ impl GameNetworking { .inspect(|_| self.blocked = BlockedStatus::ServerBlocked) } - pub fn unblock_save_server(&mut self, firewall: &Firewall) -> Result<(), Box> { + pub fn unblock_save_server(&mut self, firewall: &Firewall) -> Result<()> { firewall .remove(FILTER_NAME_SAVE_SERVER) .inspect(|_| self.blocked = BlockedStatus::NotBlocked) @@ -90,7 +82,7 @@ impl GameNetworking { &mut self, block_method: BlockMethod, firewall: &Firewall, - ) -> Result<(), Box> { + ) -> Result<()> { match block_method { BlockMethod::EntireGame => { if self.blocked == BlockedStatus::ServerBlocked { diff --git a/src/util/firewall.rs b/src/util/firewall.rs index f868238..95734b8 100644 --- a/src/util/firewall.rs +++ b/src/util/firewall.rs @@ -1,4 +1,5 @@ -use std::{error::Error, path::PathBuf}; +use anyhow::Result; +use std::path::PathBuf; use windows::{ Win32::{ NetworkManagement::WindowsFirewall::{ @@ -31,7 +32,7 @@ impl Firewall { mode: RuleMode, direction: RuleDirection, protocol: RuleProtocol, - ) -> Result<(), Box> { + ) -> Result<()> { let add_rule = || { let rules = unsafe { self.policy.Rules() }?; unsafe { rules.Remove(&BSTR::from(name)) }?; @@ -61,7 +62,7 @@ impl Firewall { add_rule().inspect_err(|e| log::warn!("Failed to add rule '{name}': {e}")) } - pub fn remove(&self, name: &str) -> Result<(), Box> { + pub fn remove(&self, name: &str) -> Result<()> { let remove_rule = || { let rules = unsafe { self.policy.Rules() }?; unsafe { rules.Remove(&BSTR::from(name)) }?; @@ -70,7 +71,7 @@ impl Firewall { remove_rule().inspect_err(|e| log::warn!("Failed to remove rule '{name}': {e}")) } - pub fn is_blocked(&self, name: &str) -> Result> { + pub fn is_blocked(&self, name: &str) -> Result { let rules = unsafe { self.policy.Rules() }?; let rule_exists = unsafe { rules.Item(&BSTR::from(name)) }.is_ok(); Ok(rule_exists)