mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 00:31:33 +10:00
Functioning download progress updates
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -4,6 +4,7 @@ use crate::downloads::download_logic;
|
||||
use crate::downloads::manifest::{DropDownloadContext, DropManifest};
|
||||
use crate::downloads::progress::ProgressChecker;
|
||||
use crate::DB;
|
||||
use atomic_counter::RelaxedCounter;
|
||||
use log::info;
|
||||
use rustix::fs::{fallocate, FallocateFlags};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -18,7 +19,7 @@ pub struct GameDownloadAgent {
|
||||
pub version: String,
|
||||
state: Mutex<GameDownloadState>,
|
||||
contexts: Mutex<Vec<DropDownloadContext>>,
|
||||
progress: ProgressChecker<DropDownloadContext>,
|
||||
pub progress: ProgressChecker<DropDownloadContext>,
|
||||
pub manifest: Mutex<Option<DropManifest>>,
|
||||
pub callback: Arc<AtomicBool>,
|
||||
}
|
||||
@ -57,8 +58,9 @@ impl GameDownloadAgent {
|
||||
callback: callback.clone(),
|
||||
progress: ProgressChecker::new(
|
||||
Box::new(download_logic::download_game_chunk),
|
||||
Arc::new(AtomicUsize::new(0)),
|
||||
Arc::new(RelaxedCounter::new(0)),
|
||||
callback,
|
||||
0
|
||||
),
|
||||
contexts: Mutex::new(Vec::new()),
|
||||
}
|
||||
@ -119,11 +121,16 @@ impl GameDownloadAgent {
|
||||
}
|
||||
|
||||
let manifest_download = response.json::<DropManifest>().unwrap();
|
||||
let length = manifest_download.iter().map(|(_, chunk)| {
|
||||
return chunk.lengths.iter().sum::<usize>();
|
||||
}).sum::<usize>();
|
||||
self.progress.set_capacity(length);
|
||||
if let Ok(mut manifest) = self.manifest.lock() {
|
||||
*manifest = Some(manifest_download)
|
||||
} else {
|
||||
return Err(GameDownloadError::System(SystemError::MutexLockFailed));
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user