Skip to main content

minecraft_java_rs_core/models/
java.rs

1use serde::{Deserialize, Serialize};
2
3// ── Java file item ────────────────────────────────────────────────────────────
4// Represents one file in the Java runtime as listed in Mojang's manifest.
5
6#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct JavaFileItem {
8    pub path: String,
9    pub executable: Option<bool>,
10    pub sha1: Option<String>,
11    pub size: Option<u64>,
12    pub url: Option<String>,
13    #[serde(rename = "type")]
14    pub file_type: Option<String>,
15}
16
17// ── Mojang all.json ───────────────────────────────────────────────────────────
18// Fetched from the hardcoded hash URL in Minecraft-Java.ts.
19// Structure: HashMap<arch_os, HashMap<component, Vec<JavaVersionManifest>>>
20
21#[derive(Debug, Deserialize)]
22pub struct JavaVersionManifest {
23    pub version: Option<JavaVersionName>,
24    pub manifest: Option<JavaManifestRef>,
25}
26
27#[derive(Debug, Deserialize)]
28pub struct JavaVersionName {
29    pub name: String,
30}
31
32#[derive(Debug, Deserialize)]
33pub struct JavaManifestRef {
34    pub url: String,
35}
36
37// ── Mojang per-version manifest ───────────────────────────────────────────────
38// Fetched from the URL inside JavaManifestRef.
39// Structure: { "files": HashMap<relative_path, JavaManifestFile> }
40
41#[derive(Debug, Deserialize)]
42pub struct JavaManifestData {
43    pub files: std::collections::HashMap<String, JavaManifestFile>,
44}
45
46#[derive(Debug, Deserialize)]
47pub struct JavaManifestFile {
48    #[serde(rename = "type")]
49    pub file_type: String, // "file", "directory", "link"
50    pub downloads: Option<JavaFileDownloads>,
51    pub executable: Option<bool>,
52}
53
54#[derive(Debug, Deserialize)]
55pub struct JavaFileDownloads {
56    pub raw: Option<JavaRawDownload>,
57    pub lzma: Option<JavaRawDownload>,
58}
59
60#[derive(Debug, Deserialize)]
61pub struct JavaRawDownload {
62    pub url: String,
63    pub sha1: String,
64    pub size: u64,
65}
66
67// ── Adoptium API ──────────────────────────────────────────────────────────────
68// Fallback when Mojang doesn't have the runtime for the current platform.
69
70#[derive(Debug, Deserialize)]
71pub struct AdoptiumRelease {
72    pub binary: AdoptiumBinary,
73}
74
75#[derive(Debug, Deserialize)]
76pub struct AdoptiumBinary {
77    pub package: AdoptiumPackage,
78}
79
80#[derive(Debug, Deserialize)]
81pub struct AdoptiumPackage {
82    pub link: String,
83    pub name: String,
84    pub checksum: Option<String>,
85    pub checksum_link: Option<String>,
86}