package d.e.c.a;

import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/* JADX INFO: compiled from: ZipUtils.java */
/* JADX INFO: loaded from: classes.dex */
public final class d {
    private static final String a = "d";

    private static void a(String str, String str2) {
        String str3;
        if (str.lastIndexOf(47) > 0 || str.lastIndexOf(92) > 0) {
            if (str2.endsWith(File.separator)) {
                str3 = str2 + str.substring(0, str.lastIndexOf(47));
            } else {
                str3 = str2 + File.separator + str.substring(0, str.lastIndexOf(47));
            }
            a.d(str3);
        }
    }

    public static void b(String str, String str2) throws Throwable {
        d(str, str2, false);
    }

    private static void c(String str, String str2, BufferedInputStream bufferedInputStream, boolean z) throws Throwable {
        Log.d(a, "Creating decompress file - " + str);
        if (z) {
            a(str, str2);
        }
        FileOutputStream fileOutputStream = null;
        try {
            FileOutputStream fileOutputStream2 = new FileOutputStream(str2 + File.separator + str);
            try {
                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream2);
                byte[] bArr = new byte[10240];
                int i2 = bufferedInputStream.read(bArr);
                while (i2 != -1) {
                    bufferedOutputStream.write(bArr, 0, i2);
                    i2 = bufferedInputStream.read(bArr);
                }
                bufferedOutputStream.close();
                fileOutputStream2.close();
            } catch (Throwable th) {
                th = th;
                fileOutputStream = fileOutputStream2;
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    private static void d(String str, String str2, boolean z) throws Throwable {
        FileInputStream fileInputStream;
        Log.d(a, "Start reading archive file...");
        FileInputStream fileInputStream2 = null;
        try {
            fileInputStream = new FileInputStream(str);
        } catch (Throwable th) {
            th = th;
        }
        try {
            CheckedInputStream checkedInputStream = new CheckedInputStream(fileInputStream, new CRC32());
            ZipInputStream zipInputStream = new ZipInputStream(checkedInputStream);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(zipInputStream);
            while (true) {
                ZipEntry nextEntry = zipInputStream.getNextEntry();
                if (nextEntry == null) {
                    bufferedInputStream.close();
                    Log.d(a, "Checksum: " + checkedInputStream.getChecksum().getValue());
                    fileInputStream.close();
                    return;
                }
                String name = nextEntry.getName();
                Log.d(a, "get entry name: " + nextEntry.getName());
                if (nextEntry.isDirectory()) {
                    Log.d(a, "Creating decompress dir - " + name);
                    File file = new File(str2 + File.separator + name);
                    if (!file.exists()) {
                        file.mkdirs();
                    }
                } else {
                    c(name, str2, bufferedInputStream, z);
                }
            }
        } catch (Throwable th2) {
            th = th2;
            fileInputStream2 = fileInputStream;
            if (fileInputStream2 != null) {
                fileInputStream2.close();
            }
            throw th;
        }
    }
}
