aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.rs
blob: 4e385177a75ccb5bac893e6efef61fbdf0de025d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2025-2026 Dillution <[email protected]>.
//
// This file is part of DPIBreak.
//
// DPIBreak is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// DPIBreak is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with DPIBreak. If not, see <https://www.gnu.org/licenses/>.

use anyhow::Result;

mod platform;
mod pkt;
mod tls;
mod log;
mod opt;

const PROJECT_NAME: &str = "DPIBreak";
const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
const PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");

fn splash_banner() {
    splash!("{PROJECT_NAME} v{PKG_VERSION}");
    splash!("{PKG_DESCRIPTION}");
    splash!("{PKG_HOMEPAGE}");
    splash!("");
}

fn main_1() -> Result<()> {
    let opt = opt::Opt::from_args()?;
    let initialized = opt.set_opt()?;
    splash_banner();
    platform::bootstrap()?;
    crate::info!("{PROJECT_NAME} v{PKG_VERSION}");
    initialized.log();
    platform::run()?;

    Ok(())
}

fn main() {
    match main_1() {
        Ok(()) => { std::process::exit(0); }
        Err(e) => {
            crate::error!("{e}");

            for (i, cause) in e.chain().skip(1).enumerate() {
                crate::error!("caused by[{i}]: {cause}");
            }
            platform::paexit(1);
        }
    };
}