fix updater

This commit is contained in:
arm64v8a 2021-11-15 23:53:37 +08:00
parent 1a384e7819
commit 87e5cb5211
2 changed files with 34 additions and 34 deletions

View File

@ -217,9 +217,8 @@ public class InternalUpdater {
AndroidUtilities.runOnUIThread(() -> {
progressDialog.setProgress(percent);
});
}, (success) -> {
}, () -> {
progressDialog.dismiss();
if (!success) return;
try {
if (NekomuraUtil.calcSHA1(f).equals(sha1)) {

View File

@ -32,13 +32,8 @@ object MiniCDNDrive {
fun callbackPercent(percent: Int);
}
interface CallbackFinished {
fun callbackFinished(success: Boolean);
}
fun Download(f: File, metaURL: String, callbackPercent: CallbackPercent, callbackFinished: CallbackFinished) {
fun Download(f: File, metaURL: String, callbackPercent: CallbackPercent, callbackFinished: Runnable) {
thread {
try {
var output = FileOutputStream(f, false)
val client = OkHttpClient();
@ -52,14 +47,24 @@ object MiniCDNDrive {
var counter = 0
for (block in meta.block) {
lateinit var data2: ByteArray
val try_max = 3
for (i in 0 until try_max) {
try {
val url = block.url.replace("http://", "https://")
val request2 = Request.Builder()
.url(url)
.build()
val response2 = client.newCall(request2).execute()
val data2 = readPhotoBytes(response2.body!!.bytes())
data2 = readPhotoBytes(response2.body!!.bytes())
} catch (e: Exception) {
if (i == try_max - 1) {
throw e
}
}
}
output.write(data2)
//TODO progress
@ -68,11 +73,7 @@ object MiniCDNDrive {
}
output.close()
callbackFinished.callbackFinished(true)
} catch (e: Exception) {
FileLog.e(e)
callbackFinished.callbackFinished(false)
}
callbackFinished.run()
}
}