diff --git a/babylonia-terminal-cli/Cargo.lock b/babylonia-terminal-cli/Cargo.lock index 4aa50ef..8ff4c95 100644 --- a/babylonia-terminal-cli/Cargo.lock +++ b/babylonia-terminal-cli/Cargo.lock @@ -252,7 +252,7 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "downloader" version = "0.2.7" -source = "git+https://github.com/ALEZ-DEV/downloader#fddaffbfc3c5c22b44033fbd5a5915fdf590a0cb" +source = "git+https://github.com/ALEZ-DEV/downloader#5572a0875ec4f04b0514342f9acff21252beb579" dependencies = [ "futures", "rand", diff --git a/babylonia-terminal-cli/src/main.rs b/babylonia-terminal-cli/src/main.rs index ce970e1..f5005f9 100644 --- a/babylonia-terminal-cli/src/main.rs +++ b/babylonia-terminal-cli/src/main.rs @@ -17,6 +17,7 @@ async fn main() { .with_module_level("tracing", LevelFilter::Off) .with_module_level("rustls", LevelFilter::Off) .with_module_level("minreq", LevelFilter::Off) + .with_module_level("tokio_utils", LevelFilter::Off) .init() .unwrap(); diff --git a/babylonia-terminal-sdk/Cargo.lock b/babylonia-terminal-sdk/Cargo.lock index b72e37b..819259c 100644 --- a/babylonia-terminal-sdk/Cargo.lock +++ b/babylonia-terminal-sdk/Cargo.lock @@ -207,7 +207,7 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "downloader" version = "0.2.7" -source = "git+https://github.com/ALEZ-DEV/downloader#fddaffbfc3c5c22b44033fbd5a5915fdf590a0cb" +source = "git+https://github.com/ALEZ-DEV/downloader#5572a0875ec4f04b0514342f9acff21252beb579" dependencies = [ "futures", "rand", diff --git a/babylonia-terminal-sdk/src/components/game_component.rs b/babylonia-terminal-sdk/src/components/game_component.rs index 5cf3d50..8b9f74e 100644 --- a/babylonia-terminal-sdk/src/components/game_component.rs +++ b/babylonia-terminal-sdk/src/components/game_component.rs @@ -5,6 +5,7 @@ use log::debug; use log::info; use serde::Deserialize; use serde::Serialize; +use std::collections::TryReserveError; use std::path::PathBuf; use std::sync::Arc; use std::sync::Mutex; @@ -49,7 +50,20 @@ impl ComponentDownloader for GameComponent { .parallel_requests(5) .build()?; + if let Some(ref p) = progress { + let mut size: u64 = 0; + + resources + .resource + .iter() + .for_each(|r| size += r.size as u64); + + p.setup(Some(size), "download has started"); + } + for chunk_resource in resources.resource.chunks(5) { + let mut output_path: Vec = vec![]; + for path in chunk_resource .iter() .map(|r| { @@ -61,18 +75,27 @@ impl ComponentDownloader for GameComponent { }) .collect::>() { - create_dir_all(path).await?; + let _ = create_dir_all(&path).await; // unecessary to check + output_path.push(path) } let to_download = chunk_resource .iter() - .map(|r| { + .enumerate() + .map(|(i, r)| { let url = r.build_download_url( &game_info.get_first_cdn(), &game_info.get_resource_base_path(), ); debug!("starting download for {}", url); - let mut dl = downloader::Download::new(&url); + let mut dl = downloader::Download::new_with_output( + &url, + output_path + .get(i) + .expect("Failed to get the write path of the concerned file") + .to_owned(), + ); + dl.check_file_name = false; if let Some(p) = progress.clone() { dl = dl.progress(FileDownloadReporter::create(p));