mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 00:02:41 +10:00
Update on GameDownload
This commit is contained in:
37
src-tauri/Cargo.lock
generated
37
src-tauri/Cargo.lock
generated
@ -1040,6 +1040,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"url",
|
||||
"uuid",
|
||||
"versions",
|
||||
"webbrowser",
|
||||
]
|
||||
|
||||
@ -2031,6 +2032,15 @@ version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.8"
|
||||
@ -2282,6 +2292,12 @@ version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.0"
|
||||
@ -2395,6 +2411,16 @@ version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
@ -4890,6 +4916,17 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "versions"
|
||||
version = "6.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f25d498b63d1fdb376b4250f39ab3a5ee8d103957346abacd911e2d8b612c139"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"nom",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vswhom"
|
||||
version = "0.1.0"
|
||||
|
||||
@ -23,7 +23,7 @@ tauri-build = { version = "2.0.0", features = [] }
|
||||
[dependencies]
|
||||
tauri = { version = "2.0.0", features = [] }
|
||||
tauri-plugin-shell = "2.0.0"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde = { version = "1", features = ["derive", "rc"] }
|
||||
serde_json = "1"
|
||||
ciborium = "0.2.2"
|
||||
rayon = "1.10.0"
|
||||
@ -38,6 +38,7 @@ tauri-plugin-dialog = "2"
|
||||
env_logger = "0.11.5"
|
||||
http = "1.1.0"
|
||||
tokio = { version = "1.40.0", features = ["rt", "tokio-macros"] }
|
||||
versions = { version = "6.3.2", features = ["serde"] }
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "1.10.0"
|
||||
|
||||
30
src-tauri/src/downloads/game_download.rs
Normal file
30
src-tauri/src/downloads/game_download.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use versions::Version;
|
||||
use crate::downloads::progress::ProgressChecker;
|
||||
|
||||
pub struct GameDownload {
|
||||
id: String,
|
||||
version: Version,
|
||||
progress: Arc<AtomicUsize>
|
||||
}
|
||||
pub struct GameChunkCtx {
|
||||
|
||||
}
|
||||
|
||||
impl GameDownload {
|
||||
pub fn new(id: String, version: Version) -> Self {
|
||||
Self {
|
||||
id,
|
||||
version,
|
||||
progress: Arc::new(AtomicUsize::new(0))
|
||||
}
|
||||
}
|
||||
pub async fn download(&self, max_threads: usize, contexts: Vec<GameChunkCtx>) {
|
||||
let progress = ProgressChecker::new(Box::new(download_game_chunk), self.progress.clone());
|
||||
progress.run_contexts_sequentially_async(contexts).await;
|
||||
}
|
||||
}
|
||||
fn download_game_chunk(ctx: GameChunkCtx) {
|
||||
todo!()
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
mod downloads;
|
||||
mod manifest;
|
||||
pub mod progress;
|
||||
pub mod progress;
|
||||
mod game_download;
|
||||
@ -5,17 +5,17 @@ use rayon::ThreadPoolBuilder;
|
||||
pub struct ProgressChecker<T>
|
||||
where T: 'static + Send + Sync
|
||||
{
|
||||
counter: AtomicUsize,
|
||||
counter: Arc<AtomicUsize>,
|
||||
f: Arc<Box<dyn Fn(T) + Send + Sync + 'static>>,
|
||||
}
|
||||
|
||||
impl<T> ProgressChecker<T>
|
||||
where T: Send + Sync
|
||||
{
|
||||
pub fn new(f: Box<dyn Fn(T) + Send + Sync + 'static>) -> Self {
|
||||
pub fn new(f: Box<dyn Fn(T) + Send + Sync + 'static>, counter_reference: Arc<AtomicUsize>) -> Self {
|
||||
Self {
|
||||
f: f.into(),
|
||||
counter: AtomicUsize::new(0)
|
||||
counter: counter_reference
|
||||
}
|
||||
}
|
||||
pub async fn run_contexts_sequentially_async(&self, contexts: Vec<T>) {
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use crate::downloads::progress::ProgressChecker;
|
||||
|
||||
#[test]
|
||||
fn test_progress_sequentially() {
|
||||
let p = ProgressChecker::new(Box::new(test_fn));
|
||||
let counter = Arc::new(AtomicUsize::new(0));
|
||||
let p = ProgressChecker::new(Box::new(test_fn), counter.clone());
|
||||
p.run_contexts_sequentially((1..100).collect());
|
||||
println!("Progress: {}", p.get_progress_percentage(100));
|
||||
}
|
||||
#[test]
|
||||
fn test_progress_parallel() {
|
||||
let p = ProgressChecker::new(Box::new(test_fn));
|
||||
let counter = Arc::new(AtomicUsize::new(0));
|
||||
let p = ProgressChecker::new(Box::new(test_fn), counter.clone());
|
||||
p.run_contexts_parallel((1..100).collect(), 10);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user