From a4e5aea2ead03562a906a2be9c2dd379ef3f7bd7 Mon Sep 17 00:00:00 2001 From: a2x <45197573+a2x@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:53:24 +1000 Subject: [PATCH] Check for `config.json` file existence before proceeding --- src/main.rs | 16 +++++++++++++--- src/util/process.rs | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index c03cfaa..c851624 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] #![feature(offset_of)] -use anyhow::Result; +use anyhow::{bail, Result}; use builder::*; @@ -14,6 +14,7 @@ use log::LevelFilter; use simplelog::{info, ColorChoice, ConfigBuilder, TermLogger, TerminalMode}; use std::fs; +use std::path::Path; use std::time::Instant; use util::Process; @@ -43,7 +44,7 @@ struct Args { schemas: bool, /// List of file builders to use. - /// Valid values are: `.cs`, `.hpp`, `.json`, `.py`, `.rs`, `.yaml`. + /// Valid values: `.cs`, `.hpp`, `.json`, `.py`, `.rs`, `.yaml`. #[arg( short, long, @@ -89,14 +90,22 @@ fn main() -> Result<()> { TermLogger::init(log_level, config, TerminalMode::Mixed, ColorChoice::Auto)?; - let now = Instant::now(); + // Check if the config file exists. + if !Path::new("config.json").exists() { + bail!("Missing config.json file"); + } + // Create the output directory if it doesn't exist. fs::create_dir_all(&output)?; + // Open a handle to the game process. let mut process = Process::new("cs2.exe")?; process.initialize()?; + // Start the timer. + let now = Instant::now(); + let all = !(interfaces || offsets || schemas); if schemas || all { @@ -111,6 +120,7 @@ fn main() -> Result<()> { dump_offsets(&mut process, &mut builders, &output, indent)?; } + // Stop the timer. info!( "Done! Time elapsed: {:?}", now.elapsed() diff --git a/src/util/process.rs b/src/util/process.rs index 20c03e8..edfc29a 100644 --- a/src/util/process.rs +++ b/src/util/process.rs @@ -47,7 +47,7 @@ impl Process { }) } - /// Initializes the process by parsing the loaded modules. + /// Initializes the `Process` instance by parsing all loaded modules in the process. /// /// # Arguments ///