You've already forked AstralRinth
forked from didirus/AstralRinth
Shader fixes (#495)
* Shader fixes * Add core shaders validator * Update validator again * Rename shaders * Fix build
This commit is contained in:
@@ -7,6 +7,9 @@ use crate::validate::modpack::ModpackValidator;
|
||||
use crate::validate::plugin::*;
|
||||
use crate::validate::quilt::QuiltValidator;
|
||||
use crate::validate::resourcepack::{PackValidator, TexturePackValidator};
|
||||
use crate::validate::shader::{
|
||||
CanvasShaderValidator, CoreShaderValidator, ShaderValidator,
|
||||
};
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::io::Cursor;
|
||||
use thiserror::Error;
|
||||
@@ -19,6 +22,7 @@ mod modpack;
|
||||
pub mod plugin;
|
||||
mod quilt;
|
||||
mod resourcepack;
|
||||
mod shader;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ValidationError {
|
||||
@@ -76,7 +80,7 @@ pub trait Validator: Sync {
|
||||
) -> Result<ValidationResult, ValidationError>;
|
||||
}
|
||||
|
||||
static VALIDATORS: [&dyn Validator; 12] = [
|
||||
static VALIDATORS: [&dyn Validator; 15] = [
|
||||
&ModpackValidator,
|
||||
&FabricValidator,
|
||||
&ForgeValidator,
|
||||
@@ -89,6 +93,9 @@ static VALIDATORS: [&dyn Validator; 12] = [
|
||||
&BungeeCordValidator,
|
||||
&VelocityValidator,
|
||||
&SpongeValidator,
|
||||
&CanvasShaderValidator,
|
||||
&ShaderValidator,
|
||||
&CoreShaderValidator,
|
||||
];
|
||||
|
||||
/// The return value is whether this file should be marked as primary or not, based on the analysis of the file
|
||||
|
||||
119
src/validate/shader.rs
Normal file
119
src/validate/shader.rs
Normal file
@@ -0,0 +1,119 @@
|
||||
use crate::validate::{
|
||||
SupportedGameVersions, ValidationError, ValidationResult,
|
||||
};
|
||||
use std::io::Cursor;
|
||||
use zip::ZipArchive;
|
||||
|
||||
pub struct ShaderValidator;
|
||||
|
||||
impl super::Validator for ShaderValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["shader"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["optifine", "iris"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
if !archive.file_names().any(|x| x.starts_with("shaders/")) {
|
||||
return Err(ValidationError::InvalidInput(
|
||||
"No shaders folder present for OptiFine/Iris shader.".into(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CanvasShaderValidator;
|
||||
|
||||
impl super::Validator for CanvasShaderValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["shader"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["canvas"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
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. Tip: Make sure pack.mcmeta is in the root directory of your pack!".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !archive.file_names().any(|x| x.contains("/pipelines/")) {
|
||||
return Err(ValidationError::InvalidInput(
|
||||
"No pipeline shaders folder present for canvas shaders.".into(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CoreShaderValidator;
|
||||
|
||||
impl super::Validator for CoreShaderValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["zip"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["shader"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["vanilla"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
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. Tip: Make sure pack.mcmeta is in the root directory of your pack!".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !archive
|
||||
.file_names()
|
||||
.any(|x| x.starts_with("assets/minecraft/shaders/"))
|
||||
{
|
||||
return Err(ValidationError::InvalidInput(
|
||||
"No shaders folder present for vanilla shaders.".into(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user