diff --git a/Cargo.lock b/Cargo.lock index 421c3bf..9624708 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,7 +213,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.76", ] [[package]] @@ -561,6 +561,19 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +[[package]] +name = "lmk" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d367f8461117f43458fa181cda8ae30c249aaccaa39cd973bf7aa8e10270b2" +dependencies = [ + "chrono", + "indoc", + "serde", + "toml", + "ulid", +] + [[package]] name = "lock_api" version = "0.4.9" @@ -663,18 +676,18 @@ checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -796,13 +809,14 @@ checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" [[package]] name = "renom" -version = "1.4.0" +version = "1.5.0" dependencies = [ "chrono", "clap", "colored", "indoc", "inquire", + "lmk", "regex", "rust-ini", "serde", @@ -873,22 +887,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.164" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.76", ] [[package]] @@ -977,9 +991,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.15" +version = "2.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" dependencies = [ "proc-macro2", "quote", @@ -1151,7 +1165,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.76", "wasm-bindgen-shared", ] @@ -1173,7 +1187,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.76", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.toml index 8817bb9..9a23900 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Mustafa "] edition = "2018" name = "renom" -version = "1.4.0" +version = "1.5.0" description = "A simple program to rename Unreal Engine projects." keywords = ["gamedev", "ue4", "ue5", "unreal_engine", "rename"] categories = [ @@ -38,3 +38,4 @@ chrono = "0.4.38" toml = "0.8.19" ulid = "1.1.3" indoc = "2.0.5" +lmk = "0.2.0" diff --git a/src/crash.rs b/src/crash.rs deleted file mode 100644 index 30db936..0000000 --- a/src/crash.rs +++ /dev/null @@ -1,117 +0,0 @@ -use std::{fs, panic::PanicInfo, path::PathBuf, time::SystemTime}; - -use chrono::{DateTime, Utc}; -use indoc::indoc; -use serde::Serialize; - -/// A crash report. -#[derive(Serialize)] -struct Report { - captured_at: String, - package_name: String, - package_version: String, - binary_name: Option, - working_dir: Option, - operating_system: String, - panic_message: Option, - panic_location: String, - backtrace: Option, -} - -impl Report { - /// Creates a new report from a panic. - pub fn new(panic: &PanicInfo) -> Self { - let captured_at = DateTime::::from(SystemTime::now()).to_rfc3339(); - const PACKAGE_NAME: &str = env!("CARGO_PKG_NAME"); - const PACKAGE_VERSION: &str = env!("CARGO_PKG_VERSION"); - let binary_name = std::env::args().next(); - let working_dir = std::env::current_dir().ok(); - let os = std::env::consts::OS.to_owned(); - - let panic_message = panic - .payload() - .downcast_ref::<&str>() - .map(|message| message.to_string()); - - let panic_location = panic - .location() - .map(|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column())) - .expect("panic location should always be set"); - - let backtrace = { - let backtrace = std::backtrace::Backtrace::capture(); - use std::backtrace::BacktraceStatus; - match backtrace.status() { - BacktraceStatus::Captured => Some(backtrace.to_string()), - _ => None, - } - }; - - Self { - captured_at, - package_name: PACKAGE_NAME.to_owned(), - package_version: PACKAGE_VERSION.to_owned(), - binary_name, - working_dir, - operating_system: os, - panic_message, - panic_location, - backtrace, - } - } -} - -/// Initializes the crash reporter. -/// -/// This installs a panic hook that will (on panic) write a crash report to file -/// and inform the user of the crash. The crash report is written to a TOML file -/// in the OS-specific temp directory with a unique id. If the report cannot be -/// written to file, it is printed to stderr instead as a last-ditch effort. The -/// message displayed to users includes information about the crash report and -/// encourages them to raise an issue on GitHub in the relevant repository. -/// -/// The panic hook is only registered for release builds. -pub fn init_crash_reporter() { - if cfg!(not(debug_assertions)) { - std::panic::set_hook(Box::new(|panic| { - let report = Report::new(panic); - let content = toml::to_string_pretty(&report).expect("report should serialize to toml"); - let output_dir = std::env::temp_dir() - .join(&report.package_name) - .join("crash"); - - let report_id = ulid::Generator::new() - .generate() - .expect("ulid gen should not error") - .to_string(); - - let report_path = output_dir.join(report_id).with_extension("toml"); - - let result = - fs::create_dir_all(output_dir).and_then(|_| fs::write(&report_path, &content)); - - if let Err(e) = result { - eprintln!( - "error: failed to save crash report to {}", - report_path.display() - ); - eprintln!("{sep}\n{e}\n{sep}", sep = "-".repeat(20)); - eprintln!("error: writing crash report directly to stderr"); - eprintln!("{sep}\n{content}\n{sep}", sep = "-".repeat(20)); - return; - } - - eprintln!( - indoc! { - "{} has crashed! - - A crash report has been saved to {}. To get support for this problem, - please raise an issue on GitHub at {}/issues and include the crash - report to help us better diagnose the problem."}, - report.package_name, - report_path.display(), - env!("CARGO_PKG_REPOSITORY") - ); - })) - } -} diff --git a/src/main.rs b/src/main.rs index 0cc6caf..90a88df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use clap::Parser; +use lmk::init_crash_reporter; use renom::{ cli::{ Cli, @@ -8,10 +9,9 @@ use renom::{ wizard::start_interactive_dialogue, workflows::{rename_module, rename_plugin, rename_project, rename_target}, }; -mod crash; fn main() { - crash::init_crash_reporter(); + init_crash_reporter!(); let cli = Cli::parse(); match cli.command {