package p421.p433.p434.p438;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.List;
import net.lingala.zip4j.exception.ZipException;
import p138.p176.p177.p242.p246.p251.C4303;
import p421.p433.p434.p439.p441.C6806;
import p421.p433.p434.p439.p441.C6810;
import p421.p433.p434.p442.C6815;
import p421.p433.p434.p442.C6817;
import p421.p433.p434.p442.C6820;
import p421.p433.p434.p442.C6821;
import p421.p433.p434.p442.C6822;
import p421.p433.p434.p442.C6824;
import p421.p433.p434.p442.C6825;
import p421.p433.p434.p442.C6828;
import p421.p433.p434.p446.C6859;

/* JADX INFO: renamed from: ޏ.ؠ.֏.ހ.ށ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6786 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C6859 f19632 = new C6859();

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public byte[] f19633 = new byte[8];

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public byte[] f19634 = new byte[4];

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final long m9948(List<C6822> list, int i) throws ZipException {
        if (list == null) {
            throw new ZipException("file headers are null, cannot calculate number of entries on this disk");
        }
        int i2 = 0;
        Iterator<C6822> it = list.iterator();
        while (it.hasNext()) {
            if (it.next().f19762 == i) {
                i2++;
            }
        }
        return i2;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9949(C6822 c6822, OutputStream outputStream) throws IOException {
        byte[] bArr;
        List<C6821> list = c6822.f19744;
        if (list == null || list.size() == 0) {
            return;
        }
        for (C6821 c6821 : c6822.f19744) {
            long j = c6821.f19758;
            if (j != EnumC6785.AES_EXTRA_DATA_RECORD.f19631 && j != EnumC6785.ZIP64_EXTRA_FIELD_SIGNATURE.f19631) {
                this.f19632.m10018(outputStream, (int) j);
                this.f19632.m10018(outputStream, c6821.f19759);
                if (c6821.f19759 > 0 && (bArr = c6821.f19760) != null) {
                    outputStream.write(bArr);
                }
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9950(C6828 c6828, int i, long j, ByteArrayOutputStream byteArrayOutputStream, C6859 c6859) throws IOException {
        List<C6822> list;
        byte[] bArr = {0, 0};
        c6859.m10015(c6859.f19898, 0, (int) EnumC6785.ZIP64_END_CENTRAL_DIRECTORY_RECORD.f19631);
        byteArrayOutputStream.write(c6859.f19898);
        c6859.m10016(c6859.f19899, 0, 44L);
        byteArrayOutputStream.write(c6859.f19899);
        C6817 c6817 = c6828.f19780;
        if (c6817 == null || (list = c6817.f19746) == null || list.size() <= 0) {
            byteArrayOutputStream.write(bArr);
            byteArrayOutputStream.write(bArr);
        } else {
            c6859.m10018(byteArrayOutputStream, c6828.f19780.f19746.get(0).f19761);
            c6859.m10018(byteArrayOutputStream, c6828.f19780.f19746.get(0).f19727);
        }
        c6859.m10015(c6859.f19898, 0, c6828.f19781.f19751);
        byteArrayOutputStream.write(c6859.f19898);
        c6859.m10015(c6859.f19898, 0, c6828.f19781.f19752);
        byteArrayOutputStream.write(c6859.f19898);
        long size = c6828.f19780.f19746.size();
        c6859.m10016(c6859.f19899, 0, c6828.f19784 ? m9948(c6828.f19780.f19746, c6828.f19781.f19751) : size);
        byteArrayOutputStream.write(c6859.f19899);
        c6859.m10016(c6859.f19899, 0, size);
        byteArrayOutputStream.write(c6859.f19899);
        c6859.m10016(c6859.f19899, 0, i);
        byteArrayOutputStream.write(c6859.f19899);
        c6859.m10016(c6859.f19899, 0, j);
        byteArrayOutputStream.write(c6859.f19899);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9951(C6828 c6828, int i, long j, ByteArrayOutputStream byteArrayOutputStream, C6859 c6859, Charset charset) throws IOException {
        byte[] bArr = new byte[8];
        c6859.m10015(c6859.f19898, 0, (int) EnumC6785.END_OF_CENTRAL_DIRECTORY.f19631);
        byteArrayOutputStream.write(c6859.f19898);
        c6859.m10018(byteArrayOutputStream, c6828.f19781.f19751);
        c6859.m10018(byteArrayOutputStream, c6828.f19781.f19752);
        long size = c6828.f19780.f19746.size();
        long jM9948 = c6828.f19784 ? m9948(c6828.f19780.f19746, c6828.f19781.f19751) : size;
        if (jM9948 > 65535) {
            jM9948 = 65535;
        }
        c6859.m10018(byteArrayOutputStream, (int) jM9948);
        if (size > 65535) {
            size = 65535;
        }
        c6859.m10018(byteArrayOutputStream, (int) size);
        c6859.m10015(c6859.f19898, 0, i);
        byteArrayOutputStream.write(c6859.f19898);
        if (j > 4294967295L) {
            c6859.m10016(bArr, 0, 4294967295L);
            byteArrayOutputStream.write(bArr, 0, 4);
        } else {
            c6859.m10016(bArr, 0, j);
            byteArrayOutputStream.write(bArr, 0, 4);
        }
        String str = c6828.f19781.f19757;
        if (!C4303.m7202(str)) {
            c6859.m10018(byteArrayOutputStream, 0);
            return;
        }
        byte[] bytes = str.getBytes(charset);
        c6859.m10018(byteArrayOutputStream, bytes.length);
        byteArrayOutputStream.write(bytes);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9952(C6828 c6828, ByteArrayOutputStream byteArrayOutputStream, C6859 c6859) throws IOException {
        c6859.m10015(c6859.f19898, 0, (int) EnumC6785.ZIP64_END_CENTRAL_DIRECTORY_LOCATOR.f19631);
        byteArrayOutputStream.write(c6859.f19898);
        c6859.m10015(c6859.f19898, 0, c6828.f19782.f19767);
        byteArrayOutputStream.write(c6859.f19898);
        c6859.m10016(c6859.f19899, 0, c6828.f19782.f19768);
        byteArrayOutputStream.write(c6859.f19899);
        c6859.m10015(c6859.f19898, 0, c6828.f19782.f19769);
        byteArrayOutputStream.write(c6859.f19898);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9953(C6828 c6828, ByteArrayOutputStream byteArrayOutputStream, C6859 c6859, Charset charset) throws ZipException {
        List<C6822> list;
        boolean z;
        byte[] bArr;
        C6817 c6817 = c6828.f19780;
        if (c6817 == null || (list = c6817.f19746) == null || list.size() <= 0) {
            return;
        }
        for (C6822 c6822 : c6828.f19780.f19746) {
            if (c6822 == null) {
                throw new ZipException("input parameters is null, cannot write local file header");
            }
            try {
                byte[] bArr2 = {0, 0};
                boolean z2 = c6822.f19733 >= 4294967295L || c6822.f19734 >= 4294967295L || c6822.f19764 >= 4294967295L || c6822.f19762 >= 65535;
                c6859.m10015(c6859.f19898, 0, (int) c6822.f19778.f19631);
                byteArrayOutputStream.write(c6859.f19898);
                c6859.m10018(byteArrayOutputStream, c6822.f19761);
                c6859.m10018(byteArrayOutputStream, c6822.f19727);
                byteArrayOutputStream.write(c6822.f19728);
                c6859.m10018(byteArrayOutputStream, c6822.f19729.f19834);
                c6859.m10016(this.f19633, 0, c6822.f19730);
                byteArrayOutputStream.write(this.f19633, 0, 4);
                c6859.m10016(this.f19633, 0, c6822.f19731);
                byteArrayOutputStream.write(this.f19633, 0, 4);
                if (z2) {
                    c6859.m10016(this.f19633, 0, 4294967295L);
                    byteArrayOutputStream.write(this.f19633, 0, 4);
                    byteArrayOutputStream.write(this.f19633, 0, 4);
                    c6828.f19787 = true;
                } else {
                    c6859.m10016(this.f19633, 0, c6822.f19733);
                    byteArrayOutputStream.write(this.f19633, 0, 4);
                    c6859.m10016(this.f19633, 0, c6822.f19734);
                    byteArrayOutputStream.write(this.f19633, 0, 4);
                }
                byte[] bytes = new byte[0];
                if (C4303.m7202(c6822.f19737)) {
                    bytes = c6822.f19737.getBytes(charset);
                }
                c6859.m10018(byteArrayOutputStream, bytes.length);
                byte[] bArr3 = new byte[4];
                if (z2) {
                    z = z2;
                    c6859.m10016(this.f19633, 0, 4294967295L);
                    System.arraycopy(this.f19633, 0, bArr3, 0, 4);
                    bArr = bArr3;
                } else {
                    z = z2;
                    c6859.m10016(this.f19633, 0, c6822.f19764);
                    bArr = bArr3;
                    System.arraycopy(this.f19633, 0, bArr, 0, 4);
                }
                int i = z ? 32 : 0;
                if (c6822.f19742 != null) {
                    i += 11;
                }
                List<C6821> list2 = c6822.f19744;
                if (list2 != null) {
                    for (C6821 c6821 : list2) {
                        byte[] bArr4 = bArr;
                        long j = c6821.f19758;
                        int i2 = i;
                        i = (j == EnumC6785.AES_EXTRA_DATA_RECORD.f19631 || j == EnumC6785.ZIP64_EXTRA_FIELD_SIGNATURE.f19631) ? i2 : c6821.f19759 + 4 + i2;
                        bArr = bArr4;
                    }
                }
                byte[] bArr5 = bArr;
                c6859.m10018(byteArrayOutputStream, i);
                String str = c6822.f19765;
                byte[] bytes2 = new byte[0];
                if (C4303.m7202(str)) {
                    bytes2 = str.getBytes(charset);
                }
                c6859.m10018(byteArrayOutputStream, bytes2.length);
                if (z) {
                    c6859.m10015(this.f19634, 0, 65535);
                    byteArrayOutputStream.write(this.f19634, 0, 2);
                } else {
                    c6859.m10018(byteArrayOutputStream, c6822.f19762);
                }
                byteArrayOutputStream.write(bArr2);
                byteArrayOutputStream.write(c6822.f19763);
                byteArrayOutputStream.write(bArr5);
                if (bytes.length > 0) {
                    byteArrayOutputStream.write(bytes);
                }
                if (z) {
                    c6828.f19787 = true;
                    c6859.m10018(byteArrayOutputStream, (int) EnumC6785.ZIP64_EXTRA_FIELD_SIGNATURE.f19631);
                    c6859.m10018(byteArrayOutputStream, 28);
                    c6859.m10016(c6859.f19899, 0, c6822.f19734);
                    byteArrayOutputStream.write(c6859.f19899);
                    c6859.m10016(c6859.f19899, 0, c6822.f19733);
                    byteArrayOutputStream.write(c6859.f19899);
                    c6859.m10016(c6859.f19899, 0, c6822.f19764);
                    byteArrayOutputStream.write(c6859.f19899);
                    c6859.m10015(c6859.f19898, 0, c6822.f19762);
                    byteArrayOutputStream.write(c6859.f19898);
                }
                if (c6822.f19742 != null) {
                    C6815 c6815 = c6822.f19742;
                    c6859.m10018(byteArrayOutputStream, (int) c6815.f19778.f19631);
                    c6859.m10018(byteArrayOutputStream, c6815.f19722);
                    c6859.m10018(byteArrayOutputStream, c6815.f19723.f19822);
                    byteArrayOutputStream.write(c6815.f19724.getBytes());
                    byteArrayOutputStream.write(new byte[]{(byte) c6815.f19725.f19815});
                    c6859.m10018(byteArrayOutputStream, c6815.f19726.f19834);
                }
                m9949(c6822, byteArrayOutputStream);
                if (bytes2.length > 0) {
                    byteArrayOutputStream.write(bytes2);
                }
            } catch (Exception e) {
                throw new ZipException(e);
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9954(C6828 c6828, OutputStream outputStream) {
        int iM9972;
        if (outputStream instanceof C6806) {
            C6820 c6820 = c6828.f19781;
            C6806 c6806 = (C6806) outputStream;
            OutputStream outputStream2 = c6806.f19696;
            c6820.f19755 = outputStream2 instanceof C6810 ? ((C6810) outputStream2).m9975() : c6806.f19697;
            iM9972 = c6806.m9972();
        } else {
            iM9972 = 0;
        }
        if (c6828.f19787) {
            if (c6828.f19783 == null) {
                c6828.f19783 = new C6825();
            }
            if (c6828.f19782 == null) {
                c6828.f19782 = new C6824();
            }
            C6824 c6824 = c6828.f19782;
            c6824.f19767 = iM9972;
            c6824.f19769 = iM9972 + 1;
        }
        C6820 c68202 = c6828.f19781;
        c68202.f19751 = iM9972;
        c68202.f19752 = iM9972;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x001d A[Catch: all -> 0x00c9, TryCatch #1 {all -> 0x00c9, blocks: (B:5:0x0009, B:7:0x0012, B:9:0x0016, B:13:0x0021, B:17:0x0038, B:42:0x00b3, B:19:0x0045, B:21:0x0049, B:22:0x0050, B:24:0x0054, B:25:0x005b, B:27:0x0067, B:35:0x0081, B:37:0x0085, B:39:0x0092, B:41:0x00a4, B:38:0x008b, B:40:0x009c, B:31:0x0074, B:33:0x0078, B:12:0x001d), top: B:57:0x0009 }] */
    /* JADX WARN: Removed duplicated region for block: B:30:0x0072  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0081 A[Catch: all -> 0x00c9, TryCatch #1 {all -> 0x00c9, blocks: (B:5:0x0009, B:7:0x0012, B:9:0x0016, B:13:0x0021, B:17:0x0038, B:42:0x00b3, B:19:0x0045, B:21:0x0049, B:22:0x0050, B:24:0x0054, B:25:0x005b, B:27:0x0067, B:35:0x0081, B:37:0x0085, B:39:0x0092, B:41:0x00a4, B:38:0x008b, B:40:0x009c, B:31:0x0074, B:33:0x0078, B:12:0x001d), top: B:57:0x0009 }] */
    /* JADX WARN: Removed duplicated region for block: B:40:0x009c A[Catch: all -> 0x00c9, TryCatch #1 {all -> 0x00c9, blocks: (B:5:0x0009, B:7:0x0012, B:9:0x0016, B:13:0x0021, B:17:0x0038, B:42:0x00b3, B:19:0x0045, B:21:0x0049, B:22:0x0050, B:24:0x0054, B:25:0x005b, B:27:0x0067, B:35:0x0081, B:37:0x0085, B:39:0x0092, B:41:0x00a4, B:38:0x008b, B:40:0x009c, B:31:0x0074, B:33:0x0078, B:12:0x001d), top: B:57:0x0009 }] */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void m9955(C6828 c6828, OutputStream outputStream, Charset charset) throws IOException {
        long j;
        boolean zM9973;
        C6825 c6825;
        if (c6828 == null || outputStream == null) {
            throw new ZipException("input parameters is null, cannot finalize zip file");
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            m9954(c6828, outputStream);
            if (!c6828.f19787 || (c6825 = c6828.f19783) == null) {
                j = c6828.f19781.f19755;
            } else {
                j = c6825.f19773;
                if (j != -1) {
                }
            }
            long j2 = j;
            m9953(c6828, byteArrayOutputStream, this.f19632, charset);
            int size = byteArrayOutputStream.size();
            if (c6828.f19787 || j2 >= 4294967295L || c6828.f19780.f19746.size() >= 65535) {
                if (c6828.f19783 == null) {
                    c6828.f19783 = new C6825();
                }
                if (c6828.f19782 == null) {
                    c6828.f19782 = new C6824();
                }
                c6828.f19782.f19768 = ((long) size) + j2;
                if (outputStream instanceof C6810) {
                    zM9973 = ((C6810) outputStream).f19701 != -1;
                    if (zM9973) {
                        c6828.f19782.f19767 = 0;
                        c6828.f19782.f19769 = 1;
                    } else {
                        int iM9972 = outputStream instanceof C6810 ? ((C6810) outputStream).f19703 : ((C6806) outputStream).m9972();
                        c6828.f19782.f19767 = iM9972;
                        c6828.f19782.f19769 = iM9972 + 1;
                    }
                    m9950(c6828, size, j2, byteArrayOutputStream, this.f19632);
                    m9952(c6828, byteArrayOutputStream, this.f19632);
                } else {
                    if (outputStream instanceof C6806) {
                        zM9973 = ((C6806) outputStream).m9973();
                    }
                    if (zM9973) {
                    }
                    m9950(c6828, size, j2, byteArrayOutputStream, this.f19632);
                    m9952(c6828, byteArrayOutputStream, this.f19632);
                }
            }
            m9951(c6828, size, j2, byteArrayOutputStream, this.f19632, charset);
            m9956(c6828, outputStream, byteArrayOutputStream.toByteArray(), charset);
            byteArrayOutputStream.close();
        } catch (Throwable th) {
            try {
                throw th;
            } catch (Throwable th2) {
                try {
                    byteArrayOutputStream.close();
                } catch (Throwable th3) {
                    th.addSuppressed(th3);
                }
                throw th2;
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9956(C6828 c6828, OutputStream outputStream, byte[] bArr, Charset charset) throws IOException {
        if (bArr == null) {
            throw new ZipException("invalid buff to write as zip headers");
        }
        if (outputStream instanceof C6806) {
            C6806 c6806 = (C6806) outputStream;
            int length = bArr.length;
            boolean z = false;
            if (c6806.m9973()) {
                C6810 c6810 = (C6810) c6806.f19696;
                if (c6810 == null) {
                    throw null;
                }
                if (length < 0) {
                    throw new ZipException("negative buffersize for checkBufferSizeAndStartNextSplitFile");
                }
                long j = c6810.f19701;
                if (!(j < 65536 || c6810.f19704 + ((long) length) <= j)) {
                    try {
                        c6810.m9976();
                        c6810.f19704 = 0L;
                        z = true;
                    } catch (IOException e) {
                        throw new ZipException(e);
                    }
                }
            }
            if (z) {
                m9955(c6828, outputStream, charset);
                return;
            }
        }
        outputStream.write(bArr);
    }
}
