From 86e94da6a63c0cb27ca7daca6f9a53bd7d67c2f5 Mon Sep 17 00:00:00 2001 From: metacubex Date: Mon, 27 Feb 2023 18:36:12 +0800 Subject: [PATCH] fix: the error caused by too large value of subscription information --- .../main/java/com/github/kr328/clash/design/util/I18n.kt | 6 ++++++ .../com/github/kr328/clash/service/ProfileManager.kt | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt b/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt index 11076d615..96ac583ff 100644 --- a/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt +++ b/design/src/main/java/com/github/kr328/clash/design/util/I18n.kt @@ -56,6 +56,12 @@ fun Date.format( fun Long.toBytesString(): String { return when { + this > 1024.0 * 1024 * 1024 * 1024 * 1024 * 1024 -> + String.format("%.2f EiB", (this.toDouble() / 1024 / 1024 / 1024 / 1024 / 1024 / 1024)) + this > 1024.0 * 1024 * 1024 * 1024 * 1024 -> + String.format("%.2f PiB", (this.toDouble() / 1024 / 1024 / 1024 / 1024 / 1024)) + this > 1024.0 * 1024 * 1024 * 1024 -> + String.format("%.2f TiB", (this.toDouble() / 1024 / 1024 / 1024 / 1024)) this > 1024 * 1024 * 1024 -> String.format("%.2f GiB", (this.toDouble() / 1024 / 1024 / 1024)) this > 1024 * 1024 -> diff --git a/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt b/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt index 4eace2f0c..d79ea6cd4 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.withContext import okhttp3.OkHttpClient import okhttp3.Request import java.io.FileNotFoundException +import java.math.BigDecimal import java.util.* class ProfileManager(private val context: Context) : IProfileManager, @@ -159,13 +160,13 @@ class ProfileManager(private val context: Context) : IProfileManager, val info = flag.split("=") when { info[0].contains("upload") -> upload = - info[1].toLong() + BigDecimal(info[1]).longValueExact() info[0].contains("download") -> download = - info[1].toLong() + BigDecimal(info[1]).longValueExact() - info[0].contains("total") -> total = - info[1].toLong() + info[0].contains("total") -> total = + BigDecimal(info[1]).longValueExact() info[0].contains("expire") -> { if (info[1].isNotEmpty()) {