翰林优商.apk(点击下载) / FileStorage.java


package com.nirvana.tools.logger.storage;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import com.kuaishou.weapon.p0.h;
import com.nirvana.tools.core.SupportJarUtils;
import java.io.File;
import java.io.IOException;

/* access modifiers changed from: package-private */
public class FileStorage {
    private static final String BASE_DIR = ".pns";
    public static final String DIR_UNIQUE_ID = ".uniqueId";
    private Context mContext;

    public FileStorage(Context context) {
        this.mContext = context;
    }

    private boolean isBaseDirExist() {
        if (SupportJarUtils.checkSelfPermission(this.mContext, h.i) == -1 || !Environment.getExternalStorageState().equals("mounted")) {
            return false;
        }
        File file = new File(Environment.getExternalStorageDirectory(), BASE_DIR);
        return file.isDirectory() && file.exists();
    }

    private boolean newBaseDir() {
        if (SupportJarUtils.checkSelfPermission(this.mContext, h.j) != -1 && Environment.getExternalStorageState().equals("mounted")) {
            return new File(Environment.getExternalStorageDirectory(), BASE_DIR).mkdirs();
        }
        return false;
    }

    public boolean createNewFile(String str, String str2, boolean z) {
        boolean isEmpty = TextUtils.isEmpty(str);
        String str3 = BASE_DIR;
        if (!isEmpty) {
            str3 = str3 + File.separator + str;
        }
        if (SupportJarUtils.checkSelfPermission(this.mContext, h.j) == -1) {
            return false;
        }
        File file = new File(Environment.getExternalStorageDirectory(), str3);
        if (!file.exists() && !file.mkdirs()) {
            return false;
        }
        File file2 = new File(file, str2);
        if (file2.exists()) {
            return true;
        }
        if (!z) {
            return file2.createNewFile();
        }
        try {
            return file2.mkdirs();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }

    public String firstFileName(String str) {
        String[] list;
        if (TextUtils.isEmpty(str) || !isBaseDirExist()) {
            return null;
        }
        File file = new File(new File(Environment.getExternalStorageDirectory(), BASE_DIR), str);
        if (!file.exists() || !file.isDirectory() || (list = file.list()) == null || list.length <= 0) {
            return null;
        }
        return list[0];
    }

    public boolean isFileExist(String str) {
        if (!TextUtils.isEmpty(str) && isBaseDirExist()) {
            return new File(new File(Environment.getExternalStorageDirectory(), BASE_DIR), str).exists();
        }
        return false;
    }
}