1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-27 20:34:03 +00:00

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
This commit is contained in:
asimon-1 2023-08-22 20:44:46 -04:00 committed by GitHub
parent 00f2284397
commit df6b3ec493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -10,8 +10,10 @@ use serde_json::Value;
use zip::ZipArchive;
lazy_static! {
pub static ref CURRENT_VERSION: Mutex<String> =
Mutex::new(get_current_version().expect("Could not find current modpack version!\n"));
pub static ref CURRENT_VERSION: Mutex<String> = Mutex::new(match get_current_version() {
Ok(v) => v,
Err(e) => panic!("Could not find current modpack version!: {}", e),
});
}
#[derive(Debug)]

View file

@ -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)?;