package com.tencent.mm.plugin.fts.b;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.compatible.util.e;
import com.tencent.mm.g.a.bf;
import com.tencent.mm.kernel.g;
import com.tencent.mm.plugin.fts.a.a.a;
import com.tencent.mm.plugin.fts.a.a.i;
import com.tencent.mm.plugin.fts.a.m;
import com.tencent.mm.plugin.fts.a.n;
import com.tencent.mm.sdk.b.c;
import com.tencent.mm.sdk.platformtools.aa;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.vfs.j;
import com.tencent.ttpic.baseutils.FileUtils;
import com.tencent.ttpic.baseutils.IOUtils;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public final class b extends com.tencent.mm.plugin.fts.a.b {
    m eAX;
    private c<bf> fAP = new 2(this);
    private c mFG = new 1(this);
    com.tencent.mm.plugin.fts.c.b mGl;

    public b() {
        AppMethodBeat.i(136724);
        AppMethodBeat.o(136724);
    }

    public final a a(i iVar) {
        AppMethodBeat.i(136725);
        a a = this.eAX.a(-65536, new c(this, iVar, (byte) 0));
        AppMethodBeat.o(136725);
        return a;
    }

    public final boolean onCreate() {
        AppMethodBeat.i(136726);
        if (((n) g.M(n.class)).isFTSContextReady()) {
            ab.i("MicroMsg.FTS.FTS5SearchFeatureLogic", "Create Success!");
            this.eAX = ((n) g.M(n.class)).getFTSTaskDaemon();
            this.mGl = (com.tencent.mm.plugin.fts.c.b) ((n) g.M(n.class)).getFTSIndexStorage(17);
            this.mFG.dnU();
            this.fAP.dnU();
            this.eAX.a(131132, new b(this, (byte) 0));
            this.eAX.a(131133, new a(this, (byte) 0));
            AppMethodBeat.o(136726);
            return true;
        }
        ab.i("MicroMsg.FTS.FTS5SearchFeatureLogic", "Create Fail!");
        AppMethodBeat.o(136726);
        return false;
    }

    public final boolean Pq() {
        AppMethodBeat.i(136727);
        this.mFG.dead();
        this.fAP.dead();
        this.mGl = null;
        this.eAX = null;
        AppMethodBeat.o(136727);
        return true;
    }

    public final String getName() {
        return "FTS5SearchFeatureLogic";
    }

    public static com.tencent.mm.vfs.b bAx() {
        AppMethodBeat.i(136728);
        com.tencent.mm.vfs.b bVar = new com.tencent.mm.vfs.b(new com.tencent.mm.vfs.b(e.eSk, "fts"), "feature");
        if (!bVar.exists()) {
            bVar.mkdirs();
        }
        AppMethodBeat.o(136728);
        return bVar;
    }

    public static com.tencent.mm.vfs.b bAy() {
        AppMethodBeat.i(136729);
        com.tencent.mm.vfs.b bVar = new com.tencent.mm.vfs.b(bAx(), "fts_feature");
        if (!bVar.exists()) {
            bVar.mkdirs();
        }
        AppMethodBeat.o(136729);
        return bVar;
    }

    static int j(com.tencent.mm.vfs.b bVar) {
        AppMethodBeat.i(136730);
        com.tencent.mm.vfs.b bVar2 = new com.tencent.mm.vfs.b(bVar, "version.info");
        int i = -1;
        try {
            if (bVar2.exists()) {
                i = Integer.parseInt(com.tencent.mm.vfs.e.cy(j.w(bVar2.dMD())), 10);
            } else {
                ab.i("MicroMsg.FTS.FTS5SearchFeatureLogic", "version file %s not exist", new Object[]{j.w(bVar2.dMD())});
            }
        } catch (Exception e) {
            ab.printErrStackTrace("MicroMsg.FTS.FTS5SearchFeatureLogic", e, "getFeatureVersion", new Object[0]);
        }
        AppMethodBeat.o(136730);
        return i;
    }

    static int bAz() {
        Exception e;
        Throwable th;
        AppMethodBeat.i(136731);
        int i = -1;
        Closeable bufferedReader;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(ah.getContext().getAssets().open("fts/version.info")));
            try {
                i = Integer.valueOf(bufferedReader.readLine()).intValue();
                bo.b(bufferedReader);
            } catch (Exception e2) {
                e = e2;
                try {
                    ab.printErrStackTrace("MicroMsg.FTS.FTS5SearchFeatureLogic", e, e.getMessage(), new Object[0]);
                    bo.b(bufferedReader);
                    AppMethodBeat.o(136731);
                    return i;
                } catch (Throwable th2) {
                    th = th2;
                    bo.b(bufferedReader);
                    AppMethodBeat.o(136731);
                    throw th;
                }
            }
        } catch (Exception e3) {
            e = e3;
            bufferedReader = null;
            ab.printErrStackTrace("MicroMsg.FTS.FTS5SearchFeatureLogic", e, e.getMessage(), new Object[0]);
            bo.b(bufferedReader);
            AppMethodBeat.o(136731);
            return i;
        } catch (Throwable th3) {
            th = th3;
            bufferedReader = null;
            bo.b(bufferedReader);
            AppMethodBeat.o(136731);
            throw th;
        }
        AppMethodBeat.o(136731);
        return i;
    }

    static /* synthetic */ List Nl(String str) {
        AppMethodBeat.i(136732);
        String str2 = "%s/feature_%s.conf";
        Object[] objArr = new Object[2];
        objArr[0] = str;
        String gw = aa.gw(ah.getContext());
        if (gw.equalsIgnoreCase("zh_CN")) {
            gw = "zh_CN".toLowerCase();
        } else if (gw.equalsIgnoreCase("zh_TW") || gw.equalsIgnoreCase("zh_HK")) {
            gw = "zh_TW".toLowerCase();
        } else {
            gw = "en".toLowerCase();
        }
        objArr[1] = gw;
        gw = String.format(str2, objArr);
        ab.i("MicroMsg.FTS.FTS5SearchFeatureLogic", "decodeToFeatureList %s", new Object[]{gw});
        long ata = com.tencent.mm.vfs.e.ata(gw);
        int asZ = (int) com.tencent.mm.vfs.e.asZ(gw);
        ArrayList arrayList = new ArrayList();
        com.tencent.mm.plugin.fts.a.a.n nVar;
        if (asZ == 0) {
            nVar = new com.tencent.mm.plugin.fts.a.a.n("data file no exist error");
            AppMethodBeat.o(136732);
            throw nVar;
        }
        String[] split = new String(com.tencent.mm.vfs.e.e(gw, 0, asZ)).split(IOUtils.LINE_SEPARATOR_UNIX);
        com.tencent.mm.plugin.fts.a.a.c cVar = null;
        for (String str3 : split) {
            String str32;
            if (str32 != null) {
                str32 = str32.trim();
                if (str32.length() != 0) {
                    int indexOf = str32.indexOf("=");
                    if (indexOf >= 0) {
                        String substring = str32.substring(0, indexOf);
                        str32 = str32.substring(indexOf + 1);
                        if (substring.equals("FeatureID")) {
                            if (cVar != null) {
                                cVar.field_iconPath = str + "/icon/" + cVar.field_featureId + FileUtils.PIC_POSTFIX_PNG;
                                arrayList.add(cVar);
                            }
                            cVar = new com.tencent.mm.plugin.fts.a.a.c();
                            cVar.field_featureId = Integer.valueOf(str32).intValue();
                            cVar.field_timestamp = ata;
                        }
                        if (cVar != null) {
                            if (substring.equals("Title")) {
                                cVar.field_title = str32;
                            } else if (substring.equals("TitlePY")) {
                                cVar.field_titlePY = str32;
                            } else if (substring.equals("TitleShortPY")) {
                                cVar.field_titleShortPY = str32;
                            } else if (substring.equals("Tag")) {
                                cVar.field_tag = str32;
                            } else if (substring.equals("ActionType")) {
                                if (str32.equals("H5")) {
                                    cVar.field_actionType = 2;
                                } else if (str32.equals("Native")) {
                                    cVar.field_actionType = 1;
                                }
                            } else if (substring.equals("Url")) {
                                cVar.field_url = str32;
                            } else if (substring.equals("HelpUrl")) {
                                cVar.field_helpUrl = str32;
                            } else if (substring.equals("UpdateUrl")) {
                                cVar.field_updateUrl = str32;
                            } else if (substring.equals("AndroidUrl")) {
                                cVar.field_androidUrl = str32;
                            }
                        }
                    }
                }
            }
        }
        if (cVar != null) {
            cVar.field_iconPath = str + "/icon/" + cVar.field_featureId + FileUtils.PIC_POSTFIX_PNG;
            cVar.field_timestamp = ata;
            arrayList.add(cVar);
        }
        if (arrayList.size() == 0) {
            nVar = new com.tencent.mm.plugin.fts.a.a.n("no data error");
            AppMethodBeat.o(136732);
            throw nVar;
        }
        AppMethodBeat.o(136732);
        return arrayList;
    }
}
