Update validators again (#925)

* Update validators again

* fix tests + clippy
This commit is contained in:
Geometrically
2024-06-12 14:38:35 -07:00
committed by GitHub
parent beaaed6613
commit b8963d272a
11 changed files with 161 additions and 28 deletions

37
src/validate/neoforge.rs Normal file
View File

@@ -0,0 +1,37 @@
use crate::validate::{filter_out_packs, SupportedGameVersions, ValidationError, ValidationResult};
use std::io::Cursor;
use zip::ZipArchive;
pub struct NeoForgeValidator;
impl super::Validator for NeoForgeValidator {
fn get_file_extensions(&self) -> &[&str] {
&["jar", "zip"]
}
fn get_supported_loaders(&self) -> &[&str] {
&["forge"]
}
fn get_supported_game_versions(&self) -> SupportedGameVersions {
SupportedGameVersions::All
}
fn validate(
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
if archive.by_name("META-INF/mods.toml").is_err()
&& archive.by_name("META-INF/neoforge.mods.toml").is_err()
&& !archive.file_names().any(|x| x.ends_with(".class"))
{
return Ok(ValidationResult::Warning(
"No neoforge.mods.toml, mods.toml, or valid class files present for NeoForge file.",
));
}
filter_out_packs(archive)?;
Ok(ValidationResult::Pass)
}
}