summaryrefslogtreecommitdiff
path: root/src/commands/io.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-05-13 17:28:00 +0200
committerfx <[email protected]>2023-05-13 17:28:00 +0200
commit5a2ea0755b29a8811aeeec1c73679c5783082628 (patch)
treedb2aaedda9678465763993eeec15bd20673394e8 /src/commands/io.rs
parent9063a041f6b2e72f6e4a861c77ac16065dd5378b (diff)
parent3b9d717ecd61bd2b5c32ec117f38c7d67a109748 (diff)
downloadmodlist-5a2ea0755b29a8811aeeec1c73679c5783082628.tar
modlist-5a2ea0755b29a8811aeeec1c73679c5783082628.tar.gz
modlist-5a2ea0755b29a8811aeeec1c73679c5783082628.zip
Merge pull request 'todos' (#5) from todos into master
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/5
Diffstat (limited to 'src/commands/io.rs')
-rw-r--r--src/commands/io.rs41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/commands/io.rs b/src/commands/io.rs
index e072f00..dd294bc 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,12 @@ 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 mod_add(config.clone(), ver_ids, list, direct_download).await?;
95 //TODO impl all at once, dafuck ?done?
96 mod_add(config.clone(), mod_ids, list, direct_download, false).await?;
97 } 114 }
98 Ok(()) 115 Ok(())
99} 116}