2022-02-27 21:44:00 -07:00
|
|
|
use crate::validate::{
|
|
|
|
|
SupportedGameVersions, ValidationError, ValidationResult,
|
|
|
|
|
};
|
2022-07-31 13:29:20 -07:00
|
|
|
use chrono::{DateTime, NaiveDateTime, Utc};
|
2021-05-30 15:02:07 -07:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
use zip::ZipArchive;
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
pub struct ForgeValidator;
|
2021-05-30 15:02:07 -07:00
|
|
|
|
|
|
|
|
impl super::Validator for ForgeValidator {
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["jar", "zip"]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_project_types(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["mod"]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["forge"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
// Time since release of 1.13, the first forge version which uses the new TOML system
|
2022-07-31 13:29:20 -07:00
|
|
|
SupportedGameVersions::PastDate(DateTime::<Utc>::from_utc(
|
2023-02-22 16:11:14 -07:00
|
|
|
NaiveDateTime::from_timestamp_opt(1540122067, 0).unwrap(),
|
2022-07-31 13:29:20 -07:00
|
|
|
Utc,
|
2021-05-30 15:02:07 -07:00
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
2021-11-13 15:46:08 -07:00
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
2021-05-30 15:02:07 -07:00
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2022-04-24 13:02:41 -07:00
|
|
|
if archive.by_name("META-INF/mods.toml").is_err() {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
|
|
|
|
"No mods.toml present for Forge file.",
|
|
|
|
|
));
|
|
|
|
|
}
|
2021-05-30 15:02:07 -07:00
|
|
|
|
|
|
|
|
if !archive.file_names().any(|name| name.ends_with(".class")) {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
2021-11-13 15:46:08 -07:00
|
|
|
"Forge mod file is a source file!",
|
2021-05-30 15:02:07 -07:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: Check if file is a dev JAR?
|
|
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
pub struct LegacyForgeValidator;
|
2021-05-30 15:02:07 -07:00
|
|
|
|
|
|
|
|
impl super::Validator for LegacyForgeValidator {
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_file_extensions(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["jar", "zip"]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_project_types(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["mod"]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 11:26:59 +08:00
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
2021-05-30 15:02:07 -07:00
|
|
|
&["forge"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
|
|
|
// Times between versions 1.5.2 to 1.12.2, which all use the legacy way of defining mods
|
|
|
|
|
SupportedGameVersions::Range(
|
2022-07-31 13:29:20 -07:00
|
|
|
DateTime::from_utc(
|
2023-02-22 16:11:14 -07:00
|
|
|
NaiveDateTime::from_timestamp_opt(1366818300, 0).unwrap(),
|
2022-07-31 13:29:20 -07:00
|
|
|
Utc,
|
|
|
|
|
),
|
|
|
|
|
DateTime::from_utc(
|
2023-02-22 16:11:14 -07:00
|
|
|
NaiveDateTime::from_timestamp_opt(1505810340, 0).unwrap(),
|
2022-07-31 13:29:20 -07:00
|
|
|
Utc,
|
|
|
|
|
),
|
2021-05-30 15:02:07 -07:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn validate(
|
|
|
|
|
&self,
|
2021-11-13 15:46:08 -07:00
|
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
2021-05-30 15:02:07 -07:00
|
|
|
) -> Result<ValidationResult, ValidationError> {
|
2022-03-16 07:49:09 -07:00
|
|
|
if archive.by_name("mcmod.info").is_err() {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
|
|
|
|
"Forge mod file does not contain mcmod.info!",
|
|
|
|
|
));
|
|
|
|
|
};
|
2021-05-30 15:02:07 -07:00
|
|
|
|
|
|
|
|
if !archive.file_names().any(|name| name.ends_with(".class")) {
|
|
|
|
|
return Ok(ValidationResult::Warning(
|
2021-11-13 15:46:08 -07:00
|
|
|
"Forge mod file is a source file!",
|
2021-05-30 15:02:07 -07:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: Check if file is a dev JAR?
|
|
|
|
|
|
|
|
|
|
Ok(ValidationResult::Pass)
|
|
|
|
|
}
|
|
|
|
|
}
|