package p421.p433.p434.p445;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
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.C6784;
import p421.p433.p434.p438.EnumC6785;
import p421.p433.p434.p439.p440.AbstractC6790;
import p421.p433.p434.p439.p440.C6789;
import p421.p433.p434.p439.p440.C6792;
import p421.p433.p434.p439.p440.C6793;
import p421.p433.p434.p439.p440.C6798;
import p421.p433.p434.p439.p440.C6799;
import p421.p433.p434.p439.p440.C6800;
import p421.p433.p434.p439.p440.C6801;
import p421.p433.p434.p442.C6815;
import p421.p433.p434.p442.C6821;
import p421.p433.p434.p442.C6822;
import p421.p433.p434.p442.C6823;
import p421.p433.p434.p442.C6826;
import p421.p433.p434.p442.C6828;
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.C6858;
import p421.p433.p434.p446.C6859;

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

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

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

    public AbstractC6843(C6828 c6828, AbstractC6848.C6849 c6849) {
        super(c6849);
        this.f19873 = new byte[4096];
        this.f19872 = c6828;
    }

    @Override // p421.p433.p434.p445.AbstractC6848
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C6837.EnumC6840 mo9986() {
        return C6837.EnumC6840.EXTRACT_ENTRY;
    }

    /* JADX WARN: Removed duplicated region for block: B:127:0x02e8  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void m9987(C6800 c6800, C6822 c6822, String str, String str2, C6837 c6837) throws Exception {
        String string;
        C6823 c6823;
        String str3;
        C6823 c68232;
        C6815 c6815M9943;
        List<C6821> listEmptyList;
        long j;
        C6823 c68233;
        if (str.endsWith(C6858.f19895)) {
            string = str;
        } else {
            StringBuilder sbM4889 = C2803.m4889(str);
            sbM4889.append(C6858.f19895);
            string = sbM4889.toString();
        }
        File file = new File(C2803.m4884(C2803.m4889(string), C6858.f19895, C4303.m7202(str2) ? str2 : c6822.f19737.replaceAll("[/\\\\]", Matcher.quoteReplacement(C6858.f19895))));
        file.getAbsolutePath();
        if (c6837 == null) {
            throw null;
        }
        if (!file.getCanonicalPath().startsWith(new File(string).getCanonicalPath() + File.separator)) {
            StringBuilder sbM48892 = C2803.m4889("illegal file name that breaks out of the target directory: ");
            sbM48892.append(c6822.f19737);
            throw new ZipException(sbM48892.toString());
        }
        if (c6800.f19685 != null) {
            if (c6800.f19687 == null) {
                c6800.f19687 = new byte[512];
            }
            while (c6800.read(c6800.f19687) != -1) {
            }
        }
        C6784 c6784 = c6800.f19683;
        PushbackInputStream pushbackInputStream = c6800.f19681;
        Charset charset = c6800.f19689;
        if (c6784 == null) {
            throw null;
        }
        C6823 c68234 = new C6823();
        byte[] bArr = new byte[4];
        C6859 c6859 = c6784.f19617;
        c6859.m10013(pushbackInputStream, c6859.f19898, 4);
        long jM10011 = c6859.m10011(c6859.f19898);
        EnumC6785 enumC6785 = EnumC6785.LOCAL_FILE_HEADER;
        long j2 = -1;
        if (jM10011 != enumC6785.f19631) {
            c68232 = null;
            str3 = "\\";
        } else {
            c68234.f19778 = enumC6785;
            c68234.f19727 = c6784.f19617.m10010(pushbackInputStream);
            byte[] bArr2 = new byte[2];
            if (C4303.m6982((InputStream) pushbackInputStream, bArr2) != 2) {
                throw new ZipException("Could not read enough bytes for generalPurposeFlags");
            }
            c68234.f19738 = C4303.m7119(bArr2[0], 0);
            c68234.f19740 = C4303.m7119(bArr2[0], 3);
            c68234.f19743 = C4303.m7119(bArr2[1], 3);
            c68234.f19728 = (byte[]) bArr2.clone();
            c68234.f19729 = EnumC6834.m9978(c6784.f19617.m10010(pushbackInputStream));
            C6859 c68592 = c6784.f19617;
            c68592.m10013(pushbackInputStream, c68592.f19898, 4);
            c68234.f19730 = c68592.m10011(c68592.f19898);
            C4303.m6982((InputStream) pushbackInputStream, bArr);
            c68234.f19731 = c6784.f19617.m10017(bArr, 0);
            c68234.f19732 = (byte[]) bArr.clone();
            C6859 c68593 = c6784.f19617;
            c68593.m10019(c68593.f19899);
            c68593.m10013(pushbackInputStream, c68593.f19899, 4);
            c68234.f19733 = c68593.m10017(c68593.f19899, 0);
            C6859 c68594 = c6784.f19617;
            c68594.m10019(c68594.f19899);
            c68594.m10013(pushbackInputStream, c68594.f19899, 4);
            c68234.f19734 = c68594.m10017(c68594.f19899, 0);
            int iM10010 = c6784.f19617.m10010(pushbackInputStream);
            c68234.f19735 = iM10010;
            c68234.f19736 = c6784.f19617.m10010(pushbackInputStream);
            if (iM10010 > 0) {
                byte[] bArr3 = new byte[iM10010];
                C4303.m6982((InputStream) pushbackInputStream, bArr3);
                String strM7028 = C4303.m7028(bArr3, c68234.f19743, charset);
                StringBuilder sbM48893 = C2803.m4889(":");
                sbM48893.append(System.getProperty("file.separator"));
                if (strM7028.contains(sbM48893.toString())) {
                    StringBuilder sbM48894 = C2803.m4889(":");
                    sbM48894.append(System.getProperty("file.separator"));
                    strM7028 = strM7028.substring(strM7028.indexOf(sbM48894.toString()) + 2);
                }
                c68234.f19737 = strM7028;
                c68234.f19745 = strM7028.endsWith("/") || strM7028.endsWith("\\");
            } else {
                c68234.f19737 = null;
            }
            int i = c68234.f19736;
            if (i > 0) {
                if (i < 4) {
                    if (i > 0) {
                        pushbackInputStream.skip(i);
                    }
                    listEmptyList = null;
                } else {
                    byte[] bArr4 = new byte[i];
                    C4303.m6982((InputStream) pushbackInputStream, bArr4);
                    try {
                        listEmptyList = c6784.m9942(bArr4, i);
                    } catch (Exception unused) {
                        listEmptyList = Collections.emptyList();
                    }
                }
                c68234.f19744 = listEmptyList;
            }
            C6859 c68595 = c6784.f19617;
            List<C6821> list = c68234.f19744;
            if (list == null || list.size() <= 0) {
                c6823 = c68234;
                str3 = "\\";
            } else {
                c6823 = c68234;
                str3 = "\\";
                C6826 c6826M9945 = c6784.m9945(c68234.f19744, c68595, c68234.f19734, c68234.f19733, 0L, 0);
                if (c6826M9945 != null) {
                    c6823.f19741 = c6826M9945;
                    long j3 = c6826M9945.f19775;
                    if (j3 != -1) {
                        c6823.f19734 = j3;
                    }
                    long j4 = c6826M9945.f19774;
                    if (j4 != -1) {
                        c6823.f19733 = j4;
                    }
                }
            }
            C6859 c68596 = c6784.f19617;
            List<C6821> list2 = c6823.f19744;
            if (list2 != null && list2.size() > 0 && (c6815M9943 = c6784.m9943(c6823.f19744, c68596)) != null) {
                c6823.f19742 = c6815M9943;
                c6823.f19739 = EnumC6835.AES;
            }
            if (c6823.f19738 && c6823.f19739 != EnumC6835.AES) {
                if (BigInteger.valueOf(c6823.f19728[0]).testBit(6)) {
                    c6823.f19739 = EnumC6835.ZIP_STANDARD_VARIANT_STRONG;
                } else {
                    c6823.f19739 = EnumC6835.ZIP_STANDARD;
                }
            }
            c68232 = c6823;
        }
        c6800.f19685 = c68232;
        if (c68232 == null) {
            c68233 = null;
        } else {
            String str4 = c68232.f19737;
            if (!(str4.endsWith("/") || str4.endsWith(str3)) && c68232.f19729 == EnumC6834.STORE && c68232.f19734 < 0) {
                throw new IOException(C2803.m4884(C2803.m4889("Invalid local file header for: "), c68232.f19737, ". Uncompressed size has to be set for entry of compression type store which is not a directory"));
            }
            c6800.f19686.reset();
            if (c6822 != null) {
                C6823 c68235 = c6800.f19685;
                c68235.f19731 = c6822.f19731;
                c68235.f19733 = c6822.f19733;
                c68235.f19734 = c6822.f19734;
                c6800.f19688 = true;
            } else {
                c6800.f19688 = false;
            }
            C6823 c68236 = c6800.f19685;
            PushbackInputStream pushbackInputStream2 = c6800.f19681;
            if (C4303.m7074(c68236).equals(EnumC6834.STORE)) {
                j = c68236.f19734;
            } else {
                if (!c68236.f19740 || c6800.f19688) {
                    long j5 = c68236.f19733;
                    int i2 = 12;
                    if (c68236.f19738) {
                        if (c68236.f19739.equals(EnumC6835.AES)) {
                            i2 = 12 + c68236.f19742.f19725.f19816;
                        } else if (!c68236.f19739.equals(EnumC6835.ZIP_STANDARD)) {
                            i2 = 0;
                        }
                        j2 = j5 - ((long) i2);
                    }
                }
                j = j2;
            }
            C6799 c6799 = new C6799(pushbackInputStream2, j);
            AbstractC6790 c6793 = !c68236.f19738 ? new C6793(c6799, c68236, c6800.f19684) : c68236.f19739 == EnumC6835.AES ? new C6789(c6799, c68236, c6800.f19684) : new C6801(c6799, c68236, c6800.f19684);
            c6800.f19682 = C4303.m7074(c68236) == EnumC6834.DEFLATE ? new C6792(c6793) : new C6798(c6793);
            c68233 = c6800.f19685;
        }
        if (c68233 == null) {
            StringBuilder sbM48895 = C2803.m4889("Could not read corresponding local file header for file header: ");
            sbM48895.append(c6822.f19737);
            throw new ZipException(sbM48895.toString());
        }
        if (!c6822.f19737.equals(c68233.f19737)) {
            throw new ZipException("File header and local file header mismatch");
        }
        if (!c6822.f19745) {
            byte[] bArr5 = c6822.f19763;
            if ((bArr5 == null || bArr5.length < 4) ? false : C4303.m7119(bArr5[3], 5)) {
                int i3 = (int) c6822.f19734;
                byte[] bArr6 = new byte[i3];
                if (c6800.read(bArr6) != i3) {
                    throw new ZipException("Could not read complete entry");
                }
                c6837.m9980(i3);
                String str5 = new String(bArr6);
                if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
                    throw new ZipException("Could not create parent directories");
                }
                try {
                    Files.createSymbolicLink(file.toPath(), Paths.get(str5, new String[0]), new FileAttribute[0]);
                    C4303.m7114(c6822, file);
                } catch (NoSuchMethodError unused2) {
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    try {
                        fileOutputStream.write(str5.getBytes());
                        fileOutputStream.close();
                    } finally {
                    }
                }
            } else {
                if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
                    StringBuilder sbM48896 = C2803.m4889("Unable to create parent directories: ");
                    sbM48896.append(file.getParentFile());
                    throw new ZipException(sbM48896.toString());
                }
                try {
                    FileOutputStream fileOutputStream2 = new FileOutputStream(file);
                    while (true) {
                        try {
                            try {
                                int i4 = c6800.read(this.f19873);
                                if (i4 == -1) {
                                    fileOutputStream2.close();
                                    C4303.m7114(c6822, file);
                                    return;
                                } else {
                                    fileOutputStream2.write(this.f19873, 0, i4);
                                    c6837.m9980(i4);
                                    m9992();
                                }
                            } finally {
                            }
                        } catch (Exception e) {
                            e = e;
                            if (file.exists()) {
                                file.delete();
                            }
                            throw e;
                        }
                    }
                } catch (Exception e2) {
                    e = e2;
                }
            }
        } else if (!file.exists() && !file.mkdirs()) {
            throw new ZipException("Could not create directory: " + file);
        }
    }
}
