use of com.taobao.atlas.update.util.PatchMerger in project atlas by alibaba.
the class Updater method update.
public static void update(final Context context) {
File updateInfo = new File(context.getExternalCacheDir(), "update.json");
if (!updateInfo.exists()) {
Log.e("update", "更新信息不存在,请先 执行 buildTpatch.sh");
toast("更新信息不存在,请先 执行 buildTpatch.sh", context);
return;
}
String jsonStr = new String(FileUtils.readFile(updateInfo));
UpdateInfo info = JSON.parseObject(jsonStr, UpdateInfo.class);
File patchFile = new File(context.getExternalCacheDir(), "patch-" + info.updateVersion + "@" + info.baseVersion + ".tpatch");
try {
// AtlasUpdater.update(info, patchFile);
PatchMerger patchMerger = new PatchMerger(info, patchFile, new MergeCallback() {
@Override
public void onMergeResult(boolean result, String bundleName) {
if (result) {
toast(bundleName + "merge success!", context);
} else {
toast(bundleName + "merge failed!", context);
}
}
});
try {
patchMerger.merge();
} catch (IOException e) {
e.printStackTrace();
}
Log.e("mergeOutputs:", String.valueOf(patchMerger.mergeOutputs.size()));
PatchInstaller patchInstaller = new PatchInstaller(patchMerger.mergeOutputs, info);
patchInstaller.install();
Log.e("update", "update success");
toast("更新成功,请重启app", context);
} catch (Throwable e) {
e.printStackTrace();
toast("更新失败, " + e.getMessage(), context);
}
}
use of com.taobao.atlas.update.util.PatchMerger in project atlas by alibaba.
the class AtlasUpdater method update.
/**
* 更新主入口
* @param updateInfo 更新的基础信息
* @param patchFile tpatch包
* @throws MergeException
* @throws BundleException
*/
public static void update(UpdateInfo updateInfo, File patchFile) throws MergeException, BundleException {
MergeCallback mergeCallback = new MergeCallback() {
@Override
public void onMergeResult(boolean result, String bundleName) {
if (result) {
Log.d("[dexmerge]", "merge bundle " + bundleName + " success ");
} else {
Log.e("[dexmerge]", "merge bundle " + bundleName + " fail ");
}
}
};
PatchMerger patchMerger = new PatchMerger(updateInfo, patchFile, mergeCallback);
try {
patchMerger.merge();
} catch (IOException e) {
e.printStackTrace();
}
PatchInstaller patchInstaller = new PatchInstaller(patchMerger.mergeOutputs, updateInfo);
patchInstaller.install();
new PatchCleaner().clearUpdatePath(updateInfo.workDir.getAbsolutePath());
}
Aggregations