MCModpackManager/mcmpmgr/src/providers/mod.rs

70 lines
1.7 KiB
Rust
Raw Normal View History

2024-08-17 16:11:04 +01:00
use crate::mod_meta::ModMeta;
2024-08-18 23:32:23 +01:00
use serde::{Deserialize, Serialize};
2024-08-20 20:00:43 +01:00
use std::{collections::HashSet, fmt::Display, path::PathBuf, str::FromStr};
2024-08-17 16:11:04 +01:00
pub mod modrinth;
pub mod raw;
2024-08-17 21:06:31 +01:00
#[derive(Serialize, Deserialize, Clone)]
2024-08-18 22:25:01 +01:00
pub enum FileSource {
2024-08-18 23:32:23 +01:00
Download {
url: String,
sha1: String,
sha512: String,
filename: String,
},
Local {
path: PathBuf,
sha1: String,
sha512: String,
filename: String,
},
}
2024-08-20 20:00:43 +01:00
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
2024-08-18 23:32:23 +01:00
pub enum DownloadSide {
Both,
Server,
Client,
}
impl FromStr for DownloadSide {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"both" => Ok(DownloadSide::Both),
"client" => Ok(DownloadSide::Client),
"server" => Ok(DownloadSide::Server),
_ => Err(format!(
"Invalid side {}. Expected one of: both, server, clide",
s
)),
}
}
}
2024-08-20 20:00:43 +01:00
impl Display for DownloadSide {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2024-08-18 23:32:23 +01:00
match self {
2024-08-20 20:00:43 +01:00
DownloadSide::Both => write!(f, "Both"),
DownloadSide::Server => write!(f, "Server"),
DownloadSide::Client => write!(f, "Client"),
2024-08-18 23:32:23 +01:00
}
}
2024-08-17 16:11:04 +01:00
}
2024-08-17 21:06:31 +01:00
#[derive(Serialize, Deserialize, Clone)]
2024-08-17 16:11:04 +01:00
pub struct PinnedMod {
/// Source of the files for the mod
2024-08-18 22:25:01 +01:00
pub source: Vec<FileSource>,
2024-08-17 16:11:04 +01:00
/// Version of mod
pub version: String,
2024-08-17 16:11:04 +01:00
/// Pinned dependencies of a pinned mod
pub deps: Option<HashSet<ModMeta>>,
/// Server side
pub server_side: bool,
/// Required on client side
2024-08-18 23:32:23 +01:00
pub client_side: bool,
}