From 69aed18b78aa0fe29d6e7ca9ddc28a695d1e67e8 Mon Sep 17 00:00:00 2001 From: sisong Date: Sun, 4 Apr 2021 12:17:57 +0800 Subject: [PATCH] add hpatch interface code --- android/jni/DownloadTask.c | 7 +++++++ .../cn_reactnative_modules_update_DownloadTask.h | 8 ++++++++ android/jni/hpatch.c | 13 +++++++++++++ android/jni/hpatch.h | 13 +++++++++++++ .../cn/reactnative/modules/update/DownloadTask.java | 3 ++- 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 android/jni/hpatch.c create mode 100644 android/jni/hpatch.h diff --git a/android/jni/DownloadTask.c b/android/jni/DownloadTask.c index 32491f8..4644da9 100644 --- a/android/jni/DownloadTask.c +++ b/android/jni/DownloadTask.c @@ -108,4 +108,11 @@ JNIEXPORT jbyteArray JNICALL Java_cn_reactnative_modules_update_DownloadTask_bsd (*env)->ReleaseByteArrayElements(env, origin, originPtr, JNI_ABORT); (*env)->ReleaseByteArrayElements(env, patch, patchPtr, JNI_ABORT); return ret; +} + + +JNIEXPORT jbyteArray JNICALL Java_cn_reactnative_modules_update_DownloadTask_hdiffPatch + (JNIEnv *env, jobject self, jbyteArray origin, jbyteArray patch){ + //todo: + return 0; } \ No newline at end of file diff --git a/android/jni/cn_reactnative_modules_update_DownloadTask.h b/android/jni/cn_reactnative_modules_update_DownloadTask.h index fc08c72..0da7e9e 100644 --- a/android/jni/cn_reactnative_modules_update_DownloadTask.h +++ b/android/jni/cn_reactnative_modules_update_DownloadTask.h @@ -15,6 +15,14 @@ extern "C" { JNIEXPORT jbyteArray JNICALL Java_cn_reactnative_modules_update_DownloadTask_bsdiffPatch (JNIEnv *, jclass, jbyteArray, jbyteArray); +/* + * Class: cn_reactnative_modules_update_DownloadTask + * Method: hdiffPatch + * Signature: ([B[B)[B + */ +JNIEXPORT jbyteArray JNICALL Java_cn_reactnative_modules_update_DownloadTask_hdiffPatch + (JNIEnv *, jclass, jbyteArray, jbyteArray); + #ifdef __cplusplus } #endif diff --git a/android/jni/hpatch.c b/android/jni/hpatch.c new file mode 100644 index 0000000..0e34c9c --- /dev/null +++ b/android/jni/hpatch.c @@ -0,0 +1,13 @@ +// hpatch.c +// Copyright 2021 housisong, All rights reserved + +int hpatch_by_mem(const uint8_t* old,size_t oldsize, uint8_t* newBuf,size_t newsize, + const uint8_t* pat,size_t patsize){ + //todo: + return -1; +} + +int hpatch_by_file(const char* oldfile, const char* newfile, const char* patchfile){ + //todo: + return -1; +} \ No newline at end of file diff --git a/android/jni/hpatch.h b/android/jni/hpatch.h new file mode 100644 index 0000000..377cb23 --- /dev/null +++ b/android/jni/hpatch.h @@ -0,0 +1,13 @@ +// hpatch.h +// import HDiffPatch, support patchfile created by "hdiffz -SD -C-lzma2 oldfile newfile patchfile" +// Copyright 2021 housisong, All rights reserved + +#ifndef HDIFFPATCH_PATCH_H +#define HDIFFPATCH_PATCH_H +# include //for uint8_t + +int hpatch_by_mem(const uint8_t* old,size_t oldsize, uint8_t* newBuf,size_t newsize, + const uint8_t* pat,size_t patsize); +int hpatch_by_file(const char* oldfile, const char* newfile, const char* patchfile); + +#endif //HDIFFPATCH_PATCH_H \ No newline at end of file diff --git a/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java b/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java index 9307884..12a049b 100644 --- a/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +++ b/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java @@ -134,9 +134,10 @@ class DownloadTask extends AsyncTask { } - byte[] buffer = new byte[1024]; + 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 { int count;