use macintosh_utils::Fork;
use crate::structs::{Directory, File, v1, v5};
#[derive(Debug, Clone)]
pub enum Entry {
File(File),
Directory(Directory),
DirectoryEnd(u64),
}
impl Entry {
pub fn name(&self) -> &str {
match self {
Entry::File(f) => f.name(),
Entry::Directory(d) => d.name(),
Entry::DirectoryEnd(_) => "",
}
}
pub fn is_directory(&self) -> bool {
matches!(self, Entry::Directory(_))
}
pub fn is_file(&self) -> bool {
matches!(self, Entry::File(_))
}
pub fn uncompressed_size(&self, fork: Fork) -> usize {
match self {
Entry::File(e) => e.uncompressed_size(fork),
Entry::Directory(e) => e.uncompressed_size(fork),
Entry::DirectoryEnd(_) => 0,
}
}
pub fn checksum(&self, fork: Fork) -> u16 {
match self {
Entry::File(file) => file.checksum(fork),
Entry::Directory(dir) => dir.checksum(fork),
Entry::DirectoryEnd(_) => 0,
}
}
pub fn has(&self, fork: Fork) -> bool {
match self {
Entry::File(e) => e.has(fork),
Entry::Directory(e) => e.has(fork),
Entry::DirectoryEnd(_) => false,
}
}
pub fn encrypted(&self, fork: Fork) -> bool {
match self {
Entry::File(e) => e.encrypted(fork),
Entry::Directory(e) => e.encrypted(fork),
Entry::DirectoryEnd(_) => false,
}
}
pub fn comment(&self) -> &str {
match self {
Entry::File(file) => file.comment(),
Entry::Directory(dir) => dir.comment(),
Entry::DirectoryEnd(_) => "",
}
}
pub fn as_file(&self) -> Option<&File> {
match self {
Entry::File(file) => Some(file),
Entry::Directory(_) => None,
Entry::DirectoryEnd(_) => None,
}
}
pub fn as_directory(&self) -> Option<&Directory> {
match self {
Entry::File(_) => None,
Entry::Directory(directory) => Some(directory),
Entry::DirectoryEnd(_) => None,
}
}
}
impl From<v1::File> for File {
fn from(value: v1::File) -> Self {
File::V1(value)
}
}
impl From<v5::File> for File {
fn from(value: v5::File) -> Self {
File::V5(value)
}
}
impl From<v1::Directory> for Directory {
fn from(value: v1::Directory) -> Self {
Directory::V1(value)
}
}
impl From<v5::Directory> for Directory {
fn from(value: v5::Directory) -> Self {
Directory::V5(value)
}
}