WebVersionUtils.java 1.26 KB
package com.polysoft.nafmii.utils;

import com.whaty.nafmii.BuildConfig;

import java.io.File;

public class WebVersionUtils {

    public static String getVersion() {
        return SpUtils.getString(SpUtils.KEY_H5_VERSION, BuildConfig.H5_VERSION);
    }

    public static void setNewVersion(String version) {
        SpUtils.putString(SpUtils.KEY_H5_VERSION, version);
    }

    public static void deleteOldDist() {
        String version = getVersion();
        File hotDir = FileUtils.getHotDir();
        File[] files = hotDir.listFiles();
        for (File file : files) {
            if (!version.equals(file.getName())) {
                FileUtils.deletes(file);
            }
        }
    }

    public static File getIndex() {
        return new File(getDistDir(), "index.html");
    }

    public static File getDistDir() {
        return getDistDir(getVersion());
    }

    public static File getDistDir(String version) {
        File verisonDir = new File(FileUtils.getHotDir(), version);
        File dist = new File(verisonDir, "dist");
        if (!dist.exists()) {
            dist.mkdirs();
        }
        return dist;
    }

    public static File getDistZip(String version) {
        return new File(getDistDir(version).getParentFile(), "dist.zip");
    }

}