Check for `config.json` file existence before proceeding

This commit is contained in:
a2x 2023-12-12 12:53:24 +10:00
parent bcab0660f8
commit a4e5aea2ea
2 changed files with 14 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
#![feature(offset_of)] #![feature(offset_of)]
use anyhow::Result; use anyhow::{bail, Result};
use builder::*; use builder::*;
@ -14,6 +14,7 @@ use log::LevelFilter;
use simplelog::{info, ColorChoice, ConfigBuilder, TermLogger, TerminalMode}; use simplelog::{info, ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
use std::fs; use std::fs;
use std::path::Path;
use std::time::Instant; use std::time::Instant;
use util::Process; use util::Process;
@ -43,7 +44,7 @@ struct Args {
schemas: bool, schemas: bool,
/// List of file builders to use. /// List of file builders to use.
/// Valid values are: `.cs`, `.hpp`, `.json`, `.py`, `.rs`, `.yaml`. /// Valid values: `.cs`, `.hpp`, `.json`, `.py`, `.rs`, `.yaml`.
#[arg( #[arg(
short, short,
long, long,
@ -89,14 +90,22 @@ fn main() -> Result<()> {
TermLogger::init(log_level, config, TerminalMode::Mixed, ColorChoice::Auto)?; 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)?; fs::create_dir_all(&output)?;
// Open a handle to the game process.
let mut process = Process::new("cs2.exe")?; let mut process = Process::new("cs2.exe")?;
process.initialize()?; process.initialize()?;
// Start the timer.
let now = Instant::now();
let all = !(interfaces || offsets || schemas); let all = !(interfaces || offsets || schemas);
if schemas || all { if schemas || all {
@ -111,6 +120,7 @@ fn main() -> Result<()> {
dump_offsets(&mut process, &mut builders, &output, indent)?; dump_offsets(&mut process, &mut builders, &output, indent)?;
} }
// Stop the timer.
info!( info!(
"<on-green>Done!</> <green>Time elapsed: <b>{:?}</></>", "<on-green>Done!</> <green>Time elapsed: <b>{:?}</></>",
now.elapsed() now.elapsed()

View File

@ -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 /// # Arguments
/// ///