diff options
author | fxqnlr <[email protected]> | 2023-05-25 22:48:54 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-25 22:48:54 +0200 |
commit | d8554e30029bf43dccce72e982784cd01857b0c4 (patch) | |
tree | 72b4ee26a4f980deb1165e615e47598be017e5fa /src/files.rs | |
parent | 7f1a262999d7a8b7f12a97daf4b6722638dc62a1 (diff) | |
download | modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar modlist-d8554e30029bf43dccce72e982784cd01857b0c4.tar.gz modlist-d8554e30029bf43dccce72e982784cd01857b0c4.zip |
added mod add progress
Diffstat (limited to 'src/files.rs')
-rw-r--r-- | src/files.rs | 22 |
1 files changed, 8 insertions, 14 deletions
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 | } |