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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::minecraft::models::arguments::Arguments;
use crate::minecraft::models::asset_index::AssetIndex;
use crate::minecraft::models::downloads::Downloads;
use crate::minecraft::models::library::Library;
use crate::minecraft::models::logging_info::LoggingInfo;
use crate::minecraft::models::version_type::VersionType;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

/// The version data includes all information for installing and launching Minecraft.
/// The version data exists for every Minecraft version (alphas, betas, snapshots, rc, ...).
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct VersionData {
    /// Arguments for launching.
    pub arguments: Option<Arguments>,
    #[serde(alias = "assetIndex")]
    /// Asset index information.
    pub asset_index: Option<AssetIndex>,
    /// Used asset index.
    pub assets: String,
    /// Compliance level.
    #[serde(alias = "complianceLevel")]
    pub compliance_level: i32,
    /// Downloads of client/server.
    pub downloads: Option<Downloads>,
    /// Version ID.
    pub id: String,
    // TODO: properly deserialize
    /// Recommended java version
    #[serde(alias = "javaVersion")]
    pub java_version: serde_json::Value,
    /// Libraries.
    pub libraries: Vec<Library>,
    /// Logging information.
    pub logging: Option<LoggingInfo>,
    /// Main class / entry point.
    #[serde(alias = "mainClass")]
    pub main_class: String,
    /// Minecraft arguments.
    /// Used in older versions.
    #[serde(alias = "minecraftArguments")]
    pub minecraft_arguments: Option<String>,
    /// Minimum launcher version.
    /// Applies to the original launcher.
    #[serde(alias = "minimumLauncherVersion")]
    pub minimum_launcher_version: i32,
    /// Release time.
    #[serde(alias = "releaseTime", with = "time::serde::rfc3339")]
    pub release_time: OffsetDateTime,
    /// Release time.
    #[serde(with = "time::serde::rfc3339")]
    pub time: OffsetDateTime,
    /// Type of the version.
    #[serde(rename = "type")]
    pub _type: VersionType,
}

impl VersionData {
    /// Returns all needed libraries by applying the rule of a library.
    pub fn needed_libraries(&self) -> Vec<&Library> {
        self.libraries
            .iter()
            .filter(|library| library.check_use())
            .collect()
    }
}