OurPlay v5.5.9版本的 MD5 值为:d4e139798f4c2243a1145c8af5e21046

以下内容为反编译后的 an.java 源代码,内容仅作参考


package com.excelliance.kxqp.gs.util;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.media.session.PlaybackStateCompat;
import android.system.Os;
import android.text.TextUtils;
import android.util.Log;
import androidx.core.content.FileProvider;
import androidx.work.Data;
import com.android.spush.util.WebActionRouter;
import com.excelliance.kxqp.GameUtil;
import com.excelliance.kxqp.gs.thpool.tp;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.json.JSONArray;
import org.json.JSONObject;

public class an {
    public static void a(Context context, String str, String str2, String str3, boolean z) {
        az.d("FileUtil", String.format("FileUtil/initProcessConfig:thread(%s), proxyname(%s), port(%s)", Thread.currentThread().getName(), str, str2));
        String str4 = "ss_local_update_ver_" + str;
        int c = by.a(context, "sp_total_info").c(str4, 0);
        File file = new File(as.a(context));
        File file2 = new File(file, str);
        com.excelliance.kxqp.util.master.c.a(file2);
        if (file2.exists() && file2.isFile() && c == bt.c && !z) {
            return;
        }
        if (!file.exists()) {
            file.mkdirs();
        }
        az.d("FileUtil", "initProcessConfig: -----destDir----" + file2.getAbsolutePath());
        if (file2.exists()) {
            if (file2.isDirectory() || c < bt.c || z) {
                file2.delete();
                a(file2, str2, context, str4);
                com.excelliance.kxqp.util.master.c.a(file2);
                return;
            }
            return;
        }
        a(file2, str2, context, str4);
        com.excelliance.kxqp.util.master.c.a(file2);
    }

    private static void a(File file, String str, Context context, String str2) {
        String sb;
        byte[] bytes;
        BufferedOutputStream bufferedOutputStream;
        BufferedOutputStream bufferedOutputStream2 = null;
        try {
            try {
                StringBuilder sb2 = new StringBuilder();
                sb2.append("socks5 127.0.0.1 " + str);
                sb2.append("\n");
                sb2.append("socks5v6 ::1 " + str);
                sb2.append("\n");
                sb2.append("ssudp 127.0.0.1 " + str);
                sb2.append("\n");
                sb = sb2.toString();
                bytes = sb.getBytes();
                bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
            } catch (Throwable th) {
                th = th;
            }
        } catch (IOException e) {
            e = e;
        }
        try {
            bufferedOutputStream.write(bytes);
            bufferedOutputStream.close();
            by.a(context, "sp_total_info").a(str2, bt.c);
            az.d("FileUtil", "initProcessConfig: --------configs: " + sb);
        } catch (IOException e2) {
            e = e2;
            bufferedOutputStream2 = bufferedOutputStream;
            e.printStackTrace();
            if (bufferedOutputStream2 != null) {
                try {
                    bufferedOutputStream2.close();
                } catch (IOException e3) {
                    e3.printStackTrace();
                }
            }
        } catch (Throwable th2) {
            th = th2;
            bufferedOutputStream2 = bufferedOutputStream;
            if (bufferedOutputStream2 != null) {
                try {
                    bufferedOutputStream2.close();
                } catch (IOException e4) {
                    e4.printStackTrace();
                }
            }
            throw th;
        }
    }

    public static String a(final Context context, String str, final String str2, String str3) {
        final File file = new File(str + "");
        tp.f(new Runnable() {
            @Override
            public void run() {
                String arrays = Arrays.toString(com.excelliance.kxqp.gs.m.e.e.a(file));
                az.e("FileUtil", "run: asy thread sha :" + arrays);
                com.excelliance.kxqp.util.master.e.a(context, file, str2, 0, null, arrays);
            }
        });
        return str3;
    }

    public static String b(final Context context, final String str, final String str2, String str3) {
        final File file = new File(str + "");
        tp.f(new Runnable() {
            @Override
            public void run() {
                String a2 = an.a(str);
                Log.e("FileUtil", "run: asy md5 " + a2);
                com.excelliance.kxqp.util.master.e.a(context, file, str2, 0, a2, null);
            }
        });
        return str3;
    }

    public static String a(String str) {
        if (str == null || str.length() == 0) {
            return null;
        }
        File file = new File(str);
        if (!file.exists()) {
            Log.d("FileUtil", String.format("FileUtil/computeFileMd5:thread(%s) file(%s) not exist", Thread.currentThread().getName(), file.getAbsolutePath()));
            return null;
        }
        byte[] bArr = new byte[1024];
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file), 65536);
            while (true) {
                int read = bufferedInputStream.read(bArr, 0, 1024);
                if (read == -1) {
                    break;
                }
                messageDigest.update(bArr, 0, read);
            }
            bufferedInputStream.close();
            byte[] digest = messageDigest.digest();
            StringBuffer stringBuffer = new StringBuffer();
            for (byte b2 : digest) {
                stringBuffer.append(Integer.toString((b2 & 255) + 256, 16).substring(1));
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("FileUtil", "FileUtil/computeFileMd5:" + e.toString());
            return null;
        }
    }

    public static List<String> a(Context context, String str) {
        BufferedReader bufferedReader;
        String str2 = bn.g(context) + "extraData";
        ArrayList arrayList = new ArrayList();
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(str2))));
        } catch (IOException unused) {
            bufferedReader = null;
        } catch (Throwable unused2) {
            bufferedReader = null;
        }
        try {
            StringBuffer stringBuffer = new StringBuffer();
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    break;
                }
                stringBuffer.append(readLine);
            }
            arrayList.addAll(ay.a(stringBuffer.toString()));
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                az.i("FileUtil", "parserBlackList: -------s: " + ((String) it.next()));
            }
            q.a(bufferedReader);
            return arrayList;
        } catch (IOException unused3) {
            q.a(bufferedReader);
            return arrayList;
        } catch (Throwable unused4) {
            q.a(bufferedReader);
            return arrayList;
        }
    }

    public static void b(Context context, String str) {
        Throwable th;
        BufferedReader bufferedReader;
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(as.a(context) + "blackList"))));
            try {
                List<String> a2 = ay.a(bufferedReader.readLine(), "noNeedObbList");
                if (a2 != null && !a2.isEmpty()) {
                    com.excelliance.kxqp.bitmap.a.a.f2688a.clear();
                    com.excelliance.kxqp.bitmap.a.a.f2688a.addAll(a2);
                }
                Iterator<String> it = com.excelliance.kxqp.bitmap.a.a.f2688a.iterator();
                while (it.hasNext()) {
                    az.i("FileUtil", "parserNoNeedObbAppsList: -------s: " + it.next());
                }
            } catch (IOException unused) {
                if (bufferedReader == null) {
                    return;
                }
                bufferedReader.close();
            } catch (Throwable th2) {
                th = th2;
                if (bufferedReader != null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException unused2) {
                    }
                }
                throw th;
            }
        } catch (IOException unused3) {
            bufferedReader = null;
        } catch (Throwable th3) {
            th = th3;
            bufferedReader = null;
        }
        try {
            bufferedReader.close();
        } catch (IOException unused4) {
        }
    }

    public static void b(String str) {
        File file = new File(str);
        if (file.isFile()) {
            try {
                byte[] bytes = "fuck_snsslmm_bslznw".getBytes();
                int length = bytes.length;
                byte[] bArr = new byte[65536];
                RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
                randomAccessFile.seek(0L);
                for (int i = 0; i < 65536; i++) {
                    bArr[i] = (byte) (randomAccessFile.readByte() ^ bytes[i % length]);
                }
                randomAccessFile.seek(0L);
                randomAccessFile.write(bArr);
                long length2 = file.length() - PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH;
                randomAccessFile.seek(length2);
                for (int i2 = 0; i2 < 65536; i2++) {
                    bArr[i2] = (byte) (randomAccessFile.readByte() ^ bytes[i2 % length]);
                }
                randomAccessFile.seek(length2);
                randomAccessFile.write(bArr);
                randomAccessFile.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e2) {
                e2.printStackTrace();
            }
        }
    }

    public static boolean a(String str, String str2, String str3) {
        ZipOutputStream zipOutputStream;
        ?? file = new File(str);
        boolean z = false;
        if (!file.exists()) {
            System.out.println("待压缩的文件目录:" + str + "不存在.");
        } else {
            BufferedInputStream bufferedInputStream = null;
            try {
                try {
                    File file2 = new File(str2 + "/" + str3 + ".zip");
                    if (file2.exists()) {
                        file2.delete();
                    }
                    File[] listFiles = file.listFiles();
                    if (listFiles != null && listFiles.length >= 1) {
                        file = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file2)));
                        try {
                            byte[] bArr = new byte[Data.MAX_DATA_BYTES];
                            BufferedInputStream bufferedInputStream2 = null;
                            int i = 0;
                            while (i < listFiles.length) {
                                try {
                                    file.putNextEntry(new ZipEntry(listFiles[i].getName()));
                                    BufferedInputStream bufferedInputStream3 = new BufferedInputStream(new FileInputStream(listFiles[i]), Data.MAX_DATA_BYTES);
                                    while (true) {
                                        try {
                                            int read = bufferedInputStream3.read(bArr, 0, Data.MAX_DATA_BYTES);
                                            if (read != -1) {
                                                file.write(bArr, 0, read);
                                            }
                                        } catch (FileNotFoundException e) {
                                            e = e;
                                            e.printStackTrace();
                                            throw new RuntimeException(e);
                                        } catch (IOException e2) {
                                            e = e2;
                                            e.printStackTrace();
                                            throw new RuntimeException(e);
                                        } catch (Throwable th) {
                                            th = th;
                                            bufferedInputStream = bufferedInputStream3;
                                            if (bufferedInputStream != null) {
                                                try {
                                                    bufferedInputStream.close();
                                                } catch (IOException e3) {
                                                    e3.printStackTrace();
                                                    throw new RuntimeException(e3);
                                                }
                                            }
                                            if (file != 0) {
                                                file.close();
                                            }
                                            throw th;
                                        }
                                    }
                                    i++;
                                    bufferedInputStream2 = bufferedInputStream3;
                                } catch (FileNotFoundException e4) {
                                    e = e4;
                                } catch (IOException e5) {
                                    e = e5;
                                } catch (Throwable th2) {
                                    th = th2;
                                    bufferedInputStream = bufferedInputStream2;
                                }
                            }
                            bufferedInputStream = bufferedInputStream2;
                            z = true;
                            zipOutputStream = file;
                            if (bufferedInputStream != null) {
                                try {
                                    bufferedInputStream.close();
                                } catch (IOException e6) {
                                    e6.printStackTrace();
                                    throw new RuntimeException(e6);
                                }
                            }
                            if (zipOutputStream != null) {
                                zipOutputStream.close();
                            }
                        } catch (FileNotFoundException e7) {
                            e = e7;
                        } catch (IOException e8) {
                            e = e8;
                        }
                    }
                    System.out.println("待压缩的文件目录:" + str + "里面不存在文件,无需压缩.");
                    zipOutputStream = null;
                    if (bufferedInputStream != null) {
                    }
                    if (zipOutputStream != null) {
                    }
                } catch (Throwable th3) {
                    th = th3;
                }
            } catch (FileNotFoundException e9) {
                e = e9;
            } catch (IOException e10) {
                e = e10;
            } catch (Throwable th4) {
                th = th4;
                file = 0;
            }
        }
        return z;
    }

    public static boolean a(File file) {
        String[] list;
        Log.d("FileUtil", String.format("FileUtil/deleteDir:thread(%s) dir(%s) exist(%s)", Thread.currentThread().getName(), file.getAbsolutePath(), Boolean.valueOf(file.exists())));
        if (file.isDirectory() && (list = file.list()) != null) {
            for (String str : list) {
                if (!a(new File(file, str))) {
                    return false;
                }
            }
        }
        return file.delete();
    }

    public static void c(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        File file = new File(str);
        az.d("FileUtil", String.format("FileUtil/deleteFile:thread(%s) filePath(%s) exist(%s)", Thread.currentThread().getName(), str, Boolean.valueOf(file.exists())));
        if (file.exists()) {
            if (file.isFile()) {
                file.delete();
                return;
            }
            File[] listFiles = file.listFiles();
            if (listFiles != null) {
                for (File file2 : listFiles) {
                    c(file2.getAbsolutePath());
                }
            }
            file.delete();
        }
    }

    public static void d(String str) {
        Log.d("FileUtil", String.format("FileUtil/clearDir:thread(%s) parentDir(%s)", Thread.currentThread().getName(), str));
        if (TextUtils.isEmpty(str)) {
            return;
        }
        File file = new File(str);
        if (file.exists()) {
            if (file.isFile()) {
                file.delete();
            }
            File[] listFiles = file.listFiles();
            if (listFiles == null || listFiles.length <= 0) {
                return;
            }
            for (File file2 : listFiles) {
                c(file2.getAbsolutePath());
            }
        }
    }

    public static boolean a(InputStream inputStream, String str) {
        if (inputStream == null || TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            File parentFile = new File(str).getParentFile();
            if (!parentFile.exists()) {
                parentFile.mkdirs();
            }
            FileOutputStream fileOutputStream = new FileOutputStream(str);
            byte[] bArr = new byte[1024];
            while (true) {
                int read = inputStream.read(bArr);
                if (read > 0) {
                    fileOutputStream.write(bArr, 0, read);
                } else {
                    inputStream.close();
                    fileOutputStream.close();
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean a(String str, String str2) {
        try {
            org.apache.commons.b.b.a(new File(str), new File(str2));
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean a(List<String> list, List<String> list2) {
        for (int i = 0; i < list.size(); i++) {
            try {
                org.apache.commons.b.b.a(new File(list.get(i)), new File(list2.get(i)));
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }

    public static void a(List<String> list, List<String> list2, String str) {
        for (String str2 : list) {
            if (str2.toLowerCase().endsWith(File.separator + "base.apk")) {
                list2.add(str + File.separator + "base.apk");
            } else if (str2.endsWith(".apk")) {
                String name = new File(str2).getName();
                az.d("FileUtil", "buildApkList split_file: " + name + ",str = " + str2 + " path: " + str);
                if (name != null && !name.toLowerCase().startsWith("split_")) {
                    name = "split_" + name;
                }
                list2.add(str + File.separator + name);
            }
        }
        az.d("FileUtil", "buildApkList path: " + str + " targets: " + list2 + " sources:" + list);
    }

    public static List<String> e(String str) {
        File[] listFiles = new File(str).listFiles();
        ArrayList arrayList = new ArrayList();
        for (File file : listFiles) {
            az.d("FileUtil", "buildSourcePathList filePath:" + file.getAbsolutePath());
            if (file.isFile() && file.getAbsolutePath().endsWith(".apk")) {
                az.d("FileUtil", "buildSourcePathList is split apk filePath:" + file.getAbsolutePath());
                arrayList.add(file.getAbsolutePath());
            }
        }
        return arrayList;
    }

    public static HashMap<String, Integer> a(String str, Context context) {
        FileInputStream fileInputStream;
        FileNotFoundException e;
        HashMap<String, Integer> hashMap = new HashMap<>();
        az.d("FileUtil", "onHandleIntent initGameTypeFromCache : " + ((String) str));
        if (context == null || TextUtils.isEmpty(str) || !new File((String) str).exists()) {
            return hashMap;
        }
        try {
            try {
                fileInputStream = new FileInputStream(new File((String) str));
                try {
                    try {
                        str = a(fileInputStream, (List<String>) null);
                        try {
                            Log.d("FileUtil", "size1: " + str.size());
                            fileInputStream.close();
                            str = str;
                        } catch (FileNotFoundException e2) {
                            e = e2;
                            e.printStackTrace();
                            if (fileInputStream != null) {
                                fileInputStream.close();
                                str = str;
                            }
                            return str;
                        }
                    } catch (Throwable th) {
                        th = th;
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e3) {
                                e3.printStackTrace();
                            }
                        }
                        throw th;
                    }
                } catch (FileNotFoundException e4) {
                    e = e4;
                    str = hashMap;
                    e.printStackTrace();
                    if (fileInputStream != null) {
                    }
                    return str;
                }
            } catch (IOException e5) {
                e5.printStackTrace();
            }
        } catch (FileNotFoundException e6) {
            fileInputStream = null;
            e = e6;
        } catch (Throwable th2) {
            th = th2;
            fileInputStream = null;
            if (fileInputStream != null) {
            }
            throw th;
        }
        return str;
    }

    public static HashMap<String, Integer> a(Context context, List<String> list, int i) {
        InputStream inputStream;
        HashMap<String, Integer> hashMap;
        HashMap<String, Integer> hashMap2 = new HashMap<>();
        az.d("FileUtil", "onHandleIntent readGameTypeFromAssets libList: " + list);
        if (context == null || list == null || list.size() == 0) {
            return hashMap2;
        }
        InputStream inputStream2 = null;
        try {
            try {
                inputStream = context.getAssets().open("type");
            } catch (IOException e) {
                e = e;
            }
        } catch (Throwable unused) {
            inputStream = inputStream2;
        }
        try {
            hashMap = a(inputStream, list);
            try {
                for (String str : list) {
                    if (!hashMap.containsKey(str)) {
                        hashMap.put(str, Integer.valueOf(i));
                    }
                }
                Log.d("FileUtil", "size2: " + hashMap.size());
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e2) {
                        e2.printStackTrace();
                    }
                }
                return hashMap;
            } catch (IOException e3) {
                e = e3;
                hashMap2 = hashMap;
                inputStream2 = inputStream;
                e.printStackTrace();
                if (inputStream2 != null) {
                    try {
                        inputStream2.close();
                    } catch (IOException e4) {
                        e4.printStackTrace();
                    }
                }
                return hashMap2;
            } catch (Throwable unused2) {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e5) {
                        e5.printStackTrace();
                    }
                }
                return hashMap;
            }
        } catch (IOException e6) {
            e = e6;
        } catch (Throwable unused3) {
            hashMap = hashMap2;
            if (inputStream != null) {
            }
            return hashMap;
        }
    }

    private static HashMap<String, Integer> a(InputStream inputStream, List<String> list) {
        BufferedReader bufferedReader;
        HashMap<String, Integer> hashMap = new HashMap<>();
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            while (true) {
                try {
                    String readLine = bufferedReader.readLine();
                    if (readLine != null) {
                        if (!TextUtils.isEmpty(readLine)) {
                            String[] split = readLine.split(":");
                            if (split.length == 2) {
                                String str = split[0];
                                if (list == null || list.contains(str)) {
                                    hashMap.put(str, Integer.valueOf(split[1]));
                                }
                            }
                        }
                    } else {
                        try {
                            break;
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                } catch (Exception unused) {
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e2) {
                            e2.printStackTrace();
                        }
                    }
                    return hashMap;
                } catch (Throwable unused2) {
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e3) {
                            e3.printStackTrace();
                        }
                    }
                    return hashMap;
                }
            }
            bufferedReader.close();
            return hashMap;
        } catch (Exception unused3) {
            bufferedReader = null;
        } catch (Throwable unused4) {
            bufferedReader = null;
        }
    }

    public static String a(Context context, File file) {
        String readLine;
        StringBuilder sb = new StringBuilder();
        ?? r0 = 0;
        r0 = 0;
        r0 = 0;
        try {
            try {
                try {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                    while (true) {
                        try {
                            readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            }
                            sb.append(readLine);
                        } catch (IOException e) {
                            r0 = bufferedReader;
                            e = e;
                            e.printStackTrace();
                            if (r0 != 0) {
                                r0.close();
                                r0 = r0;
                            }
                            return sb.toString();
                        } catch (Throwable th) {
                            th = th;
                            r0 = bufferedReader;
                            if (r0 != 0) {
                                try {
                                    r0.close();
                                } catch (IOException e2) {
                                    e2.printStackTrace();
                                }
                            }
                            throw th;
                        }
                    }
                    bufferedReader.close();
                    r0 = readLine;
                } catch (IOException e3) {
                    e3.printStackTrace();
                }
            } catch (IOException e4) {
                e = e4;
            }
            return sb.toString();
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static Object a(String str, Context context, Class<?> cls) {
        BufferedReader bufferedReader;
        Boolean valueOf;
        File file = new File(bn.d(context, "state.data"));
        try {
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (!file.exists()) {
            Log.d("FileUtil", "getTCardExtraData do not exist");
            return null;
        }
        try {
            bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            while (true) {
                try {
                    try {
                        String readLine = bufferedReader.readLine();
                        if (readLine == null) {
                            bufferedReader.close();
                            break;
                        }
                        if (!TextUtils.isEmpty(readLine)) {
                            String[] split = readLine.split(":");
                            if (TextUtils.equals(split[0], str) && cls == Boolean.class) {
                                break;
                            }
                        }
                    } catch (IOException e2) {
                        e = e2;
                        e.printStackTrace();
                        if (bufferedReader != null) {
                            bufferedReader.close();
                        }
                        Log.d("FileUtil", "getTCardExtraData read error");
                        return null;
                    }
                } catch (Throwable th) {
                    th = th;
                    if (bufferedReader != null) {
                        try {
                            bufferedReader.close();
                        } catch (IOException e3) {
                            e3.printStackTrace();
                        }
                    }
                    throw th;
                }
            }
        } catch (IOException e4) {
            e = e4;
            bufferedReader = null;
        } catch (Throwable th2) {
            th = th2;
            bufferedReader = null;
            if (bufferedReader != null) {
            }
            throw th;
        }
        Log.d("FileUtil", "getTCardExtraData read error");
        return null;
        return valueOf;
    }

    public static void a(String str, Object obj, Context context) {
        FileOutputStream fileOutputStream;
        BufferedReader bufferedReader;
        File file = new File(bn.d(context, "state.data"));
        StringBuilder sb = new StringBuilder();
        ?? exists = file.exists();
        FileOutputStream fileOutputStream2 = null;
        try {
            try {
                if (exists != 0) {
                    try {
                        bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                        while (true) {
                            try {
                                String readLine = bufferedReader.readLine();
                                if (readLine == null) {
                                    break;
                                }
                                if (!TextUtils.isEmpty(readLine) && !TextUtils.equals(readLine.split(":")[0], str)) {
                                    sb.append(readLine);
                                    sb.append("\n");
                                }
                            } catch (IOException e) {
                                e = e;
                                e.printStackTrace();
                                if (bufferedReader != null) {
                                    bufferedReader.close();
                                }
                                sb.append(str);
                                sb.append(":");
                                sb.append(obj);
                                sb.append("\n");
                                try {
                                    File file2 = new File(file.getParent(), "tempState.data");
                                    fileOutputStream = new FileOutputStream(file2);
                                    fileOutputStream.write(sb.toString().getBytes());
                                    file2.renameTo(file);
                                    fileOutputStream.close();
                                } catch (IOException e2) {
                                    e = e2;
                                }
                            }
                        }
                        bufferedReader.close();
                    } catch (IOException e3) {
                        e = e3;
                        bufferedReader = null;
                    } catch (Throwable th) {
                        th = th;
                        exists = 0;
                        if (exists != 0) {
                            try {
                                exists.close();
                            } catch (IOException e4) {
                                e4.printStackTrace();
                            }
                        }
                        throw th;
                    }
                }
            } catch (Throwable th2) {
                th = th2;
            }
        } catch (IOException e5) {
            e5.printStackTrace();
        }
        sb.append(str);
        sb.append(":");
        sb.append(obj);
        sb.append("\n");
        try {
            try {
                File file22 = new File(file.getParent(), "tempState.data");
                fileOutputStream = new FileOutputStream(file22);
            } catch (Throwable th3) {
                th = th3;
            }
            try {
                fileOutputStream.write(sb.toString().getBytes());
                file22.renameTo(file);
                fileOutputStream.close();
            } catch (IOException e6) {
                e = e6;
                fileOutputStream2 = fileOutputStream;
                e.printStackTrace();
                if (fileOutputStream2 != null) {
                    fileOutputStream2.close();
                }
            } catch (Throwable th4) {
                th = th4;
                fileOutputStream2 = fileOutputStream;
                if (fileOutputStream2 != null) {
                    try {
                        fileOutputStream2.close();
                    } catch (IOException e7) {
                        e7.printStackTrace();
                    }
                }
                throw th;
            }
        } catch (IOException e8) {
            e8.printStackTrace();
        }
    }

    public static boolean[] a(List<String> list, String str, int i) {
        boolean[] zArr = new boolean[2];
        File file = new File(str);
        if (file.exists()) {
            try {
                if (file.isFile()) {
                    Enumeration<? extends ZipEntry> entries = new ZipFile(file).entries();
                    int i2 = 0;
                    while (entries.hasMoreElements()) {
                        String name = entries.nextElement().getName();
                        az.d("FileUtil", "countMatchFileNum name: " + name);
                        if (list.contains(name)) {
                            i2++;
                            az.d("FileUtil", "countMatchFileNum countNum: " + i2);
                            if (i2 >= i) {
                                zArr[0] = true;
                                return zArr;
                            }
                        }
                    }
                } else if (file.isDirectory()) {
                    zArr[0] = true;
                    return zArr;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (!file.exists()) {
            zArr[1] = true;
        }
        return zArr;
    }

    public static void a(String str, int i) {
        File file = new File(bn.a());
        if (file.exists()) {
            file.delete();
        }
        try {
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
            bufferedOutputStream.write((str + ":" + i).getBytes());
            bufferedOutputStream.flush();
            bufferedOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }

    public static Bundle a() {
        File file = new File(bn.a());
        Bundle bundle = null;
        if (!file.exists()) {
            return null;
        }
        try {
            String readLine = new BufferedReader(new FileReader(file)).readLine();
            if (TextUtils.isEmpty(readLine)) {
                return null;
            }
            String[] split = readLine.split(":");
            if (split.length != 2) {
                return null;
            }
            Bundle bundle2 = new Bundle();
            try {
                bundle2.putString(WebActionRouter.KEY_PKG, split[0]);
                bundle2.putInt("cpu", Integer.valueOf(split[1]).intValue());
                return bundle2;
            } catch (FileNotFoundException e) {
                e = e;
                bundle = bundle2;
                e.printStackTrace();
                return bundle;
            } catch (IOException e2) {
                e = e2;
                bundle = bundle2;
                e.printStackTrace();
                return bundle;
            }
        } catch (FileNotFoundException e3) {
            e = e3;
        } catch (IOException e4) {
            e = e4;
        }
    }

    public static String a(String str, Context context, String str2) {
        String l = GameUtil.getIntance().l(context, context.getPackageName());
        Log.d("FileUtil", "getSslocalDir nativeLibraryDir3: " + l);
        if (TextUtils.isEmpty(l)) {
            return null;
        }
        String str3 = com.excelliance.kxqp.gs.ui.home.b.a(context).d() ? "arm64-v8a" : "armeabi";
        Log.d("FileUtil", "cpuType: " + str3);
        Pattern compile = Pattern.compile("^lib/" + str3 + ".{0,}so$");
        try {
            ZipFile zipFile = new ZipFile(l);
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry nextElement = entries.nextElement();
                String name = nextElement.getName();
                if (name.endsWith(str)) {
                    az.d("FileUtil", "getSslocalDir: " + name);
                    if (compile.matcher(name).find()) {
                        Log.d("FileUtil", "found: " + name);
                        a(zipFile.getInputStream(nextElement), str2);
                        return str2;
                    }
                }
            }
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static File a(File file, Pattern pattern) {
        File[] listFiles = file.listFiles();
        File file2 = null;
        if (listFiles != null && listFiles.length > 0) {
            for (File file3 : listFiles) {
                if (file3.isFile() && pattern.matcher(file3.getName()).find() && 0 < file3.lastModified()) {
                    Log.d("FileUtil", "lastModifiedObbFile: " + file3);
                    file2 = file3;
                }
            }
        }
        return file2;
    }

    @TargetApi(21)
    public static JSONArray a(File file, String str) {
        File[] listFiles;
        JSONArray jSONArray = new JSONArray();
        String absolutePath = file.getAbsolutePath();
        if (file.exists()) {
            JSONObject jSONObject = new JSONObject();
            try {
                int i = Os.stat(absolutePath).st_mode & 4095;
                jSONObject.put("file", absolutePath.replace(str, ""));
                jSONObject.put("mode", String.format("%o", Integer.valueOf(i)));
                jSONArray.put(jSONObject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (file.isDirectory() && (listFiles = file.listFiles()) != null) {
            for (File file2 : listFiles) {
                JSONArray a2 = a(file2, str);
                for (int i2 = 0; i2 < a2.length(); i2++) {
                    jSONArray.put(a2.optJSONObject(i2));
                }
            }
        }
        return jSONArray;
    }

    @TargetApi(21)
    public static void a(File file, JSONArray jSONArray) {
        if (jSONArray != null) {
            int length = jSONArray.length();
            for (int i = 0; i < length; i++) {
                JSONObject optJSONObject = jSONArray.optJSONObject(i);
                String str = file.getAbsolutePath() + File.separator + optJSONObject.optString("file");
                try {
                    Os.chmod(str, Integer.parseInt(optJSONObject.optString("mode"), 8));
                    az.d("FileUtil", "chomd " + str);
                } catch (Exception unused) {
                    Log.e("FileUtil", "chmod: error " + str + "\t" + optJSONObject.optString("mode"));
                }
            }
        }
    }

    public static JSONArray b(File file) {
        return a(file, file.getAbsolutePath());
    }

    public static boolean c(Context context, String str) {
        if (TextUtils.isEmpty(str) || !new File(str).exists()) {
            return false;
        }
        PackageInfo a2 = as.a(context, str);
        Log.d("FileUtil", "checkApkFile: " + a2);
        return a2 != null;
    }

    public static void b(File file, String str) {
        FileOutputStream fileOutputStream;
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str.trim())) {
            return;
        }
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream fileOutputStream2 = null;
        try {
            try {
                try {
                    fileOutputStream = new FileOutputStream(file);
                } catch (Throwable th) {
                    th = th;
                }
            } catch (FileNotFoundException e) {
                e = e;
            } catch (IOException e2) {
                e = e2;
            }
        } catch (IOException e3) {
            e3.printStackTrace();
        }
        try {
            fileOutputStream.write(str.trim().getBytes());
            fileOutputStream.close();
        } catch (FileNotFoundException e4) {
            e = e4;
            fileOutputStream2 = fileOutputStream;
            e.printStackTrace();
            if (fileOutputStream2 != null) {
                fileOutputStream2.close();
            }
        } catch (IOException e5) {
            e = e5;
            fileOutputStream2 = fileOutputStream;
            e.printStackTrace();
            if (fileOutputStream2 != null) {
                fileOutputStream2.close();
            }
        } catch (Throwable th2) {
            th = th2;
            fileOutputStream2 = fileOutputStream;
            if (fileOutputStream2 != null) {
                try {
                    fileOutputStream2.close();
                } catch (IOException e6) {
                    e6.printStackTrace();
                }
            }
            throw th;
        }
    }

    public static File a(Context context) {
        try {
            return a(context, String.format("%s.jpg", new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date())), true);
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public static File a(Context context, String str, boolean z) throws IOException {
        String str2 = context.getExternalCacheDir() + File.separator + "image";
        if (TextUtils.isEmpty(str2)) {
            return null;
        }
        File file = new File(str2);
        if (!file.exists()) {
            file.mkdirs();
        }
        File file2 = new File(str2, str);
        if (!file2.exists()) {
            file2.createNewFile();
        } else if (z) {
            file2.delete();
            file2.createNewFile();
        }
        return file2;
    }

    public static Uri b(Context context, File file) {
        if (Build.VERSION.SDK_INT >= 24) {
            return FileProvider.getUriForFile(context, context.getPackageName() + ".fileProvider", file);
        }
        return Uri.fromFile(file);
    }
}