2023-04-20 16:38:30 -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_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
|
2023-10-11 15:55:01 -07:00
|
|
|
SupportedGameVersions::PastDate(DateTime::from_naive_utc_and_offset(
|
2023-02-22 16:11:14 -07:00
|
|
|
NaiveDateTime::from_timestamp_opt(1543969469, 0).unwrap(),
|
2022-07-31 13:29:20 -07:00
|
|
|
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> {
|
2023-04-16 20:03:53 -07:00
|
|
|
if archive.by_name("fabric.mod.json").is_err() {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
|
|
|
|
"No fabric.mod.json present for Fabric file.",
|
|
|
|
|
));
|
|
|
|
|
}
|
2021-05-30 15:02:07 -07:00
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|