use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Debug, Clone)]
pub enum DownloadStatus {
Downloading,
Done,
SkippedAlreadyExists,
Cancelled,
FinalizeFailed(String),
Error(String),
}
#[derive(Debug, Clone)]
pub struct DownloadJob {
pub id: usize,
pub rom_id: u64,
pub name: String,
pub platform: String,
pub progress: f64,
pub status: DownloadStatus,
}
static NEXT_JOB_ID: AtomicUsize = AtomicUsize::new(0);
impl DownloadJob {
pub fn new(rom_id: u64, name: String, platform: String) -> Self {
Self {
id: NEXT_JOB_ID.fetch_add(1, Ordering::Relaxed),
rom_id,
name,
platform,
progress: 0.0,
status: DownloadStatus::Downloading,
}
}
pub fn percent(&self) -> u16 {
(self.progress * 100.0).round().min(100.0) as u16
}
}