package com.cvte.udi.utils;

import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

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

    private static void unzip(ZipEntry zipEntry, ZipFile zipFile, String str) throws Throwable {
        FileOutputStream fileOutputStream;
        InputStream inputStream = null;
        try {
            InputStream inputStream2 = zipFile.getInputStream(zipEntry);
            try {
                fileOutputStream = new FileOutputStream(new File(str));
                try {
                    CommonUtils.copyStream(inputStream2, fileOutputStream);
                    CommonUtils.safeClose(inputStream2);
                } catch (IOException unused) {
                    inputStream = inputStream2;
                    try {
                        Log.e(TAG, "unzip to " + str + " failed");
                        CommonUtils.safeClose(inputStream);
                    } catch (Throwable th) {
                        th = th;
                        CommonUtils.safeClose(inputStream);
                        CommonUtils.safeClose(fileOutputStream);
                        throw th;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    inputStream = inputStream2;
                    CommonUtils.safeClose(inputStream);
                    CommonUtils.safeClose(fileOutputStream);
                    throw th;
                }
            } catch (IOException unused2) {
                fileOutputStream = null;
            } catch (Throwable th3) {
                th = th3;
                fileOutputStream = null;
            }
        } catch (IOException unused3) {
            fileOutputStream = null;
        } catch (Throwable th4) {
            th = th4;
            fileOutputStream = null;
        }
        CommonUtils.safeClose(fileOutputStream);
    }

    public static boolean unzip(File file, File file2) throws Throwable {
        try {
            ZipFile zipFile = new ZipFile(file);
            if (!file2.exists()) {
                return false;
            }
            Enumeration<? extends ZipEntry> enumerationEntries = zipFile.entries();
            while (enumerationEntries.hasMoreElements()) {
                ZipEntry zipEntryNextElement = enumerationEntries.nextElement();
                File file3 = new File(file2, zipEntryNextElement.getName());
                if (zipEntryNextElement.isDirectory()) {
                    file3.mkdirs();
                } else {
                    File parentFile = file3.getParentFile();
                    if (parentFile != null && (parentFile.exists() || parentFile.mkdirs())) {
                        unzip(zipEntryNextElement, zipFile, file3.getAbsolutePath());
                    }
                }
            }
            CommonUtils.safeClose(zipFile);
            return true;
        } catch (IOException unused) {
            return false;
        }
    }
}
