Search in sources :

Example 1 with VersionManager

use of com.benmu.framework.manager.impl.VersionManager in project WeexErosFramework by bmfe.

the class DefaultWXHttpAdapter method findMd5.

private String findMd5(String path) {
    List<Md5MapperModel.Item> lists = ManagerFactory.getManagerService(PersistentManager.class).getFileMapper();
    if (lists == null) {
        VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
        versionManager.initMapper(BMWXEnvironment.mApplicationContext);
        lists = ManagerFactory.getManagerService(PersistentManager.class).getFileMapper();
    }
    for (Md5MapperModel.Item item : lists) {
        if (path.endsWith(item.getPage())) {
            return item.getMd5();
        }
    }
    return "";
}
Also used : PersistentManager(com.benmu.framework.manager.impl.PersistentManager) Md5MapperModel(com.benmu.framework.model.Md5MapperModel) VersionManager(com.benmu.framework.manager.impl.VersionManager)

Example 2 with VersionManager

use of com.benmu.framework.manager.impl.VersionManager in project WeexErosFramework by bmfe.

the class VersionChecker method readyUpdate.

private void readyUpdate() {
    mUpdateUrl = BMWXEnvironment.mPlatformConfig.getUrl().getBundleUpdate();
    if (TextUtils.isEmpty(mUpdateUrl))
        return;
    if (Constant.INTERCEPTOR_ACTIVE.equals(SharePreferenceUtil.getInterceptorActive(mContext))) {
        mCurrentStatus = Constant.Version.UPDATING;
        VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
        versionManager.checkBundleUpdate(mContext, mUpdateUrl, true, new StringCallback() {

            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "获取更新失败");
                mCurrentStatus = Constant.Version.SLEEP;
            }

            @Override
            public void onResponse(String response, int id) {
                VersionBean version = ManagerFactory.getManagerService(ParseManager.class).parseObject(response, VersionBean.class);
                if (version == null) {
                    Log.e(TAG, "返回结果异常");
                    mCurrentStatus = Constant.Version.SLEEP;
                    return;
                }
                switch(version.resCode) {
                    case // 需要更新
                    0:
                        if (!TextUtils.isEmpty(version.data.path)) {
                            if (version.data.diff) {
                                // 更新插分包
                                Log.e(TAG, "检查插分包");
                                download(version, false);
                            } else {
                                // 下载全量包
                                Log.e(TAG, "检查全量包");
                                downloadCompleteZip();
                            }
                        } else {
                            // 下载全量包
                            Log.e(TAG, "检查全量包");
                            downloadCompleteZip();
                        }
                        break;
                    case 401:
                        Log.e(TAG, "JS文件查询失败!");
                        mCurrentStatus = Constant.Version.SLEEP;
                        break;
                    case 4000:
                        Log.e(TAG, "当前版本已是最新!");
                        mCurrentStatus = Constant.Version.SLEEP;
                        break;
                    default:
                        Log.e(TAG, "resCode:" + version.resCode);
                        mCurrentStatus = Constant.Version.SLEEP;
                        break;
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) StringCallback(com.benmu.framework.http.okhttp.callback.StringCallback) VersionManager(com.benmu.framework.manager.impl.VersionManager) VersionBean(com.benmu.framework.model.VersionBean) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with VersionManager

use of com.benmu.framework.manager.impl.VersionManager in project WeexErosFramework by bmfe.

the class VersionChecker method download.

/**
 * 下载包
 */
public void download(final VersionBean version, final boolean complete) {
    try {
        if (version == null) {
            mCurrentStatus = Constant.Version.SLEEP;
            return;
        }
        VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
        versionManager.downloadBundle(version.data.path, new FileCallBack(FileManager.getTempBundleDir(mContext).getAbsolutePath(), version.data.diff ? FileManager.PATCH_NAME : FileManager.TEMP_BUNDLE_NAME) {

            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "下载插分包出错");
                if (!complete) {
                    downloadCompleteZip();
                } else {
                    mCurrentStatus = Constant.Version.SLEEP;
                }
            }

            @Override
            public void onResponse(File response, int id) {
                Log.e("version", "下载成功" + response.getAbsolutePath());
                if (version.data.diff) {
                    bsPatch();
                } else {
                    File download = new File(FileManager.getTempBundleDir(mContext), FileManager.TEMP_BUNDLE_NAME);
                    if (checkZipValidate(download)) {
                        RenameDeleteFile();
                        // 更改本地jsversion
                        SharePreferenceUtil.setDownLoadVersion(mContext, ManagerFactory.getManagerService(ParseManager.class).toJsonString(newVersion));
                        newVersion = null;
                        mCurrentStatus = Constant.Version.SLEEP;
                    } else {
                        L.e(TAG, "更新包md5校验失败,更新失败");
                        FileManager.deleteFile(new File(FileManager.getTempBundleDir(mContext), FileManager.TEMP_BUNDLE_NAME));
                        newVersion = null;
                        mCurrentStatus = Constant.Version.SLEEP;
                    }
                }
            }
        });
    } catch (Exception e) {
        mCurrentStatus = Constant.Version.SLEEP;
        e.printStackTrace();
    }
}
Also used : Call(okhttp3.Call) FileCallBack(com.benmu.framework.http.okhttp.callback.FileCallBack) VersionManager(com.benmu.framework.manager.impl.VersionManager) ParseManager(com.benmu.framework.manager.impl.ParseManager) File(java.io.File) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with VersionManager

use of com.benmu.framework.manager.impl.VersionManager in project WeexErosFramework by bmfe.

the class VersionChecker method downloadCompleteZip.

/**
 * 下载全量包
 */
private void downloadCompleteZip() {
    VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
    versionManager.checkBundleUpdate(mContext, mUpdateUrl, false, new StringCallback() {

        @Override
        public void onError(Call call, Exception e, int id) {
            L.e(TAG, "检查全量包失败!,更新失败");
        }

        @Override
        public void onResponse(String response, int id) {
            VersionBean version = ManagerFactory.getManagerService(ParseManager.class).parseObject(response, VersionBean.class);
            if (version != null && !TextUtils.isEmpty(version.data.path)) {
                L.e(TAG, "检查全量包成功!,开始下载");
                download(version, true);
            }
        }
    });
}
Also used : Call(okhttp3.Call) StringCallback(com.benmu.framework.http.okhttp.callback.StringCallback) VersionManager(com.benmu.framework.manager.impl.VersionManager) VersionBean(com.benmu.framework.model.VersionBean) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

VersionManager (com.benmu.framework.manager.impl.VersionManager)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Call (okhttp3.Call)3 StringCallback (com.benmu.framework.http.okhttp.callback.StringCallback)2 VersionBean (com.benmu.framework.model.VersionBean)2 FileCallBack (com.benmu.framework.http.okhttp.callback.FileCallBack)1 ParseManager (com.benmu.framework.manager.impl.ParseManager)1 PersistentManager (com.benmu.framework.manager.impl.PersistentManager)1 Md5MapperModel (com.benmu.framework.model.Md5MapperModel)1 File (java.io.File)1