package defpackage;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.zip.CRC32;
import net.lingala.zip4j.exception.ZipException;

/* JADX INFO: renamed from: ˉˁᵺˁ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1161 extends ᵜᵪʾ {

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final char[] f4956;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final C1411 f4957;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public final ᵣˊˈᵪ f4958;

    public C1161(C1411 c1411, char[] cArr, ᵣˊˈᵪ r3, C1014 c1014) {
        super(c1014);
        this.f4957 = c1411;
        this.f4956 = cArr;
        this.f4958 = r3;
    }

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public static C4577 m3640(C4577 c4577, File file, C3442 c3442) throws IOException {
        C4577 c45772 = new C4577(c4577);
        if (file.isDirectory()) {
            c45772.f17403 = 0L;
        } else {
            c45772.f17403 = file.length();
        }
        if (c4577.f17400 <= 0) {
            long jLastModified = file.lastModified();
            if (jLastModified < 0) {
                c45772.f17400 = 0L;
            } else {
                c45772.f17400 = jLastModified;
            }
        }
        c45772.f17399 = false;
        if (!ᵺᵘ.ᵸˆˁ(c4577.f17405)) {
            c45772.f17405 = ˁᵨᵦ.ᵻʽᵯ(file, c4577);
        }
        if (file.isDirectory()) {
            c45772.f17401 = 1;
            c45772.f17404 = 1;
            c45772.f17396 = false;
            return c45772;
        }
        if (c45772.f17396 && c45772.f17404 == 2) {
            c3442.getClass();
            if (!file.exists() || !file.canRead()) {
                C4468.m9508("input file is null or does not exist or cannot read. Cannot calculate CRC for the file");
                return null;
            }
            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);
                    c3442.m7858(i);
                } catch (Throwable th) {
                    try {
                        fileInputStream.close();
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                    throw th;
                }
            }
            long value = crc32.getValue();
            fileInputStream.close();
            c45772.f17394 = value;
        }
        if (file.length() == 0) {
            c45772.f17401 = 1;
        }
        return c45772;
    }

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public final C2075 m3641(C4908 c4908, C3185 c3185) throws IOException {
        C1411 c1411 = this.f4957;
        if (c1411.f5820.exists()) {
            c4908.f18681.seek(c1411.f5826 ? c1411.f5824.f15827 : c1411.f5821.f8261);
        }
        C2075 c2075 = new C2075();
        c2075.f8220 = new ᵱᵻᵧᵷ();
        c2075.f8223 = new ᵣˊˈᵪ(19);
        c2075.f8231 = new CRC32();
        C2994 c2994 = new C2994(3);
        c2075.f8224 = c2994;
        c2075.f8218 = 0L;
        c2075.f8219 = true;
        if (c3185.f12092 < 512) {
            ᵕᵩʽᵲ.ᵮᵣᵗˈ("Buffer size cannot be less than 512 bytes");
            return null;
        }
        C2962 c2962 = new C2962();
        c2962.f11395 = 0L;
        c2962.f11394 = c4908;
        c2075.f8222 = c2962;
        c2075.f8226 = this.f4956;
        c2075.f8227 = c3185;
        if (c2962.m7055()) {
            c1411.f5825 = true;
            c1411.f5818 = c2962.m7055() ? c4908.f18683 : 0L;
        }
        c2075.f8225 = c1411;
        c2075.f8221 = false;
        if (!c2962.m7055()) {
            return c2075;
        }
        c2994.m7081(c2962, 134695760);
        return c2075;
    }

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final void m3642(File file, C2075 c2075, C4577 c4577, C4908 c4908) throws Throwable {
        C4577 c45772 = new C4577(c4577);
        String str = c4577.f17405;
        String name = file.getName();
        if (str.contains("/")) {
            name = str.substring(0, str.lastIndexOf("/") + 1) + name;
        }
        c45772.f17405 = name;
        c45772.f17396 = false;
        c45772.f17401 = 1;
        c2075.m5531(c45772);
        c2075.write(ˁᵨᵦ.ˉᵲ(file).getBytes());
        m3643(c2075, c4908, file, true);
    }

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public final void m3643(C2075 c2075, C4908 c4908, File file, boolean z) throws IOException {
        C4908 c49082;
        boolean z2;
        String string;
        String str;
        C1543 c1543M5532 = c2075.m5532();
        byte[] bArr = ˁᵨᵦ.ᵻˈᵦʼ(file);
        if (!z) {
            bArr[3] = AbstractC3481.m7920(bArr[3], 5);
        }
        c1543M5532.f6211 = bArr;
        ᵣˊˈᵪ r14 = this.f4958;
        C2994 c2994 = (C2994) r14.ᵜᵪʾ;
        byte[] bArr2 = (byte[]) r14.ᵔᵖᵹᵫ;
        C1411 c1411 = this.f4957;
        if (c1411 == null) {
            C4468.m9508("invalid input parameters, cannot update local file header");
            return;
        }
        if (c1543M5532.f6208 != c4908.f18684) {
            String parent = c1411.f5820.getParent();
            String str2 = ˁᵨᵦ.ᵝᵶ(c1411.f5820.getName());
            if (parent != null) {
                StringBuilder sbM8219 = AbstractC3653.m8219(parent);
                sbM8219.append(System.getProperty("file.separator"));
                string = sbM8219.toString();
            } else {
                string = "";
            }
            z2 = true;
            if (c1543M5532.f6208 < 9) {
                str = string + str2 + ".z0" + (c1543M5532.f6208 + 1);
            } else {
                str = string + str2 + ".z" + (c1543M5532.f6208 + 1);
            }
            c49082 = new C4908(new File(str));
        } else {
            c49082 = c4908;
            z2 = false;
        }
        long filePointer = c49082.f18681.getFilePointer();
        c49082.f18681.seek(c1543M5532.f6210 + 14);
        C2994.m7075(c1543M5532.f15134, bArr2);
        c49082.write(bArr2, 0, 4);
        if (c1543M5532.f15148 >= 4294967295L) {
            C2994.m7075(4294967295L, bArr2);
            c49082.write(bArr2, 0, 4);
            c49082.write(bArr2, 0, 4);
            int i = c1543M5532.f15140 + 8;
            if (c49082.f18681.skipBytes(i) != i) {
                C4468.m9508(AbstractC0793.m2876(i, "Unable to skip ", " bytes to update LFH"));
                return;
            } else {
                c2994.m7080(c49082, c1543M5532.f15148);
                c2994.m7080(c49082, c1543M5532.f15138);
            }
        } else {
            C2994.m7075(c1543M5532.f15138, bArr2);
            c49082.write(bArr2, 0, 4);
            C2994.m7075(c1543M5532.f15148, bArr2);
            c49082.write(bArr2, 0, 4);
        }
        if (z2) {
            c49082.close();
        } else {
            c4908.f18681.seek(filePointer);
        }
    }

    /* JADX WARN: Finally extract failed */
    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final void m3644(ᵜᵪʾ r17, C3442 c3442) throws IOException {
        C0503 c0503 = (C0503) r17;
        C4577 c4577 = c0503.f2633;
        int i = c4577.f17395;
        int i2 = c4577.f17401;
        if (i2 != 1 && i2 != 2) {
            C4468.m9508("unsupported compression type");
            return;
        }
        if (!c4577.f17396) {
            c4577.f17404 = 1;
        } else {
            if (c4577.f17404 == 1) {
                C4468.m9508("Encryption method has to be set, when encrypt files flag is set");
                return;
            }
            char[] cArr = this.f4956;
            if (cArr == null || cArr.length <= 0) {
                C4468.m9508("input password is empty or null");
                return;
            }
        }
        ArrayList arrayList = new ArrayList();
        for (File file : c0503.f2634) {
            arrayList.add(file);
            if (ˁᵨᵦ.ˋˈ(file) && !AbstractC3653.m8217(1, i)) {
                arrayList.addAll(ˁᵨᵦ.ᵵᵽ(file, c4577));
            }
        }
        C3185 c3185 = (C3185) ((ᵜᵪʾ) c0503).ˌᴵ;
        int size = arrayList.size();
        int i3 = 0;
        while (i3 < size) {
            Object obj = arrayList.get(i3);
            i3++;
            File file2 = (File) obj;
            if (!ˁᵨᵦ.ˋˈ(file2)) {
                if (!file2.exists()) {
                    throw new ZipException("File does not exist: " + file2);
                }
            } else if (AbstractC3653.m8217(i, 3) || AbstractC3653.m8217(i, 2)) {
                if (!file2.exists()) {
                    throw new ZipException("Symlink target '" + ˁᵨᵦ.ˉᵲ(file2) + "' does not exist for link '" + file2 + "'");
                }
            }
        }
        byte[] bArr = new byte[c3185.f12092];
        ArrayList arrayList2 = new ArrayList(arrayList);
        C1411 c1411 = this.f4957;
        if (c1411.f5820.exists()) {
            int size2 = arrayList.size();
            int i4 = 0;
            while (i4 < size2) {
                Object obj2 = arrayList.get(i4);
                i4++;
                File file3 = (File) obj2;
                if (!ᵺᵘ.ᵸˆˁ(file3.getName())) {
                    arrayList2.remove(file3);
                }
                C1543 c1543 = ᵬʕˎʽ.ᵪᵹᵥᵻ(c1411, ˁᵨᵦ.ᵻʽᵯ(file3, c4577));
                if (c1543 != null) {
                    if (c4577.f17397) {
                        c3442.getClass();
                        new C1852(c1411, this.f4958, new C1014(c3442)).ᵱᵽʡᵚ(new C0835(Collections.singletonList(c1543.f15143), c3185));
                        ˌᴵ();
                    } else {
                        arrayList2.remove(file3);
                    }
                }
            }
        }
        C4908 c4908 = new C4908(c1411.f5820, c1411.f5818);
        try {
            C2075 c2075M3641 = m3641(c4908, c3185);
            try {
                int size3 = arrayList2.size();
                int i5 = 0;
                while (i5 < size3) {
                    Object obj3 = arrayList2.get(i5);
                    i5++;
                    File file4 = (File) obj3;
                    ˌᴵ();
                    C4577 c4577M3640 = m3640(c4577, file4, c3442);
                    int i6 = c4577M3640.f17395;
                    file4.getAbsolutePath();
                    c3442.getClass();
                    if (ˁᵨᵦ.ˋˈ(file4) && (AbstractC3653.m8217(1, i6) || AbstractC3653.m8217(3, i6))) {
                        m3642(file4, c2075M3641, c4577M3640, c4908);
                        if (AbstractC3653.m8217(1, i6)) {
                        }
                    }
                    c2075M3641.m5531(c4577M3640);
                    if (file4.exists() && !file4.isDirectory()) {
                        FileInputStream fileInputStream = new FileInputStream(file4);
                        while (true) {
                            try {
                                int i7 = fileInputStream.read(bArr);
                                if (i7 == -1) {
                                    break;
                                }
                                c2075M3641.write(bArr, 0, i7);
                                c3442.m7858(i7);
                                ˌᴵ();
                            } catch (Throwable th) {
                                try {
                                    fileInputStream.close();
                                    throw th;
                                } catch (Throwable th2) {
                                    th.addSuppressed(th2);
                                    throw th;
                                }
                            }
                        }
                        fileInputStream.close();
                    }
                    m3643(c2075M3641, c4908, file4, false);
                }
                c2075M3641.close();
                c4908.close();
            } catch (Throwable th3) {
                try {
                    c2075M3641.close();
                    throw th3;
                } catch (Throwable th4) {
                    th3.addSuppressed(th4);
                    throw th3;
                }
            }
        } finally {
        }
    }
}
