From 8398b4003b72b3eefea11d8f71897ddb48f4b0ad Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Sat, 13 May 2023 12:37:07 +0200 Subject: impl of set_version import --- src/commands/io.rs | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src/commands/io.rs') diff --git a/src/commands/io.rs b/src/commands/io.rs index e072f00..2bab132 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -4,9 +4,9 @@ use std::io::prelude::*; use crate::{ config::Cfg, - db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids}, + db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_set_version, userlist_get_all_ids, userlist_get_current_version}, error::MLE, - mod_add, IDSelector, List, Modloader, + mod_add, IDSelector, List, Modloader, AddMod, }; #[derive(Debug, Serialize, Deserialize)] @@ -14,10 +14,25 @@ struct Export { lists: Vec, } +#[derive(Debug, Serialize, Deserialize)] +struct ExportVersion { + version: String, + set: bool +} + +impl ExportVersion { + fn from(config: Cfg, list_id: &str, mod_id: &str) -> MLE { + Ok(Self { + version: userlist_get_current_version(config.clone(), list_id, mod_id)?, + set: userlist_get_set_version(config.clone(), list_id, mod_id)? + }) + } +} + #[derive(Debug, Serialize, Deserialize)] struct ExportList { id: String, - mods: String, + versions: Vec, launcher: String, mc_version: String, download_folder: Option, @@ -32,11 +47,15 @@ impl ExportList { dl_folder = Some(list.download_folder) }; - let mods = userlist_get_all_ids(config, list_id)?.join("|"); + let mods = userlist_get_all_ids(config.clone(), &list_id)?; + let mut versions = vec![]; + for m in mods { + versions.push(ExportVersion::from(config.clone(), &list_id, &m)?) + } Ok(Self { id: list.id, - mods, + versions, launcher: list.modloader.to_string(), mc_version: list.mc_version, download_folder: dl_folder, @@ -86,14 +105,14 @@ pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE list.modloader.clone(), String::from(&list.download_folder), )?; - let mods: Vec<&str> = exportlist.mods.split('|').collect(); - let mut mod_ids = vec![]; - for mod_id in mods { - mod_ids.push(IDSelector::ModificationID(String::from(mod_id))); + + let mut ver_ids = vec![]; + for id in exportlist.versions { + ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} ); } //TODO impl set_version and good direct download //TODO impl all at once, dafuck ?done? - mod_add(config.clone(), mod_ids, list, direct_download, false).await?; + mod_add(config.clone(), ver_ids, list, direct_download).await?; } Ok(()) } -- cgit v1.2.3 From 3181da20e001146653a09f0734e0340b043d9b4b Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 13 May 2023 12:59:38 +0200 Subject: removed todos, fixed get version set --- src/commands/io.rs | 2 -- src/commands/modification.rs | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'src/commands/io.rs') diff --git a/src/commands/io.rs b/src/commands/io.rs index 2bab132..dd294bc 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -110,8 +110,6 @@ pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE for id in exportlist.versions { ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} ); } - //TODO impl set_version and good direct download - //TODO impl all at once, dafuck ?done? mod_add(config.clone(), ver_ids, list, direct_download).await?; } Ok(()) diff --git a/src/commands/modification.rs b/src/commands/modification.rs index ab42468..9a1a651 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -35,7 +35,6 @@ pub struct ProjectInfo { pub set_version: bool, } -//TODO fix setversion to per mod pub async fn mod_add( config: Cfg, mods: Vec, @@ -264,7 +263,7 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE