From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/commands/io.rs | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'src/commands/io.rs') diff --git a/src/commands/io.rs b/src/commands/io.rs index 5de8dd1..7f03eec 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -1,12 +1,18 @@ +use serde::{Deserialize, Serialize}; use std::fs::File; use std::io::prelude::*; -use serde::{Serialize, Deserialize}; -use crate::{db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, List, devdir, error::MLE, mod_add, IDSelector}; +use crate::{ + config::Cfg, + db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids}, + devdir, + error::MLE, + mod_add, IDSelector, List, Modloader, +}; #[derive(Debug, Serialize, Deserialize)] struct Export { - lists: Vec + lists: Vec, } #[derive(Debug, Serialize, Deserialize)] @@ -20,15 +26,22 @@ struct ExportList { impl ExportList { pub fn from(config: Cfg, list_id: String, download: bool) -> MLE { - let list = lists_get(config.clone(), String::from(&list_id))?; let mut dl_folder = None; - if download{ dl_folder = Some(list.download_folder) }; + if download { + dl_folder = Some(list.download_folder) + }; let mods = userlist_get_all_ids(config, list_id)?.join("|"); - Ok(Self { id: list.id, mods, launcher: list.modloader.to_string(), mc_version: list.mc_version, download_folder: dl_folder }) + Ok(Self { + id: list.id, + mods, + launcher: list.modloader.to_string(), + mc_version: list.mc_version, + download_folder: dl_folder, + }) } } @@ -43,32 +56,44 @@ pub fn export(config: Cfg, list: Option) -> MLE<()> { for list_id in list_ids { lists.push(ExportList::from(config.clone(), list_id, true)?); } - - let toml = toml::to_string( &Export { lists } )?; + + let toml = toml::to_string(&Export { lists })?; let filestr = dirs::home_dir().unwrap().join("mlexport.toml"); - let mut file = File::create(devdir(filestr.into_os_string().into_string().unwrap().as_str()))?; + let mut file = File::create(devdir( + filestr.into_os_string().into_string().unwrap().as_str(), + ))?; file.write_all(toml.as_bytes())?; Ok(()) } pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE<()> { - let mut file = File::open(file_str)?; let mut content = String::new(); file.read_to_string(&mut content)?; let export: Export = toml::from_str(&content)?; for exportlist in export.lists { - let list = List { id: exportlist.id, mc_version: exportlist.mc_version, modloader: Modloader::from(&exportlist.launcher)?, download_folder: exportlist.download_folder.ok_or("NO_DL").unwrap() }; - lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; + let list = List { + id: exportlist.id, + mc_version: exportlist.mc_version, + modloader: Modloader::from(&exportlist.launcher)?, + download_folder: exportlist.download_folder.ok_or("NO_DL").unwrap(), + }; + lists_insert( + config.clone(), + list.id.clone(), + list.mc_version.clone(), + 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))); - }; + } //TODO impl set_version and good direct download //TODO impl all at once, dafuck mod_add(config.clone(), mod_ids, list, direct_download, false).await?; -- cgit v1.2.3