diff --git a/src/commands/create.rs b/src/commands/create.rs index b7dc5d9..bd27aea 100644 --- a/src/commands/create.rs +++ b/src/commands/create.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, error::Error}; +use std::error::Error; use dialoguer::{FuzzySelect, Select, theme::ColorfulTheme}; use futures_util::StreamExt; @@ -6,7 +6,7 @@ use tokio::{fs::File, io::AsyncWriteExt}; use crate::{ models::{ - config::{Config, Server}, + config::{Config, Mods, Server}, fabric::FabricVersions, vanilla::{VanillaVersionDetail, VanillaVersionType, VanillaVersions}, }, @@ -188,7 +188,7 @@ impl LoaderDownloader for VanillaDownloader { loader: Self::name(), loader_version: None, }, - mods: HashMap::new(), + mods: Mods {}, }; Ok(config) @@ -302,7 +302,7 @@ impl LoaderDownloader for FabricDownloader { loader: Self::name(), loader_version: create.loader_version.clone(), }, - mods: HashMap::new(), + mods: Mods {}, }; Ok(config) diff --git a/src/commands/install.rs b/src/commands/install.rs index caa1b74..45b7579 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -27,7 +27,7 @@ impl Install { if file_res.is_err() { return Err("current directory is not a mcsm project".into()); } - let mut config: Config = toml::from_str(&file_res.unwrap())?; + let config: Config = toml::from_str(&file_res.unwrap())?; if config.server.loader == "Vanilla" { return Err("cannot search for mods on Vanilla server".into()); @@ -47,7 +47,7 @@ impl Install { game_versions: format!(r#"["{}"]"#, config.server.version), }; - let res: Vec = with_spinner( + let install_result: Vec = with_spinner( format!("fetching {}", mod_name).as_str(), format!("fetched {}", mod_name).as_str(), || async { @@ -62,9 +62,7 @@ impl Install { ) .await?; - let install_result = res.first().unwrap(); - let file = &install_result.files.first().unwrap(); - let version_number = &install_result.version_number; + let file = install_result.first().unwrap().files.first().unwrap(); with_progressbar( format!("downloading {}", mod_name).as_str(), format!("downloaded {}", mod_name).as_str(), @@ -90,7 +88,7 @@ impl Install { let verified = verify_sha512(&data, &file.hashes.sha512); if !verified { - tokio::fs::remove_file(&file.filename).await?; + tokio::fs::remove_file("server.jar").await?; return Err("sha1 verifaction failed for downloaded file".into()); } @@ -98,8 +96,6 @@ impl Install { }) .await?; println!(); - - config.mods.insert(mod_name.clone(), version_number.clone()); } println!( @@ -107,13 +103,6 @@ impl Install { dialoguer::console::style("✔").green() ); - with_spinner("saving to config", "saved to config", || async { - std::env::set_current_dir("..")?; - let config_str = toml::to_string(&config)?; - tokio::fs::write("mcsm.toml", config_str).await?; - Ok(()) - }).await?; - Ok(()) } } diff --git a/src/models/config.rs b/src/models/config.rs index 74852a6..3505350 100644 --- a/src/models/config.rs +++ b/src/models/config.rs @@ -1,11 +1,9 @@ -use std::collections::HashMap; - use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] pub struct Config { pub server: Server, - pub mods: HashMap, + pub mods: Mods, } #[derive(Deserialize, Serialize)] @@ -14,3 +12,6 @@ pub struct Server { pub loader: String, pub loader_version: Option, } + +#[derive(Deserialize, Serialize)] +pub struct Mods {}