Improve logging
This commit is contained in:
@@ -46,6 +46,7 @@ impl GameNetworking {
|
|||||||
firewall: &Firewall,
|
firewall: &Firewall,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let Some(exe_path) = system_info.get_game_exe_path() else {
|
let Some(exe_path) = system_info.get_game_exe_path() else {
|
||||||
|
log::warn!("Unable to find game executable path.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
firewall
|
firewall
|
||||||
|
|||||||
+2
-2
@@ -12,8 +12,8 @@ fn app_creator(
|
|||||||
cc: &eframe::CreationContext<'_>,
|
cc: &eframe::CreationContext<'_>,
|
||||||
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// initialize COM just in case
|
// initialize COM just in case
|
||||||
if unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) }.is_err() {
|
if let Err(e) = unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) }.ok() {
|
||||||
log::error!("couldn't initialize COM");
|
log::error!("couldn't initialize COM: {e}");
|
||||||
}
|
}
|
||||||
// initialize App early to modify some things before returning it
|
// initialize App early to modify some things before returning it
|
||||||
let mut app = Box::new(App::default());
|
let mut app = Box::new(App::default());
|
||||||
|
|||||||
+11
-4
@@ -32,14 +32,16 @@ impl Firewall {
|
|||||||
direction: RuleDirection,
|
direction: RuleDirection,
|
||||||
protocol: RuleProtocol,
|
protocol: RuleProtocol,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
|
let add_rule = || {
|
||||||
let rules = unsafe { self.policy.Rules() }?;
|
let rules = unsafe { self.policy.Rules() }?;
|
||||||
unsafe { rules.Remove(&BSTR::from(name)) }?;
|
unsafe { rules.Remove(&BSTR::from(name)) }?;
|
||||||
let rule: INetFwRule = unsafe { CoCreateInstance(&NetFwRule, None, CLSCTX_INPROC_SERVER) }?;
|
let rule: INetFwRule =
|
||||||
|
unsafe { CoCreateInstance(&NetFwRule, None, CLSCTX_INPROC_SERVER) }?;
|
||||||
unsafe { rule.SetName(&BSTR::from(name)) }?;
|
unsafe { rule.SetName(&BSTR::from(name)) }?;
|
||||||
match mode {
|
match mode {
|
||||||
RuleMode::Executable(exe) => {
|
RuleMode::Executable(exe) => unsafe {
|
||||||
unsafe { rule.SetApplicationName(&BSTR::from(exe.to_string_lossy().to_string())) }?
|
rule.SetApplicationName(&BSTR::from(exe.to_string_lossy().to_string()))
|
||||||
}
|
}?,
|
||||||
RuleMode::Address(ip) => unsafe { rule.SetRemoteAddresses(&BSTR::from(ip)) }?,
|
RuleMode::Address(ip) => unsafe { rule.SetRemoteAddresses(&BSTR::from(ip)) }?,
|
||||||
}
|
}
|
||||||
match direction {
|
match direction {
|
||||||
@@ -55,12 +57,17 @@ impl Firewall {
|
|||||||
}
|
}
|
||||||
unsafe { rules.Add(&rule) }?;
|
unsafe { rules.Add(&rule) }?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
};
|
||||||
|
add_rule().inspect_err(|e| log::warn!("Failed to add rule '{name}': {e}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&self, name: &str) -> Result<(), Box<dyn Error>> {
|
pub fn remove(&self, name: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
let remove_rule = || {
|
||||||
let rules = unsafe { self.policy.Rules() }?;
|
let rules = unsafe { self.policy.Rules() }?;
|
||||||
unsafe { rules.Remove(&BSTR::from(name)) }?;
|
unsafe { rules.Remove(&BSTR::from(name)) }?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
};
|
||||||
|
remove_rule().inspect_err(|e| log::warn!("Failed to remove rule '{name}': {e}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_blocked(&self, name: &str) -> Result<bool, Box<dyn Error>> {
|
pub fn is_blocked(&self, name: &str) -> Result<bool, Box<dyn Error>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user