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
|
|
|
};
|
2025-06-16 18:30:01 +02:00
|
|
|
use chrono::DateTime;
|
2022-12-23 19:49:47 -07:00
|
|
|
|
|
|
|
|
pub struct DataPackValidator;
|
|
|
|
|
|
|
|
|
|
impl super::Validator for DataPackValidator {
|
|
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
|
|
|
&["zip"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
|
|
|
&["datapack"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
2025-06-16 18:30:01 +02:00
|
|
|
// Time since release of 17w43a, 2017-10-25, which introduced datapacks
|
|
|
|
|
SupportedGameVersions::PastDate(
|
2025-10-15 14:45:47 -06:00
|
|
|
DateTime::from_timestamp_secs(1508889600).unwrap(),
|
2025-06-16 18:30:01 +02:00
|
|
|
)
|
2022-12-23 19:49:47 -07:00
|
|
|
}
|
|
|
|
|
|
2025-06-16 18:30:01 +02:00
|
|
|
fn validate_maybe_protected_zip(
|
2022-12-23 19:49:47 -07:00
|
|
|
&self,
|
2025-06-16 18:30:01 +02:00
|
|
|
file: &mut MaybeProtectedZipFile,
|
2022-12-23 19:49:47 -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(
|
2023-04-16 20:03:53 -07:00
|
|
|
"No pack.mcmeta present for datapack file. Tip: Make sure pack.mcmeta is in the root directory of your datapack!",
|
2025-06-16 18:30:01 +02:00
|
|
|
))
|
2023-04-16 20:03:53 -07:00
|
|
|
}
|
2022-12-23 19:49:47 -07:00
|
|
|
}
|
|
|
|
|
}
|