From df6b3ec49392e85dfac3813dd3e01f54fa6d14c5 Mon Sep 17 00:00:00 2001 From: asimon-1 <40246417+asimon-1@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:44:46 -0400 Subject: [PATCH] Fix crash if the TRAINING_MODPACK_ROOT path doesn't already exist (#606) * Fix crash if the TRAINING_MODPACK_ROOT path doesn't already exist * rustfmt --- src/common/release.rs | 6 ++++-- training_mod_consts/src/config.rs | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/common/release.rs b/src/common/release.rs index e18e3fa..ab0f5e5 100644 --- a/src/common/release.rs +++ b/src/common/release.rs @@ -10,8 +10,10 @@ use serde_json::Value; use zip::ZipArchive; lazy_static! { - pub static ref CURRENT_VERSION: Mutex = - Mutex::new(get_current_version().expect("Could not find current modpack version!\n")); + pub static ref CURRENT_VERSION: Mutex = Mutex::new(match get_current_version() { + Ok(v) => v, + Err(e) => panic!("Could not find current modpack version!: {}", e), + }); } #[derive(Debug)] diff --git a/training_mod_consts/src/config.rs b/training_mod_consts/src/config.rs index 9608822..f0462d7 100644 --- a/training_mod_consts/src/config.rs +++ b/training_mod_consts/src/config.rs @@ -64,6 +64,11 @@ impl TrainingModpackConfig { if fs::metadata(TRAINING_MODPACK_TOML_PATH).is_ok() { Err(io::Error::from(io::ErrorKind::AlreadyExists).into()) } else { + if !fs::metadata(TRAINING_MODPACK_ROOT).is_ok() { + // Root path doesn't exist, create it before trying to make the file + println!("Creating directory..."); + fs::create_dir_all(TRAINING_MODPACK_ROOT)?; + } let default_config: TrainingModpackConfig = TrainingModpackConfig::new(); let contents = toml::to_string(&default_config)?; fs::write(TRAINING_MODPACK_TOML_PATH, contents)?;