package p421.p433.p434.p445;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.util.zip.CRC32;
import net.lingala.zip4j.exception.ZipException;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p421.p433.p434.p438.C6786;
import p421.p433.p434.p438.EnumC6785;
import p421.p433.p434.p439.p441.C6806;
import p421.p433.p434.p439.p441.C6810;
import p421.p433.p434.p439.p441.C6813;
import p421.p433.p434.p442.C6820;
import p421.p433.p434.p442.C6822;
import p421.p433.p434.p442.C6823;
import p421.p433.p434.p442.C6828;
import p421.p433.p434.p442.C6829;
import p421.p433.p434.p442.p443.EnumC6832;
import p421.p433.p434.p442.p443.EnumC6834;
import p421.p433.p434.p442.p443.EnumC6835;
import p421.p433.p434.p444.C6837;
import p421.p433.p434.p445.AbstractC6848;
import p421.p433.p434.p446.C6857;
import p421.p433.p434.p446.C6859;

/* JADX INFO: renamed from: ޏ.ؠ.֏.ބ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC6842<T> extends AbstractC6848<T> {

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public C6828 f19867;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public char[] f19868;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public C6786 f19869;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public byte[] f19870;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public int f19871;

    public AbstractC6842(C6828 c6828, char[] cArr, C6786 c6786, AbstractC6848.C6849 c6849) {
        super(c6849);
        this.f19870 = new byte[4096];
        this.f19871 = -1;
        this.f19867 = c6828;
        this.f19868 = cArr;
        this.f19869 = c6786;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C6813 m9981(C6810 c6810, Charset charset) throws IOException {
        if (this.f19867.f19786.exists()) {
            C6820 c6820 = this.f19867.f19781;
            if (c6820 == null) {
                throw new ZipException("invalid end of central directory record");
            }
            c6810.f19700.seek(c6820.f19755);
        }
        return new C6813(c6810, this.f19868, charset, this.f19867);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6829 m9982(C6829 c6829, File file, C6837 c6837) throws IOException {
        C6829 c68292 = new C6829(c6829);
        long jM7179 = C4303.m7179(file.lastModified());
        if (jM7179 > 0) {
            c68292.f19800 = jM7179;
        }
        if (file.isDirectory()) {
            c68292.f19801 = 0L;
        } else {
            c68292.f19801 = file.length();
        }
        c68292.f19802 = false;
        long jLastModified = file.lastModified();
        if (jLastModified > 0) {
            c68292.f19800 = jLastModified;
        }
        if (!C4303.m7202(c6829.f19799)) {
            c68292.f19799 = C6857.m10001(file, c6829);
        }
        if (file.isDirectory()) {
            c68292.f19788 = EnumC6834.STORE;
            c68292.f19791 = EnumC6835.NONE;
            c68292.f19790 = false;
        } else {
            if (c68292.f19790 && c68292.f19791 == EnumC6835.ZIP_STANDARD) {
                C6837.EnumC6840 enumC6840 = C6837.EnumC6840.CALCULATE_CRC;
                if (c6837 == null) {
                    throw null;
                }
                if (!file.exists() || !file.canRead()) {
                    throw new ZipException("input file is null or does not exist or cannot read. Cannot calculate CRC for the file");
                }
                byte[] bArr = new byte[16384];
                CRC32 crc32 = new CRC32();
                FileInputStream fileInputStream = new FileInputStream(file);
                while (true) {
                    try {
                        int i = fileInputStream.read(bArr);
                        if (i == -1) {
                            break;
                        }
                        crc32.update(bArr, 0, i);
                        c6837.m9980(i);
                    } finally {
                    }
                }
                long value = crc32.getValue();
                fileInputStream.close();
                c68292.f19797 = value;
                C6837.EnumC6840 enumC68402 = C6837.EnumC6840.ADD_ENTRY;
            }
            if (file.length() == 0) {
                c68292.f19788 = EnumC6834.STORE;
            }
        }
        return c68292;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9983(File file, C6813 c6813, C6829 c6829, C6810 c6810) throws IOException {
        C6829 c68292 = new C6829(c6829);
        String str = c6829.f19799;
        String name = file.getName();
        if (str.contains("/")) {
            name = str.substring(0, str.lastIndexOf("/") + 1) + name;
        }
        c68292.f19799 = name;
        c68292.f19790 = false;
        c68292.f19788 = EnumC6834.STORE;
        c6813.m9977(c68292);
        c6813.write(file.toPath().toRealPath(new LinkOption[0]).toString().getBytes());
        m9985(c6813, c6810, file, true);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9984(File file, C6813 c6813, C6829 c6829, C6810 c6810, C6837 c6837) throws IOException {
        c6813.m9977(c6829);
        if (!file.isDirectory()) {
            FileInputStream fileInputStream = new FileInputStream(file);
            while (true) {
                try {
                    int i = fileInputStream.read(this.f19870);
                    this.f19871 = i;
                    if (i == -1) {
                        break;
                    }
                    c6813.write(this.f19870, 0, i);
                    c6837.m9980(this.f19871);
                    m9992();
                } catch (Throwable th) {
                    try {
                        throw th;
                    } catch (Throwable th2) {
                        try {
                            fileInputStream.close();
                        } catch (Throwable th3) {
                            th.addSuppressed(th3);
                        }
                        throw th2;
                    }
                }
            }
            fileInputStream.close();
        }
        m9985(c6813, c6810, file, false);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9985(C6813 c6813, C6810 c6810, File file, boolean z) throws IOException {
        byte[] bArrM10009;
        C6810 c68102;
        String string;
        c6813.f19712.mo9971();
        long j = c6813.f19712.f19695.f19693.f19706;
        C6822 c6822 = c6813.f19713;
        c6822.f19733 = j;
        C6823 c6823 = c6813.f19714;
        c6823.f19733 = j;
        long j2 = c6813.f19719;
        c6822.f19734 = j2;
        c6823.f19734 = j2;
        boolean z2 = true;
        if (!(c6822.f19738 && c6822.f19739.equals(EnumC6835.AES)) ? true : c6822.f19742.f19723.equals(EnumC6832.ONE)) {
            c6813.f19713.f19731 = c6813.f19717.getValue();
            c6813.f19714.f19731 = c6813.f19717.getValue();
        }
        c6813.f19711.f19779.add(c6813.f19714);
        c6813.f19711.f19780.f19746.add(c6813.f19713);
        C6823 c68232 = c6813.f19714;
        if (c68232.f19740) {
            C6786 c6786 = c6813.f19716;
            C6806 c6806 = c6813.f19709;
            if (c6786 == null) {
                throw null;
            }
            if (c6806 == null) {
                throw new ZipException("input parameters is null, cannot write extended local header");
            }
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            try {
                C6859 c6859 = c6786.f19632;
                c6859.m10015(c6859.f19898, 0, (int) EnumC6785.EXTRA_DATA_RECORD.f19631);
                byteArrayOutputStream.write(c6859.f19898);
                c6786.f19632.m10016(c6786.f19633, 0, c68232.f19731);
                byteArrayOutputStream.write(c6786.f19633, 0, 4);
                if (c68232.f19766) {
                    C6859 c68592 = c6786.f19632;
                    c68592.m10016(c68592.f19899, 0, c68232.f19733);
                    byteArrayOutputStream.write(c68592.f19899);
                    C6859 c68593 = c6786.f19632;
                    c68593.m10016(c68593.f19899, 0, c68232.f19734);
                    byteArrayOutputStream.write(c68593.f19899);
                } else {
                    c6786.f19632.m10016(c6786.f19633, 0, c68232.f19733);
                    byteArrayOutputStream.write(c6786.f19633, 0, 4);
                    c6786.f19632.m10016(c6786.f19633, 0, c68232.f19734);
                    byteArrayOutputStream.write(c6786.f19633, 0, 4);
                }
                c6806.write(byteArrayOutputStream.toByteArray());
                byteArrayOutputStream.close();
            } finally {
            }
        }
        c6813.f19719 = 0L;
        c6813.f19717.reset();
        c6813.f19712.f19695.close();
        C6822 c68222 = c6813.f19713;
        if (file != null) {
            try {
                if (file.exists()) {
                    Path path = file.toPath();
                    String lowerCase = System.getProperty("os.name").toLowerCase();
                    bArrM10009 = C6857.m10008(lowerCase) ? C6857.m10009(path) : (lowerCase.contains("mac") || lowerCase.contains("nux")) ? C6857.m10007(path) : new byte[4];
                } else {
                    bArrM10009 = new byte[4];
                }
            } catch (NoSuchMethodError unused) {
                bArrM10009 = new byte[4];
            }
        } else {
            bArrM10009 = new byte[4];
        }
        if (!z) {
            bArrM10009[3] = C4303.m7175(bArrM10009[3], 5);
        }
        c68222.f19763 = bArrM10009;
        C6786 c67862 = this.f19869;
        C6828 c6828 = this.f19867;
        if (c67862 == null) {
            throw null;
        }
        if (c6828 == null) {
            throw new ZipException("invalid input parameters, cannot update local file header");
        }
        if (c68222.f19762 != c6810.f19703) {
            String parent = c6828.f19786.getParent();
            String strM10002 = C6857.m10002(c6828.f19786.getName());
            StringBuilder sbM4889 = C2803.m4889(parent);
            sbM4889.append(System.getProperty("file.separator"));
            String string2 = sbM4889.toString();
            if (c68222.f19762 < 9) {
                StringBuilder sbM4898 = C2803.m4898(string2, strM10002, ".z0");
                sbM4898.append(c68222.f19762 + 1);
                string = sbM4898.toString();
            } else {
                StringBuilder sbM48982 = C2803.m4898(string2, strM10002, ".z");
                sbM48982.append(c68222.f19762 + 1);
                string = sbM48982.toString();
            }
            c68102 = new C6810(new File(string), -1L);
        } else {
            z2 = false;
            c68102 = c6810;
        }
        long jM9975 = c68102.m9975();
        c68102.f19700.seek(c68222.f19764 + 14);
        c67862.f19632.m10016(c67862.f19633, 0, c68222.f19731);
        c68102.write(c67862.f19633, 0, 4);
        if (c68222.f19734 >= 4294967295L) {
            c67862.f19632.m10016(c67862.f19633, 0, 4294967295L);
            c68102.write(c67862.f19633, 0, 4);
            c68102.write(c67862.f19633, 0, 4);
            int iM4861 = C2803.m4861(c68222.f19735, 4, 2, 2);
            if (c68102.f19700.skipBytes(iM4861) != iM4861) {
                throw new ZipException(C2803.m4872("Unable to skip ", iM4861, " bytes to update LFH"));
            }
            C6859 c68594 = c67862.f19632;
            c68594.m10016(c68594.f19899, 0, c68222.f19734);
            c68102.write(c68594.f19899);
            C6859 c68595 = c67862.f19632;
            c68595.m10016(c68595.f19899, 0, c68222.f19733);
            c68102.write(c68595.f19899);
        } else {
            c67862.f19632.m10016(c67862.f19633, 0, c68222.f19733);
            c68102.write(c67862.f19633, 0, 4);
            c67862.f19632.m10016(c67862.f19633, 0, c68222.f19734);
            c68102.write(c67862.f19633, 0, 4);
        }
        if (z2) {
            c68102.f19700.close();
        } else {
            c6810.f19700.seek(jM9975);
        }
    }
}
