1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-30 22:00:16 +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; use zip::ZipArchive;
lazy_static! { lazy_static! {
pub static ref CURRENT_VERSION: Mutex<String> = pub static ref CURRENT_VERSION: Mutex<String> = Mutex::new(match get_current_version() {
Mutex::new(get_current_version().expect("Could not find current modpack version!\n")); Ok(v) => v,
Err(e) => panic!("Could not find current modpack version!: {}", e),
});
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -64,6 +64,11 @@ impl TrainingModpackConfig {
if fs::metadata(TRAINING_MODPACK_TOML_PATH).is_ok() { if fs::metadata(TRAINING_MODPACK_TOML_PATH).is_ok() {
Err(io::Error::from(io::ErrorKind::AlreadyExists).into()) Err(io::Error::from(io::ErrorKind::AlreadyExists).into())
} else { } 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 default_config: TrainingModpackConfig = TrainingModpackConfig::new();
let contents = toml::to_string(&default_config)?; let contents = toml::to_string(&default_config)?;
fs::write(TRAINING_MODPACK_TOML_PATH, contents)?; fs::write(TRAINING_MODPACK_TOML_PATH, contents)?;