Search in sources :

Example 1 with Md5MapperModel

use of com.benmu.framework.model.Md5MapperModel in project WeexErosFramework by bmfe.

the class VersionManager method initMapper.

public void initMapper(Context context) {
    File file = new File(FileManager.getBundleDir(context), "bundle/md5.json");
    if (file.exists()) {
        String json = FileManager.loadJs(file.getAbsolutePath());
        Md5MapperModel mapper = ManagerFactory.getManagerService(ParseManager.class).parseObject(json, Md5MapperModel.class);
        ManagerFactory.getManagerService(PersistentManager.class).setFileMapper(mapper.getFilesMd5());
    }
}
Also used : Md5MapperModel(com.benmu.framework.model.Md5MapperModel) File(java.io.File)

Example 2 with Md5MapperModel

use of com.benmu.framework.model.Md5MapperModel in project WeexErosFramework by bmfe.

the class VersionChecker method checkZipValidate.

/**
 * MD5 效验
 */
private boolean checkZipValidate(File file) {
    if (file.exists()) {
        byte[] json = FileManager.extractZip(file, "md5.json");
        try {
            Md5MapperModel mapper = ManagerFactory.getManagerService(ParseManager.class).parseObject(new String(json, "UTF-8"), Md5MapperModel.class);
            // 校验文件正确性
            List<Md5MapperModel.Item> lists = mapper.getFilesMd5();
            // 按照md5值从小到大排列
            Collections.sort(lists);
            // 所有md5想加得到总的md5
            String total = "";
            for (Md5MapperModel.Item item : lists) {
                total = total + item.getMd5();
            }
            String finalMd5 = Md5Util.getMd5code(total);
            // 比较md5是否正确
            newVersion = new JsVersionInfoBean(mapper.getJsVersion(), mapper.getAndroid(), mapper.getTimestamp());
            return mapper.getJsVersion().equals(finalMd5);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return false;
}
Also used : Md5MapperModel(com.benmu.framework.model.Md5MapperModel) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsVersionInfoBean(com.benmu.framework.model.JsVersionInfoBean) ParseManager(com.benmu.framework.manager.impl.ParseManager)

Aggregations

Md5MapperModel (com.benmu.framework.model.Md5MapperModel)2 ParseManager (com.benmu.framework.manager.impl.ParseManager)1 JsVersionInfoBean (com.benmu.framework.model.JsVersionInfoBean)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1