mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-07 17:25:13 +08:00
extend new patchType: *.apk.hpatch & *.ppk.hpatch
This commit is contained in:
@@ -301,7 +301,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
}
|
||||
}
|
||||
|
||||
private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONException {
|
||||
private void doPatchFromApk(DownloadTaskParams param,int apkPatchType) throws IOException, JSONException {
|
||||
downloadFile(param);
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(param.targetFile)));
|
||||
@@ -349,8 +349,12 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
}
|
||||
if (fn.equals("index.bundlejs.patch")) {
|
||||
foundBundlePatch = true;
|
||||
// do bsdiff patch
|
||||
byte[] patched = bsdiffPatch(readOriginBundle(), readBytes(zis));
|
||||
|
||||
byte[] patched;
|
||||
if (DownloadTaskParams.isHPatchType(apkPatchType)) // hpatch
|
||||
patched = hdiffPatch(readOriginBundle(), readBytes(zis));
|
||||
else // do bsdiff patch
|
||||
patched = bsdiffPatch(readOriginBundle(), readBytes(zis));
|
||||
|
||||
FileOutputStream fout = new FileOutputStream(new File(param.unzipDirectory, "index.bundlejs"));
|
||||
fout.write(patched);
|
||||
@@ -387,7 +391,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
|
||||
}
|
||||
|
||||
private void doPatchFromPpk(DownloadTaskParams param) throws IOException, JSONException {
|
||||
private void doPatchFromPpk(DownloadTaskParams param,int ppkPatchType) throws IOException, JSONException {
|
||||
downloadFile(param);
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(param.targetFile)));
|
||||
@@ -427,8 +431,11 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
}
|
||||
if (fn.equals("index.bundlejs.patch")) {
|
||||
foundBundlePatch = true;
|
||||
// do bsdiff patch
|
||||
byte[] patched = bsdiffPatch(readFile(new File(param.originDirectory, "index.bundlejs")), readBytes(zis));
|
||||
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));
|
||||
|
||||
FileOutputStream fout = new FileOutputStream(new File(param.unzipDirectory, "index.bundlejs"));
|
||||
fout.write(patched);
|
||||
@@ -490,10 +497,12 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
doFullPatch(params[0]);
|
||||
break;
|
||||
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK:
|
||||
doPatchFromApk(params[0]);
|
||||
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_APK:
|
||||
doPatchFromApk(params[0],type);
|
||||
break;
|
||||
case DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK:
|
||||
doPatchFromPpk(params[0]);
|
||||
case DownloadTaskParams.TASK_TYPE_HPATCH_FROM_PPK:
|
||||
doPatchFromPpk(params[0],type);
|
||||
break;
|
||||
case DownloadTaskParams.TASK_TYPE_CLEANUP:
|
||||
doCleanUp(params[0]);
|
||||
@@ -515,6 +524,8 @@ 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) {
|
||||
|
@@ -8,12 +8,19 @@ import java.io.File;
|
||||
* Created by tdzl2003 on 3/31/16.
|
||||
*/
|
||||
class DownloadTaskParams {
|
||||
static final int TASK_TYPE_PATCH_FULL = 1;
|
||||
static final int TASK_TYPE_CLEANUP = 0; //Keep hash & originHash
|
||||
|
||||
static final int TASK_TYPE_PATCH_FULL = 1;
|
||||
static final int TASK_TYPE_PATCH_FROM_APK = 2;
|
||||
static final int TASK_TYPE_PATCH_FROM_PPK = 3;
|
||||
static final int TASK_TYPE_PLAIN_DOWNLOAD = 4;
|
||||
|
||||
static final int TASK_TYPE_CLEANUP = 0; //Keep hash & originHash
|
||||
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;
|
||||
|
@@ -90,13 +90,30 @@ public class UpdateContext {
|
||||
void onDownloadFailed(Throwable error);
|
||||
}
|
||||
|
||||
private String zipExtension(int patchType){
|
||||
switch (patchType) {
|
||||
case TASK_TYPE_PATCH_FULL:
|
||||
return ".ppk";
|
||||
case TASK_TYPE_PATCH_FROM_APK:
|
||||
return ".apk.patch";
|
||||
case TASK_TYPE_PATCH_FROM_PPK:
|
||||
return ".ppk.patch";
|
||||
case TASK_TYPE_HPATCH_FROM_APK:
|
||||
return ".apk.hpatch";
|
||||
case 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 + ".ppk");
|
||||
params.targetFile = new File(rootDir, hash + zipExtension(params.type));
|
||||
params.unzipDirectory = new File(rootDir, hash);
|
||||
new DownloadTask(context).executeOnExecutor(this.executor, params);
|
||||
}
|
||||
@@ -112,25 +129,25 @@ public class UpdateContext {
|
||||
new DownloadTask(context).executeOnExecutor(this.executor, params);
|
||||
}
|
||||
|
||||
public void downloadPatchFromApk(String url, String hash, DownloadFileListener listener) {
|
||||
public void downloadPatchFromApk(String url, String hash,int apkPatchType,DownloadFileListener listener) {
|
||||
DownloadTaskParams params = new DownloadTaskParams();
|
||||
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_APK;
|
||||
params.type = apkPatchType;
|
||||
params.url = url;
|
||||
params.hash = hash;
|
||||
params.listener = listener;
|
||||
params.targetFile = new File(rootDir, hash + ".apk.patch");
|
||||
params.targetFile = new File(rootDir, hash + zipExtension(params.type));
|
||||
params.unzipDirectory = new File(rootDir, hash);
|
||||
new DownloadTask(context).executeOnExecutor(this.executor, params);
|
||||
}
|
||||
|
||||
public void downloadPatchFromPpk(String url, String hash, String originHash, DownloadFileListener listener) {
|
||||
public void downloadPatchFromPpk(String url,String hash,String originHash,int ppkPatchType,DownloadFileListener listener) {
|
||||
DownloadTaskParams params = new DownloadTaskParams();
|
||||
params.type = DownloadTaskParams.TASK_TYPE_PATCH_FROM_PPK;
|
||||
params.type = ppkPatchType;
|
||||
params.url = url;
|
||||
params.hash = hash;
|
||||
params.originHash = originHash;
|
||||
params.listener = listener;
|
||||
params.targetFile = new File(rootDir, originHash + "-" + hash + ".ppk.patch");
|
||||
params.targetFile = new File(rootDir, originHash + "-" + hash + zipExtension(params.type));
|
||||
params.unzipDirectory = new File(rootDir, hash);
|
||||
params.originDirectory = new File(rootDir, originHash);
|
||||
new DownloadTask(context).executeOnExecutor(this.executor, params);
|
||||
|
@@ -135,15 +135,36 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ReactMethod
|
||||
public void downloadPatchFromPackage(ReadableMap options, final Promise promise) {
|
||||
private void _downloadPatchFromPackage(ReadableMap options, final Promise promise,int apkPatchType) {
|
||||
String url = options.getString("updateUrl");
|
||||
String hash = options.getString("hash");
|
||||
if (hash == null) {
|
||||
hash = options.getString("hashName");
|
||||
}
|
||||
updateContext.downloadPatchFromApk(url, hash, new UpdateContext.DownloadFileListener() {
|
||||
updateContext.downloadPatchFromApk(url,hash,apkPatchType,new UpdateContext.DownloadFileListener() {
|
||||
@Override
|
||||
public void onDownloadCompleted(DownloadTaskParams params) {
|
||||
promise.resolve(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadFailed(Throwable error) {
|
||||
promise.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void _downloadPatchFromPpk(ReadableMap options, final Promise promise,int ppkPatchType) {
|
||||
String url = options.getString("updateUrl");
|
||||
String hash = options.getString("hash");
|
||||
if (hash == null) {
|
||||
hash = options.getString("hashName");
|
||||
}
|
||||
String originHash = options.getString("originHash");
|
||||
if (originHash == null) {
|
||||
originHash = options.getString(("originHashName"));
|
||||
}
|
||||
updateContext.downloadPatchFromPpk(url,hash,originHash,ppkPatchType,new UpdateContext.DownloadFileListener() {
|
||||
@Override
|
||||
public void onDownloadCompleted(DownloadTaskParams params) {
|
||||
promise.resolve(null);
|
||||
@@ -157,27 +178,23 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void downloadPatchFromPpk(ReadableMap options, final Promise promise) {
|
||||
String url = options.getString("updateUrl");
|
||||
String hash = options.getString("hash");
|
||||
if (hash == null) {
|
||||
hash = options.getString("hashName");
|
||||
}
|
||||
String originHash = options.getString("originHash");
|
||||
if (originHash == null) {
|
||||
originHash = options.getString(("originHashName"));
|
||||
}
|
||||
updateContext.downloadPatchFromPpk(url, hash, originHash, new UpdateContext.DownloadFileListener() {
|
||||
@Override
|
||||
public void onDownloadCompleted(DownloadTaskParams params) {
|
||||
promise.resolve(null);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadFailed(Throwable error) {
|
||||
promise.reject(error);
|
||||
}
|
||||
});
|
||||
@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
|
||||
|
Reference in New Issue
Block a user