package com.bytedance.sdk.component.adexpress.YFl.Sg;

import android.text.TextUtils;
import com.bytedance.sdk.component.adexpress.YFl.tN.YFl;
import com.bytedance.sdk.component.utils.YI;
import com.bytedance.sdk.component.utils.YoT;
import com.facebook.cache.disk.DefaultDiskStorage;
import com.ironsource.rb;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public abstract class tN {
    public abstract File YFl();

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean YFl(Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> map) {
        if (map == null || map.size() == 0) {
            return false;
        }
        for (String str : map.keySet()) {
            com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl = map.get(str);
            if (yFl != null && !YFl(yFl.vc())) {
                return false;
            }
        }
        return true;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* JADX WARN: Removed duplicated region for block: B:12:0x001a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean YFl(java.util.List<com.bytedance.sdk.component.adexpress.YFl.tN.YFl.C0109YFl> r6) {
        /*
            r5 = this;
            r0 = 0
            if (r6 == 0) goto L5b
            int r1 = r6.size()
            if (r1 <= 0) goto L5b
            java.io.File r1 = r5.YFl()
            if (r1 != 0) goto L10
            goto L5b
        L10:
            java.util.Iterator r6 = r6.iterator()
        L14:
            boolean r1 = r6.hasNext()
            if (r1 == 0) goto L59
            java.lang.Object r1 = r6.next()
            com.bytedance.sdk.component.adexpress.YFl.tN.YFl$YFl r1 = (com.bytedance.sdk.component.adexpress.YFl.tN.YFl.C0109YFl) r1
            java.lang.String r2 = r1.YFl()
            java.lang.String r2 = com.bytedance.sdk.component.utils.wN.YFl(r2)
            boolean r3 = android.text.TextUtils.isEmpty(r2)
            if (r3 == 0) goto L2f
            return r0
        L2f:
            java.io.File r3 = new java.io.File
            java.io.File r4 = r5.YFl()
            r3.<init>(r4, r2)
            java.lang.String r2 = com.bytedance.sdk.component.utils.wN.YFl(r3)
            boolean r4 = r3.exists()
            if (r4 == 0) goto L58
            boolean r3 = r3.isFile()
            if (r3 == 0) goto L58
            java.lang.String r3 = r1.Sg()
            if (r3 == 0) goto L58
            java.lang.String r1 = r1.Sg()
            boolean r1 = r1.equals(r2)
            if (r1 != 0) goto L14
        L58:
            return r0
        L59:
            r6 = 1
            return r6
        L5b:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.sdk.component.adexpress.YFl.Sg.tN.YFl(java.util.List):boolean");
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* JADX WARN: Removed duplicated region for block: B:14:0x0020  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean YFl(com.bytedance.sdk.component.adexpress.YFl.tN.YFl.Sg r5) {
        /*
            r4 = this;
            r0 = 0
            if (r5 == 0) goto L42
            java.io.File r1 = r4.YFl()
            if (r1 != 0) goto La
            goto L42
        La:
            java.util.List r5 = r5.Sg()
            if (r5 == 0) goto L40
            int r1 = r5.size()
            if (r1 <= 0) goto L40
            java.util.Iterator r5 = r5.iterator()
        L1a:
            boolean r1 = r5.hasNext()
            if (r1 == 0) goto L40
            java.lang.Object r1 = r5.next()
            android.util.Pair r1 = (android.util.Pair) r1
            java.io.File r2 = new java.io.File
            java.io.File r3 = r4.YFl()
            java.lang.Object r1 = r1.first
            java.lang.String r1 = (java.lang.String) r1
            r2.<init>(r3, r1)
            boolean r1 = r2.exists()
            if (r1 == 0) goto L3f
            boolean r1 = r2.isFile()
            if (r1 != 0) goto L1a
        L3f:
            return r0
        L40:
            r5 = 1
            return r5
        L42:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.sdk.component.adexpress.YFl.Sg.tN.YFl(com.bytedance.sdk.component.adexpress.YFl.tN.YFl$Sg):boolean");
    }

    public List<YFl.C0109YFl> YFl(com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl, com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl2) {
        Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> YFl = yFl.YFl();
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        if (YFl.size() == 0) {
            if (yFl2 != null && yFl2.YFl().size() != 0) {
                Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> YFl2 = yFl2.YFl();
                for (String str : YFl2.keySet()) {
                    com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl3 = YFl2.get(str);
                    if (yFl3 != null) {
                        arrayList.addAll(yFl3.vc());
                    }
                }
            }
        } else if (yFl2 == null || yFl2.YFl().size() == 0) {
            if (YFl.size() != 0) {
                for (String str2 : YFl.keySet()) {
                    com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl4 = YFl.get(str2);
                    if (yFl4 != null) {
                        arrayList2.addAll(yFl4.vc());
                    }
                }
            }
        } else {
            Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> YFl3 = yFl2.YFl();
            for (String str3 : YFl.keySet()) {
                com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl5 = YFl.get(str3);
                com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl6 = YFl3.get(str3);
                if (yFl6 == null && yFl5 != null) {
                    arrayList2.addAll(yFl5.vc());
                } else if (yFl5 == null && yFl6 != null) {
                    arrayList.addAll(yFl6.vc());
                } else if (yFl5 != null) {
                    for (YFl.C0109YFl c0109YFl : yFl5.vc()) {
                        if (c0109YFl != null && !yFl6.vc().contains(c0109YFl) && c0109YFl.Sg() != null && c0109YFl.YFl() != null) {
                            arrayList2.add(c0109YFl);
                        }
                    }
                    for (YFl.C0109YFl c0109YFl2 : yFl6.vc()) {
                        if (c0109YFl2 != null && !yFl5.vc().contains(c0109YFl2)) {
                            arrayList.add(c0109YFl2);
                        }
                    }
                }
            }
        }
        if (YFl(arrayList2, arrayList3)) {
            return arrayList;
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:5:0x000a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean YFl(java.util.List<com.bytedance.sdk.component.adexpress.YFl.tN.YFl.C0109YFl> r8, java.util.List<com.bytedance.sdk.component.adexpress.YFl.tN.YFl.C0109YFl> r9) {
        /*
            r7 = this;
            java.util.Iterator r8 = r8.iterator()
        L4:
            boolean r0 = r8.hasNext()
            if (r0 == 0) goto L89
            java.lang.Object r0 = r8.next()
            com.bytedance.sdk.component.adexpress.YFl.tN.YFl$YFl r0 = (com.bytedance.sdk.component.adexpress.YFl.tN.YFl.C0109YFl) r0
            java.lang.String r1 = r0.YFl()
            java.lang.String r2 = com.bytedance.sdk.component.utils.wN.YFl(r1)
            java.io.File r3 = new java.io.File
            java.io.File r4 = r7.YFl()
            r3.<init>(r4, r2)
            java.io.File r4 = new java.io.File
            java.lang.StringBuilder r5 = new java.lang.StringBuilder
            r5.<init>()
            java.lang.StringBuilder r5 = r5.append(r3)
            java.lang.String r6 = ".tmp"
            java.lang.StringBuilder r5 = r5.append(r6)
            java.lang.String r5 = r5.toString()
            r4.<init>(r5)
            boolean r5 = r3.exists()
            if (r5 == 0) goto L42
            r3.delete()     // Catch: java.lang.Throwable -> L42
        L42:
            boolean r3 = r4.exists()
            if (r3 == 0) goto L4b
            r4.delete()     // Catch: java.lang.Throwable -> L4b
        L4b:
            com.bytedance.sdk.component.adexpress.YFl.YFl.YFl r3 = com.bytedance.sdk.component.adexpress.YFl.YFl.YFl.YFl()
            com.bytedance.sdk.component.adexpress.YFl.YFl.tN r3 = r3.tN()
            com.bytedance.sdk.component.DSW.Sg.YFl r3 = r3.vc()
            r3.Sg(r1)
            java.io.File r1 = r7.YFl()
            java.lang.String r1 = r1.getAbsolutePath()
            r3.YFl(r1, r2)
            com.bytedance.sdk.component.DSW.Sg r1 = r3.YFl()
            r9.add(r0)
            if (r1 == 0) goto L84
            boolean r0 = r1.vc()
            if (r0 == 0) goto L84
            java.io.File r0 = r1.wN()
            if (r0 == 0) goto L84
            java.io.File r0 = r1.wN()
            boolean r0 = r0.exists()
            if (r0 != 0) goto L4
        L84:
            r7.tN(r9)
            r8 = 0
            return r8
        L89:
            r8 = 1
            return r8
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.sdk.component.adexpress.YFl.Sg.tN.YFl(java.util.List, java.util.List):boolean");
    }

    public List<YFl.C0109YFl> Sg(com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl, com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl2) {
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        if (yFl2 == null || yFl2.vc().isEmpty()) {
            arrayList2.addAll(yFl.vc());
        } else if (yFl.vc().isEmpty()) {
            arrayList.addAll(yFl2.vc());
        } else {
            for (YFl.C0109YFl c0109YFl : yFl.vc()) {
                if (!yFl2.vc().contains(c0109YFl) && c0109YFl != null && c0109YFl.YFl() != null && c0109YFl.Sg() != null) {
                    arrayList2.add(c0109YFl);
                }
            }
            for (YFl.C0109YFl c0109YFl2 : yFl2.vc()) {
                if (!yFl.vc().contains(c0109YFl2)) {
                    arrayList.add(c0109YFl2);
                }
            }
        }
        if (YFl(arrayList2, arrayList3)) {
            return arrayList;
        }
        return null;
    }

    public void Sg(List<YFl.C0109YFl> list) {
        if (list == null || list.isEmpty()) {
            return;
        }
        for (YFl.C0109YFl c0109YFl : list) {
            File file = new File(YFl(), com.bytedance.sdk.component.utils.wN.YFl(c0109YFl.YFl()));
            File file2 = new File(file + DefaultDiskStorage.FileType.TEMP);
            if (file.exists()) {
                try {
                    file.delete();
                } catch (Throwable unused) {
                }
            }
            if (file2.exists()) {
                try {
                    file2.delete();
                } catch (Throwable unused2) {
                }
            }
        }
    }

    public boolean YFl(String str) {
        File file = new File(YFl().getAbsoluteFile(), com.bytedance.sdk.component.utils.wN.YFl(str) + ".zip");
        com.bytedance.sdk.component.DSW.Sg.YFl vc = com.bytedance.sdk.component.adexpress.YFl.YFl.YFl.YFl().tN().vc();
        vc.Sg(str);
        vc.YFl(file.getParent(), file.getName());
        com.bytedance.sdk.component.DSW.Sg YFl = vc.YFl();
        if (YFl.vc() && YFl.wN() != null && YFl.wN().exists()) {
            File wN = YFl.wN();
            try {
                YI.YFl(wN.getAbsolutePath(), file.getParent());
                if (wN.exists()) {
                    wN.delete();
                    return true;
                }
                return true;
            } catch (Exception unused) {
            }
        }
        return false;
    }

    public void YFl(int i) {
        if (com.bytedance.sdk.component.adexpress.YFl.YFl.YFl.YFl().AlY() != null) {
            com.bytedance.sdk.component.adexpress.YFl.YFl.YFl.YFl().AlY().YFl(i);
        }
    }

    public void tN(List<YFl.C0109YFl> list) {
        if (list == null || list.isEmpty()) {
            return;
        }
        for (YFl.C0109YFl c0109YFl : list) {
            File file = new File(YFl(), com.bytedance.sdk.component.utils.wN.YFl(c0109YFl.YFl()));
            File file2 = new File(file + DefaultDiskStorage.FileType.TEMP);
            if (file.exists()) {
                try {
                    file.delete();
                } catch (Throwable unused) {
                }
            }
            if (file2.exists()) {
                try {
                    file2.delete();
                } catch (Throwable unused2) {
                }
            }
        }
    }

    public static void YFl(File file, com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl, String str) {
        if (yFl == null) {
            return;
        }
        String NjR = yFl.NjR();
        if (TextUtils.isEmpty(NjR)) {
            return;
        }
        File file2 = new File(file, str);
        File file3 = new File(file2 + DefaultDiskStorage.FileType.TEMP);
        if (file3.exists()) {
            file3.delete();
        }
        FileOutputStream fileOutputStream = null;
        try {
            FileOutputStream fileOutputStream2 = new FileOutputStream(file3);
            try {
                fileOutputStream2.write(NjR.getBytes(rb.N));
                if (file2.exists()) {
                    file2.delete();
                }
                file3.renameTo(file2);
                try {
                    fileOutputStream2.close();
                } catch (IOException unused) {
                }
            } catch (Throwable th) {
                th = th;
                fileOutputStream = fileOutputStream2;
                try {
                    YoT.YFl("PlayComponentEngineCacheManager", "version save error3", th);
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException unused2) {
                        }
                    }
                } catch (Throwable th2) {
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException unused3) {
                        }
                    }
                    throw th2;
                }
            }
        } catch (Throwable th3) {
            th = th3;
        }
    }

    public static boolean tN(com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl, com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl2) {
        if (yFl != null) {
            try {
                if (!TextUtils.isEmpty(yFl.tN())) {
                    if (yFl2 == null) {
                        return false;
                    }
                    if (YFl(yFl.tN(), yFl2.tN())) {
                        return true;
                    }
                    Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> YFl = yFl.YFl();
                    Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> YFl2 = yFl2.YFl();
                    if (YFl.isEmpty()) {
                        return !YFl2.isEmpty();
                    } else if (YFl2.isEmpty()) {
                        return false;
                    } else {
                        return YFl(YFl, YFl2);
                    }
                }
            } catch (Throwable th) {
                th.getMessage();
                return false;
            }
        }
        return true;
    }

    private static boolean YFl(Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> map, Map<String, com.bytedance.sdk.component.adexpress.YFl.tN.YFl> map2) {
        if (map.size() != map2.size()) {
            return true;
        }
        for (String str : map2.keySet()) {
            com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl = map.get(str);
            if (yFl == null) {
                return true;
            }
            com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl2 = map2.get(str);
            if (yFl2 == null) {
                return false;
            }
            if (YFl(yFl.tN(), yFl2.tN())) {
                return true;
            }
        }
        return false;
    }

    /* JADX WARN: Code restructure failed: missing block: B:20:0x0042, code lost:
        return false;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static boolean YFl(java.lang.String r6, java.lang.String r7) {
        /*
            java.lang.String r0 = "\\."
            java.lang.String[] r7 = r7.split(r0)
            java.lang.String[] r6 = r6.split(r0)
            int r0 = r7.length
            int r1 = r6.length
            int r0 = java.lang.Math.min(r0, r1)
            r1 = 0
            r2 = r1
        L12:
            if (r2 >= r0) goto L42
            r3 = r7[r2]
            int r3 = r3.length()
            r4 = r6[r2]
            int r4 = r4.length()
            int r3 = r3 - r4
            r4 = 1
            if (r3 != 0) goto L3f
            r3 = r7[r2]
            r5 = r6[r2]
            int r3 = r3.compareTo(r5)
            if (r3 <= 0) goto L2f
            return r4
        L2f:
            if (r3 >= 0) goto L32
            return r1
        L32:
            int r3 = r0 + (-1)
            if (r2 != r3) goto L3c
            int r7 = r7.length
            int r6 = r6.length
            if (r7 <= r6) goto L3b
            return r4
        L3b:
            return r1
        L3c:
            int r2 = r2 + 1
            goto L12
        L3f:
            if (r3 <= 0) goto L42
            return r4
        L42:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.sdk.component.adexpress.YFl.Sg.tN.YFl(java.lang.String, java.lang.String):boolean");
    }

    @Deprecated
    public static boolean YFl(com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl, String str) {
        if (yFl != null) {
            try {
                if (TextUtils.isEmpty(yFl.tN())) {
                    return true;
                }
                if (TextUtils.isEmpty(str)) {
                    return false;
                }
                return YFl(yFl.tN(), str);
            } catch (Throwable unused) {
                return false;
            }
        }
        return true;
    }

    public static void Sg(File file, com.bytedance.sdk.component.adexpress.YFl.tN.YFl yFl, String str) {
        if (yFl == null || file == null) {
            return;
        }
        try {
            new File(file, str).delete();
        } catch (Throwable unused) {
        }
        if (yFl.vc() != null) {
            for (YFl.C0109YFl c0109YFl : yFl.vc()) {
                try {
                    new File(file, com.bytedance.sdk.component.utils.wN.YFl(c0109YFl.YFl())).delete();
                } catch (Throwable unused2) {
                }
            }
        }
    }
}
