1
0

Add even more validators (#385)

* Add even more validators

I was gonna add shaderpacks too, but those have no standard metadata file at all.

* Make it compile

* Fix logic

* Update validators

* fix mistake

Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Emma Cypress ⚘
2022-07-10 03:25:44 +00:00
committed by GitHub
parent 68f7dc9512
commit 02c3894fc9
5 changed files with 167 additions and 20 deletions

View File

@@ -2,11 +2,48 @@ use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use std::io::Cursor;
use time::OffsetDateTime;
use zip::ZipArchive;
pub struct ResourcePackValidator;
pub struct PackValidator;
impl super::Validator for ResourcePackValidator {
impl super::Validator for PackValidator {
fn get_file_extensions(&self) -> &[&str] {
&["zip"]
}
fn get_project_types(&self) -> &[&str] {
&["resourcepack", "datapack"]
}
fn get_supported_loaders(&self) -> &[&str] {
&["minecraft"]
}
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 13w24a which replaced texture packs with resource packs
SupportedGameVersions::PastDate(OffsetDateTime::from_unix_timestamp(
1371137542,
))
}
fn validate(
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
archive.by_name("pack.mcmeta").map_err(|_| {
ValidationError::InvalidInput(
"No pack.mcmeta present for pack file.".into(),
)
})?;
Ok(ValidationResult::Pass)
}
}
pub struct TexturePackValidator;
impl super::Validator for TexturePackValidator {
fn get_file_extensions(&self) -> &[&str] {
&["zip"]
}
@@ -20,16 +57,20 @@ impl super::Validator for ResourcePackValidator {
}
fn get_supported_game_versions(&self) -> SupportedGameVersions {
SupportedGameVersions::All
// a1.2.2a to 13w23b
SupportedGameVersions::Range(
OffsetDateTime::from_unix_timestamp(1289339999),
OffsetDateTime::from_unix_timestamp(1370651522),
)
}
fn validate(
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
archive.by_name("pack.mcmeta").map_err(|_| {
archive.by_name("pack.txt").map_err(|_| {
ValidationError::InvalidInput(
"No pack.mcmeta present for resourcepack file.".into(),
"No pack.txt present for pack file.".into(),
)
})?;