Skip to content

Commit

Permalink
Move cli option to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
MolotovCherry committed Nov 12, 2024
1 parent 2604a87 commit 8de7fa7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
3 changes: 3 additions & 0 deletions crates/shared/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct Core {
/// Except for those in this list, all plugins are enabled by default
/// e.g. FooBar.dll should have an entry for "FooBar"
pub disabled: Vec<String>,
/// Whether to show cli window
pub cli: bool,
}

impl Default for Core {
Expand All @@ -32,6 +34,7 @@ impl Default for Core {
// the default location for most people
install_root: r"C:\Program Files (x86)\Steam\steamapps\common\Baldurs Gate 3".into(),
disabled: Vec::new(),
cli: false,
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions crates/yabg3nml/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ use argh::FromArgs;
/// A simple, non-invasive BG3 native mod loader
#[derive(Default, FromArgs)]
pub struct Args {
/// show console window
#[argh(switch)]
pub cli: bool,

/// binary to test inject
#[cfg(feature = "test-injection")]
#[argh(option)]
Expand Down
9 changes: 4 additions & 5 deletions crates/yabg3nml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use eyre::Result;
use shared::popup::{display_popup, fatal_popup, MessageBoxIcon};
use tracing::{error, trace};

#[cfg(feature = "test-injection")]
use cli::Args;
use event::Event;
use loader::run_loader;
Expand All @@ -47,9 +48,10 @@ pub fn run(run_type: RunType) -> Result<()> {
let _singleton = SingleInstance::new();
let _event = Event::new()?;

#[cfg(feature = "test-injection")]
let args: Args = argh::from_env();

let mut init = init(&args)?;
let mut init = init()?;
let _loader_lock = init.loader.file.take();
let _worker_guard = init.worker.take();

Expand Down Expand Up @@ -132,10 +134,7 @@ pub fn autostart(pid: Pid) -> Result<()> {
let _singleton = SingleInstance::new();
let _event = Event::new()?;

// DO NOT use argh, since it doesn't understand bg3 cli args
let args = Args::default();

let mut init = init(&args)?;
let mut init = init()?;
let _loader_lock = init.loader.file.take();
let _worker_guard = init.worker.take();

Expand Down
10 changes: 2 additions & 8 deletions crates/yabg3nml/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ use tracing::level_filters::LevelFilter;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_subscriber::EnvFilter;

use crate::cli::Args;

pub fn setup_logs<P: AsRef<Path>>(
config: &Config,
plugins_dir: P,
args: &Args,
) -> Result<Option<WorkerGuard>> {
pub fn setup_logs<P: AsRef<Path>>(config: &Config, plugins_dir: P) -> Result<Option<WorkerGuard>> {
let mut worker_guard: Option<WorkerGuard> = None;

// env var takes precedence over config value
Expand All @@ -22,7 +16,7 @@ pub fn setup_logs<P: AsRef<Path>>(
.with_default_directive(LevelFilter::INFO.into())
.parse_lossy(env);

if cfg!(debug_assertions) || args.cli {
if cfg!(debug_assertions) || config.core.cli {
#[cfg(not(debug_assertions))]
{
use crate::console::debug_console;
Expand Down
5 changes: 2 additions & 3 deletions crates/yabg3nml/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use tracing_appender::non_blocking::WorkerGuard;
use windows::Win32::Security::SE_DEBUG_NAME;

use crate::{
cli::Args,
is_admin::is_admin,
logging::setup_logs,
panic::set_hook,
Expand All @@ -27,7 +26,7 @@ pub struct InitData {
pub loader: Loader,
}

pub fn init(args: &Args) -> Result<InitData> {
pub fn init() -> Result<InitData> {
let span = trace_span!("setup");
let _guard = span.enter();

Expand Down Expand Up @@ -66,7 +65,7 @@ pub fn init(args: &Args) -> Result<InitData> {
};

// start logger
let worker_guard = setup_logs(config, &plugins_dir, args).context("Failed to set up logs")?;
let worker_guard = setup_logs(config, &plugins_dir).context("Failed to set up logs")?;

if first_time {
display_popup(
Expand Down

0 comments on commit 8de7fa7

Please sign in to comment.