diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/download.rs | 31 | ||||
-rw-r--r-- | src/commands/io.rs | 14 | ||||
-rw-r--r-- | src/commands/list.rs | 8 | ||||
-rw-r--r-- | src/commands/modification.rs | 62 | ||||
-rw-r--r-- | src/commands/update.rs | 23 | ||||
-rw-r--r-- | src/db.rs | 4 | ||||
-rw-r--r-- | src/files.rs | 22 | ||||
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 20 |
9 files changed, 98 insertions, 91 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index e9a96b5..7aa0156 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | 1 | ||
2 | use indicatif::MultiProgress; | 2 | use indicatif::{MultiProgress, ProgressStyle, ProgressBar}; |
3 | 3 | ||
4 | use crate::{STYLE_BAR_POS, PROGRESS_CHARS}; | ||
4 | use crate::{config::Cfg, List}; | 5 | use crate::{config::Cfg, List}; |
5 | use crate::{ | 6 | use crate::{ |
6 | db::userlist_get_all_current_versions_with_mods, | 7 | db::userlist_get_all_current_versions_with_mods, |
@@ -14,9 +15,12 @@ use crate::{ | |||
14 | pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> { | 15 | pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> { |
15 | 16 | ||
16 | let mp = MultiProgress::new(); | 17 | let mp = MultiProgress::new(); |
18 | let download_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | ||
19 | download_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); | ||
17 | 20 | ||
18 | for current_list in liststack { | 21 | for current_list in liststack { |
19 | println!("Downloading current versions of mods in {}", current_list.id); | 22 | download_p.set_message(format!("Download in {}", current_list.id)); |
23 | |||
20 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 24 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; |
21 | let current_version_ids = match userlist_get_all_current_versions_with_mods( | 25 | let current_version_ids = match userlist_get_all_current_versions_with_mods( |
22 | config, | 26 | config, |
@@ -59,24 +63,41 @@ pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_ol | |||
59 | config.clone(), | 63 | config.clone(), |
60 | get_raw_versions(&config.apis.modrinth, to_download).await, | 64 | get_raw_versions(&config.apis.modrinth, to_download).await, |
61 | &mp, | 65 | &mp, |
62 | None | 66 | &download_p, |
63 | ) | 67 | ) |
64 | .await?; | 68 | .await?; |
65 | } else { | 69 | } else { |
66 | println!("There are no new versions to download"); | 70 | download_p.println(format!("There are no new versions to download for {}", current_list.id)); |
67 | } | 71 | } |
68 | 72 | ||
69 | if !to_disable.is_empty() { | 73 | if !to_disable.is_empty() { |
74 | let d_p = mp.insert_before(&download_p, ProgressBar::new(to_disable.len().try_into().unwrap())); | ||
75 | d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); | ||
70 | for ver in to_disable { | 76 | for ver in to_disable { |
71 | if delete_old { | 77 | if delete_old { |
72 | // println!("Deleting version {} for mod {}", ver.1, ver.0); | 78 | d_p.set_message(format!("Delete version {}", ver.1)); |
79 | d_p.inc(1); | ||
73 | delete_version(current_list.clone(), ver.1)?; | 80 | delete_version(current_list.clone(), ver.1)?; |
74 | } else { | 81 | } else { |
82 | d_p.set_message(format!("Disable version {}", ver.1)); | ||
83 | d_p.inc(1); | ||
75 | disable_version(config, current_list.clone(), ver.1, ver.0)?; | 84 | disable_version(config, current_list.clone(), ver.1, ver.0)?; |
76 | }; | 85 | }; |
77 | } | 86 | } |
87 | |||
88 | let del_msg = if delete_old { | ||
89 | "Deleted all old versions" | ||
90 | } else { | ||
91 | "Disabled all old versions" | ||
92 | }; | ||
93 | |||
94 | d_p.finish_with_message(del_msg); | ||
78 | } | 95 | } |
96 | |||
97 | download_p.inc(1); | ||
79 | } | 98 | } |
80 | 99 | ||
100 | download_p.finish_with_message("Downloaded all lists"); | ||
101 | |||
81 | Ok(()) | 102 | Ok(()) |
82 | } | 103 | } |
diff --git a/src/commands/io.rs b/src/commands/io.rs index 43e642a..45e363e 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -39,18 +39,18 @@ struct ExportList { | |||
39 | } | 39 | } |
40 | 40 | ||
41 | impl ExportList { | 41 | impl ExportList { |
42 | pub fn from(config: &Cfg, list_id: String, download: bool) -> MLE<Self> { | 42 | pub fn from(config: &Cfg, list_id: &str, download: bool) -> MLE<Self> { |
43 | let list = lists_get(config, String::from(&list_id))?; | 43 | let list = lists_get(config, list_id)?; |
44 | 44 | ||
45 | let mut dl_folder = None; | 45 | let mut dl_folder = None; |
46 | if download { | 46 | if download { |
47 | dl_folder = Some(list.download_folder) | 47 | dl_folder = Some(list.download_folder) |
48 | }; | 48 | }; |
49 | 49 | ||
50 | let mods = userlist_get_all_ids(config, &list_id)?; | 50 | let mods = userlist_get_all_ids(config, list_id)?; |
51 | let mut versions = vec![]; | 51 | let mut versions = vec![]; |
52 | for m in mods { | 52 | for m in mods { |
53 | versions.push(ExportVersion::from(config, &list_id, &m)?) | 53 | versions.push(ExportVersion::from(config, list_id, &m)?) |
54 | } | 54 | } |
55 | 55 | ||
56 | Ok(Self { | 56 | Ok(Self { |
@@ -68,11 +68,11 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
68 | if list.is_none() { | 68 | if list.is_none() { |
69 | list_ids = lists_get_all_ids(config)?; | 69 | list_ids = lists_get_all_ids(config)?; |
70 | } else { | 70 | } else { |
71 | list_ids.push(lists_get(config, list.unwrap())?.id); | 71 | list_ids.push(lists_get(config, &list.unwrap())?.id); |
72 | } | 72 | } |
73 | let mut lists: Vec<ExportList> = vec![]; | 73 | let mut lists: Vec<ExportList> = vec![]; |
74 | for list_id in list_ids { | 74 | for list_id in list_ids { |
75 | lists.push(ExportList::from(config, list_id, true)?); | 75 | lists.push(ExportList::from(config, &list_id, true)?); |
76 | } | 76 | } |
77 | 77 | ||
78 | let toml = toml::to_string(&Export { lists })?; | 78 | let toml = toml::to_string(&Export { lists })?; |
@@ -85,7 +85,7 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
85 | Ok(()) | 85 | Ok(()) |
86 | } | 86 | } |
87 | 87 | ||
88 | pub async fn import(config: &Cfg, file_str: String, direct_download: bool) -> MLE<()> { | 88 | pub async fn import(config: &Cfg, file_str: &str, direct_download: bool) -> MLE<()> { |
89 | let mut file = File::open(file_str)?; | 89 | let mut file = File::open(file_str)?; |
90 | let mut content = String::new(); | 90 | let mut content = String::new(); |
91 | file.read_to_string(&mut content)?; | 91 | file.read_to_string(&mut content)?; |
diff --git a/src/commands/list.rs b/src/commands/list.rs index 95f9927..52f14f2 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -18,7 +18,7 @@ pub struct List { | |||
18 | 18 | ||
19 | pub fn get_current_list(config: &Cfg) -> MLE<List> { | 19 | pub fn get_current_list(config: &Cfg) -> MLE<List> { |
20 | let id = config_get_current_list(config)?; | 20 | let id = config_get_current_list(config)?; |
21 | lists_get(config, id) | 21 | lists_get(config, &id) |
22 | } | 22 | } |
23 | 23 | ||
24 | pub fn list_add( | 24 | pub fn list_add( |
@@ -52,7 +52,7 @@ pub fn list_remove(config: &Cfg, id: String) -> MLE<()> { | |||
52 | /// * `args` - All args, to extract the new version | 52 | /// * `args` - All args, to extract the new version |
53 | pub async fn list_version( | 53 | pub async fn list_version( |
54 | config: &Cfg, | 54 | config: &Cfg, |
55 | id: String, | 55 | id: &str, |
56 | mc_version: String, | 56 | mc_version: String, |
57 | download: bool, | 57 | download: bool, |
58 | delete: bool, | 58 | delete: bool, |
@@ -62,7 +62,7 @@ pub async fn list_version( | |||
62 | id, mc_version | 62 | id, mc_version |
63 | ); | 63 | ); |
64 | 64 | ||
65 | lists_version(config, &id, &mc_version)?; | 65 | lists_version(config, id, &mc_version)?; |
66 | 66 | ||
67 | println!( | 67 | println!( |
68 | "\nCheck for updates for new minecraft version in list {}", | 68 | "\nCheck for updates for new minecraft version in list {}", |
@@ -75,7 +75,7 @@ pub async fn list_version( | |||
75 | pub fn list_list(config: &Cfg) -> MLE<()> { | 75 | pub fn list_list(config: &Cfg) -> MLE<()> { |
76 | let lists = lists_get_all_ids(config)?; | 76 | let lists = lists_get_all_ids(config)?; |
77 | for list in lists { | 77 | for list in lists { |
78 | let l = lists_get(config, list)?; | 78 | let l = lists_get(config, &list)?; |
79 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) | 79 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) |
80 | } | 80 | } |
81 | Ok(()) | 81 | Ok(()) |
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index d369c4b..8abf913 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -11,7 +11,7 @@ use crate::{ | |||
11 | error::{ErrorType, MLError, MLE}, | 11 | error::{ErrorType, MLError, MLE}, |
12 | files::{delete_version, download_versions}, | 12 | files::{delete_version, download_versions}, |
13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, | 13 | modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, |
14 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, | 14 | List, PROGRESS_CHARS, STYLE_BAR_POS, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | #[derive(Debug)] | 17 | #[derive(Debug)] |
@@ -43,57 +43,49 @@ pub async fn mod_add( | |||
43 | list: List, | 43 | list: List, |
44 | direct_download: bool, | 44 | direct_download: bool, |
45 | ) -> MLE<()> { | 45 | ) -> MLE<()> { |
46 | let mp = MultiProgress::new(); | ||
46 | 47 | ||
47 | //TODO MultiProgress | ||
48 | |||
49 | let spinner_style = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); | ||
50 | let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS); | ||
51 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); | 48 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); |
52 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); | 49 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); |
53 | 50 | ||
54 | let p = ProgressBar::new(mods.len().try_into().unwrap()); | 51 | let add_p = mp.add(ProgressBar::new(mods.len().try_into().unwrap())); |
55 | p.set_style(spinner_style.clone()); | 52 | add_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
56 | p.set_message("Sort ids"); | 53 | add_p.set_message("Sort ids"); |
57 | 54 | ||
58 | //"Sort" project ids from version ids to be able to handle them differently but in a batch | 55 | //"Sort" project ids from version ids to be able to handle them differently but in a batch |
59 | for m in mods { | 56 | for m in mods { |
60 | p.inc(1); | 57 | add_p.inc(1); |
61 | match m.id { | 58 | match m.id { |
62 | IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), | 59 | IDSelector::ModificationID(pid) => mod_ids.push((pid, m.set_version)), |
63 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), | 60 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), |
64 | } | 61 | } |
65 | } | 62 | } |
63 | |||
64 | add_p.set_message("Get infos"); | ||
66 | 65 | ||
67 | p.finish_with_message("Sort ids done"); | ||
68 | |||
69 | let info_p = ProgressBar::new(2); | ||
70 | info_p.set_message("Get infos"); | ||
71 | info_p.set_style(bar_style.clone()); | ||
72 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); | 66 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); |
73 | if !mod_ids.is_empty() { | 67 | if !mod_ids.is_empty() { |
74 | projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); | 68 | projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); |
75 | info_p.inc(1); | ||
76 | }; | 69 | }; |
77 | if !ver_ids.is_empty() { | 70 | if !ver_ids.is_empty() { |
78 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); | 71 | projectinfo.append(&mut get_ver_info(config, ver_ids).await?); |
79 | info_p.inc(1); | ||
80 | }; | 72 | }; |
81 | 73 | ||
82 | info_p.finish_with_message("Get infos done"); | ||
83 | |||
84 | if projectinfo.is_empty() { | 74 | if projectinfo.is_empty() { |
85 | return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); | 75 | return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); |
86 | }; | 76 | }; |
87 | 77 | ||
78 | add_p.set_message("Add mods to database"); | ||
79 | |||
88 | let mut downloadstack: Vec<Version> = Vec::new(); | 80 | let mut downloadstack: Vec<Version> = Vec::new(); |
89 | 81 | ||
90 | //Adding each mod to the lists and downloadstack | 82 | //Adding each mod to the lists and downloadstack |
91 | let add_p = ProgressBar::new(projectinfo.len().try_into().unwrap()); | 83 | let project_p = mp.insert_before(&add_p, ProgressBar::new(projectinfo.len().try_into().unwrap())); |
92 | add_p.set_style(bar_style); | 84 | project_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
93 | 85 | ||
94 | for project in projectinfo { | 86 | for project in projectinfo { |
95 | 87 | ||
96 | add_p.set_message(format!("Add {}", project.title)); | 88 | project_p.set_message(format!("Add {}", project.title)); |
97 | 89 | ||
98 | let current_version_id = if project.current_version.is_none() { | 90 | let current_version_id = if project.current_version.is_none() { |
99 | String::from("NONE") | 91 | String::from("NONE") |
@@ -144,18 +136,19 @@ pub async fn mod_add( | |||
144 | downloadstack.push(project.current_version.unwrap()) | 136 | downloadstack.push(project.current_version.unwrap()) |
145 | }; | 137 | }; |
146 | 138 | ||
147 | // add_p.println(format!("Added {}", project.title)); | 139 | project_p.inc(1); |
148 | add_p.inc(1); | ||
149 | } | 140 | } |
150 | 141 | ||
151 | add_p.finish_with_message("Added all mods"); | 142 | project_p.finish_with_message("Added all mods to the database"); |
152 | 143 | ||
153 | //Download all the added mods | 144 | //Download all the added mods |
154 | if direct_download { | 145 | if direct_download { |
155 | let mp = MultiProgress::new(); | 146 | add_p.set_message("Download mods"); |
156 | download_versions(list.clone(), config.clone(), downloadstack, &mp, None).await?; | 147 | download_versions(list.clone(), config.clone(), downloadstack, &mp, &add_p).await?; |
157 | }; | 148 | }; |
158 | 149 | ||
150 | add_p.finish_with_message("Added all mods"); | ||
151 | |||
159 | Ok(()) | 152 | Ok(()) |
160 | } | 153 | } |
161 | 154 | ||
@@ -277,14 +270,17 @@ async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE<Vec<Pro | |||
277 | 270 | ||
278 | for (i, project) in v_projects.into_iter().enumerate() { | 271 | for (i, project) in v_projects.into_iter().enumerate() { |
279 | let version = &v_versions[i]; | 272 | let version = &v_versions[i]; |
280 | // println!("\t└{}({})", project.title, version.id); | 273 | |
281 | let file = version | 274 | let files = version |
282 | .clone() | 275 | .clone() |
283 | .files | 276 | .files; |
284 | .into_iter() | 277 | |
285 | .find(|f| f.primary) | 278 | let file = match files.clone().into_iter().find(|f| f.primary) { |
286 | .unwrap() | 279 | Some(f) => f, |
280 | None => { files[0].clone() } | ||
281 | } | ||
287 | .url; | 282 | .url; |
283 | |||
288 | projectinfo.push(ProjectInfo { | 284 | projectinfo.push(ProjectInfo { |
289 | mod_id: String::from(&project.id), | 285 | mod_id: String::from(&project.id), |
290 | slug: project.slug, | 286 | slug: project.slug, |
diff --git a/src/commands/update.rs b/src/commands/update.rs index bde6896..194bbe5 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -9,7 +9,7 @@ use crate::{ | |||
9 | error::{ErrorType, MLError, MLE}, | 9 | error::{ErrorType, MLError, MLE}, |
10 | files::{clean_list_dir, delete_version, disable_version, download_versions}, | 10 | files::{clean_list_dir, delete_version, disable_version, download_versions}, |
11 | modrinth::{extract_current_version, versions, Version}, | 11 | modrinth::{extract_current_version, versions, Version}, |
12 | List, PROGRESS_CHARS, STYLE_BAR_POS, | 12 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | pub async fn update( | 15 | pub async fn update( |
@@ -23,23 +23,21 @@ pub async fn update( | |||
23 | let mp = MultiProgress::new(); | 23 | let mp = MultiProgress::new(); |
24 | 24 | ||
25 | let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | 25 | let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); |
26 | let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS); | 26 | update_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
27 | update_p.set_style(bar_style.clone()); | ||
28 | update_p.set_message("Update"); | ||
29 | 27 | ||
30 | for current_list in liststack { | 28 | for current_list in liststack { |
29 | update_p.set_message(format!("Update {}", current_list.id)); | ||
30 | |||
31 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); | 31 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); |
32 | list_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); | 32 | list_p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
33 | list_p.set_message(format!("Update {}", current_list.id)); | 33 | list_p.set_message("Update mods"); |
34 | 34 | ||
35 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; | 35 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; |
36 | 36 | ||
37 | let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); | 37 | let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); |
38 | list_u_p.set_style(bar_style.clone()); | 38 | list_u_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
39 | list_u_p.set_message(format!("Update {}", current_list.id)); | ||
40 | 39 | ||
41 | let mut current_versions: Vec<(String, String)> = vec![]; | 40 | let mut current_versions: Vec<(String, String)> = vec![]; |
42 | |||
43 | let mut updatestack: Vec<Version> = vec![]; | 41 | let mut updatestack: Vec<Version> = vec![]; |
44 | 42 | ||
45 | for id in mods { | 43 | for id in mods { |
@@ -84,7 +82,6 @@ pub async fn update( | |||
84 | } | 82 | } |
85 | 83 | ||
86 | list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id)); | 84 | list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id)); |
87 | list_p.inc(1); | ||
88 | 85 | ||
89 | if clean { | 86 | if clean { |
90 | list_p.set_message("Cleaning"); | 87 | list_p.set_message("Cleaning"); |
@@ -92,12 +89,12 @@ pub async fn update( | |||
92 | }; | 89 | }; |
93 | 90 | ||
94 | if direct_download && !updatestack.is_empty() { | 91 | if direct_download && !updatestack.is_empty() { |
95 | download_versions(current_list.clone(), config.clone(), updatestack, &mp, Some(&list_p)).await?; | 92 | download_versions(current_list.clone(), config.clone(), updatestack, &mp, &list_p).await?; |
96 | 93 | ||
97 | //Disable old versions | 94 | //Disable old versions |
98 | if !clean { | 95 | if !clean { |
99 | let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap())); | 96 | let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap())); |
100 | d_p.set_style(bar_style.clone()); | 97 | d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
101 | for ver in current_versions { | 98 | for ver in current_versions { |
102 | if delete_old { | 99 | if delete_old { |
103 | d_p.set_message(format!("Delete version {}", ver.0)); | 100 | d_p.set_message(format!("Delete version {}", ver.0)); |
@@ -119,14 +116,12 @@ pub async fn update( | |||
119 | d_p.finish_with_message(del_msg); | 116 | d_p.finish_with_message(del_msg); |
120 | } | 117 | } |
121 | }; | 118 | }; |
122 | list_p.inc(1); | ||
123 | list_p.finish_with_message(format!("Updated {}", current_list.id)); | 119 | list_p.finish_with_message(format!("Updated {}", current_list.id)); |
124 | update_p.inc(1); | 120 | update_p.inc(1); |
125 | } | 121 | } |
126 | 122 | ||
127 | update_p.finish_with_message("Updated all lists"); | 123 | update_p.finish_with_message("Updated all lists"); |
128 | 124 | ||
129 | |||
130 | Ok(()) | 125 | Ok(()) |
131 | } | 126 | } |
132 | 127 | ||
@@ -525,7 +525,7 @@ pub fn lists_remove(config: &Cfg, id: String) -> MLE<()> { | |||
525 | Ok(()) | 525 | Ok(()) |
526 | } | 526 | } |
527 | 527 | ||
528 | pub fn lists_get(config: &Cfg, list_id: String) -> MLE<List> { | 528 | pub fn lists_get(config: &Cfg, list_id: &str) -> MLE<List> { |
529 | let data = format!("{}/data.db", config.data); | 529 | let data = format!("{}/data.db", config.data); |
530 | let connection = Connection::open(data).unwrap(); | 530 | let connection = Connection::open(data).unwrap(); |
531 | 531 | ||
@@ -549,7 +549,7 @@ pub fn lists_get(config: &Cfg, list_id: String) -> MLE<List> { | |||
549 | for l in list_iter { | 549 | for l in list_iter { |
550 | let li = l?; | 550 | let li = l?; |
551 | list = List { | 551 | list = List { |
552 | id: String::from(&list_id), | 552 | id: list_id.to_string(), |
553 | mc_version: String::from(&li[0]), | 553 | mc_version: String::from(&li[0]), |
554 | modloader: Modloader::from(&li[1])?, | 554 | modloader: Modloader::from(&li[1])?, |
555 | download_folder: String::from(&li[2]), | 555 | download_folder: String::from(&li[2]), |
diff --git a/src/files.rs b/src/files.rs index 2830a5f..814f06d 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -14,37 +14,29 @@ use crate::{ | |||
14 | db::{mods_get_info, userlist_add_disabled_versions}, | 14 | db::{mods_get_info, userlist_add_disabled_versions}, |
15 | error::{ErrorType, MLError, MLE}, | 15 | error::{ErrorType, MLError, MLE}, |
16 | modrinth::Version, | 16 | modrinth::Version, |
17 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER, STYLE_BAR_BYTE, | 17 | List, PROGRESS_CHARS, STYLE_SPINNER, STYLE_BAR_BYTE, STYLE_BAR_POS, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>, progress: &MultiProgress, progress_before: Option<&ProgressBar>) -> MLE<()> { | 20 | pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>, progress: &MultiProgress, progress_before: &ProgressBar) -> MLE<()> { |
21 | let cached = get_cached_versions(&config.cache); | 21 | let cached = get_cached_versions(&config.cache); |
22 | 22 | ||
23 | let mut js = JoinSet::new(); | 23 | let mut js = JoinSet::new(); |
24 | 24 | ||
25 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); | 25 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); |
26 | 26 | ||
27 | let all = match progress_before { | 27 | let all = progress.insert_before(progress_before, ProgressBar::new(versions.len().try_into().unwrap())); |
28 | Some(p) => progress.insert_before(p, ProgressBar::new(versions.len().try_into().unwrap())), | ||
29 | None => progress.add(ProgressBar::new(versions.len().try_into().unwrap())), | ||
30 | |||
31 | |||
32 | }; | ||
33 | all.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); | 28 | all.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); |
34 | all.set_message("Downloading"); | 29 | all.set_message(format!("✓Downloading {}", list.id)); |
35 | 30 | ||
36 | for ver in versions { | 31 | for ver in versions { |
37 | let p = progress.insert_before(&all, ProgressBar::new(1)); | 32 | let p = progress.insert_before(&all, ProgressBar::new(1)); |
38 | p.set_style(style_spinner.clone()); | 33 | p.set_style(style_spinner.clone()); |
39 | js.spawn(download_version(config.clone(), list.clone(), ver, cached.clone(), p)); | 34 | js.spawn(download_version(config.clone(), list.clone(), ver, cached.clone(), p)); |
40 | // std::thread::sleep(std::time::Duration::from_millis(200)); | ||
41 | } | 35 | } |
42 | 36 | ||
43 | while js.join_next().await.is_some() { all.inc(1) } | 37 | while js.join_next().await.is_some() { all.inc(1) } |
44 | 38 | ||
45 | all.finish(); | 39 | all.finish_with_message(format!("✓Downloading {}", list.id)); |
46 | |||
47 | // mp.clear().unwrap(); | ||
48 | 40 | ||
49 | Ok(()) | 41 | Ok(()) |
50 | } | 42 | } |
@@ -56,10 +48,12 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: | |||
56 | 48 | ||
57 | progress.set_message(format!("{} - {}", project_info.title, version.id)); | 49 | progress.set_message(format!("{} - {}", project_info.title, version.id)); |
58 | 50 | ||
51 | let mut cache_msg = ""; | ||
59 | //Check cache if already downloaded | 52 | //Check cache if already downloaded |
60 | let c = cached.remove(&version.id); | 53 | let c = cached.remove(&version.id); |
61 | if c.is_some() { | 54 | if c.is_some() { |
62 | progress.set_message(format!("Get {} from cache", version.id)); | 55 | progress.set_message(format!("Get {} from cache", version.id)); |
56 | cache_msg = " (cached)"; | ||
63 | copy_cached_version(&c.unwrap(), &dl_path); | 57 | copy_cached_version(&c.unwrap(), &dl_path); |
64 | } else { | 58 | } else { |
65 | let files = version.files; | 59 | let files = version.files; |
@@ -95,7 +89,7 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: | |||
95 | copy(dl_path_file, cache_path)?; | 89 | copy(dl_path_file, cache_path)?; |
96 | } | 90 | } |
97 | 91 | ||
98 | progress.finish_with_message(format!("✓{} - {}", project_info.title, version.id)); | 92 | progress.finish_with_message(format!("✓{} - {}{}", project_info.title, version.id, cache_msg)); |
99 | 93 | ||
100 | Ok(()) | 94 | Ok(()) |
101 | } | 95 | } |
@@ -15,9 +15,10 @@ use error::{ErrorType, MLError, MLE}; | |||
15 | use indicatif::{ProgressStyle, ProgressBar}; | 15 | use indicatif::{ProgressStyle, ProgressBar}; |
16 | use serde::{Deserialize, Serialize}; | 16 | use serde::{Deserialize, Serialize}; |
17 | 17 | ||
18 | pub static STYLE_BAR_POS: &str = "{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]"; | ||
19 | pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; | 18 | pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; |
19 | pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; | ||
20 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; | 20 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; |
21 | pub static STYLE_OPERATION: &str = " {wide_msg}"; | ||
21 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; | 22 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; |
22 | pub static PROGRESS_CHARS: &str = "#>-"; | 23 | pub static PROGRESS_CHARS: &str = "#>-"; |
23 | 24 | ||
@@ -70,7 +71,7 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { | |||
70 | 71 | ||
71 | let creation_time = fs::metadata(path)?.created()?; | 72 | let creation_time = fs::metadata(path)?.created()?; |
72 | if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } | 73 | if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } |
73 | std::io::stdout().flush()?; | 74 | |
74 | let versions = get_game_versions().await; | 75 | let versions = get_game_versions().await; |
75 | remove_file(path)?; | 76 | remove_file(path)?; |
76 | let mut file = File::create(path)?; | 77 | let mut file = File::create(path)?; |
diff --git a/src/main.rs b/src/main.rs index 7e00368..d03f88a 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -170,10 +170,10 @@ async fn main() { | |||
170 | lock, | 170 | lock, |
171 | } => { | 171 | } => { |
172 | let listf = match list { | 172 | let listf = match list { |
173 | Some(list) => lists_get(&config, list).unwrap(), | 173 | Some(list) => lists_get(&config, &list).unwrap(), |
174 | None => lists_get( | 174 | None => lists_get( |
175 | &config, | 175 | &config, |
176 | config_get_current_list(&config).unwrap(), | 176 | &config_get_current_list(&config).unwrap(), |
177 | ) | 177 | ) |
178 | .unwrap(), | 178 | .unwrap(), |
179 | }; | 179 | }; |
@@ -189,10 +189,10 @@ async fn main() { | |||
189 | } | 189 | } |
190 | ModCommands::Remove { id, list } => { | 190 | ModCommands::Remove { id, list } => { |
191 | let listf = match list { | 191 | let listf = match list { |
192 | Some(list) => lists_get(&config, list).unwrap(), | 192 | Some(list) => lists_get(&config, &list).unwrap(), |
193 | None => lists_get( | 193 | None => lists_get( |
194 | &config, | 194 | &config, |
195 | config_get_current_list(&config).unwrap(), | 195 | &config_get_current_list(&config).unwrap(), |
196 | ) | 196 | ) |
197 | .unwrap(), | 197 | .unwrap(), |
198 | }; | 198 | }; |
@@ -231,7 +231,7 @@ async fn main() { | |||
231 | version, | 231 | version, |
232 | download, | 232 | download, |
233 | remove, | 233 | remove, |
234 | } => list_version(&config, id, version, download, remove).await, | 234 | } => list_version(&config, &id, version, download, remove).await, |
235 | } | 235 | } |
236 | } | 236 | } |
237 | Commands::Update { | 237 | Commands::Update { |
@@ -245,11 +245,11 @@ async fn main() { | |||
245 | if all { | 245 | if all { |
246 | let list_ids = lists_get_all_ids(&config).unwrap(); | 246 | let list_ids = lists_get_all_ids(&config).unwrap(); |
247 | for id in list_ids { | 247 | for id in list_ids { |
248 | liststack.push(lists_get(&config, id).unwrap()); | 248 | liststack.push(lists_get(&config, &id).unwrap()); |
249 | } | 249 | } |
250 | } else { | 250 | } else { |
251 | let current = match list { | 251 | let current = match list { |
252 | Some(l) => lists_get(&config, l).unwrap(), | 252 | Some(l) => lists_get(&config, &l).unwrap(), |
253 | None => get_current_list(&config).unwrap(), | 253 | None => get_current_list(&config).unwrap(), |
254 | }; | 254 | }; |
255 | liststack.push(current) | 255 | liststack.push(current) |
@@ -262,11 +262,11 @@ async fn main() { | |||
262 | if all { | 262 | if all { |
263 | let list_ids = lists_get_all_ids(&config).unwrap(); | 263 | let list_ids = lists_get_all_ids(&config).unwrap(); |
264 | for id in list_ids { | 264 | for id in list_ids { |
265 | liststack.push(lists_get(&config, id).unwrap()); | 265 | liststack.push(lists_get(&config, &id).unwrap()); |
266 | } | 266 | } |
267 | } else { | 267 | } else { |
268 | let current = match list { | 268 | let current = match list { |
269 | Some(l) => lists_get(&config, l).unwrap(), | 269 | Some(l) => lists_get(&config, &l).unwrap(), |
270 | None => get_current_list(&config).unwrap(), | 270 | None => get_current_list(&config).unwrap(), |
271 | }; | 271 | }; |
272 | liststack.push(current) | 272 | liststack.push(current) |
@@ -285,7 +285,7 @@ async fn main() { | |||
285 | .unwrap(), | 285 | .unwrap(), |
286 | }; | 286 | }; |
287 | 287 | ||
288 | import(&config, filestr, download).await | 288 | import(&config, &filestr, download).await |
289 | } | 289 | } |
290 | Commands::Export { list } => export(&config, list), | 290 | Commands::Export { list } => export(&config, list), |
291 | Commands::Test => Ok(()), | 291 | Commands::Test => Ok(()), |