pub type ModProgressCallback<'a> = &'a (dyn Fn(&ModProgress) + Sync + Send);
#[derive(Debug, Clone)]
pub struct ModProgress {
pub phase: ModPhase,
pub current: usize,
pub total: usize,
pub current_file: Option<String>,
}
impl ModProgress {
#[must_use]
pub fn new(phase: ModPhase, current: usize, total: usize) -> Self {
Self {
phase,
current,
total,
current_file: None,
}
}
#[must_use]
pub fn with_file(
phase: ModPhase,
current: usize,
total: usize,
file: impl Into<String>,
) -> Self {
Self {
phase,
current,
total,
current_file: Some(file.into()),
}
}
#[must_use]
pub fn percentage(&self) -> f32 {
if self.total == 0 {
1.0
} else {
self.current as f32 / self.total as f32
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ModPhase {
Validating,
CalculatingHash,
GeneratingJson,
Complete,
}
impl ModPhase {
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::Validating => "Validating structure",
Self::CalculatingHash => "Calculating MD5 hash",
Self::GeneratingJson => "Generating info.json",
Self::Complete => "Complete",
}
}
}