You've already forked AstralRinth
Add method of storing launcher data, fix forge 1.17+, add launcher settings
This commit is contained in:
@@ -7,7 +7,6 @@ use crate::launcher::ModLoader;
|
||||
|
||||
use super::pack::ModpackGame;
|
||||
use super::{pack, ModpackError, ModpackResult};
|
||||
use daedalus::modded::LoaderType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_FORMAT_VERSION: u32 = 1;
|
||||
@@ -45,7 +44,7 @@ impl TryFrom<Manifest<'_>> for pack::Modpack {
|
||||
}
|
||||
}
|
||||
|
||||
const MODRINTH_GAMEDATA_URL: &'static str = "https://staging-cdn.modrinth.com/gamedata";
|
||||
const MODRINTH_GAMEDATA_URL: &str = "https://staging-cdn.modrinth.com/gamedata";
|
||||
fn get_loader_version(loader: ModLoader, version: &str) -> ModpackResult<String> {
|
||||
let source = match loader {
|
||||
ModLoader::Vanilla => Err(ModpackError::VersionError(String::from(
|
||||
@@ -60,11 +59,14 @@ fn get_loader_version(loader: ModLoader, version: &str) -> ModpackResult<String>
|
||||
.game_versions
|
||||
.iter()
|
||||
.find(|&it| it.id == version)
|
||||
.ok_or(ModpackError::VersionError(format!(
|
||||
"No versions of modloader {:?} exist for Minecraft {}",
|
||||
loader, version
|
||||
)))?
|
||||
.loaders[&LoaderType::Latest]
|
||||
.map(|x| x.loaders.first())
|
||||
.flatten()
|
||||
.ok_or_else(|| {
|
||||
ModpackError::VersionError(format!(
|
||||
"No versions of modloader {:?} exist for Minecraft {}",
|
||||
loader, version
|
||||
))
|
||||
})?
|
||||
.id
|
||||
.clone())
|
||||
}
|
||||
@@ -88,7 +90,7 @@ impl<'a> TryFrom<&'a pack::Modpack> for Manifest<'a> {
|
||||
game: game_field,
|
||||
version_id: &pack.version,
|
||||
name: &pack.name,
|
||||
summary: pack.summary.as_ref().map(String::as_str),
|
||||
summary: pack.summary.as_deref(),
|
||||
files,
|
||||
dependencies: ManifestDeps::try_from(&pack.game)?,
|
||||
})
|
||||
@@ -333,9 +335,9 @@ mod tests {
|
||||
summary: None,
|
||||
files: vec![ManifestFile {
|
||||
path: Path::new("mods/testmod.jar"),
|
||||
hashes: ManifestHashes {
|
||||
hashes: Some(ManifestHashes {
|
||||
sha1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
},
|
||||
}),
|
||||
env: ManifestEnvs::default(),
|
||||
downloads: vec!["https://example.com/testmod.jar"],
|
||||
}],
|
||||
@@ -383,9 +385,9 @@ mod tests {
|
||||
summary: None,
|
||||
files: vec![ManifestFile {
|
||||
path: Path::new("mods/testmod.jar"),
|
||||
hashes: ManifestHashes {
|
||||
hashes: Some(ManifestHashes {
|
||||
sha1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
},
|
||||
}),
|
||||
env: ManifestEnvs::default(),
|
||||
downloads: vec!["https://example.com/testmod.jar"],
|
||||
}],
|
||||
@@ -438,9 +440,9 @@ mod tests {
|
||||
summary: Some("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."),
|
||||
files: vec![ManifestFile {
|
||||
path: Path::new("mods/testmod.jar"),
|
||||
hashes: ManifestHashes {
|
||||
hashes: Some(ManifestHashes {
|
||||
sha1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
},
|
||||
}),
|
||||
env: ManifestEnvs {
|
||||
client: ManifestEnv::Required,
|
||||
server: ManifestEnv::Unsupported,
|
||||
|
||||
@@ -18,11 +18,11 @@ pub mod manifest;
|
||||
pub mod modrinth_api;
|
||||
pub mod pack;
|
||||
|
||||
pub const COMPILED_PATH: &'static str = "compiled/";
|
||||
pub const COMPILED_ZIP: &'static str = "compiled.mrpack";
|
||||
pub const MANIFEST_PATH: &'static str = "modrinth.index.json";
|
||||
pub const OVERRIDES_PATH: &'static str = "overrides/";
|
||||
pub const PACK_JSON5_PATH: &'static str = "modpack.json5";
|
||||
pub const COMPILED_PATH: &str = "compiled/";
|
||||
pub const COMPILED_ZIP: &str = "compiled.mrpack";
|
||||
pub const MANIFEST_PATH: &str = "modrinth.index.json";
|
||||
pub const OVERRIDES_PATH: &str = "overrides/";
|
||||
pub const PACK_JSON5_PATH: &str = "modpack.json5";
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum ModpackError {
|
||||
@@ -121,9 +121,9 @@ pub async fn realise_modpack(
|
||||
// NOTE: I'm using standard files here, since Serde does not support async readers
|
||||
let manifest_path = Some(dir.join(MANIFEST_PATH))
|
||||
.filter(|it| it.exists() && it.is_file())
|
||||
.ok_or(ModpackError::ManifestError(String::from(
|
||||
"Manifest missing or is not a file",
|
||||
)))?;
|
||||
.ok_or_else(|| {
|
||||
ModpackError::ManifestError(String::from("Manifest missing or is not a file"))
|
||||
})?;
|
||||
let manifest_file = std::fs::File::open(manifest_path)?;
|
||||
let reader = io::BufReader::new(manifest_file);
|
||||
let mut deserializer = serde_json::Deserializer::from_reader(reader);
|
||||
@@ -169,7 +169,7 @@ pub async fn compile_modpack(dir: &Path) -> ModpackResult<()> {
|
||||
let result_dir = dir.join(COMPILED_PATH);
|
||||
let pack: Modpack = json5::from_str(&fs::read_to_string(dir.join(PACK_JSON5_PATH)).await?)?;
|
||||
|
||||
fs::create_dir(&result_dir).await;
|
||||
fs::create_dir(&result_dir).await?;
|
||||
if dir.join(OVERRIDES_PATH).exists() {
|
||||
fs_extra::dir::copy(
|
||||
dir.join(OVERRIDES_PATH),
|
||||
|
||||
@@ -116,10 +116,12 @@ impl ModrinthAPI for ModrinthV1 {
|
||||
&& it.game_versions.contains(&game_version.as_str())
|
||||
&& it.loaders.contains(&loader_str)
|
||||
})
|
||||
.ok_or(ModpackError::VersionError(format!(
|
||||
"Unable to find compatible version of mod {}",
|
||||
project.title
|
||||
)))?;
|
||||
.ok_or_else(|| {
|
||||
ModpackError::VersionError(format!(
|
||||
"Unable to find compatible version of mod {}",
|
||||
project.title
|
||||
))
|
||||
})?;
|
||||
|
||||
// Project fields
|
||||
let envs = ModpackEnv::try_from(ManifestEnvs {
|
||||
@@ -135,7 +137,7 @@ impl ModrinthAPI for ModrinthV1 {
|
||||
.map(ModpackFile::from)
|
||||
.collect::<HashSet<ModpackFile>>();
|
||||
|
||||
let dep_futures = version.dependencies.iter().map(|it| self.get_version(&it));
|
||||
let dep_futures = version.dependencies.iter().map(|it| self.get_version(it));
|
||||
let deps = try_join_all(dep_futures)
|
||||
.await?
|
||||
.into_iter()
|
||||
|
||||
@@ -15,13 +15,13 @@ use super::{
|
||||
};
|
||||
use crate::launcher::ModLoader;
|
||||
|
||||
pub const MODRINTH_DEFAULT_MODPACK_DOMAINS: &'static [&'static str] = &[
|
||||
pub const MODRINTH_DEFAULT_MODPACK_DOMAINS: &[&str] = &[
|
||||
"cdn.modrinth.com",
|
||||
"edge.forgecdn.net",
|
||||
"github.com",
|
||||
"raw.githubusercontent.com",
|
||||
];
|
||||
pub const MODRINTH_MODPACK_DOMAIN_WHITELIST_VAR: &'static str = "WHITELISTED_MODPACK_DOMAINS";
|
||||
pub const MODRINTH_MODPACK_DOMAIN_WHITELIST_VAR: &str = "WHITELISTED_MODPACK_DOMAINS";
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||
pub struct Modpack {
|
||||
@@ -114,18 +114,17 @@ impl Modpack {
|
||||
) -> ModpackResult<()> {
|
||||
let whitelisted_domains = std::env::var(MODRINTH_MODPACK_DOMAIN_WHITELIST_VAR)
|
||||
.map(|it| serde_json::from_str::<Vec<String>>(&it).ok().unwrap())
|
||||
.unwrap_or(
|
||||
.unwrap_or_else(|_| {
|
||||
MODRINTH_DEFAULT_MODPACK_DOMAINS
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(String::from)
|
||||
.collect::<Vec<String>>(),
|
||||
);
|
||||
.collect::<Vec<String>>()
|
||||
});
|
||||
|
||||
if whitelisted_domains
|
||||
if !whitelisted_domains
|
||||
.iter()
|
||||
.find(|it| it == &source.host_str().unwrap())
|
||||
.is_none()
|
||||
.any(|it| it == source.host_str().unwrap())
|
||||
{
|
||||
return Err(ModpackError::SourceWhitelistError(String::from(
|
||||
source.host_str().unwrap(),
|
||||
@@ -136,7 +135,7 @@ impl Modpack {
|
||||
path: PathBuf::from(dest),
|
||||
hashes,
|
||||
env: env.unwrap_or(ModpackEnv::Both),
|
||||
downloads: HashSet::from_iter([String::from(source)].into_iter().cloned()),
|
||||
downloads: HashSet::from_iter([String::from(source)].iter().cloned()),
|
||||
};
|
||||
|
||||
self.files.insert(file);
|
||||
@@ -180,8 +179,7 @@ impl ModpackFile {
|
||||
// URLs, I'm supplying it with an empty string to avoid reinventing the wheel.
|
||||
let bytes = download_file_mirrors(
|
||||
"",
|
||||
&self
|
||||
.downloads
|
||||
self.downloads
|
||||
.iter()
|
||||
.map(|it| it.as_str())
|
||||
.collect::<Vec<&str>>()
|
||||
|
||||
Reference in New Issue
Block a user