package c.t.m.g; import a30.h; 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 f2222a = "ModuleUpadateImpl"; private Context b; public ev(Context context) { this.b = context; } private List<ew> b(List<ew> list, List<ew> list2) { boolean z; ArrayList arrayList = new ArrayList(); for (int i = 0; i < list.size(); i++) { ew ewVar = list.get(i); int i3 = 0; while (true) { if (i3 >= list2.size()) { z = false; break; } else if (ewVar.f2223a == list2.get(i3).f2223a) { arrayList.add(list2.get(i3)); z = true; break; } else { i3++; } } if (!z) { arrayList.add(ewVar); } } return arrayList; } private synchronized boolean c(List<ew> list, List<ew> list2) { long e = fk.e(); if (e < 10485760) { if (ey.f2232a) { ey.a(this.f2222a, "Not enough storage, cancel!"); } eo.a().a("MDS", "NoSpaceEnough," + e); return false; } String b2 = fk.b(this.b, "TMLSDK_hp"); ArrayList arrayList = new ArrayList(); for (int i = 0; i < list.size(); i++) { ew ewVar = list.get(i); if (a(b2, ewVar)) { arrayList.add(ewVar); eo.a().a("MDS", "already," + ewVar.f2224c); } else { if (ey.f2232a) { ey.b(this.f2222a, "current download module is " + ewVar.toString()); } try { String str = "https://maplbs-40171.sh.gfp.tencent-cloud.com/modules/" + ewVar.e; if (ey.f2232a) { ey.a(this.f2222a, "dex down load url is " + str); } byte[] a5 = fd.a(str); if (a5 != null) { boolean a12 = a(b2 + File.separator + ewVar.e + "." + ewVar.f, fk.a(fb.b(a5, fk.a("m_plugin_pwd", fg.n))), ewVar); if (ey.f2232a) { ey.a(this.f2222a, "down load so check result:" + a12); } eo.a().a("MDS", "download res," + a12 + "," + ewVar.f2224c); if (a12) { arrayList.add(ewVar); } } else { eo.a().a("MDS", "netError"); if (ey.f2232a) { ey.a(this.f2222a, "down load module failed!!!," + str); } } } catch (Throwable th2) { if (ey.f2232a) { ey.a(this.f2222a, th2); } } } } if (ey.f2232a) { String str2 = this.f2222a; StringBuilder sb2 = new StringBuilder(); sb2.append("all module download "); sb2.append(list.size() == arrayList.size()); ey.a(str2, sb2.toString()); ey.a(this.f2222a, "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 a13 = fk.a(b(list2, arrayList)); boolean a14 = fk.a(this.b, "SP_TMLSDK_MODULE_INFO", a13); if (ey.f2232a) { ey.b(this.f2222a, "module update success desc " + a13); } eo.a().a("MDS", "update result," + a14 + "," + a13); return true; } public void a(List<ew> list, List<ew> list2) { try { fi.a(this.b).a("update"); int i = 0; while (true) { if (i >= 3) { break; } boolean c5 = c(list, list2); if (ey.f2232a) { String str = this.f2222a; ey.a(str, "down load new module result " + c5 + ", retry " + i); } if (c5) { break; } i++; } fi.a(this.b).b("update"); eo.a().d(); } catch (Throwable th2) { if (ey.f2232a) { ey.a(this.f2222a, th2); } } } private boolean a(String str, byte[] bArr, ew ewVar) { if (bArr == null || bArr.length == 0) { if (ey.f2232a) { h.m("write to this path with data null,", str, this.f2222a); } return false; } else if (!new fj(str).a(bArr, false)) { if (ey.f2232a) { h.m("write to this path failed !!!,", str, this.f2222a); } return false; } else { String a5 = fk.a(new File(str)); if (a5 == null || !ewVar.e.equals(a5)) { if (ey.f2232a) { h.m("check data from server failed !!!,", str, this.f2222a); } return false; } else if (!ey.f2232a) { return true; } else { h.m("download and check data from server success !!!,", str, this.f2222a); return true; } } } private boolean a(String str, ew ewVar) { try { File file = new File(str, ewVar.e + "." + ewVar.f); if (!file.exists()) { if (ey.f2232a) { String str2 = this.f2222a; ey.b(str2, "checkIsDownLoadMoudle path is not exists," + file.getAbsolutePath()); } return false; } long length = file.length(); String a5 = fk.a(file); if (a5 != null && ewVar.d == length && ewVar.e.equals(a5)) { if (!ey.f2232a) { return true; } String str3 = this.f2222a; ey.a(str3, "module to download is same to update dir ,so donot to download " + ewVar); return true; } return false; } catch (Exception e) { if (ey.f2232a) { ey.a(this.f2222a, e); } } } }