package com.google.android.play.core.assetpacks;

import X.0HH;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.google.android.play.core.b.bf;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public final class cp {
    public static final Pattern LIZ = Pattern.compile("[0-9]+-(NAM|LFH)\\.dat");

    static {
        Covode.recordClassIndex(44176);
    }

    public static List<File> LIZ(File file, File file2) {
        File[] fileArr;
        MethodCollector.i(18835);
        ArrayList arrayList = new ArrayList();
        File[] listFiles = file2.listFiles(co.LIZ);
        if (listFiles == null) {
            fileArr = new File[0];
        } else {
            fileArr = new File[r6];
            for (File file3 : listFiles) {
                int parseInt = Integer.parseInt(file3.getName().split("-")[0]);
                if (parseInt > listFiles.length || fileArr[parseInt] != null) {
                    au auVar = new au("Metadata folder ordering corrupt.");
                    MethodCollector.o(18835);
                    throw auVar;
                }
                fileArr[parseInt] = file3;
            }
        }
        for (File file4 : fileArr) {
            arrayList.add(file4);
            if (file4.getName().contains("LFH")) {
                FileInputStream fileInputStream = new FileInputStream(file4);
                try {
                    ct LIZ2 = new al(fileInputStream).LIZ();
                    if (LIZ2.LIZ != null) {
                        File file5 = new File(file, LIZ2.LIZ);
                        if (file5.exists()) {
                            arrayList.add(file5);
                            fileInputStream.close();
                        } else {
                            au auVar2 = new au(0HH.LIZ("Missing asset file %s during slice reconstruction.", new Object[]{file5.getCanonicalPath()}));
                            MethodCollector.o(18835);
                            throw auVar2;
                        }
                    } else {
                        au auVar3 = new au("Metadata files corrupt. Could not read local file header.");
                        MethodCollector.o(18835);
                        throw auVar3;
                    }
                } catch (Throwable th) {
                    bf.LIZ(th, th);
                }
            }
        }
        MethodCollector.o(18835);
        return arrayList;
        MethodCollector.o(18835);
        throw th;
    }
}
