Skip to content

Commit

Permalink
Merge pull request #2886 from MrMalekfar/master
Browse files Browse the repository at this point in the history
Addressing issue #2880
  • Loading branch information
2dust authored Mar 1, 2024
2 parents bf030e1 + 19cd24c commit 945c584
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import android.util.Log
import androidx.preference.PreferenceManager
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken
import com.tencent.mmkv.MMKV
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_CONFIG
Expand All @@ -22,6 +27,7 @@ import com.v2ray.ang.dto.V2rayConfig.Companion.TLS
import com.v2ray.ang.util.MmkvManager.KEY_SELECTED_SERVER
import java.net.URI
import java.util.*
import java.lang.reflect.Type
import com.v2ray.ang.extension.idnHost
import com.v2ray.ang.extension.removeWhiteSpace

Expand Down Expand Up @@ -987,9 +993,18 @@ object AngConfigManager {
&& server.contains("routing")
) {
try {
val gson = GsonBuilder().setPrettyPrinting().create()
//val gson = GsonBuilder().setPrettyPrinting().create()
val gson = GsonBuilder()
.setPrettyPrinting()
.disableHtmlEscaping()
.registerTypeAdapter( // custom serialiser is needed here since JSON by default parse number as Double, core will fail to start
object : TypeToken<Double>() {}.type,
JsonSerializer { src: Double?, _: Type?, _: JsonSerializationContext? -> JsonPrimitive(src?.toInt()) }
)
.create()
val serverList: Array<V2rayConfig> =
Gson().fromJson(server, Array<V2rayConfig>::class.java)
Gson().fromJson(server, Array<V2rayConfig>::class.java)

if (serverList.isNotEmpty()) {
var count = 0
for (srv in serverList) {
Expand All @@ -1016,7 +1031,7 @@ object AngConfigManager {
config.subscriptionId = subid
config.fullConfig = Gson().fromJson(server, V2rayConfig::class.java)
config.remarks = System.currentTimeMillis().toString()
// config.remarks = config.fullConfig?.remarks ?: System.currentTimeMillis().toString()
//config.remarks = config.fullConfig?.remarks ?: System.currentTimeMillis().toString()
val key = MmkvManager.encodeServerConfig("", config)
serverRawStorage?.encode(key, server)
return 1
Expand Down

0 comments on commit 945c584

Please sign in to comment.