124 lines
2.8 KiB
Rust
124 lines
2.8 KiB
Rust
use crate::manifest::{installer::Installer, link::Link};
|
|
use serde::{Deserialize, Serialize};
|
|
use std::collections::HashSet;
|
|
use url::Url;
|
|
|
|
pub mod installer;
|
|
pub mod link;
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct Manifest {
|
|
pub id: String,
|
|
#[serde(rename = "type")]
|
|
pub manifest_type: ManifestType,
|
|
pub versions: Vec<Version>,
|
|
#[serde(default)]
|
|
pub repositories: Vec<Repository>,
|
|
pub meta: Meta,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct Meta {
|
|
pub name: String,
|
|
#[serde(default)]
|
|
pub contributors: Vec<Contributor>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub description: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub icon_url: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub website_url: Option<Url>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct Contributor {
|
|
pub name: String,
|
|
pub roles: Vec<String>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct Repository {
|
|
pub id: String,
|
|
#[serde(rename = "type")]
|
|
pub repo_type: RepositoryType,
|
|
pub url: Url,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum RepositoryType {
|
|
Maven,
|
|
Curseforge,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct Version {
|
|
pub version: String,
|
|
pub mcversion: Vec<String>,
|
|
#[serde(default)]
|
|
pub files: Vec<File>,
|
|
#[serde(default)]
|
|
pub relations: Vec<Relation>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct Relation {
|
|
pub id: String,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub file: Option<File>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub versions: Option<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub meta: Option<Meta>,
|
|
#[serde(rename = "type")]
|
|
pub relation_type: RelationType,
|
|
pub options: HashSet<FileOpt>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Eq, PartialEq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum RelationType {
|
|
Mod,
|
|
Modloader,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug, Hash, Eq, PartialEq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum FileOpt {
|
|
Required,
|
|
Client,
|
|
Server,
|
|
Included,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
#[serde(untagged)]
|
|
pub enum File {
|
|
Link {
|
|
id: Option<String>,
|
|
installer: Installer,
|
|
link: Link,
|
|
options: Option<HashSet<FileOpt>>,
|
|
},
|
|
Maven {
|
|
installer: Installer,
|
|
artifact: String,
|
|
repository: String,
|
|
},
|
|
}
|
|
|
|
impl File {
|
|
pub fn installer(&self) -> &Installer {
|
|
match self {
|
|
File::Link { installer, .. } => installer,
|
|
File::Maven { installer, .. } => installer,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum ManifestType {
|
|
Modpack,
|
|
}
|