1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-08 02:15:13 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Remove bsdiff in android

This commit is contained in:
sunnylqm
2021-04-13 16:53:32 +08:00
parent 6f5d12594b
commit 8e60956af0
24 changed files with 23 additions and 5599 deletions

View File

@@ -136,7 +136,6 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
byte[] buffer = new byte[1024*4];
private static native byte[] bsdiffPatch(byte[] origin, byte[] patch);
private static native byte[] hdiffPatch(byte[] origin, byte[] patch);
private void unzipToFile(ZipInputStream zis, File fmd) throws IOException {
@@ -301,7 +300,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
}
}
private void doPatchFromApk(DownloadTaskParams param,int apkPatchType) throws IOException, JSONException {
private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONException {
downloadFile(param);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(param.targetFile)));
@@ -350,11 +349,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
if (fn.equals("index.bundlejs.patch")) {
foundBundlePatch = true;
byte[] patched;
if (DownloadTaskParams.isHPatchType(apkPatchType)) // hpatch
patched = hdiffPatch(readOriginBundle(), readBytes(zis));
else // do bsdiff patch
patched = bsdiffPatch(readOriginBundle(), readBytes(zis));
byte[] patched = hdiffPatch(readOriginBundle(), readBytes(zis));
FileOutputStream fout = new FileOutputStream(new File(param.unzipDirectory, "index.bundlejs"));
fout.write(patched);
@@ -391,7 +386,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
}
private void doPatchFromPpk(DownloadTaskParams param,int ppkPatchType) throws IOException, JSONException {
private void doPatchFromPpk(DownloadTaskParams param) throws IOException, JSONException {
downloadFile(param);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(param.targetFile)));
@@ -431,12 +426,8 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
}
if (fn.equals("index.bundlejs.patch")) {
foundBundlePatch = true;
byte[] patched;
if (DownloadTaskParams.isHPatchType(ppkPatchType)) // hpatch
patched = hdiffPatch(readFile(new File(param.originDirectory, "index.bundlejs")), readBytes(zis));
else // do bsdiff patch
patched = bsdiffPatch(readFile(new File(param.originDirectory, "index.bundlejs")), readBytes(zis));
byte[] patched = hdiffPatch(readFile(new File(param.originDirectory, "index.bundlejs")), readBytes(zis));
FileOutputStream fout = new FileOutputStream(new File(param.unzipDirectory, "index.bundlejs"));
fout.write(patched);
fout.close();
@@ -497,12 +488,10 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
doFullPatch(params[0]);
break;
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK:
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_APK:
doPatchFromApk(params[0],taskType);
doPatchFromApk(params[0]);
break;
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK:
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_PPK:
doPatchFromPpk(params[0],taskType);
doPatchFromPpk(params[0]);
break;
case DownloadTaskParams.TASK_TYPE_CLEANUP:
doCleanUp(params[0]);
@@ -524,8 +513,6 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
case DownloadTaskParams.TASK_TYPE_PATCH_FULL:
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK:
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK:
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_APK:
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_PPK:
try {
removeDirectory(params[0].unzipDirectory);
} catch (IOException ioException) {

View File

@@ -15,12 +15,6 @@ class DownloadTaskParams {
static final int TASK_TYPE_PATCH_FROM_PPK = 3;
static final int TASK_TYPE_PLAIN_DOWNLOAD = 4;
static final int TASK_TYPE_HPATCH_FROM_APK = 5;
static final int TASK_TYPE_HPATCH_FROM_PPK = 6;
static boolean isHPatchType(int patchType){
return (patchType==TASK_TYPE_HPATCH_FROM_APK)||(patchType==TASK_TYPE_HPATCH_FROM_PPK);
}
int type;
String url;

View File

@@ -90,30 +90,13 @@ public class UpdateContext {
void onDownloadFailed(Throwable error);
}
private String zipExtension(int patchType){
switch (patchType) {
case DownloadTaskParams.TASK_TYPE_PATCH_FULL:
return ".ppk";
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK:
return ".apk.patch";
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK:
return ".ppk.patch";
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_APK:
return ".apk.hpatch";
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_PPK:
return ".ppk.hpatch";
default:
return "";//unknown type
}
}
public void downloadFullUpdate(String url, String hash, DownloadFileListener listener) {
DownloadTaskParams params = new DownloadTaskParams();
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FULL;
params.url = url;
params.hash = hash;
params.listener = listener;
params.targetFile = new File(rootDir, hash + zipExtension(params.type));
params.targetFile = new File(rootDir, hash + ".ppk");
params.unzipDirectory = new File(rootDir, hash);
new DownloadTask(context).executeOnExecutor(this.executor, params);
}
@@ -129,25 +112,25 @@ public class UpdateContext {
new DownloadTask(context).executeOnExecutor(this.executor, params);
}
public void downloadPatchFromApk(String url, String hash,int apkPatchType,DownloadFileListener listener) {
public void downloadPatchFromApk(String url, String hash, DownloadFileListener listener) {
DownloadTaskParams params = new DownloadTaskParams();
params.type = apkPatchType;
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK;
params.url = url;
params.hash = hash;
params.listener = listener;
params.targetFile = new File(rootDir, hash + zipExtension(params.type));
params.targetFile = new File(rootDir, hash + ".apk.patch");
params.unzipDirectory = new File(rootDir, hash);
new DownloadTask(context).executeOnExecutor(this.executor, params);
}
public void downloadPatchFromPpk(String url,String hash,String originHash,int ppkPatchType,DownloadFileListener listener) {
public void downloadPatchFromPpk(String url, String hash, String originHash, DownloadFileListener listener) {
DownloadTaskParams params = new DownloadTaskParams();
params.type = ppkPatchType;
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
params.url = url;
params.hash = hash;
params.originHash = originHash;
params.listener = listener;
params.targetFile = new File(rootDir, originHash + "-" + hash + zipExtension(params.type));
params.targetFile = new File(rootDir, originHash + "-" + hash + ".ppk.patch");
params.unzipDirectory = new File(rootDir, hash);
params.originDirectory = new File(rootDir, originHash);
new DownloadTask(context).executeOnExecutor(this.executor, params);

View File

@@ -135,13 +135,14 @@ public class UpdateModule extends ReactContextBaseJavaModule {
}
}
private void _downloadPatchFromPackage(ReadableMap options, final Promise promise,int apkPatchType) {
@ReactMethod
private void downloadPatchFromPackage(ReadableMap options, final Promise promise) {
String url = options.getString("updateUrl");
String hash = options.getString("hash");
if (hash == null) {
hash = options.getString("hashName");
}
updateContext.downloadPatchFromApk(url,hash,apkPatchType,new UpdateContext.DownloadFileListener() {
updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() {
@Override
public void onDownloadCompleted(DownloadTaskParams params) {
promise.resolve(null);
@@ -153,8 +154,9 @@ public class UpdateModule extends ReactContextBaseJavaModule {
}
});
}
private void _downloadPatchFromPpk(ReadableMap options, final Promise promise,int ppkPatchType) {
@ReactMethod
private void downloadPatchFromPpk(ReadableMap options, final Promise promise) {
String url = options.getString("updateUrl");
String hash = options.getString("hash");
if (hash == null) {
@@ -164,7 +166,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
if (originHash == null) {
originHash = options.getString(("originHashName"));
}
updateContext.downloadPatchFromPpk(url,hash,originHash,ppkPatchType,new UpdateContext.DownloadFileListener() {
updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() {
@Override
public void onDownloadCompleted(DownloadTaskParams params) {
promise.resolve(null);
@@ -177,26 +179,6 @@ public class UpdateModule extends ReactContextBaseJavaModule {
});
}
@ReactMethod
public void downloadPatchFromPackage(ReadableMap options, final Promise promise) {
_downloadPatchFromPackage(options,promise,DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK);
}
@ReactMethod
public void downloadHPatchFromPackage(ReadableMap options, final Promise promise) {
_downloadPatchFromPackage(options,promise,DownloadTaskParams.TASK_TYPE_HPATCH_FROM_APK);
}
@ReactMethod
public void downloadPatchFromPpk(ReadableMap options, final Promise promise) {
_downloadPatchFromPpk(options,promise,DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK);
}
@ReactMethod
public void downloadHPatchFromPpk(ReadableMap options, final Promise promise) {
_downloadPatchFromPpk(options,promise,DownloadTaskParams.TASK_TYPE_HPATCH_FROM_PPK);
}
@ReactMethod
public void reloadUpdate(ReadableMap options) {
final String hash = options.getString("hash") == null ?