package com.shizhuang.duapp.modules.live.anchor.livestream.effect.model; import a.f; import android.content.Context; import androidx.appcompat.widget.a; import com.liulishuo.okdownload.core.cause.EndCause; import com.meituan.robust.ChangeQuickRedirect; import com.meituan.robust.PatchProxy; import com.shizhuang.duapp.libs.dulogger.Printer; import com.shizhuang.duapp.stream.util.ResourceHelper; import fd.i; import fd.n; import fd.q; import h.b; import io.reactivex.functions.Action; import java.io.File; import s9.c; import uk.j; public class TTCVHelper { public static float BEAUTY_EYE; public static float BEAUTY_FACE; public static float BEAUTY_SHARP; public static float BEAUTY_SMOOTH; public static float BEAUTY_WHITE; private static String COMPOSE_CONFIG_FILE = f.g(f.h("beauty_Android_camera"), File.separator, "config.json"); private static String FILTERS_URL; private static String FOLDER; private static String LICENSE_FILE; private static String LICENSE_FOLDER; private static String MakeUpURL; private static String TAG; private static String ZIP; public static ChangeQuickRedirect changeQuickRedirect; public interface TtcvInitListener { void onError(String str); void onSuccess(); } public static void downloadAssets(final Context context, final TtcvInitListener ttcvInitListener) { if (!PatchProxy.proxy(new Object[]{context, ttcvInitListener}, null, changeQuickRedirect, true, 181266, new Class[]{Context.class, TtcvInitListener.class}, Void.TYPE).isSupported && context != null) { final String e = ResourceHelper.f26082a.e(context); StringBuilder h12 = f.h(e); String str = File.separator; b.u(h12, str, "ComposeMakeup.bundle", str, "ComposeMakeup.bundle"); a.n(h12, str, "ComposeMakeup", str); h12.append(COMPOSE_CONFIG_FILE); if (!new File(h12.toString()).exists()) { File file = new File(e); if (!file.exists()) { file.mkdirs(); } if (!tl.a.E(MakeUpURL)) { String str2 = MakeUpURL; tl.a.i(str2, e, FOLDER + ZIP); String str3 = MakeUpURL; tl.a.r(str3, e, FOLDER + ZIP, new vl.a() { /* class com.shizhuang.duapp.modules.live.anchor.livestream.effect.model.TTCVHelper.AnonymousClass2 */ public static ChangeQuickRedirect changeQuickRedirect; public static /* synthetic */ void lambda$onTaskEnd$0(Context context, String str, TtcvInitListener ttcvInitListener) { if (!PatchProxy.proxy(new Object[]{context, str, ttcvInitListener}, null, changeQuickRedirect, true, 181272, new Class[]{Context.class, String.class, TtcvInitListener.class}, Void.TYPE).isSupported) { ResourceHelper resourceHelper = ResourceHelper.f26082a; StringBuilder h12 = f.h(str); String str2 = File.separator; h12.append(str2); h12.append(TTCVHelper.FOLDER); h12.append(TTCVHelper.ZIP); String j = resourceHelper.j(context, new File(h12.toString())); if (j != null && j.length() >= 1) { StringBuilder j12 = a40.f.j(str, str2); j12.append(TTCVHelper.FOLDER); j12.append(TTCVHelper.ZIP); File file = new File(j12.toString()); if (file.exists()) { ki.a.a(file); } if (ttcvInitListener != null) { ttcvInitListener.onSuccess(); } } else if (ttcvInitListener != null) { ttcvInitListener.onError("资源解压失败"); } } } @Override // vl.a public void onTaskEnd(c cVar, EndCause endCause, Exception exc) { if (!PatchProxy.proxy(new Object[]{cVar, endCause, exc}, this, changeQuickRedirect, false, 181271, new Class[]{c.class, EndCause.class, Exception.class}, Void.TYPE).isSupported) { if (endCause == EndCause.COMPLETED) { q.a(new cc.c(context, e, ttcvInitListener, 1)); return; } Printer u4 = fo.a.u(TTCVHelper.TAG); StringBuilder sb2 = new StringBuilder(); sb2.append("download assets error: "); sb2.append(endCause); sb2.append("; "); sb2.append(exc != null ? exc.getLocalizedMessage() : null); u4.i(sb2.toString(), new Object[0]); TtcvInitListener ttcvInitListener = ttcvInitListener; if (ttcvInitListener != null) { ttcvInitListener.onError(exc != null ? exc.getLocalizedMessage() : ""); } } } }); } } else if (ttcvInitListener != null) { ttcvInitListener.onSuccess(); } } } public static void downloadFiltersResource(Context context, TtcvInitListener ttcvInitListener) { if (!PatchProxy.proxy(new Object[]{context, ttcvInitListener}, null, changeQuickRedirect, true, 181268, new Class[]{Context.class, TtcvInitListener.class}, Void.TYPE).isSupported) { downloadResource(context, FILTERS_URL, ttcvInitListener); } } public static void downloadModelResource(Context context, TtcvInitListener ttcvInitListener) { if (!PatchProxy.proxy(new Object[]{context, ttcvInitListener}, null, changeQuickRedirect, true, 181267, new Class[]{Context.class, TtcvInitListener.class}, Void.TYPE).isSupported) { downloadResource(context, (String) n.c("community_module", "ModelResourceV2", String.class, "https://apk.poizon.com/duApp/Android_Config/resource/updatehair.zip"), ttcvInitListener); } } private static void downloadResource(final Context context, String str, final TtcvInitListener ttcvInitListener) { if (!PatchProxy.proxy(new Object[]{context, str, ttcvInitListener}, null, changeQuickRedirect, true, 181269, new Class[]{Context.class, String.class, TtcvInitListener.class}, Void.TYPE).isSupported) { File t = tl.a.t(str); if (t == null || !t.exists()) { tl.a.n(str, new vl.a() { /* class com.shizhuang.duapp.modules.live.anchor.livestream.effect.model.TTCVHelper.AnonymousClass3 */ public static ChangeQuickRedirect changeQuickRedirect; public static /* synthetic */ void lambda$onTaskEnd$0(Context context, c cVar, TtcvInitListener ttcvInitListener) { if (!PatchProxy.proxy(new Object[]{context, cVar, ttcvInitListener}, null, changeQuickRedirect, true, 181274, new Class[]{Context.class, c.class, TtcvInitListener.class}, Void.TYPE).isSupported) { String h12 = ResourceHelper.f26082a.h(context, cVar.i()); if (h12 == null || h12.length() < 1) { if (ttcvInitListener != null) { ttcvInitListener.onError("资源解压失败"); } } else if (ttcvInitListener != null) { ttcvInitListener.onSuccess(); } } } @Override // vl.a public void onTaskEnd(c cVar, EndCause endCause, Exception exc) { if (!PatchProxy.proxy(new Object[]{cVar, endCause, exc}, this, changeQuickRedirect, false, 181273, new Class[]{c.class, EndCause.class, Exception.class}, Void.TYPE).isSupported) { super.onTaskEnd(cVar, endCause, exc); if (endCause == EndCause.COMPLETED) { q.a(new j(context, cVar, ttcvInitListener, 1)); return; } Printer u4 = fo.a.u(TTCVHelper.TAG); StringBuilder sb2 = new StringBuilder(); sb2.append("download model error: "); sb2.append(endCause); sb2.append("; "); sb2.append(exc != null ? exc.getLocalizedMessage() : null); u4.i(sb2.toString(), new Object[0]); TtcvInitListener ttcvInitListener = ttcvInitListener; if (ttcvInitListener != null) { ttcvInitListener.onError(exc != null ? exc.getLocalizedMessage() : ""); } } } }); return; } ResourceHelper resourceHelper = ResourceHelper.f26082a; String f = resourceHelper.f(context, t); if (f == null || !i.t(f)) { String h12 = resourceHelper.h(context, t); if (h12 == null || h12.length() < 1) { if (ttcvInitListener != null) { ttcvInitListener.onError("资源解压失败"); } } else if (ttcvInitListener != null) { ttcvInitListener.onSuccess(); } } else if (ttcvInitListener != null) { ttcvInitListener.onSuccess(); } } } public static void initLicense(Context context, final Action action) { if (!PatchProxy.proxy(new Object[]{context, action}, null, changeQuickRedirect, true, 181265, new Class[]{Context.class, Action.class}, Void.TYPE).isSupported) { try { String str = (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"); File t = tl.a.t(str); if (t == null || !t.exists()) { tl.a.n(str, new vl.a() { /* class com.shizhuang.duapp.modules.live.anchor.livestream.effect.model.TTCVHelper.AnonymousClass1 */ public static ChangeQuickRedirect changeQuickRedirect; @Override // vl.a public void onTaskEnd(c cVar, EndCause endCause, Exception exc) { if (!PatchProxy.proxy(new Object[]{cVar, endCause, exc}, this, changeQuickRedirect, false, 181270, new Class[]{c.class, EndCause.class, Exception.class}, Void.TYPE).isSupported) { try { action.run(); } catch (Exception e) { e.printStackTrace(); } } } }); return; } try { action.run(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e6) { e6.printStackTrace(); Printer u4 = fo.a.u(TAG); StringBuilder h12 = f.h("init cv license "); h12.append(e6.getLocalizedMessage()); u4.w(h12.toString(), new Object[0]); } } } }