2024-10-18 16:07:35 -07:00
|
|
|
use crate::validate::{
|
2025-06-16 18:30:01 +02:00
|
|
|
MaybeProtectedZipFile, PLAUSIBLE_PACK_REGEX, SupportedGameVersions,
|
|
|
|
|
ValidationError, ValidationResult,
|
2024-10-18 16:07:35 -07:00
|
|
|
};
|
2024-08-14 17:14:52 -07:00
|
|
|
use chrono::DateTime;
|
2022-06-26 10:39:38 -07:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
use zip::ZipArchive;
|
|
|
|
|
|
2022-07-10 03:25:44 +00:00
|
|
|
pub struct PackValidator;
|
2022-06-26 10:39:38 -07:00
|
|
|
|
2022-07-10 03:25:44 +00:00
|
|
|
impl super::Validator for PackValidator {
|
2022-06-26 10:39:38 -07:00
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
|
|
|
&["minecraft"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
2022-07-10 03:25:44 +00:00
|
|
|
// Time since release of 13w24a which replaced texture packs with resource packs
|
2024-10-18 16:07:35 -07:00
|
|
|
SupportedGameVersions::PastDate(
|
|
|
|
|
DateTime::from_timestamp(1371137542, 0).unwrap(),
|
|
|
|
|
)
|
2022-06-26 10:39:38 -07:00
|
|
|
}
|
|
|
|
|
|
2025-06-16 18:30:01 +02:00
|
|
|
fn validate_maybe_protected_zip(
|
2022-06-26 10:39:38 -07:00
|
|
|
&self,
|
2025-06-16 18:30:01 +02:00
|
|
|
file: &mut MaybeProtectedZipFile,
|
2022-06-26 10:39:38 -07:00
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2025-06-16 18:30:01 +02:00
|
|
|
if match file {
|
|
|
|
|
MaybeProtectedZipFile::Unprotected(archive) => {
|
|
|
|
|
archive.by_name("pack.mcmeta").is_ok()
|
|
|
|
|
}
|
|
|
|
|
MaybeProtectedZipFile::MaybeProtected { data, .. } => {
|
|
|
|
|
PLAUSIBLE_PACK_REGEX.is_match(data)
|
|
|
|
|
}
|
|
|
|
|
} {
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
} else {
|
|
|
|
|
Ok(ValidationResult::Warning(
|
|
|
|
|
"No pack.mcmeta present for resourcepack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
|
|
|
|
))
|
2023-04-16 20:03:53 -07:00
|
|
|
}
|
2022-07-10 03:25:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct TexturePackValidator;
|
|
|
|
|
|
|
|
|
|
impl super::Validator for TexturePackValidator {
|
|
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
|
|
|
&["minecraft"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
// a1.2.2a to 13w23b
|
|
|
|
|
SupportedGameVersions::Range(
|
2024-08-14 17:14:52 -07:00
|
|
|
DateTime::from_timestamp(1289339999, 0).unwrap(),
|
|
|
|
|
DateTime::from_timestamp(1370651522, 0).unwrap(),
|
2022-07-10 03:25:44 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
|
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
|
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2023-04-16 20:03:53 -07:00
|
|
|
if archive.by_name("pack.txt").is_err() {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
|
|
|
|
"No pack.txt present for pack file.",
|
|
|
|
|
));
|
|
|
|
|
}
|
2022-06-26 10:39:38 -07:00
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|