package p421.p433.p434.p445;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
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.p439.p441.C6810;
import p421.p433.p434.p442.C6820;
import p421.p433.p434.p442.C6822;
import p421.p433.p434.p442.C6826;
import p421.p433.p434.p442.C6828;
import p421.p433.p434.p442.p443.EnumC6836;
import p421.p433.p434.p444.C6837;
import p421.p433.p434.p445.AbstractC6848;

/* JADX INFO: renamed from: ޏ.ؠ.֏.ބ.އ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6854 extends AbstractC6844<C6855> {

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

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

    /* JADX INFO: renamed from: ޏ.ؠ.֏.ބ.އ$֏, reason: contains not printable characters */
    public static class C6855 extends AbstractC6845 {

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public List<String> f19893;

        public C6855(List<String> list, Charset charset) {
            super(charset);
            this.f19893 = list;
        }
    }

    public C6854(C6828 c6828, C6786 c6786, AbstractC6848.C6849 c6849) {
        super(c6849);
        this.f19891 = c6828;
        this.f19892 = c6786;
    }

    @Override // p421.p433.p434.p445.AbstractC6848
    /* JADX INFO: renamed from: ֏ */
    public long mo9990(Object obj) {
        return this.f19891.f19786.length();
    }

    @Override // p421.p433.p434.p445.AbstractC6848
    /* JADX INFO: renamed from: ֏ */
    public C6837.EnumC6840 mo9986() {
        return C6837.EnumC6840.REMOVE_ENTRY;
    }

    @Override // p421.p433.p434.p445.AbstractC6848
    /* JADX INFO: renamed from: ֏ */
    public void mo9991(Object obj, C6837 c6837) throws Throwable {
        C6810 c6810;
        Throwable th;
        RandomAccessFile randomAccessFile;
        boolean z;
        C6855 c6855 = (C6855) obj;
        if (this.f19891.f19784) {
            throw new ZipException("This is a split archive. Zip file format does not allow updating split/spanned files");
        }
        List<String> list = c6855.f19893;
        ArrayList arrayList = new ArrayList();
        for (String str : list) {
            if (C4303.m7073(this.f19891, str) != null) {
                arrayList.add(str);
            }
        }
        if (arrayList.isEmpty()) {
            return;
        }
        String path = this.f19891.f19786.getPath();
        Random random = new Random();
        StringBuilder sbM4889 = C2803.m4889(path);
        sbM4889.append(random.nextInt(10000));
        File file = new File(sbM4889.toString());
        while (file.exists()) {
            StringBuilder sbM48892 = C2803.m4889(path);
            sbM48892.append(random.nextInt(10000));
            file = new File(sbM48892.toString());
        }
        boolean z2 = false;
        boolean z3 = true;
        try {
            c6810 = new C6810(file, -1L);
            try {
                randomAccessFile = new RandomAccessFile(this.f19891.f19786, EnumC6836.READ.f19843);
            } catch (Throwable th2) {
                th = th2;
            }
        } catch (Throwable th3) {
            th = th3;
            z3 = z2;
            m9989(z3, this.f19891.f19786, file);
            throw th;
        }
        try {
            long j = 0;
            for (C6822 c6822 : new ArrayList(this.f19891.f19780.f19746)) {
                C6828 c6828 = this.f19891;
                int iM6991 = C4303.m6991(c6828, c6822);
                List<C6822> list2 = c6828.f19780.f19746;
                long jM9975 = (iM6991 == list2.size() + (-1) ? c6828.f19787 ? c6828.f19783.f19773 : c6828.f19781.f19755 : list2.get(iM6991 + 1).f19764) - c6810.m9975();
                Iterator it = arrayList.iterator();
                while (true) {
                    if (it.hasNext()) {
                        if (c6822.f19737.startsWith((String) it.next())) {
                            z = true;
                            break;
                        }
                    } else {
                        z = false;
                        break;
                    }
                }
                if (z) {
                    m9998(c6822, jM9975);
                    if (!this.f19891.f19780.f19746.remove(c6822)) {
                        throw new ZipException("Could not remove entry from list of central directory headers");
                    }
                    j += jM9975;
                } else {
                    super.m9988(randomAccessFile, c6810, j, jM9975, c6837);
                    j += jM9975;
                }
                m9992();
            }
            this.f19892.m9955(this.f19891, c6810, c6855.f19874);
            try {
                randomAccessFile.close();
                try {
                    c6810.f19700.close();
                    m9989(true, this.f19891.f19786, file);
                } catch (Throwable th4) {
                    th = th4;
                    m9989(z3, this.f19891.f19786, file);
                    throw th;
                }
            } catch (Throwable th5) {
                th = th5;
                z2 = true;
                try {
                    throw th;
                } catch (Throwable th6) {
                    try {
                        c6810.f19700.close();
                        throw th6;
                    } catch (Throwable th7) {
                        th.addSuppressed(th7);
                        throw th6;
                    }
                }
            }
        } finally {
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9998(C6822 c6822, long j) throws ZipException {
        C6826 c6826;
        C6828 c6828 = this.f19891;
        long j2 = ށ.֏(j);
        int iM6991 = C4303.m6991(c6828, c6822);
        if (iM6991 == -1) {
            throw new ZipException("Could not locate modified file header in zipModel");
        }
        List<C6822> list = c6828.f19780.f19746;
        while (true) {
            iM6991++;
            if (iM6991 >= list.size()) {
                break;
            }
            C6822 c68222 = list.get(iM6991);
            c68222.f19764 += j2;
            if (c6828.f19787 && (c6826 = c68222.f19741) != null) {
                long j3 = c6826.f19776;
                if (j3 != -1) {
                    c6826.f19776 = j3 + j2;
                }
            }
        }
        C6820 c6820 = this.f19891.f19781;
        c6820.f19755 -= j;
        c6820.f19754--;
        int i = c6820.f19753;
        if (i > 0) {
            c6820.f19753 = i - 1;
        }
        C6828 c68282 = this.f19891;
        if (c68282.f19787) {
            c68282.f19783.f19773 -= j;
            c68282.f19782.f19768 -= j;
        }
    }
}
