package p421.p433.p434;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import net.lingala.zip4j.exception.ZipException;
import p138.p176.p177.p242.p246.p251.C4303;
import p421.p433.p434.p438.C6784;
import p421.p433.p434.p438.C6786;
import p421.p433.p434.p439.p440.C6796;
import p421.p433.p434.p442.C6828;
import p421.p433.p434.p442.C6829;
import p421.p433.p434.p442.p443.EnumC6836;
import p421.p433.p434.p444.C6837;
import p421.p433.p434.p445.AbstractC6848;
import p421.p433.p434.p445.C6846;
import p421.p433.p434.p445.C6850;
import p421.p433.p434.p446.C6858;

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public File f19564;

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

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

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public ThreadFactory f19571;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public ExecutorService f19572;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public C6786 f19569 = new C6786();

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public Charset f19570 = C6858.f19896;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public boolean f19567 = false;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public C6837 f19566 = new C6837();

    public C6771(File file, char[] cArr) {
        this.f19564 = file;
        this.f19568 = cArr;
    }

    public String toString() {
        return this.f19564.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final AbstractC6848.C6849 m9927() {
        if (this.f19567) {
            if (this.f19571 == null) {
                this.f19571 = Executors.defaultThreadFactory();
            }
            this.f19572 = Executors.newSingleThreadExecutor(this.f19571);
        }
        return new AbstractC6848.C6849(this.f19572, this.f19567, this.f19566);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9928(File file, C6829 c6829) throws ZipException {
        List<File> listSingletonList = Collections.singletonList(file);
        if (listSingletonList == null || listSingletonList.size() == 0) {
            throw new ZipException("input file List is null or empty");
        }
        if (c6829 == null) {
            throw new ZipException("input parameters are null");
        }
        if (this.f19566.f19844 == C6837.EnumC6839.BUSY) {
            throw new ZipException("invalid operation - Zip4j is in busy state");
        }
        for (File file2 : listSingletonList) {
            if (!file2.exists()) {
                throw new ZipException("File does not exist: " + file2);
            }
        }
        m9931();
        if (this.f19565 == null) {
            throw new ZipException("internal error: zip model is null");
        }
        if (this.f19564.exists() && this.f19565.f19784) {
            throw new ZipException("Zip file already exists. Zip file format does not allow updating split/spanned files");
        }
        new C6846(this.f19565, this.f19568, this.f19569, m9927()).m9993(new C6846.C6847(listSingletonList, c6829, this.f19570));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9929(String str) throws ZipException {
        if (!C4303.m7202(str)) {
            throw new ZipException("output path is null or invalid");
        }
        File file = new File(str);
        if (file.exists()) {
            if (!file.isDirectory()) {
                throw new ZipException("output directory is not valid");
            }
        } else if (!file.mkdirs()) {
            throw new ZipException("Cannot create output directories");
        }
        if (this.f19565 == null) {
            m9931();
        }
        C6828 c6828 = this.f19565;
        if (c6828 == null) {
            throw new ZipException("Internal error occurred when extracting zip file");
        }
        if (this.f19566.f19844 == C6837.EnumC6839.BUSY) {
            throw new ZipException("invalid operation - Zip4j is in busy state");
        }
        new C6850(c6828, this.f19568, m9927()).m9993(new C6850.C6851(str, this.f19570));
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final RandomAccessFile m9930() throws IOException {
        if (!this.f19564.getName().endsWith(".zip.001")) {
            return new RandomAccessFile(this.f19564, EnumC6836.READ.f19843);
        }
        File file = this.f19564;
        final String name = file.getName();
        int iLastIndexOf = name.lastIndexOf(".");
        if (iLastIndexOf != -1) {
            name = name.substring(0, iLastIndexOf);
        }
        File[] fileArrListFiles = file.getParentFile().listFiles(new FilenameFilter() { // from class: ޏ.ؠ.֏.ޅ.֏
            @Override // java.io.FilenameFilter
            public final boolean accept(File file2, String str) {
                return str.startsWith(name + ".");
            }
        });
        if (fileArrListFiles == null) {
            fileArrListFiles = new File[0];
        } else {
            Arrays.sort(fileArrListFiles);
        }
        C6796 c6796 = new C6796(this.f19564, EnumC6836.READ.f19843, fileArrListFiles);
        c6796.m9964(c6796.f19667.length - 1);
        return c6796;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final void m9931() throws ZipException {
        if (this.f19565 != null) {
            return;
        }
        if (!this.f19564.exists()) {
            C6828 c6828 = new C6828();
            this.f19565 = c6828;
            c6828.f19786 = this.f19564;
        } else {
            if (!this.f19564.canRead()) {
                throw new ZipException("no read access for the input zip file");
            }
            try {
                RandomAccessFile randomAccessFileM9930 = m9930();
                try {
                    C6828 c6828M9946 = new C6784().m9946(randomAccessFileM9930, this.f19570);
                    this.f19565 = c6828M9946;
                    c6828M9946.f19786 = this.f19564;
                    randomAccessFileM9930.close();
                } finally {
                }
            } catch (ZipException e) {
                throw e;
            } catch (IOException e2) {
                throw new ZipException(e2);
            }
        }
    }
}
