1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/// Enum that is sent when installing minecraft.
/// Tells what kind of resource is getting installed, if installation is finished or canceled.
#[derive(Clone, Debug)]
pub enum InstallationUpdate {
    /// Currently installing library
    Library(Progress),
    /// Currently installing asset
    Asset(Progress),
    /// Currently installing log config
    LogConfig(Progress),
    /// Currently installing the client
    Client(Progress),
    /// Installation canceled
    Cancel,
    /// Installation succeeded
    Success,
}

impl InstallationUpdate {
    /// Returns the name of the resource that is being installed,
    pub fn resource_type(&self) -> String {
        match self {
            InstallationUpdate::Library(_) => "Library".to_string(),
            InstallationUpdate::Asset(_) => "Asset".to_string(),
            InstallationUpdate::LogConfig(_) => "LogConfig".to_string(),
            InstallationUpdate::Client(_) => "Client".to_string(),
            _ => "Other".to_string(),
        }
    }
}

/// Installation progress of one kind of resource
#[derive(Clone, Debug, Default)]
pub struct Progress {
    /// Total amount of files of that resource kind
    pub total_files: usize,
    /// Current file number
    pub current_file: usize,
    /// URL of the current file
    pub current_file_url: String,
    /// Size of the current file in bytes
    pub current_file_size: Option<usize>,
}