mirror of
https://github.com/GyulyVGC/sniffnet.git
synced 2026-08-31 23:49:25 +00:00
only truncate the log file if the --logs argument isn't passed
This commit is contained in:
parent
d24dc9a85b
commit
668ea3d0c7
3 changed files with 21 additions and 14 deletions
|
|
@ -13,7 +13,7 @@ use iced::{window, Task};
|
|||
version = APP_VERSION,
|
||||
about = "Application to comfortably monitor your network traffic"
|
||||
)]
|
||||
struct Args {
|
||||
pub struct Args {
|
||||
/// Start sniffing packets from the supplied network adapter
|
||||
#[arg(short, long, value_name = "NAME", default_missing_value = CONFIGS.device.device_name.as_str(), num_args = 0..=1)]
|
||||
adapter: Option<String>,
|
||||
|
|
@ -26,9 +26,7 @@ struct Args {
|
|||
restore_default: bool,
|
||||
}
|
||||
|
||||
pub fn parse_cli_args() -> Task<Message> {
|
||||
let args = Args::parse();
|
||||
|
||||
pub fn handle_cli_args(args: Args) -> Task<Message> {
|
||||
#[cfg(windows)]
|
||||
if args.logs {
|
||||
std::process::Command::new("explorer")
|
||||
|
|
|
|||
15
src/main.rs
15
src/main.rs
|
|
@ -6,13 +6,15 @@ use std::borrow::Cow;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::{panic, process, thread};
|
||||
|
||||
use clap::Parser;
|
||||
#[cfg(target_os = "linux")]
|
||||
use iced::window::settings::PlatformSpecific;
|
||||
use iced::{application, window, Font, Pixels, Settings};
|
||||
|
||||
use crate::cli::Args;
|
||||
use chart::types::chart_type::ChartType;
|
||||
use chart::types::traffic_chart::TrafficChart;
|
||||
use cli::parse_cli_args;
|
||||
use cli::handle_cli_args;
|
||||
use configs::types::config_device::ConfigDevice;
|
||||
use configs::types::config_settings::ConfigSettings;
|
||||
use gui::pages::types::running_page::RunningPage;
|
||||
|
|
@ -55,19 +57,22 @@ pub const SNIFFNET_TITLECASE: &str = "Sniffnet";
|
|||
///
|
||||
/// It initializes shared variables and loads configuration parameters
|
||||
pub fn main() -> iced::Result {
|
||||
let configs = CONFIGS.clone();
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
#[cfg(all(windows, not(debug_assertions)))]
|
||||
let _gag1: gag::Redirect<std::fs::File>;
|
||||
#[cfg(all(windows, not(debug_assertions)))]
|
||||
let _gag2: gag::Redirect<std::fs::File>;
|
||||
#[cfg(all(windows, not(debug_assertions)))]
|
||||
if let Some((gag1, gag2)) = utils::formatted_strings::redirect_stdout_stderr_to_file() {
|
||||
if let Some((gag1, gag2)) = utils::formatted_strings::redirect_stdout_stderr_to_file(args.logs)
|
||||
{
|
||||
_gag1 = gag1;
|
||||
_gag2 = gag2;
|
||||
}
|
||||
|
||||
let configs = CONFIGS.clone();
|
||||
|
||||
let boot_task_chain = parse_cli_args();
|
||||
let boot_task_chain = handle_cli_args(args);
|
||||
|
||||
let configs1 = Arc::new(Mutex::new(configs));
|
||||
let configs2 = configs1.clone();
|
||||
|
|
|
|||
|
|
@ -176,12 +176,16 @@ pub fn get_logs_file_path() -> Option<String> {
|
|||
#[allow(dead_code)]
|
||||
#[cfg(windows)]
|
||||
pub fn redirect_stdout_stderr_to_file(
|
||||
logs: bool,
|
||||
) -> Option<(gag::Redirect<std::fs::File>, gag::Redirect<std::fs::File>)> {
|
||||
if let Ok(logs_file) = std::fs::File::create(get_logs_file_path()?) {
|
||||
return Some((
|
||||
gag::Redirect::stdout(logs_file.try_clone().ok()?).ok()?,
|
||||
gag::Redirect::stderr(logs_file).ok()?,
|
||||
));
|
||||
// only truncate the log file if the --logs argument isn't passed
|
||||
if !logs {
|
||||
if let Ok(logs_file) = std::fs::File::create(get_logs_file_path()?) {
|
||||
return Some((
|
||||
gag::Redirect::stdout(logs_file.try_clone().ok()?).ok()?,
|
||||
gag::Redirect::stderr(logs_file).ok()?,
|
||||
));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue