2022-02-27 21:44:00 -07:00
|
|
|
use crate::validate::{
|
|
|
|
|
SupportedGameVersions, ValidationError, ValidationResult,
|
|
|
|
|
};
|
2022-07-31 13:29:20 -07:00
|
|
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
2021-05-30 15:02:07 -07:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
use zip::ZipArchive;
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
pub struct FabricValidator;
|
2021-05-30 15:02:07 -07:00
|
|
|
|
|
|
|
|
impl super::Validator for FabricValidator {
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["jar", "zip"]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_project_types(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["mod"]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["fabric"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
// Time since release of 18w49a, the first fabric version
|
2022-07-31 13:29:20 -07:00
|
|
|
SupportedGameVersions::PastDate(DateTime::from_utc(
|
|
|
|
|
NaiveDateTime::from_timestamp(1543969469, 0),
|
|
|
|
|
Utc,
|
2021-05-30 15:02:07 -07:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
2021-11-13 15:46:08 -07:00
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
2021-05-30 15:02:07 -07:00
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2021-06-02 18:33:11 -07:00
|
|
|
archive.by_name("fabric.mod.json").map_err(|_| {
|
2022-03-27 19:12:42 -07:00
|
|
|
ValidationError::InvalidInput(
|
2022-02-27 21:44:00 -07:00
|
|
|
"No fabric.mod.json present for Fabric file.".into(),
|
|
|
|
|
)
|
2021-06-02 18:33:11 -07:00
|
|
|
})?;
|
2021-05-30 15:02:07 -07:00
|
|
|
|
2022-02-27 21:44:00 -07:00
|
|
|
if !archive.file_names().any(|name| {
|
|
|
|
|
name.ends_with("refmap.json") || name.ends_with(".class")
|
|
|
|
|
}) {
|
2021-05-30 15:02:07 -07:00
|
|
|
return Ok(ValidationResult::Warning(
|
2021-11-13 15:46:08 -07:00
|
|
|
"Fabric mod file is a source file!",
|
2021-05-30 15:02:07 -07:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|