Can now download all game file correctly

but sometime crash in the middle of the download, but that's because of the progress trait and nothing else, so that's okay
This commit is contained in:
ALEZ-DEV 2024-04-27 00:00:44 +02:00
parent 5146562bd5
commit c4958fdd4f
4 changed files with 29 additions and 5 deletions

View File

@ -252,7 +252,7 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "downloader" name = "downloader"
version = "0.2.7" version = "0.2.7"
source = "git+https://github.com/ALEZ-DEV/downloader#fddaffbfc3c5c22b44033fbd5a5915fdf590a0cb" source = "git+https://github.com/ALEZ-DEV/downloader#5572a0875ec4f04b0514342f9acff21252beb579"
dependencies = [ dependencies = [
"futures", "futures",
"rand", "rand",

View File

@ -17,6 +17,7 @@ async fn main() {
.with_module_level("tracing", LevelFilter::Off) .with_module_level("tracing", LevelFilter::Off)
.with_module_level("rustls", LevelFilter::Off) .with_module_level("rustls", LevelFilter::Off)
.with_module_level("minreq", LevelFilter::Off) .with_module_level("minreq", LevelFilter::Off)
.with_module_level("tokio_utils", LevelFilter::Off)
.init() .init()
.unwrap(); .unwrap();

View File

@ -207,7 +207,7 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "downloader" name = "downloader"
version = "0.2.7" version = "0.2.7"
source = "git+https://github.com/ALEZ-DEV/downloader#fddaffbfc3c5c22b44033fbd5a5915fdf590a0cb" source = "git+https://github.com/ALEZ-DEV/downloader#5572a0875ec4f04b0514342f9acff21252beb579"
dependencies = [ dependencies = [
"futures", "futures",
"rand", "rand",

View File

@ -5,6 +5,7 @@ use log::debug;
use log::info; use log::info;
use serde::Deserialize; use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
use std::collections::TryReserveError;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;
use std::sync::Mutex; use std::sync::Mutex;
@ -49,7 +50,20 @@ impl ComponentDownloader for GameComponent {
.parallel_requests(5) .parallel_requests(5)
.build()?; .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) { for chunk_resource in resources.resource.chunks(5) {
let mut output_path: Vec<PathBuf> = vec![];
for path in chunk_resource for path in chunk_resource
.iter() .iter()
.map(|r| { .map(|r| {
@ -61,18 +75,27 @@ impl ComponentDownloader for GameComponent {
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
{ {
create_dir_all(path).await?; let _ = create_dir_all(&path).await; // unecessary to check
output_path.push(path)
} }
let to_download = chunk_resource let to_download = chunk_resource
.iter() .iter()
.map(|r| { .enumerate()
.map(|(i, r)| {
let url = r.build_download_url( let url = r.build_download_url(
&game_info.get_first_cdn(), &game_info.get_first_cdn(),
&game_info.get_resource_base_path(), &game_info.get_resource_base_path(),
); );
debug!("starting download for {}", url); 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() { if let Some(p) = progress.clone() {
dl = dl.progress(FileDownloadReporter::create(p)); dl = dl.progress(FileDownloadReporter::create(p));