Functioning download progress updates

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-11-04 17:11:37 +11:00
parent bd39f1fd72
commit 0528c78092
9 changed files with 89 additions and 27 deletions

View File

@ -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(())
}