Skip to content

Commit

Permalink
Merge pull request #6 from modrinth/quilt-m1-support
Browse files Browse the repository at this point in the history
Support for ARM + Quilt
  • Loading branch information
Geometrically authored Apr 26, 2023
2 parents fd19bb7 + 3afda71 commit 6512dba
Show file tree
Hide file tree
Showing 10 changed files with 577 additions and 29 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2022 Rinth, Inc.
Copyright © 2023 Rinth, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion daedalus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "daedalus"
version = "0.1.19"
version = "0.1.20"
authors = ["Jai A <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
81 changes: 72 additions & 9 deletions daedalus/src/minecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ pub struct Download {
}

#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Download information of a library
pub struct LibraryDownload {
#[serde(skip_serializing_if = "Option::is_none")]
/// The path that the library should be saved to
pub path: String,
pub path: Option<String>,
/// The SHA1 hash of the library
pub sha1: String,
/// The size of the library
Expand All @@ -163,7 +164,7 @@ pub struct LibraryDownload {
}

#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A list of files that should be downloaded for libraries
pub struct LibraryDownloads {
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -188,15 +189,23 @@ pub enum RuleAction {

#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(rename_all = "kebab-case")]
/// An enum representing the different types of operating systems
pub enum Os {
/// MacOS
/// MacOS (x86)
Osx,
/// Windows
/// M1-Based Macs
OsxArm64,
/// Windows (x86)
Windows,
/// Linux and its derivatives
/// Windows ARM
WindowsArm64,
/// Linux (x86) and its derivatives
Linux,
/// Linux ARM 64
LinuxArm64,
/// Linux ARM 32
LinuxArm32,
/// The OS is unknown
Unknown,
}
Expand Down Expand Up @@ -243,7 +252,7 @@ pub struct Rule {
}

#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Information delegating the extraction of the library
pub struct LibraryExtract {
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -263,7 +272,7 @@ pub struct JavaVersion {
}

#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
/// A library which the game relies on to run
pub struct Library {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -291,6 +300,60 @@ pub struct Library {
pub include_in_classpath: bool,
}

#[derive(Deserialize, Debug, Clone)]
/// A partial library which should be merged with a full library
pub struct PartialLibrary {
/// The files the library has
pub downloads: Option<LibraryDownloads>,
/// Rules of the extraction of the file
pub extract: Option<LibraryExtract>,
/// The maven name of the library. The format is `groupId:artifactId:version`
pub name: Option<String>,
/// The URL to the repository where the library can be downloaded
pub url: Option<String>,
/// Native files that the library relies on
pub natives: Option<HashMap<Os, String>>,
/// Rules deciding whether the library should be downloaded or not
pub rules: Option<Vec<Rule>>,
/// SHA1 Checksums for validating the library's integrity. Only present for forge libraries
pub checksums: Option<Vec<String>>,
/// Whether the library should be included in the classpath at the game's launch
pub include_in_classpath: Option<bool>,
}

/// Merges a partial library to make a complete library
pub fn merge_partial_library(
partial: PartialLibrary,
mut merge: Library,
) -> Library {
if let Some(downloads) = partial.downloads {
merge.downloads = Some(downloads)
}
if let Some(extract) = partial.extract {
merge.extract = Some(extract)
}
if let Some(name) = partial.name {
merge.name = name
}
if let Some(url) = partial.url {
merge.url = Some(url)
}
if let Some(natives) = partial.natives {
merge.natives = Some(natives)
}
if let Some(rules) = partial.rules {
merge.rules = Some(rules)
}
if let Some(checksums) = partial.checksums {
merge.checksums = Some(checksums)
}
if let Some(include_in_classpath) = partial.include_in_classpath {
merge.include_in_classpath = include_in_classpath
}

merge
}

fn default_include_in_classpath() -> bool {
true
}
Expand Down
2 changes: 2 additions & 0 deletions daedalus/src/modded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use bincode::{Decode, Encode};
pub const CURRENT_FABRIC_FORMAT_VERSION: usize = 0;
/// The latest version of the format the fabric model structs deserialize to
pub const CURRENT_FORGE_FORMAT_VERSION: usize = 0;
/// The latest version of the format the quilt model structs deserialize to
pub const CURRENT_QUILT_FORMAT_VERSION: usize = 0;

/// The dummy replace string library names, inheritsFrom, and version names should be replaced with
pub const DUMMY_REPLACE_STRING: &str = "${modrinth.gameVersion}";
Expand Down
2 changes: 1 addition & 1 deletion daedalus_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "daedalus_client"
version = "0.1.19"
version = "0.1.20"
authors = ["Jai A <[email protected]>"]
edition = "2018"

Expand Down
31 changes: 21 additions & 10 deletions daedalus_client/src/fabric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,29 @@ pub async fn retrieve_data(
))
.await?;

versions.push(Version {
id: DUMMY_REPLACE_STRING.to_string(),
stable: true,
loaders: loader_version_mutex.into_inner(),
});
let mut loader_version_mutex = loader_version_mutex.into_inner();
if !loader_version_mutex.is_empty() {
if let Some(version) =
versions.iter_mut().find(|x| x.id == DUMMY_REPLACE_STRING)
{
version.loaders.append(&mut loader_version_mutex);
} else {
versions.push(Version {
id: DUMMY_REPLACE_STRING.to_string(),
stable: true,
loaders: loader_version_mutex,
});
}
}

for version in &list.game {
versions.push(Version {
id: version.version.clone(),
stable: version.stable,
loaders: vec![],
});
if !versions.iter().any(|x| x.id == version.version) {
versions.push(Version {
id: version.version.clone(),
stable: version.stable,
loaders: vec![],
});
}
}

versions.sort_by(|x, y| {
Expand Down
17 changes: 13 additions & 4 deletions daedalus_client/src/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ pub async fn retrieve_data(

async move {
/// These forge versions are not worth supporting!
const WHITELIST : [&str; 1] = [
const WHITELIST : &[&str] = &[
// Not supported due to `data` field being `[]` even though the type is a map
"1.12.2-14.23.5.2851",
// Malformed Archives
"1.6.1-8.9.0.749",
"1.6.1-8.9.0.751",
"1.6.4-9.11.1.960",
"1.6.4-9.11.1.961",
"1.6.4-9.11.1.963",
"1.6.4-9.11.1.964",
];

if WHITELIST.contains(&&*loader_version_full) {
Expand Down Expand Up @@ -459,19 +466,20 @@ pub async fn retrieve_data(
});

{
let len = loaders_futures.len();
let mut versions = loaders_futures.into_iter().peekable();
let mut chunk_index = 0;
while versions.peek().is_some() {
let now = Instant::now();

let chunk: Vec<_> = versions.by_ref().take(10).collect();
let chunk: Vec<_> = versions.by_ref().take(1).collect();
let res = futures::future::try_join_all(chunk).await?;
loaders_versions.extend(res.into_iter().flatten());

chunk_index += 1;

let elapsed = now.elapsed();
info!("Chunk {} Elapsed: {:.2?}", chunk_index, elapsed);
info!("Loader Chunk {}/{len} Elapsed: {:.2?}", chunk_index, elapsed);
}
}
//futures::future::try_join_all(loaders_futures).await?;
Expand All @@ -489,6 +497,7 @@ pub async fn retrieve_data(
}

{
let len = version_futures.len();
let mut versions = version_futures.into_iter().peekable();
let mut chunk_index = 0;
while versions.peek().is_some() {
Expand All @@ -500,7 +509,7 @@ pub async fn retrieve_data(
chunk_index += 1;

let elapsed = now.elapsed();
info!("Chunk {} Elapsed: {:.2?}", chunk_index, elapsed);
info!("Chunk {}/{len} Elapsed: {:.2?}", chunk_index, elapsed);
}
}
//futures::future::try_join_all(version_futures).await?;
Expand Down
13 changes: 12 additions & 1 deletion daedalus_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tokio::sync::Semaphore;
mod fabric;
mod forge;
mod minecraft;
mod quilt;

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -45,7 +46,7 @@ async fn main() {
}

let mut timer = tokio::time::interval(Duration::from_secs(60 * 60));
let semaphore = Arc::new(Semaphore::new(50));
let semaphore = Arc::new(Semaphore::new(10));

loop {
timer.tick().await;
Expand Down Expand Up @@ -87,6 +88,16 @@ async fn main() {
Ok(..) => {}
Err(err) => error!("{:?}", err),
};
match quilt::retrieve_data(
&manifest,
&mut uploaded_files,
semaphore.clone(),
)
.await
{
Ok(..) => {}
Err(err) => error!("{:?}", err),
};
}
}
}
Expand Down
Loading

0 comments on commit 6512dba

Please sign in to comment.