use crate::minify::{MinifyType, only_recompress};
pub(crate) const REPACKED: &str = "$repack";
#[derive(PartialEq)]
pub enum FileType {
Other,
Original,
Repacked
}
pub fn check_file_type(s: &str) -> FileType {
use FileType::*;
match s.rsplit_once('.') {
Some((n, "jar" | "zip")) => if n.ends_with(REPACKED) { Repacked } else { Original }
_ => Other
}
}
pub enum FileOp {
Recompress(usize),
Minify(MinifyType),
Ignore,
Signfile
}
impl FileOp {
pub(crate) fn by_name(fname: &str, use_blacklist: bool) -> Self {
use FileOp::*;
if fname.starts_with(".cache/") { return Ignore }
if fname.starts_with("META-INF/") {
let sub = &fname[9..];
match sub {
"MANIFEST.MF" => {return Recompress(64) }
"SIGNFILE.SF" | "SIGNFILE.DSA" => { return Signfile }
x if x.starts_with("SIG-") || [".DSA", ".RSA", ".SF"].into_iter().any(|e| x.ends_with(e)) => {
return Signfile
}
x if x.starts_with("services/") => { return Recompress(64) }
_ => {}
}
}
let ftype = fname.rsplit_once('.').unzip().1.unwrap_or("");
if ftype == "class" {
return Recompress(64)
}
if only_recompress(ftype) {
return Recompress(4)
}
if let Some(x) = MinifyType::by_extension(ftype) {
return Minify(x)
}
if use_blacklist && crate::blacklist::can_ignore_type(ftype) { Ignore } else { Recompress(2) }
}
}