Daedalus Rewrite + Code Cleanup (#16)

* [wip] rewrite daedalus, vanilla, fabric, and quilt

* finish forge + neo

* fix docker

* fix neoforge 1.21+

* update concurrency limit

* finish

* remove mac garb
This commit is contained in:
Geometrically
2024-06-25 15:47:27 -07:00
committed by GitHub
parent ac07ac5234
commit 8b16cd1b36
19 changed files with 2334 additions and 2529 deletions

View File

@@ -1,16 +1,11 @@
use crate::modded::{Processor, SidedDataEntry};
use crate::{download_file, Error};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[cfg(feature = "bincode")]
use bincode::{Decode, Encode};
/// The latest version of the format the model structs deserialize to
pub const CURRENT_FORMAT_VERSION: usize = 0;
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
/// The version type
@@ -37,7 +32,6 @@ impl VersionType {
}
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
/// A game version of Minecraft
@@ -50,26 +44,18 @@ pub struct Version {
/// A link to additional information about the version
pub url: String,
/// The latest time a file in this version was updated
#[cfg_attr(feature = "bincode", bincode(with_serde))]
pub time: DateTime<Utc>,
/// The time this version was released
#[cfg_attr(feature = "bincode", bincode(with_serde))]
pub release_time: DateTime<Utc>,
/// The SHA1 hash of the additional information about the version
pub sha1: String,
/// Whether the version supports the latest player safety features
pub compliance_level: u32,
#[serde(skip_serializing_if = "Option::is_none")]
/// (Modrinth Provided) The link to the assets index for this version
/// This is only available when using the Modrinth mirror
pub assets_index_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
/// (Modrinth Provided) The SHA1 hash of the assets index for this version
/// This is only available when using the Modrinth mirror
pub assets_index_sha1: Option<String>,
/// (Modrinth Provided) The SHA1 hash of the original unmodified Minecraft versions JSON
pub original_sha1: Option<String>,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// The latest snapshot and release of the game
pub struct LatestVersion {
@@ -79,7 +65,6 @@ pub struct LatestVersion {
pub snapshot: String,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Data of all game versions of Minecraft
pub struct VersionManifest {
@@ -93,16 +78,6 @@ pub struct VersionManifest {
pub const VERSION_MANIFEST_URL: &str =
"https://piston-meta.mojang.com/mc/game/version_manifest_v2.json";
/// Fetches a version manifest from the specified URL. If no URL is specified, the default is used.
pub async fn fetch_version_manifest(
url: Option<&str>,
) -> Result<VersionManifest, Error> {
Ok(serde_json::from_slice(
&download_file(url.unwrap_or(VERSION_MANIFEST_URL), None).await?,
)?)
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
/// Information about the assets of the game
@@ -119,7 +94,6 @@ pub struct AssetIndex {
pub url: String,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash)]
#[serde(rename_all = "snake_case")]
/// The type of download
@@ -136,7 +110,6 @@ pub enum DownloadType {
WindowsServer,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
/// Download information of a file
pub struct Download {
@@ -148,7 +121,6 @@ pub struct Download {
pub url: String,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Download information of a library
pub struct LibraryDownload {
@@ -163,7 +135,6 @@ pub struct LibraryDownload {
pub url: String,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A list of files that should be downloaded for libraries
pub struct LibraryDownloads {
@@ -176,7 +147,6 @@ pub struct LibraryDownloads {
pub classifiers: Option<HashMap<String, LibraryDownload>>,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
/// The action a rule can follow
@@ -187,7 +157,6 @@ pub enum RuleAction {
Disallow,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
#[serde(rename_all = "kebab-case")]
/// An enum representing the different types of operating systems
@@ -210,7 +179,6 @@ pub enum Os {
Unknown,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A rule which depends on what OS the user is on
pub struct OsRule {
@@ -225,7 +193,6 @@ pub struct OsRule {
pub arch: Option<String>,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A rule which depends on the toggled features of the launcher
pub struct FeatureRule {
@@ -248,7 +215,6 @@ pub struct FeatureRule {
pub is_quick_play_realms: Option<bool>,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A rule deciding whether a file is downloaded, an argument is used, etc.
pub struct Rule {
@@ -262,7 +228,6 @@ pub struct Rule {
pub features: Option<FeatureRule>,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Information delegating the extraction of the library
pub struct LibraryExtract {
@@ -271,7 +236,6 @@ pub struct LibraryExtract {
pub exclude: Option<Vec<String>>,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
/// Information about the java version the game needs
@@ -282,7 +246,6 @@ pub struct JavaVersion {
pub major_version: u32,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A library which the game relies on to run
pub struct Library {
@@ -309,6 +272,9 @@ pub struct Library {
#[serde(default = "default_include_in_classpath")]
/// Whether the library should be included in the classpath at the game's launch
pub include_in_classpath: bool,
#[serde(default = "default_downloadable")]
/// Whether the library should be downloaded
pub downloadable: bool,
}
#[derive(Deserialize, Debug, Clone)]
@@ -397,8 +363,10 @@ pub fn merge_partial_library(
fn default_include_in_classpath() -> bool {
true
}
fn default_downloadable() -> bool {
true
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
/// A container for an argument or multiple arguments
@@ -409,7 +377,6 @@ pub enum ArgumentValue {
Many(Vec<String>),
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
/// A command line argument passed to a program
@@ -425,7 +392,6 @@ pub enum Argument {
},
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone, Copy)]
#[serde(rename_all = "snake_case")]
/// The type of argument
@@ -436,7 +402,6 @@ pub enum ArgumentType {
Jvm,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
/// Information about a version
@@ -481,16 +446,6 @@ pub struct VersionInfo {
pub processors: Option<Vec<Processor>>,
}
/// Fetches detailed information about a version from the manifest
pub async fn fetch_version_info(
version: &Version,
) -> Result<VersionInfo, Error> {
Ok(serde_json::from_slice(
&download_file(&version.url, Some(&version.sha1)).await?,
)?)
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
/// An asset of the game
pub struct Asset {
@@ -500,23 +455,9 @@ pub struct Asset {
pub size: u32,
}
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
/// An index containing all assets the game needs
pub struct AssetsIndex {
/// A hashmap containing the filename (key) and asset (value)
pub objects: HashMap<String, Asset>,
}
/// Fetches the assets index from the version info
pub async fn fetch_assets_index(
version: &VersionInfo,
) -> Result<AssetsIndex, Error> {
Ok(serde_json::from_slice(
&download_file(
&version.asset_index.url,
Some(&version.asset_index.sha1),
)
.await?,
)?)
}