summaryrefslogtreecommitdiff
path: root/src/files.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-04-27 10:08:20 +0200
committerFxQnLr <[email protected]>2023-04-27 10:08:20 +0200
commit4e6466af1329f7b9e341df2e76ab696d11f80c93 (patch)
treeeef58fecfadad90386b38af581abab8cc3d3cfc0 /src/files.rs
parentf1912007484f077b5585a872ca732d087beefa9a (diff)
downloadmodlist-4e6466af1329f7b9e341df2e76ab696d11f80c93.tar
modlist-4e6466af1329f7b9e341df2e76ab696d11f80c93.tar.gz
modlist-4e6466af1329f7b9e341df2e76ab696d11f80c93.zip
version bump, cargo fmt and cargo update
Diffstat (limited to 'src/files.rs')
-rw-r--r--src/files.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/files.rs b/src/files.rs
index a73fc18..59fc7de 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -2,20 +2,20 @@ use futures_util::StreamExt;
2use reqwest::Client; 2use reqwest::Client;
3use std::{ 3use std::{
4 collections::HashMap, 4 collections::HashMap,
5 fs::{read_dir, remove_file, rename, File, copy}, 5 fs::{copy, read_dir, remove_file, rename, File},
6 io::Write, 6 io::Write,
7}; 7};
8 8
9use crate::{ 9use crate::{
10 cache::{copy_cached_version, get_cached_versions},
10 config::Cfg, 11 config::Cfg,
11 db::{mods_get_info, userlist_add_disabled_versions}, 12 db::{mods_get_info, userlist_add_disabled_versions},
12 error::{ErrorType, MLError, MLE}, 13 error::{ErrorType, MLError, MLE},
13 modrinth::Version, 14 modrinth::Version,
14 List, cache::{get_cached_versions, copy_cached_version}, 15 List,
15}; 16};
16 17
17pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) -> MLE<String> { 18pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) -> MLE<String> {
18
19 let mut cached = get_cached_versions(&config.cache); 19 let mut cached = get_cached_versions(&config.cache);
20 20
21 println!("{:#?}", cached); 21 println!("{:#?}", cached);
@@ -30,7 +30,10 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>)
30 //Check cache if already downloaded 30 //Check cache if already downloaded
31 let c = cached.remove(&ver.id); 31 let c = cached.remove(&ver.id);
32 if c.is_some() { 32 if c.is_some() {
33 print!("\t└({})Get version {} from cache", project_info.title, ver.id); 33 print!(
34 "\t└({})Get version {} from cache",
35 project_info.title, ver.id
36 );
34 //Force flush of stdout, else print! doesn't print instantly 37 //Force flush of stdout, else print! doesn't print instantly
35 std::io::stdout().flush()?; 38 std::io::stdout().flush()?;
36 copy_cached_version(&c.unwrap(), &dl_path); 39 copy_cached_version(&c.unwrap(), &dl_path);
@@ -52,7 +55,12 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>)
52 ver.id, 55 ver.id,
53 extension 56 extension
54 ); 57 );
55 download_file(primary_file.url, list.clone().download_folder, filename.clone()).await?; 58 download_file(
59 primary_file.url,
60 list.clone().download_folder,
61 filename.clone(),
62 )
63 .await?;
56 println!(" ✓"); 64 println!(" ✓");
57 //Copy file to cache 65 //Copy file to cache
58 print!("\t └Copy to cache"); 66 print!("\t └Copy to cache");
@@ -64,7 +72,6 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>)
64 copy(dl_path_file, cache_path)?; 72 copy(dl_path_file, cache_path)?;
65 println!(" ✓"); 73 println!(" ✓");
66 } 74 }
67
68 } 75 }
69 76
70 Ok(dl_path) 77 Ok(dl_path)