summaryrefslogtreecommitdiff
path: root/src/commands/io.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-05-13 12:37:07 +0200
committerFxQnLr <[email protected]>2023-05-13 12:37:07 +0200
commit8398b4003b72b3eefea11d8f71897ddb48f4b0ad (patch)
treee389808b24fca06aed882177c9d70a5d9121c619 /src/commands/io.rs
parentbf8fa23bf00584e4efa3060cf8ca4932173061c9 (diff)
downloadmodlist-8398b4003b72b3eefea11d8f71897ddb48f4b0ad.tar
modlist-8398b4003b72b3eefea11d8f71897ddb48f4b0ad.tar.gz
modlist-8398b4003b72b3eefea11d8f71897ddb48f4b0ad.zip
impl of set_version import
Diffstat (limited to 'src/commands/io.rs')
-rw-r--r--src/commands/io.rs39
1 files changed, 29 insertions, 10 deletions
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::*;
4 4
5use crate::{ 5use crate::{
6 config::Cfg, 6 config::Cfg,
7 db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids}, 7 db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_set_version, userlist_get_all_ids, userlist_get_current_version},
8 error::MLE, 8 error::MLE,
9 mod_add, IDSelector, List, Modloader, 9 mod_add, IDSelector, List, Modloader, AddMod,
10}; 10};
11 11
12#[derive(Debug, Serialize, Deserialize)] 12#[derive(Debug, Serialize, Deserialize)]
@@ -15,9 +15,24 @@ struct Export {
15} 15}
16 16
17#[derive(Debug, Serialize, Deserialize)] 17#[derive(Debug, Serialize, Deserialize)]
18struct ExportVersion {
19 version: String,
20 set: bool
21}
22
23impl ExportVersion {
24 fn from(config: Cfg, list_id: &str, mod_id: &str) -> MLE<Self> {
25 Ok(Self {
26 version: userlist_get_current_version(config.clone(), list_id, mod_id)?,
27 set: userlist_get_set_version(config.clone(), list_id, mod_id)?
28 })
29 }
30}
31
32#[derive(Debug, Serialize, Deserialize)]
18struct ExportList { 33struct ExportList {
19 id: String, 34 id: String,
20 mods: String, 35 versions: Vec<ExportVersion>,
21 launcher: String, 36 launcher: String,
22 mc_version: String, 37 mc_version: String,
23 download_folder: Option<String>, 38 download_folder: Option<String>,
@@ -32,11 +47,15 @@ impl ExportList {
32 dl_folder = Some(list.download_folder) 47 dl_folder = Some(list.download_folder)
33 }; 48 };
34 49
35 let mods = userlist_get_all_ids(config, list_id)?.join("|"); 50 let mods = userlist_get_all_ids(config.clone(), &list_id)?;
51 let mut versions = vec![];
52 for m in mods {
53 versions.push(ExportVersion::from(config.clone(), &list_id, &m)?)
54 }
36 55
37 Ok(Self { 56 Ok(Self {
38 id: list.id, 57 id: list.id,
39 mods, 58 versions,
40 launcher: list.modloader.to_string(), 59 launcher: list.modloader.to_string(),
41 mc_version: list.mc_version, 60 mc_version: list.mc_version,
42 download_folder: dl_folder, 61 download_folder: dl_folder,
@@ -86,14 +105,14 @@ pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE
86 list.modloader.clone(), 105 list.modloader.clone(),
87 String::from(&list.download_folder), 106 String::from(&list.download_folder),
88 )?; 107 )?;
89 let mods: Vec<&str> = exportlist.mods.split('|').collect(); 108
90 let mut mod_ids = vec![]; 109 let mut ver_ids = vec![];
91 for mod_id in mods { 110 for id in exportlist.versions {
92 mod_ids.push(IDSelector::ModificationID(String::from(mod_id))); 111 ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} );
93 } 112 }
94 //TODO impl set_version and good direct download 113 //TODO impl set_version and good direct download
95 //TODO impl all at once, dafuck ?done? 114 //TODO impl all at once, dafuck ?done?
96 mod_add(config.clone(), mod_ids, list, direct_download, false).await?; 115 mod_add(config.clone(), ver_ids, list, direct_download).await?;
97 } 116 }
98 Ok(()) 117 Ok(())
99} 118}