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;

/* renamed from: ˊᵘᵕ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1337 extends ᵢˇᵭ {

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C4348 f5496;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final ᵧˉʙ f5497;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final char[] f5498;

    public C1337(C4348 c4348, char[] cArr, ᵧˉʙ r3, C3718 c3718) {
        super(c3718);
        this.f5496 = c4348;
        this.f5498 = cArr;
        this.f5497 = r3;
    }

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public static C5254 m4127(C5254 c5254, File file, C3944 c3944) throws IOException {
        C5254 c52542 = new C5254(c5254);
        if (file.isDirectory()) {
            c52542.f19682 = 0L;
        } else {
            c52542.f19682 = file.length();
        }
        if (c5254.f19681 <= 0) {
            long jLastModified = file.lastModified();
            if (jLastModified < 0) {
                c52542.f19681 = 0L;
            } else {
                c52542.f19681 = jLastModified;
            }
        }
        c52542.f19672 = false;
        if (!ᵙᵛᵯ.ᵢˇᵭ(c5254.f19676)) {
            c52542.f19676 = AbstractC4618.m9806(file, c5254);
        }
        if (file.isDirectory()) {
            c52542.f19677 = 1;
            c52542.f19684 = 1;
            c52542.f19675 = false;
            return c52542;
        }
        if (c52542.f19675 && c52542.f19684 == 2) {
            c3944.getClass();
            if (!file.exists() || !file.canRead()) {
                C0190.m1425("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);
                    c3944.m8729(i);
                } catch (Throwable th) {
                    try {
                        fileInputStream.close();
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                    throw th;
                }
            }
            long value = crc32.getValue();
            fileInputStream.close();
            c52542.f19683 = value;
        }
        if (file.length() == 0) {
            c52542.f19677 = 1;
        }
        return c52542;
    }

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public final void m4128(C4254 c4254, C4218 c4218, File file, boolean z) throws IOException {
        C4218 c42182;
        boolean z2;
        String string;
        String str;
        C1451 c1451M9204 = c4254.m9204();
        byte[] bArrM9785 = AbstractC4618.m9785(file);
        if (!z) {
            bArrM9785[3] = ᵯᵽᵦ.ᵳᵹᵺˋ(bArrM9785[3], 5);
        }
        c1451M9204.f5867 = bArrM9785;
        ᵧˉʙ r14 = this.f5497;
        C1601 c1601 = (C1601) r14.ᵢˇᵭ;
        byte[] bArr = (byte[]) r14.ᵿʗᵝʽ;
        C4348 c4348 = this.f5496;
        if (c4348 == null) {
            C0190.m1425("invalid input parameters, cannot update local file header");
            return;
        }
        if (c1451M9204.f5866 != c4218.f15810) {
            String parent = c4348.f16271.getParent();
            String strM9804 = AbstractC4618.m9804(c4348.f16271.getName());
            if (parent != null) {
                StringBuilder sbM4096 = AbstractC1327.m4096(parent);
                sbM4096.append(System.getProperty("file.separator"));
                string = sbM4096.toString();
            } else {
                string = "";
            }
            z2 = true;
            if (c1451M9204.f5866 < 9) {
                str = string + strM9804 + ".z0" + (c1451M9204.f5866 + 1);
            } else {
                str = string + strM9804 + ".z" + (c1451M9204.f5866 + 1);
            }
            c42182 = new C4218(new File(str));
        } else {
            c42182 = c4218;
            z2 = false;
        }
        long filePointer = c42182.f15809.getFilePointer();
        c42182.f15809.seek(c1451M9204.f5870 + 14);
        C1601.m4583(c1451M9204.f4030, bArr);
        c42182.write(bArr, 0, 4);
        if (c1451M9204.f4034 >= 4294967295L) {
            C1601.m4583(4294967295L, bArr);
            c42182.write(bArr, 0, 4);
            c42182.write(bArr, 0, 4);
            int i = c1451M9204.f4032 + 8;
            if (c42182.f15809.skipBytes(i) != i) {
                C0190.m1425(AbstractC3915.m8596(i, "Unable to skip ", " bytes to update LFH"));
                return;
            } else {
                c1601.m4585(c42182, c1451M9204.f4034);
                c1601.m4585(c42182, c1451M9204.f4037);
            }
        } else {
            C1601.m4583(c1451M9204.f4037, bArr);
            c42182.write(bArr, 0, 4);
            C1601.m4583(c1451M9204.f4034, bArr);
            c42182.write(bArr, 0, 4);
        }
        if (z2) {
            c42182.close();
        } else {
            c4218.f15809.seek(filePointer);
        }
    }

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final void m4129(File file, C4254 c4254, C5254 c5254, C4218 c4218) throws Throwable {
        C5254 c52542 = new C5254(c5254);
        String str = c5254.f19676;
        String name = file.getName();
        if (str.contains("/")) {
            name = str.substring(0, str.lastIndexOf("/") + 1) + name;
        }
        c52542.f19676 = name;
        c52542.f19675 = false;
        c52542.f19677 = 1;
        c4254.m9203(c52542);
        c4254.write(AbstractC4618.m9800(file).getBytes());
        m4128(c4254, c4218, file, true);
    }

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public final C4254 m4130(C4218 c4218, C2723 c2723) throws IOException {
        C4348 c4348 = this.f5496;
        if (c4348.f16271.exists()) {
            c4218.f15809.seek(c4348.f16270 ? c4348.f16274.f20294 : c4348.f16277.f3553);
        }
        C4254 c4254 = new C4254();
        c4254.f15926 = new ᵼᵫᵧˀ(24);
        c4254.f15930 = new ᵧˉʙ(19);
        c4254.f15928 = new CRC32();
        C1601 c1601 = new C1601(3);
        c4254.f15927 = c1601;
        c4254.f15936 = 0L;
        c4254.f15929 = true;
        if (c2723.f10553 < 512) {
            ᵹˉᵞ.ˌᵜᵹᵩ("Buffer size cannot be less than 512 bytes");
            return null;
        }
        C4277 c4277 = new C4277();
        c4277.f16048 = 0L;
        c4277.f16049 = c4218;
        c4254.f15935 = c4277;
        c4254.f15932 = this.f5498;
        c4254.f15934 = c2723;
        if (c4277.m9261()) {
            c4348.f16272 = true;
            c4348.f16269 = c4277.m9261() ? c4218.f15807 : 0L;
        }
        c4254.f15939 = c4348;
        c4254.f15937 = false;
        if (!c4277.m9261()) {
            return c4254;
        }
        c1601.m4591(c4277, 134695760);
        return c4254;
    }

    /* JADX WARN: Finally extract failed */
    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void m4131(ᵢˇᵭ r17, C3944 c3944) throws IOException {
        C3121 c3121 = (C3121) r17;
        C5254 c5254 = c3121.f11884;
        int i = c5254.f19678;
        int i2 = c5254.f19677;
        if (i2 != 1 && i2 != 2) {
            C0190.m1425("unsupported compression type");
            return;
        }
        if (!c5254.f19675) {
            c5254.f19684 = 1;
        } else {
            if (c5254.f19684 == 1) {
                C0190.m1425("Encryption method has to be set, when encrypt files flag is set");
                return;
            }
            char[] cArr = this.f5498;
            if (cArr == null || cArr.length <= 0) {
                C0190.m1425("input password is empty or null");
                return;
            }
        }
        ArrayList arrayList = new ArrayList();
        for (File file : c3121.f11883) {
            arrayList.add(file);
            if (AbstractC4618.m9783(file) && !AbstractC1327.m4108(1, i)) {
                arrayList.addAll(AbstractC4618.m9809(file, c5254));
            }
        }
        C2723 c2723 = (C2723) ((ᵢˇᵭ) c3121).ᵧᵾˀˈ;
        int size = arrayList.size();
        int i3 = 0;
        while (i3 < size) {
            Object obj = arrayList.get(i3);
            i3++;
            File file2 = (File) obj;
            if (!AbstractC4618.m9783(file2)) {
                if (!file2.exists()) {
                    throw new ZipException("File does not exist: " + file2);
                }
            } else if (AbstractC1327.m4108(i, 3) || AbstractC1327.m4108(i, 2)) {
                if (!file2.exists()) {
                    throw new ZipException("Symlink target '" + AbstractC4618.m9800(file2) + "' does not exist for link '" + file2 + "'");
                }
            }
        }
        byte[] bArr = new byte[c2723.f10553];
        ArrayList arrayList2 = new ArrayList(arrayList);
        C4348 c4348 = this.f5496;
        if (c4348.f16271.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);
                }
                C1451 c1451 = ˉᵜˆ.ᵳٴᵶ(c4348, AbstractC4618.m9806(file3, c5254));
                if (c1451 != null) {
                    if (c5254.f19679) {
                        c3944.getClass();
                        new C0639(c4348, this.f5497, new C3718(c3944)).ᵶᵷᵕ(new C4712(Collections.singletonList(c1451.f4041), c2723));
                        ᵧᵾˀˈ();
                    } else {
                        arrayList2.remove(file3);
                    }
                }
            }
        }
        C4218 c4218 = new C4218(c4348.f16271, c4348.f16269);
        try {
            C4254 c4254M4130 = m4130(c4218, c2723);
            try {
                int size3 = arrayList2.size();
                int i5 = 0;
                while (i5 < size3) {
                    Object obj3 = arrayList2.get(i5);
                    i5++;
                    File file4 = (File) obj3;
                    ᵧᵾˀˈ();
                    C5254 c5254M4127 = m4127(c5254, file4, c3944);
                    int i6 = c5254M4127.f19678;
                    file4.getAbsolutePath();
                    c3944.getClass();
                    if (AbstractC4618.m9783(file4) && (AbstractC1327.m4108(1, i6) || AbstractC1327.m4108(3, i6))) {
                        m4129(file4, c4254M4130, c5254M4127, c4218);
                        if (AbstractC1327.m4108(1, i6)) {
                        }
                    }
                    c4254M4130.m9203(c5254M4127);
                    if (file4.exists() && !file4.isDirectory()) {
                        FileInputStream fileInputStream = new FileInputStream(file4);
                        while (true) {
                            try {
                                int i7 = fileInputStream.read(bArr);
                                if (i7 == -1) {
                                    break;
                                }
                                c4254M4130.write(bArr, 0, i7);
                                c3944.m8729(i7);
                                ᵧᵾˀˈ();
                            } catch (Throwable th) {
                                try {
                                    fileInputStream.close();
                                    throw th;
                                } catch (Throwable th2) {
                                    th.addSuppressed(th2);
                                    throw th;
                                }
                            }
                        }
                        fileInputStream.close();
                    }
                    m4128(c4254M4130, c4218, file4, false);
                }
                c4254M4130.close();
                c4218.close();
            } catch (Throwable th3) {
                try {
                    c4254M4130.close();
                    throw th3;
                } catch (Throwable th4) {
                    th3.addSuppressed(th4);
                    throw th3;
                }
            }
        } finally {
        }
    }
}
