得物.apk(点击下载) / ResourceHelper.java


package com.shizhuang.duapp.stream.util;

import a.f;
import android.content.Context;
import android.text.TextUtils;
import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleCoroutineScope;
import androidx.lifecycle.LifecycleOwnerKt;
import com.meituan.robust.ChangeQuickRedirect;
import com.meituan.robust.PatchProxy;
import com.meituan.robust.PatchProxyResult;
import com.shizhuang.duapp.libs.dulogger.Printer;
import fd.n;
import fo.a;
import h.b;
import ik1.h0;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import kotlin.Unit;
import kotlin.collections.ArraysKt___ArraysKt;
import kotlin.collections.CollectionsKt__IteratorsJVMKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt__StringsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/* compiled from: ResourceHelper.kt */
public final class ResourceHelper {
    @NotNull

    /* renamed from: a  reason: collision with root package name */
    public static final ResourceHelper f26082a = new ResourceHelper();
    public static ChangeQuickRedirect changeQuickRedirect;

    @NotNull
    public final String a(@NonNull @NotNull Context context) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 335111, new Class[]{Context.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        StringBuilder sb2 = new StringBuilder();
        sb2.append(e(context));
        String str = File.separator;
        b.u(sb2, str, "ComposeMakeup.bundle", str, "ComposeMakeup.bundle");
        String g3 = f.g(sb2, str, "ComposeMakeup/");
        a.u("livecamera").i(a40.f.g("composePath = ", g3), new Object[0]);
        return g3;
    }

    @Nullable
    public final String b(@NotNull Context context) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 335113, new Class[]{Context.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        File t = tl.a.t((String) n.c("community_module", "community_cv_license_v2", String.class, "https://apk.poizon.com/duApp/Android_Config/license/cv/duapp_20210309_20210608_com.shizhuang.duapp_v1.0.2.licbag"));
        if (t != null) {
            return t.getAbsolutePath();
        }
        return null;
    }

    @NotNull
    public final String c(@NonNull @NotNull Context context) {
        String name;
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 335112, new Class[]{Context.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        File t = tl.a.t((String) n.c("community_module", "ModelResourceV2", String.class, "https://apk.poizon.com/duApp/Android_Config/resource/updatehair.zip"));
        if (t == null || (name = t.getName()) == null) {
            return "";
        }
        String substring = name.substring(0, StringsKt__StringsKt.indexOf$default((CharSequence) name, ".", 0, false, 6, (Object) null));
        StringBuilder sb2 = new StringBuilder();
        sb2.append(e(context));
        return f.g(sb2, File.separator, substring);
    }

    public final String d(File file) {
        File file2;
        int i = 0;
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{file}, this, changeQuickRedirect, false, 335123, new Class[]{File.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        File[] listFiles = file.listFiles();
        if (listFiles == null) {
            return "";
        }
        int length = listFiles.length;
        String str = null;
        if (length == 1) {
            File file3 = (File) ArraysKt___ArraysKt.getOrNull(file.listFiles(), 0);
            if (file3 != null) {
                str = file3.getAbsolutePath();
            }
            if (str != null) {
                return str;
            }
            return "";
        }
        int length2 = listFiles.length;
        while (true) {
            if (i >= length2) {
                file2 = null;
                break;
            }
            file2 = listFiles[i];
            if (Intrinsics.areEqual("__MACOSX", file2.getName())) {
                break;
            }
            i++;
        }
        if (file2 != null) {
            int i3 = length - 1;
            if (i3 > 1) {
                String absolutePath = file.getAbsolutePath();
                if (absolutePath != null) {
                    return absolutePath;
                }
                return "";
            }
            File file4 = (File) ArraysKt___ArraysKt.getOrNull(listFiles, i3 - ArraysKt___ArraysKt.indexOf(listFiles, file2));
            if (file4 != null) {
                str = file4.getAbsolutePath();
            }
            if (str != null) {
                return str;
            }
            return "";
        }
        String absolutePath2 = file.getAbsolutePath();
        if (absolutePath2 != null) {
            return absolutePath2;
        }
        return "";
    }

    @NotNull
    public final String e(@NotNull Context context) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context}, this, changeQuickRedirect, false, 335110, new Class[]{Context.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        StringBuilder sb2 = new StringBuilder();
        File externalFilesDir = context.getExternalFilesDir("assets");
        sb2.append(externalFilesDir != null ? externalFilesDir.getAbsolutePath() : null);
        return f.g(sb2, File.separator, "resource");
    }

    @Nullable
    public final String f(@Nullable Context context, @Nullable File file) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, file}, this, changeQuickRedirect, false, 335122, new Class[]{Context.class, File.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        if (file == null) {
            return "";
        }
        File file2 = new File(f.g(f.h(context != null ? f26082a.e(context) : null), File.separator, file.getName().substring(StringsKt__StringsKt.lastIndexOf$default((CharSequence) file.getName(), '/', 0, false, 6, (Object) null) + 1, StringsKt__StringsKt.lastIndexOf$default((CharSequence) file.getName(), '.', 0, false, 6, (Object) null))));
        if (!file2.exists() || !file2.isDirectory()) {
            return null;
        }
        return f26082a.d(file2);
    }

    @Nullable
    public final String g(@Nullable Context context, @Nullable File file) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, file}, this, changeQuickRedirect, false, 335120, new Class[]{Context.class, File.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        if (file == null) {
            return "";
        }
        try {
            ZipFile zipFile = new ZipFile(file);
            try {
                String name = zipFile.getName();
                int lastIndexOf$default = StringsKt__StringsKt.lastIndexOf$default((CharSequence) zipFile.getName(), '/', 0, false, 6, (Object) null) + 1;
                int lastIndexOf$default2 = StringsKt__StringsKt.lastIndexOf$default((CharSequence) zipFile.getName(), '.', 0, false, 6, (Object) null);
                if (name != null) {
                    String substring = name.substring(lastIndexOf$default, lastIndexOf$default2);
                    String e = context != null ? f26082a.e(context) : null;
                    if (TextUtils.isEmpty(e)) {
                        return null;
                    }
                    File file2 = new File(e + File.separator + substring);
                    if (!file2.exists()) {
                        file2.mkdirs();
                    }
                    try {
                        Iterator it2 = CollectionsKt__IteratorsJVMKt.iterator(zipFile.entries());
                        while (it2.hasNext()) {
                            ZipEntry zipEntry = (ZipEntry) it2.next();
                            String name2 = zipEntry.getName();
                            if (!StringsKt__StringsKt.contains$default((CharSequence) name2, (CharSequence) "../", false, 2, (Object) null)) {
                                InputStream inputStream = zipFile.getInputStream(zipEntry);
                                StringBuilder sb2 = new StringBuilder();
                                sb2.append(e);
                                String str = File.separator;
                                sb2.append(str);
                                sb2.append(substring);
                                sb2.append(str);
                                sb2.append(name2);
                                String sb3 = sb2.toString();
                                int lastIndexOf$default3 = StringsKt__StringsKt.lastIndexOf$default((CharSequence) sb3, '/', 0, false, 6, (Object) null);
                                if (sb3 != null) {
                                    File file3 = new File(sb3.substring(0, lastIndexOf$default3));
                                    if (!file3.exists()) {
                                        file3.mkdirs();
                                    }
                                    if (!new File(sb3).isDirectory()) {
                                        FileOutputStream fileOutputStream = new FileOutputStream(sb3);
                                        byte[] bArr = new byte[6144];
                                        while (true) {
                                            int read = inputStream.read(bArr);
                                            if (read == -1) {
                                                break;
                                            }
                                            fileOutputStream.write(bArr, 0, read);
                                        }
                                        fileOutputStream.close();
                                    }
                                } else {
                                    throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
                                }
                            }
                        }
                    } catch (Exception unused) {
                    } catch (Throwable th2) {
                        zipFile.close();
                        throw th2;
                    }
                    zipFile.close();
                    return file2.getAbsolutePath();
                }
                throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
            } catch (Exception e6) {
                e6.printStackTrace();
                return "";
            }
        } catch (Exception e12) {
            ki.a.a(file);
            e12.printStackTrace();
            return "";
        }
    }

    @Nullable
    public final String h(@Nullable Context context, @Nullable File file) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, file}, this, changeQuickRedirect, false, 335119, new Class[]{Context.class, File.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        if (file == null) {
            return "";
        }
        try {
            ZipFile zipFile = new ZipFile(file);
            try {
                String name = zipFile.getName();
                int lastIndexOf$default = StringsKt__StringsKt.lastIndexOf$default((CharSequence) zipFile.getName(), '/', 0, false, 6, (Object) null) + 1;
                int lastIndexOf$default2 = StringsKt__StringsKt.lastIndexOf$default((CharSequence) zipFile.getName(), '.', 0, false, 6, (Object) null);
                if (name != null) {
                    String substring = name.substring(lastIndexOf$default, lastIndexOf$default2);
                    String e = context != null ? f26082a.e(context) : null;
                    if (TextUtils.isEmpty(e)) {
                        return null;
                    }
                    File file2 = new File(e + File.separator + substring);
                    if (!file2.exists()) {
                        file2.mkdirs();
                    }
                    try {
                        Iterator it2 = CollectionsKt__IteratorsJVMKt.iterator(zipFile.entries());
                        while (it2.hasNext()) {
                            ZipEntry zipEntry = (ZipEntry) it2.next();
                            String name2 = zipEntry.getName();
                            if (!StringsKt__StringsKt.contains$default((CharSequence) name2, (CharSequence) "../", false, 2, (Object) null)) {
                                if (!StringsKt__StringsKt.contains$default((CharSequence) name2, (CharSequence) "MACOSX", false, 2, (Object) null)) {
                                    InputStream inputStream = zipFile.getInputStream(zipEntry);
                                    StringBuilder sb2 = new StringBuilder();
                                    sb2.append(e);
                                    String str = File.separator;
                                    sb2.append(str);
                                    sb2.append(substring);
                                    sb2.append(str);
                                    sb2.append(name2);
                                    String sb3 = sb2.toString();
                                    int lastIndexOf$default3 = StringsKt__StringsKt.lastIndexOf$default((CharSequence) sb3, '/', 0, false, 6, (Object) null);
                                    if (sb3 != null) {
                                        File file3 = new File(sb3.substring(0, lastIndexOf$default3));
                                        if (!file3.exists()) {
                                            file3.mkdirs();
                                        }
                                        if (!new File(sb3).isDirectory()) {
                                            FileOutputStream fileOutputStream = new FileOutputStream(sb3);
                                            byte[] bArr = new byte[6144];
                                            while (true) {
                                                int read = inputStream.read(bArr);
                                                if (read == -1) {
                                                    break;
                                                }
                                                fileOutputStream.write(bArr, 0, read);
                                            }
                                            fileOutputStream.close();
                                        }
                                    } else {
                                        throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
                                    }
                                }
                            }
                        }
                    } catch (Exception unused) {
                    } catch (Throwable th2) {
                        zipFile.close();
                        throw th2;
                    }
                    zipFile.close();
                    return f26082a.d(file2);
                }
                throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
            } catch (Exception e6) {
                e6.printStackTrace();
                return "";
            }
        } catch (Exception e12) {
            ki.a.a(file);
            e12.printStackTrace();
            return "";
        }
    }

    public final void i(@Nullable Context context, @Nullable File file, @Nullable Function1<? super String, Unit> function1) {
        LifecycleCoroutineScope lifecycleScope;
        if (!PatchProxy.proxy(new Object[]{context, file, function1}, this, changeQuickRedirect, false, 335118, new Class[]{Context.class, File.class, Function1.class}, Void.TYPE).isSupported) {
            ComponentActivity componentActivity = (ComponentActivity) (!(context instanceof ComponentActivity) ? null : context);
            if (componentActivity != null && (lifecycleScope = LifecycleOwnerKt.getLifecycleScope(componentActivity)) != null) {
                ik1.f.i(lifecycleScope, h0.b(), null, new ResourceHelper$unZipSafe$1(file, context, function1, null), 2, null);
            }
        }
    }

    @Nullable
    public final String j(@Nullable Context context, @Nullable File file) {
        PatchProxyResult proxy = PatchProxy.proxy(new Object[]{context, file}, this, changeQuickRedirect, false, 335121, new Class[]{Context.class, File.class}, String.class);
        if (proxy.isSupported) {
            return (String) proxy.result;
        }
        if (file == null) {
            return "";
        }
        try {
            ZipFile zipFile = new ZipFile(file);
            try {
                String name = zipFile.getName();
                int lastIndexOf$default = StringsKt__StringsKt.lastIndexOf$default((CharSequence) zipFile.getName(), '/', 0, false, 6, (Object) null) + 1;
                int lastIndexOf$default2 = StringsKt__StringsKt.lastIndexOf$default((CharSequence) zipFile.getName(), '.', 0, false, 6, (Object) null);
                if (name != null) {
                    String substring = name.substring(lastIndexOf$default, lastIndexOf$default2);
                    String e = context != null ? f26082a.e(context) : null;
                    if (TextUtils.isEmpty(e)) {
                        return null;
                    }
                    File file2 = new File(e + File.separator + substring);
                    if (!file2.exists()) {
                        file2.mkdirs();
                    }
                    try {
                        Iterator it2 = CollectionsKt__IteratorsJVMKt.iterator(zipFile.entries());
                        while (it2.hasNext()) {
                            ZipEntry zipEntry = (ZipEntry) it2.next();
                            String name2 = zipEntry.getName();
                            if (!StringsKt__StringsKt.contains$default((CharSequence) name2, (CharSequence) "../", false, 2, (Object) null)) {
                                if (!StringsKt__StringsKt.contains$default((CharSequence) name2, (CharSequence) "MACOSX", false, 2, (Object) null)) {
                                    InputStream inputStream = zipFile.getInputStream(zipEntry);
                                    StringBuilder sb2 = new StringBuilder();
                                    sb2.append(e);
                                    String str = File.separator;
                                    sb2.append(str);
                                    sb2.append(substring);
                                    sb2.append(str);
                                    sb2.append(name2);
                                    String sb3 = sb2.toString();
                                    int lastIndexOf$default3 = StringsKt__StringsKt.lastIndexOf$default((CharSequence) sb3, '/', 0, false, 6, (Object) null);
                                    if (sb3 != null) {
                                        File file3 = new File(sb3.substring(0, lastIndexOf$default3));
                                        if (!file3.exists()) {
                                            file3.mkdirs();
                                        }
                                        if (!new File(sb3).isDirectory()) {
                                            FileOutputStream fileOutputStream = new FileOutputStream(sb3);
                                            byte[] bArr = new byte[6144];
                                            while (true) {
                                                int read = inputStream.read(bArr);
                                                if (read == -1) {
                                                    break;
                                                }
                                                fileOutputStream.write(bArr, 0, read);
                                            }
                                            fileOutputStream.close();
                                        }
                                    } else {
                                        throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
                                    }
                                }
                            }
                        }
                    } catch (Exception unused) {
                    } catch (Throwable th2) {
                        zipFile.close();
                        throw th2;
                    }
                    zipFile.close();
                    return f26082a.d(file2);
                }
                throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
            } catch (Exception e6) {
                e6.printStackTrace();
                return "";
            }
        } catch (Exception e12) {
            e12.printStackTrace();
            Printer u4 = a.u("livecamera");
            u4.w("unzip compose error: " + e12.getLocalizedMessage(), e12);
            return "";
        }
    }
}