mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-16 17:38:51 +00:00
can now resume download by checking game file and md5 checksum
This commit is contained in:
parent
c4958fdd4f
commit
2c6e1c67b2
47
babylonia-terminal-cli/Cargo.lock
generated
47
babylonia-terminal-cli/Cargo.lock
generated
@ -75,6 +75,7 @@ name = "babylonia-terminal-sdk"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"chksum-md5",
|
||||||
"dirs",
|
"dirs",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"downloader",
|
"downloader",
|
||||||
@ -159,6 +160,52 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-core"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6db20071fdeca52ed6a7745519fb2d343fddcb93af81448373b851f072aaec5"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-hash-core",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-hash-core"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "221456234d441c788a2c51a27b91c4380f499de560670a67d3303e621d37b3bd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-hash-md5"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "80c33d01c33c9e193fe33e719a29a7eb900c08583375dd1d3269991aacbe434a"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-hash-core",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-md5"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95dda0f76fbb6069e042c370a928457086e1b4eabc7e75f5f49fe1b913634351"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-core",
|
||||||
|
"chksum-hash-md5",
|
||||||
|
"chksum-reader",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-reader"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8bcdf6bcd410820599b7501d9bc3346964c4d472f48905685e08e07359d2fff9"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colored"
|
name = "colored"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
|
|||||||
47
babylonia-terminal-sdk/Cargo.lock
generated
47
babylonia-terminal-sdk/Cargo.lock
generated
@ -62,6 +62,7 @@ name = "babylonia-terminal-sdk"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"chksum-md5",
|
||||||
"dirs",
|
"dirs",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"downloader",
|
"downloader",
|
||||||
@ -146,6 +147,52 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-core"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6db20071fdeca52ed6a7745519fb2d343fddcb93af81448373b851f072aaec5"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-hash-core",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-hash-core"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "221456234d441c788a2c51a27b91c4380f499de560670a67d3303e621d37b3bd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-hash-md5"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "80c33d01c33c9e193fe33e719a29a7eb900c08583375dd1d3269991aacbe434a"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-hash-core",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-md5"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95dda0f76fbb6069e042c370a928457086e1b4eabc7e75f5f49fe1b913634351"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-core",
|
||||||
|
"chksum-hash-md5",
|
||||||
|
"chksum-reader",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chksum-reader"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8bcdf6bcd410820599b7501d9bc3346964c4d472f48905685e08e07359d2fff9"
|
||||||
|
dependencies = [
|
||||||
|
"chksum-core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "constant_time_eq"
|
name = "constant_time_eq"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|||||||
@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.81"
|
anyhow = "1.0.81"
|
||||||
|
chksum-md5 = { version = "0.0.0", features = ["reader"] }
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
downloader = { git = "https://github.com/ALEZ-DEV/downloader" } # version = "0.2.7",
|
downloader = { git = "https://github.com/ALEZ-DEV/downloader" } # version = "0.2.7",
|
||||||
|
|||||||
@ -6,16 +6,20 @@ use log::info;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::collections::TryReserveError;
|
use std::collections::TryReserveError;
|
||||||
|
use std::fs as std_fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
use tokio::fs::create_dir_all;
|
use tokio::fs::File;
|
||||||
|
use tokio::fs::{create_dir_all, remove_file};
|
||||||
|
|
||||||
use super::component_downloader::ComponentDownloader;
|
use super::component_downloader::ComponentDownloader;
|
||||||
use crate::utils::github_requester::GithubRequester;
|
use crate::utils::github_requester::GithubRequester;
|
||||||
use crate::utils::kuro_prod_api;
|
use crate::utils::kuro_prod_api;
|
||||||
|
use crate::utils::kuro_prod_api::Resource;
|
||||||
|
use crate::utils::kuro_prod_api::Resources;
|
||||||
|
|
||||||
pub struct GameComponent {
|
pub struct GameComponent {
|
||||||
game_dir: PathBuf,
|
game_dir: PathBuf,
|
||||||
@ -25,6 +29,43 @@ impl GameComponent {
|
|||||||
pub fn new(game_dir: PathBuf) -> Self {
|
pub fn new(game_dir: PathBuf) -> Self {
|
||||||
Self { game_dir }
|
Self { game_dir }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn check_and_get_resources_to_download(
|
||||||
|
game_dir: &std::path::PathBuf,
|
||||||
|
resources: &Resources,
|
||||||
|
) -> anyhow::Result<Vec<Resource>> {
|
||||||
|
info!("checking all files...");
|
||||||
|
let mut to_download: Vec<Resource> = vec![];
|
||||||
|
|
||||||
|
for r in &resources.resource {
|
||||||
|
let file_path = game_dir.join(r.dest.clone().strip_prefix("/").unwrap());
|
||||||
|
|
||||||
|
if file_path.try_exists()? {
|
||||||
|
let blocking_file_path = file_path.clone();
|
||||||
|
let file =
|
||||||
|
tokio::task::spawn_blocking(move || std_fs::File::open(blocking_file_path))
|
||||||
|
.await??; // only the std::File is supported by chksum_md5, that's why I block
|
||||||
|
let digest = chksum_md5::chksum(file)?;
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"{} = {} -> {}",
|
||||||
|
digest.to_hex_lowercase(),
|
||||||
|
r.md5,
|
||||||
|
digest.to_hex_lowercase() == r.md5
|
||||||
|
);
|
||||||
|
|
||||||
|
if digest.to_hex_lowercase() != r.md5 {
|
||||||
|
to_download.push(r.clone());
|
||||||
|
remove_file(file_path).await?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("{:?} don't exist", file_path);
|
||||||
|
to_download.push(r.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(to_download)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GithubRequester for GameComponent {}
|
impl GithubRequester for GameComponent {}
|
||||||
@ -50,18 +91,21 @@ impl ComponentDownloader for GameComponent {
|
|||||||
.parallel_requests(5)
|
.parallel_requests(5)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
if let Some(ref p) = progress {
|
//if let Some(ref p) = progress {
|
||||||
let mut size: u64 = 0;
|
// let mut size: u64 = 0;
|
||||||
|
|
||||||
resources
|
// resources
|
||||||
.resource
|
// .resource
|
||||||
.iter()
|
// .iter()
|
||||||
.for_each(|r| size += r.size as u64);
|
// .for_each(|r| size += r.size as u64);
|
||||||
|
|
||||||
p.setup(Some(size), "download has started");
|
// p.setup(Some(size), "download has started");
|
||||||
}
|
//}
|
||||||
|
|
||||||
for chunk_resource in resources.resource.chunks(5) {
|
let checked_resources =
|
||||||
|
GameComponent::check_and_get_resources_to_download(output_dir, &resources).await?;
|
||||||
|
|
||||||
|
for chunk_resource in checked_resources.chunks(5) {
|
||||||
let mut output_path: Vec<PathBuf> = vec![];
|
let mut output_path: Vec<PathBuf> = vec![];
|
||||||
|
|
||||||
for path in chunk_resource
|
for path in chunk_resource
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user