package c.t.m.g; import android.content.Context; import java.io.File; import java.util.ArrayList; import java.util.List; /* compiled from: TML */ public class ev { /* renamed from: a reason: collision with root package name */ private String f10134a = "ModuleUpadateImpl"; /* renamed from: b reason: collision with root package name */ private Context f10135b; public ev(Context context) { this.f10135b = context; } private List<ew> b(List<ew> list, List<ew> list2) { boolean z14; ArrayList arrayList = new ArrayList(); for (int i10 = 0; i10 < list.size(); i10++) { ew ewVar = list.get(i10); int i14 = 0; while (true) { if (i14 >= list2.size()) { z14 = false; break; } else if (ewVar.f10136a == list2.get(i14).f10136a) { arrayList.add(list2.get(i14)); z14 = true; break; } else { i14++; } } if (!z14) { arrayList.add(ewVar); } } return arrayList; } private synchronized boolean c(List<ew> list, List<ew> list2) { long d14 = fj.d(); if (d14 < 10485760) { if (ey.f10154a) { ey.a(this.f10134a, "Not enough storage, cancel!"); } eo.a().a("MDS", "NoSpaceEnough," + d14); return false; } String b14 = fj.b(this.f10135b, "TMLSDK_hp"); ArrayList arrayList = new ArrayList(); for (int i10 = 0; i10 < list.size(); i10++) { ew ewVar = list.get(i10); if (a(b14, ewVar)) { arrayList.add(ewVar); eo.a().a("MDS", "already," + ewVar.f10138c); } else { if (ey.f10154a) { ey.b(this.f10134a, "current download module is " + ewVar.toString()); } try { String str = "https://maplbs-40171.sh.gfp.tencent-cloud.com/modules/" + ewVar.f10140e; if (ey.f10154a) { ey.a(this.f10134a, "dex down load url is " + str); } byte[] a14 = fc.a(str); if (a14 != null) { boolean a15 = a(b14 + File.separator + ewVar.f10140e + "." + ewVar.f10141f, fj.a(fb.b(a14, fj.a("m_plugin_pwd", ff.f10194n))), ewVar); if (ey.f10154a) { ey.a(this.f10134a, "down load so check result:" + a15); } eo.a().a("MDS", "download res," + a15 + "," + ewVar.f10138c); if (a15) { arrayList.add(ewVar); } } else { eo.a().a("MDS", "netError"); if (ey.f10154a) { ey.a(this.f10134a, "down load module failed!!!," + str); } } } catch (Throwable th3) { if (ey.f10154a) { ey.a(this.f10134a, th3); } } } } if (ey.f10154a) { String str2 = this.f10134a; StringBuilder sb3 = new StringBuilder(); sb3.append("all module download "); sb3.append(list.size() == arrayList.size()); ey.a(str2, sb3.toString()); ey.a(this.f10134a, "start rename download files"); } eo.a().a("MDS", "should download," + list.size() + ",real download suc," + arrayList.size()); if (list.size() != arrayList.size()) { return false; } String a16 = fj.a(b(list2, arrayList)); boolean a17 = fj.a(this.f10135b, "SP_TMLSDK_MODULE_INFO", a16); if (ey.f10154a) { ey.b(this.f10134a, "module update success desc " + a16); } eo.a().a("MDS", "update result," + a17 + "," + a16); return true; } public void a(List<ew> list, List<ew> list2) { try { fh.a(this.f10135b).a("update"); int i10 = 0; while (true) { if (i10 >= 3) { break; } boolean c14 = c(list, list2); if (ey.f10154a) { String str = this.f10134a; ey.a(str, "down load new module result " + c14 + ", retry " + i10); } if (c14) { break; } i10++; } fh.a(this.f10135b).b("update"); eo.a().d(); } catch (Throwable th3) { if (ey.f10154a) { ey.a(this.f10134a, th3); } } } private boolean a(String str, byte[] bArr, ew ewVar) { if (bArr == null || bArr.length == 0) { if (ey.f10154a) { String str2 = this.f10134a; ey.a(str2, "write to this path with data null," + str); } return false; } else if (!new fi(str).a(bArr, false)) { if (ey.f10154a) { String str3 = this.f10134a; ey.a(str3, "write to this path failed !!!," + str); } return false; } else { String a14 = fj.a(new File(str)); if (a14 == null || !ewVar.f10140e.equals(a14)) { if (ey.f10154a) { String str4 = this.f10134a; ey.a(str4, "check data from server failed !!!," + str); } return false; } else if (!ey.f10154a) { return true; } else { String str5 = this.f10134a; ey.a(str5, "download and check data from server success !!!," + str); return true; } } } private boolean a(String str, ew ewVar) { try { File file = new File(str, ewVar.f10140e + "." + ewVar.f10141f); if (!file.exists()) { if (ey.f10154a) { String str2 = this.f10134a; ey.b(str2, "checkIsDownLoadMoudle path is not exists," + file.getAbsolutePath()); } return false; } long length = file.length(); String a14 = fj.a(file); if (a14 != null && ewVar.f10139d == length && ewVar.f10140e.equals(a14)) { if (!ey.f10154a) { return true; } String str3 = this.f10134a; ey.a(str3, "module to download is same to update dir ,so donot to download " + ewVar); return true; } return false; } catch (Exception e14) { if (ey.f10154a) { ey.a(this.f10134a, e14); } } } }