mc_launcher/client/
mod.rs

1mod argument;
2mod assetindex;
3pub(crate) mod classpath;
4mod downloads;
5mod javaversion;
6mod library;
7mod rules;
8
9pub(crate) trait CollectArguments {
10  fn collect(&self) -> Vec<String>;
11}
12
13use std::fs::File;
14use std::io;
15use std::io::{Error, ErrorKind, Read};
16use std::path::PathBuf;
17use serde::{Deserialize, Serialize};
18use crate::client::argument::Arguments;
19use crate::client::assetindex::AssetIndex;
20use crate::client::downloads::Downloads;
21use crate::client::javaversion::ClientJavaVersion;
22use crate::client::library::Library;
23
24/// Implementation of ``client.json`` files structure
25///
26/// Reference: https://minecraft.fandom.com/wiki/Client.json
27#[derive(Serialize, Deserialize, Debug, Clone)]
28pub struct ClientFile {
29  pub arguments: Arguments,
30  #[serde(rename = "assetIndex")]
31  pub asset_index: AssetIndex,
32  pub assets: String,
33  #[serde(rename = "complianceLevel")]
34  /// Its value is 1 for all recent versions of the game (1.16.4 and above) or 0 for all others.\
35  /// This tag tells the launcher whether it should urge the user to be careful since this version is older and might not support the latest player safety features.
36  pub compliance_level: Option<u8>,
37  pub downloads: Downloads,
38  /// The name of this version client (e.g. 1.14.4).
39  pub id: String,
40  #[serde(rename = "javaVersion")]
41  pub java_version: ClientJavaVersion,
42  pub libraries: Vec<Library>,
43  // logging: ,
44  #[serde(rename = "mainClass")]
45  pub main_class: String,
46  #[serde(rename = "minimumLauncherVersion")]
47  pub minimum_launcher_version: usize,
48  #[serde(rename = "releaseTime")]
49  pub release_time: String,
50  pub time: String,
51  pub r#type: String
52}
53
54impl ClientFile {
55  pub fn new(version_file: PathBuf) -> io::Result<Self> {
56    if !version_file.is_file() {
57      return Err(Error::new(ErrorKind::NotFound, "Version file is not a file"));
58    }
59
60    let mut content = String::new();
61    let mut file = File::open(version_file)?;
62    file.read_to_string(&mut content)?;
63
64    Ok(serde_json::from_str(&content)?)
65  }
66}