package com.tencent.mm.plugin.emoji.model;

import android.util.Base64;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.a.a;
import com.tencent.mm.at.a.c.c;
import com.tencent.mm.plugin.emoji.h.b;
import com.tencent.mm.protocal.protobuf.xx;
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.sdk.platformtools.r;
import com.tencent.mm.storage.emotion.EmojiInfo;
import com.tencent.mm.vfs.e;
import com.tencent.mm.vfs.j;
import com.tencent.smtt.sdk.TbsMediaPlayer$TbsMediaPlayerListener;
import com.tencent.ytcommon.BuildConfig;

class c$1 implements c {
    final /* synthetic */ c kVe;

    c$1(c cVar) {
        this.kVe = cVar;
    }

    public final void a(boolean z, Object... objArr) {
        AppMethodBeat.i(52998);
        if (objArr == null || objArr.length < 2) {
            ab.w("MicroMsg.emoji.EmojiAppMsgDownloadService", "extra obj error");
            AppMethodBeat.o(52998);
            return;
        }
        xx xxVar;
        int intValue = ((Integer) objArr[1]).intValue();
        if (objArr[0] instanceof xx) {
            xxVar = (xx) objArr[0];
        } else {
            xxVar = null;
        }
        if (xxVar == null) {
            ab.e("MicroMsg.emoji.EmojiAppMsgDownloadService", "msginfo or  emojiInfo");
            AppMethodBeat.o(52998);
            return;
        }
        String str;
        boolean z2;
        String L = EmojiLogic.L(b.Yb(), BuildConfig.FLAVOR, xxVar.Md5);
        new StringBuilder().append(L).append("_encrypt");
        if (intValue == TbsMediaPlayer$TbsMediaPlayerListener.MEDIA_EXTRA_SUBTITLE_COUNT) {
            str = L + "_extern";
            z2 = true;
        } else if (intValue == TbsMediaPlayer$TbsMediaPlayerListener.MEDIA_EXTRA_SUBTITLE_INDEX) {
            str = L + "_encrypt";
            z2 = true;
        } else {
            str = null;
            z2 = false;
        }
        if (z) {
            if (z2) {
                boolean z3 = false;
                if (e.asZ(str) > 0) {
                    long currentTimeMillis = System.currentTimeMillis();
                    try {
                        z3 = a.g(Base64.encodeToString(bo.anf(xxVar.AesKey), 0), str, L);
                        if (z3) {
                            com.tencent.mm.plugin.emoji.c.hF(7);
                        } else {
                            com.tencent.mm.plugin.emoji.c.hF(8);
                        }
                    } catch (Exception e) {
                        ab.e("MicroMsg.emoji.EmojiAppMsgDownloadService", "encrypt file failed. exception:%s", new Object[]{bo.l(e)});
                        com.tencent.mm.plugin.emoji.c.hF(8);
                    }
                    ab.i("MicroMsg.emoji.EmojiAppMsgDownloadService", "encrypt file use time:%d", new Object[]{Long.valueOf(System.currentTimeMillis() - currentTimeMillis)});
                    if (z3) {
                        e.deleteFile(str);
                    } else {
                        String str2 = "MicroMsg.emoji.EmojiAppMsgDownloadService";
                        String str3 = "handleCNDDownloadResult file aes failed. try to download by cgi.emojiMd5:%s buf size:%d buf md5:%s key:%s eUrl:%s ";
                        Object[] objArr2 = new Object[5];
                        objArr2[0] = xxVar.Md5;
                        objArr2[1] = Long.valueOf(e.asZ(str));
                        objArr2[2] = e.atg(str) == null ? BuildConfig.FLAVOR : e.atg(str);
                        objArr2[3] = xxVar.AesKey;
                        objArr2[4] = xxVar.EncryptUrl;
                        ab.i(str2, str3, objArr2);
                        com.tencent.mm.plugin.emoji.c.a(xxVar.Md5, 3, 0, 1, BuildConfig.FLAVOR, 1, BuildConfig.FLAVOR);
                        e.deleteFile(str);
                        c.cb(xxVar.Md5, 2);
                        AppMethodBeat.o(52998);
                        return;
                    }
                }
                ab.i("MicroMsg.emoji.EmojiAppMsgDownloadService", "handleCNDDownloadResult file aes download failed., try to download by cgi.emojiMd5:%s", new Object[]{xxVar.Md5});
                com.tencent.mm.plugin.emoji.c.a(xxVar.Md5, 3, 1, 1, BuildConfig.FLAVOR, 1, BuildConfig.FLAVOR);
                c.cb(xxVar.Md5, 2);
                AppMethodBeat.o(52998);
                return;
            }
            com.tencent.mm.vfs.b bVar = new com.tencent.mm.vfs.b(L);
            int asZ = (int) e.asZ(L);
            byte[] e2 = e.e(L, 0, 10);
            if (asZ <= 0 || e2 == null) {
                c.a(xxVar, z2);
                AppMethodBeat.o(52998);
                return;
            }
            String atg = e.atg(j.w(bVar.mUri));
            String str4 = xxVar.Md5;
            if (intValue == TbsMediaPlayer$TbsMediaPlayerListener.MEDIA_EXTRA_SUBTITLE_COUNT) {
                str4 = xxVar.ExternMd5;
            }
            if (bo.isNullOrNil(atg) || !atg.equalsIgnoreCase(str4)) {
                ab.i("MicroMsg.emoji.EmojiAppMsgDownloadService", "handleCNDDownloadResult md5 check failed, try to download by cgi. buf md5:%s emojiMd5:%s field_cdnUrl:%s", new Object[]{atg, xxVar.Md5, xxVar.Url});
                bVar.delete();
                c.cb(xxVar.Md5, 2);
                if (z2) {
                    com.tencent.mm.plugin.emoji.c.hF(5);
                    com.tencent.mm.plugin.emoji.c.a(xxVar.Md5, 3, 0, 1, BuildConfig.FLAVOR, 1, BuildConfig.FLAVOR);
                    AppMethodBeat.o(52998);
                    return;
                }
                com.tencent.mm.plugin.emoji.c.hF(5);
                com.tencent.mm.plugin.emoji.c.a(xxVar.Md5, 2, 0, 1, BuildConfig.FLAVOR, 1, BuildConfig.FLAVOR);
                AppMethodBeat.o(52998);
                return;
            }
            if (z2) {
                com.tencent.mm.plugin.emoji.c.hF(4);
                com.tencent.mm.plugin.emoji.c.a(xxVar.Md5, 3, 0, 0, BuildConfig.FLAVOR, 0, BuildConfig.FLAVOR);
            } else {
                com.tencent.mm.plugin.emoji.c.hF(4);
                com.tencent.mm.plugin.emoji.c.a(xxVar.Md5, 2, 0, 0, BuildConfig.FLAVOR, 1, BuildConfig.FLAVOR);
            }
            asZ = EmojiInfo.yaq;
            if (r.bS(e2)) {
                asZ = EmojiInfo.yap;
            } else {
                asZ = EmojiInfo.yaq;
            }
            EmojiInfo aqi = j.getEmojiStorageMgr().xYn.aqi(atg);
            if (aqi == null) {
                aqi = new EmojiInfo();
                aqi.field_md5 = xxVar.Md5;
                aqi.field_catalog = EmojiInfo.yaf;
                aqi.field_size = (int) e.asZ(L);
            }
            aqi.field_type = asZ;
            aqi.field_state = EmojiInfo.yat;
            j.getEmojiStorageMgr().xYn.G(aqi);
            c.cb(xxVar.Md5, 1);
            EmojiLogic.a(ah.getContext(), null, aqi.Aq(), aqi.ptQ, aqi);
            AppMethodBeat.o(52998);
            return;
        }
        c.a(xxVar, z2);
        AppMethodBeat.o(52998);
    }
}
