package com.ygtx.emcs.util;

import android.content.Context;
import android.os.Environment;

import java.io.File;

/**
 * 项目工具类
 */
public class ProjectUtils {

    /**
     * 根目录
     */
    public static File ROOT_DIRECTORY = Environment.getExternalStorageDirectory();

    /**
     * 下载目录
     */
    public static File CACHE_DIRECTORY = Environment.getDownloadCacheDirectory();

    /**
     * 项目路径
     */
    public static String PROJECT_PATH = ROOT_DIRECTORY.getAbsolutePath() + "/"+Constant.PROJECT_NAME+"/";

    /**
     * 缓存
     */
    public static final String CACHE = PROJECT_PATH + "CACHE/";

    /**
     * 图片
     */
    public static String IMG = PROJECT_PATH + "IMG/";

    /**
     * Log
     */
    public static final String LOG = PROJECT_PATH + "LOG/";

    /**
     * Apk下载路径
     */
    public static String APK = PROJECT_PATH + "APK/";

    /**
     * 创建文件
     *
     * @param s
     * @return If you create a file successfully returned to the current file, otherwise
     * Null
     */
    public static File createFile(String s) {
        return new File(s);
    }

    /**
     * 创建文件夹
     *
     * @param s
     * @return If you create a folder successfully returned to the current folder, otherwise
     * Null
     */
    public static File createFolder(String s) {
        File file = ProjectUtils.createFile(s);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    /**
     * 初始化
     *
     * @return If true is returned to the initial success, otherwise false
     */
    public static boolean init(Context context) {
        PROJECT_PATH = context.getExternalFilesDir(null) + "/"+Constant.PROJECT_NAME+"/";
        boolean result = false;
        result &= createFolder(PROJECT_PATH) != null;
//        result &= createFolder(CACHE) != null;
        result &= createFolder(IMG) != null;
//        result &= createFolder(LOG) != null;
        result &= createFolder(APK) != null;
        APK = PROJECT_PATH + "APK/";
        IMG = PROJECT_PATH + "IMG/";
        return result;
    }

    public static String getProjectURL(){
        return Constant.UPDATE_URL;
    }
}
